| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |
|
What's up with all the {} embedded in there? Please tell me that's Alex's new way of showing a snippet...
|
|
Oh well, at least it was caught!
|
|
Now, all thats left to do is take this coders face, push it into the monitor showing his code, and say "NO. BAD.". It's either that, or electric collars...
|
|
I especially love this part:
" // this is required, or it will not work for some reason " |
Best comment in the whole WTF. Good thing he didn't try to read any documentation, or he might've stumbled upon sprintf. |
|
Finally! Comments that aid in understanding the code! // this is required, or it will not work for some reason And, oh yeah, "FIRST!" |
|
Well, it was first when I started posting.... |
// this is required, or it will not work for some reason |
|
Seriously. I've never seen "{}" used like this anywhere before. Is it supposed to be a seperator or something? What's wrong with "// *******" or the like? Someone had to teach him that...
|
|
Alex, may I ask wether you sprinkled all the spelling mistakes in this stuff of if they're genuine on top of the programmatic WTF? |
|
How does one know about vfprintf but not sprintf? Like knowing
foreach() and not for() or XPath but not getElementById() or unsigned int but not int..... |
|
Clearly this is a new form of 'C', what with the inline function declarations:
*(char*)*va_arg( marker, char * ); the empty blocks {} (obviously a special command to their proprietary compiler) and the lack of a string formatting function. |
|
Please kill this "programmer". There is nothing more to say.
|
|
Wow! So this guy never heard of pipes? Assuming the code doesn't need to be thread safe, he could have done one mkfifo() call, and use dit over and over.
|
Am I the only one noticing that double bignumberjustincase = ftell( FILE11 ); Or what? BIG NUMBER JUST IN CASE? That is casted to short later on? WTF?! :D |
That's why you should avoid screaming "FIRST" when you post... it only makes people look more idiotic by trying to proudly let everyone know they got the first post when they are the 10th reply. ;) Of course, anyone who feels special and proud because they have the first post is idiotic enough. This isn't slashdumb... er... slashdot after all. ;) |
*(char*)*va_arg( marker, char * ); |
I really like this comment: |
|
This look like an awful workaround that I don't want to try and
understand to the fact that he apparently couldn't understand the docs for stdargs. I actually think he read the msdn docs, because their samples use the same names for the variables: first and marker. Here is a snippet from the beginning of an example: int average( int first, ... ) { int count = 0, sum = 0, i = first; va_list marker; va_start( marker, first ); /* Initialize variable arguments. */ |
|
temporary_file_name and temporary_file_name_name..................classic |
|
(...second attempt, posting with this forum software is less enjoyable that eating broken glass)
This look like an awful workaround that I don't want to try and understand to the fact that he apparently couldn't understand the docs for stdargs. I actually think he read the msdn docs, because their samples use the same names for the variables: first and marker. Here is a snippet from the beginning of an example: int average( int first, ... ) { int count = 0, sum = 0, i = first; va_list marker; va_start( marker, first ); /* Initialize variable arguments. */ (snip) So he apparently didn't get that the second argumment to va_start is the last argument before the ellipsis, regardless of its type. It's amazing that he found about vfprintf, which is rarely used, and entirely miss sprintf. Other WTF: The usage of read with a FILE* which require using _fileno, instead of just using fread which takes a FILE* directly. The usage of the antiquated and dangerous C formatting functions and file API instead of C?? iostream/stringstream |
|
What i find incredible is that he knows/found out how to use va_list but doesnt know / bother to look up spintf / snprintf ( snprinf may be usefull if the input length isnt limited ).
Also he asumes that he was the first to think of it and thus has to impletement it himself. // 2 is to the end ... it took some experamenting I guess SEEK_END must be equal to 2 on this machine .// -1 is so we go back and dont get the blank after it fseek( FILE11, -1, 2 ); strcpy( temporary_file_name, "thefileXXXX" ); Gee that is descritive. Maybe 'theStudpidFileXXXXXX' would be better.double bignumberjustincase = ftell( FILE11 ); Using a floating point to store a filelength ...... The varible naming is .... well ick. read( _fileno( FILE111 ), string_write_to, (short)bignumberjustincase ); And then cast it to a short |
Yay for cargo cult programming! |
|
Not to defend the code, or the technique but I always like finding a bright side of things...
I'd like to point out that the general technique has one advantage that sprintf does not: you can allocate exactly the amount of memory that you need to hold an arbitrarily formatted string. sprintf(buf, "%f", f); // How many bytes for buf? |
snprintf. int snprintf(char *str, size_t size, const char *format, ...); |
|
I particularly liked his filehandle naming convention:
FILE1 FILE11 FILE111 |
|
@If(@current_floor() > 4; @shove_out_window();
@wall_composed_of(BRICK) || @wall_composed_of(CONCRETE); @bash_head_in(); @promote_to_management()) |
|
Since he declares variables in between statements, this is C++.
So he could have done: stringstream sstr; sstr << "blabla " << somevariable << someotherone etc. The destination buffer is dynamically allocated so you can't overflow, it is disposed of automatically as soon as you leave the scope where sstr is defined, and you can't have mismatches as you can with C formatting functions between formatting characters and the actual datatype. |
comments like this help me get through my day. Keep up the good sarcasm!!! |
C does something pretty clever. Many popular languages put function parameters on the stack from left to right. C (and C++) reverse this calling convention, putting function parameters on the stack form right to left. In other words, when a function is called the stack contains, working from the bottom up, the return address, the last parameter, the second to last parameter, ..., the second parameter, and the first parameter. In this way, as long as the function can determine at runtime how many times to pop the stack, the function can have a variable number of parameters. One of the named parameters must indicate, in some way, how many other parameters there are. The call to va_start initializes a control structure that allows the stack to be popped. Then each call to va_args pops each subsequent value off the stack, the type of the value is given by the type parameter. (va_args here is not a function but a macro, that 'char *' parameter will get wrapped in a sizeof in order to pop the correct number of bytes.) va_end closes up all the processing. The problem is that va_start is normally initialized with the name of the last named parameter. In this case, it was called incorrectly, so the developer popped an extra pointer off the stack in order to get rid of the extra named parameter before getting the unnamed parameters. |
But then he'd be using shift operators on these things, a WTF in itself. Oh, operator overloading? That makes everything much more readable. :) |
|
Hooah for reinventing the wheel. And making it square instead of round, to boot.
|
No, the technique allocates at least an entire block of disk, generally only allocatable in quanta of 512 or some multiple of 512. (differs machine to machine). |
|
"temorary_file_name_name", "bignumberjustincase" and "FILE111"...
Classic. |
It's not the shift operator here, it quite obviously the streaming operator. Yeah, its definition of it as a streaming operator isn't hardcoded in the compiler like it's definition as the shifting operator for numeric datatypes, but this is a very specious argument.
I totally agree. vector = vector1 + vector2 * scale is barely understandable compared to something like vector = vector1.add( vector2.multiply( scale ) ). |
Uh... no. snprintf allows you to avoid overflowing your allocation, by telling the function how much you allocated, yes. What it does not do, that "Anonymous" was trying to suggest, is actually tell you how many bytes the sprintf operation will be creating. There's a difference between calculating the allocated size before allocating it, and allocating first, then detecting an overflow afterwards. |
|
Now, see, I would have implemented this one a little bit differently. If you're using bignumberjustincase, why not go for: largeintegerifweneedit humongousvaluecauseyouneverknow gargantuandoubletoprotectusfromunexpectedsitutationskindalikeyouknowright [H] |
|
I love how he opens the file with several different handles and only closes one of them (twice, to boot!) As mentioned, sprintf can be bad if you don't know what you're dealing with length-wise. I'd love to see him try to figure out snprintf, though (especially if the string ended without a NULL terminator!) |
So tell me, what does vector1 * vector2 evaluate to? |
|
I love his way of pragmatic programming.. you can tell he just KNOWS what the code is doing properly. After all, he probably fed all his 31337 values into it.. You made my day again, Alex. |
snprintf returns the number of characters that would have been written had the buffer been large enough. size_t sz = snprintf(NULL, 0, fmt, ...) + 1; char *s = malloc(sz); if (s) snprintf(s, sz, fmt, ...); Many platforms provide asprintf(), which does the above for you. |
|
I still don't understand how someone who knows how to use the variable argument list doesn't know about sprintf... This dude had to be on crack. That is the only logical explanation. There is just so much wrong with this code that it hurts me to look at it. To actually think that this person has/had a job is astounding. Are college professors passing people in programming courses just because they have to? Are they using grading curves? If no one in the class can code, then no one should pass. Grading coding and math clases on scales is what produces code like this. No good can come of it!
bignumberjustincase has got to be THE absolute WORST name for ANY variable EVER... EVER! |
It could have been in Hungarian notation. |
speaking of eating glass ...
2005-12-19 15:03
•
by
Anonymous Coward
|
|
http://www.geocities.com/nodotus/hbglass.html
|
Yeah, I saw it. It barely registered amidst the sea of wtf |
Hopefully the scalar product of vector1 and vector2 (so that * means · as with numbers). The cross product has to use some other symbol. |
I guess it depends whose snprintf you use. glibc 2.0, for instance, just returns -1 if the buffer isn't big enough. Sweet. The Microsoft snprintf documentation says it returns "a negative value" (can this be used as a random number generator?) |
A double; the dot product of the two vectors. We'll use "<<" for "multiply by the transpose," (we'll return an array), ">>" for "pairwise multiply" (we'll return a vector) then we'll drink a beer and laugh at the poor saps who'll be maintaining our code when we move on. |
|
Since everyone is so focused on other aspects of this post, here's a very minor WTF, but one that gets under my skin regardless: stopHere = stopHere + (bignumberjustincase); Could he really not know about the += operator? |
|
this is freaking painful to even look at...
|
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |