- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Bruce M. should have made an auto-generator for the retry_force_upload script. That way he could easily tune the number of forced uploads depending on the network load, weather conditions, etc.
<font face="Courier New" size="2">#!/bin/sh
# AUTOGEN (TM)
# A script to automatically generate a retry_upload_site script
# Usage: autogen [number]
# Version 10.0 (Final)
# Added support for numbers 901-1000
# snip................
# ................ snip
# Version 3.0
# Added support for numbers 201-300
# Version 2.0
# Added support for numbers 101-200
# Version 1.0
# Supports numbers 1-100
Number=$1
File="./retry_upload_site"
UploadScript="./upload-site"
echo "#!/bin/sh" > $File
echo "# This file is auto-generated by AUTOGEN 10.0 (TM)" >> $File
if [ $Number = 1 ]; then
echo "$UploadScript" >> $File
elif [ $Number = 2 ]; then
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
elif [ $Number = 3 ]; then
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
# snip................
# ................ snip
elif [ $Number = 1000 ]; then
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
# snip................
# ................ snip
echo "$UploadScript" >> $File
echo "$UploadScript" >> $File
else
echo "Unsupported number, contact your administrator"
fi
</font>
Admin
Didnt that get posted as a WTF here?
Admin
ROFL LOL ROFLMAO Hahahahahahahahahahaha! WTF?
Admin
while ./upload_script; do :; done
Admin
augh. (this is my reward for posting about shell scripts while waiting for visual studio to do its magic). retry:
while true; do ./upload_script || break; done
(tested this time)
Admin
Only if you can vertically align braces in your head over 30 lines. With tabs at 4 chars or less (don't get me started on tabs). I never look for {s. And since half-decent text editors will highlight ifs and fors, the opening { doesn't really matter.
Personally, it just wastes space and dissociates the block from the statement. And if it makes sense to go
if (a)
b;
then obviously with a block, it looks like
if (a)
{
b;
}
unless blocks don't automatically increase indent level, in which case gratituous blocks (i.e. to limit the scope of local variables) don't change the formatting at all.
For my third-year project I think I'll work on a text editor that automatically hilights missing }s for you.
I'm also a big fan of "always use a {", leading to my one-line "if (a) { b; }". Sometimes it makes sense, like for error handling in C. Or anything short. (missing }s are occasionally a pain).
captcha: stfu
Admin
IIRC GNU programs use this indention style.
Don't forget macros in C:
/* stupid but possible */
#define a(x) b(x);c(x)
int x() {
if (0==1) a(3);
}
executes c(3).
Admin
Well, that script should run slightly faster than emerge sync..
Admin
Hmm. Writing 'C' structure accessor macros for a weird, 24-bit hybrid 1MHz processor that goes into an implanted medical device? Although, in truth, our underlying architecture is so feeble that pretty much everything we write turns into pigs' ears, so you may not be off the mark. Can you say "global variable hell?" (I sure can!)
Honestly, though, I think that Emerson was prescient in this instance. I mean, the original description indicated that the author knew that the upload wouldn't work sometimes, so just reapplying the same, known-to-be-poor solution, sounds a pretty accurate implementation of Emerson's maxim.
---Jason
Admin
I apologize for that last post. Here's the context in which it was written.
Hmm. Writing 'C' structure accessor macros for a weird, 24-bit hybrid 1MHz processor that goes into an implanted medical device? Although, in truth, our underlying architecture is so feeble that pretty much everything we write turns into pigs' ears, so you may not be off the mark. Can you say "global variable hell?" (I sure can!)
Honestly, though, I think that Emerson was prescient in this instance. I mean, the original description indicated that the author knew that the upload wouldn't work sometimes, so just reapplying the same, known-to-be-poor solution, sounds a pretty accurate implementation of Emerson's maxim.
---Jason
Admin
Because vi is the only editor I know of that's virtually universally available on machines in the field. ssh, edit, fix, rerun, rinse and repeat is so much simpler if your code is written is such a way that you can easily edit in vi.
Admin
The % command shows matching brackets in vi, should be good enough to check if the first { matches the last }
Admin
You might have it universally available to you but you don't have a grasp of how to use it apparently. vi has the functionality that you claim it does not.
sincerely,
Richard Nixon
Admin
Like /* before the first line, and */ after the last one?
Admin
"TheDailyWTF.com - for when aleph-0 just isn't infinite enough"
Admin
As an Intel(tm) Core 2 Duo(r) Certified Developer, let me add this: All of the previously posted approaches make insufficient use of the new and exciting MultiMultiMultimedia(r)-ready Intel(tm) Core Duo(r) Dual Core Processing Capabilities(r).
Clearly, we need a solution that can make use of whatever Symmetric Multiprocessing Resources(r) it can find, a solution that scales right up to the largest supercomputers ever built in human history. A solution like this:
>script-b
echo ./upload_site >script-a
while true; do
cat script-a >>script-b
cat script-b >>script-a
./script-a &
done
Admin
<font face="Arial">Alternately:</font>
<font face="Courier New">
while : ; do
if ./upload_script ; then break; fi
done</font>
<font face="Arial">or even:</font>
<font face="Courier New">
while ./upload_script ; do : ; done
(The
:' command in Berkley compatible shells is a shell built-in equvalent to /bin/true . While most shells treat
true' as a synonym for : and don't exec() a new /bin/true process, it's best not to rely on it. Explicit /bin/true always exec()s a new process. Don't use it.)</font>