| « Prev | Page 1 | Page 2 | Next » |
|
I don't know what kind of self-respecting C programmer uses double-parentheses ((when single will do))
|
|
I think there's a secret message hidden in that code...
|
|
This is one of the times I actually said WTF out loud (well, the full phrase).
|
|
for (i=0,j=0;i
case '+': value[j] = ' '; buff[i] = ' '; break; case '%': You can't nest case statements in a for loop. |
|
hahahhhahaha!!!! BLIND! thanks for reminding me how much i hate C. last time i really hated it was when i had to convert a C funtion to vb.net, and there were no comments at all!!!!!! kill this language now!!!! move over to vb!!!!!!!! (btw if u could use copper wires it would probably make it much easier!!!) |
|
BTW well done bro, this is the funniest site i've ever seen, been coming home and checking my rss for the new WTF's! some ppl are soooo stupid! anyways, tnx for the free laughs!
|
There's a problem in the HTML. View source and you'll see that it's supposed to say: for (i=0,j=0;i<strlen(buff);i++,j++) etc |
|
oy! it gets worse:
for (i=0,j=0;i strlen is O(N) for the length of the buffer, effectively turning this into an O(N^2) algorithm. I'd say it's C written with a VB accent. |
|
Of course you can't, but I expect someone would know that '<' is the open tag for html elements so all text after that point until the next tag hasn't been displayed :) for(i=0,j=0;i<STRLEN(BUFF);I++,J++) switch |
|
begin(pedantry):
seems Alex got a little overexcited when posting.. and stated that this was an "ASCII to HEX function".. and unless I'm missing something it is indeed quite the opposite end Although I must say these things lose some of their impact when they repetitive bits are snipped out :) still a good laugh. And just to add some balance to all these silly comments about C being evil, or VB being evil for that matter: Get over it, on both/all sides. Languages for problems, any sufficiently stupid person can write utterly horrific code in any language. The worst cases in some languages are perhaps wors than those in others, just as the most elegent solution for a given problem in one language might be more elegent than the same in another. (or the most efficient, or short, or readable, etc) (Don't have an account, but I'm David) |
|
I hope he gets paid per line of code. Or wait. I don't. Oh nevermind.
|
|
WTF! A VB programmer coding in C! ;)
|
|
Yeah, this totally looks like a VB programmer trying to write in C.
|
|
I am disturbed by seeing ugly stuff like this in the beautiful C-language.
Maybe this kind of stuff should be censored when it's in C, and only shown when written in VB (or BASIC V2.0?), so you won't be responsible for making people like me depressed. I feel this WTF is intrusive, and i feel that my personal life and even my will to live has been compromised. It is unresposible to publish stuff like this on an open forum, and the poster clearly have not considered the consequenses it could have. To prevent any serious injury in the future (maybe some people will kill themself when seeing this), i'm planning to sue the owner of this website. |
|
ah, but when you use the correct compiler and the correct optimizer
flags and pray to the correct deity, this code actually compiles to the fastest, most optimized, least memory hungry binary. |
|
The full file isn't quite the full file. It's just the section that's
posted. Even though I'm sure I could reconstruct it, I want to see it for myself! Talk about your massively unrolled loop. |
|
Please now, let us not condem an entire programming language because some idiot doesn't know how to use it. Here is a more reasonable and concise "hard core" bit of 'C' code to ponder... If you're really "hard core", you'll probably recognize the following code snippet as Duff's Device. Otherwise, you'll probably not be able to figure out what it does, or how. register n = (count + 7) / 8; /* count > 0 assumed */ |
Haha. *sob* I would advise you to take a class in assembly language, to avoid becoming a WTF yourself in the future. ;p It used to be that with a well-written C program you could compile down to vector jumps with switch statements and judicious use of registers. To be honest I don't know how it would be done in these days of huge caches and long pipelines, but what I have seen is usually just extrapolations on the theme. Not... this. Eek. I take your point that a compiler could refactor this whole pile into one tiny, tight routine. Except that compiler doesn't exist, and if it did we'd all write shitty code because the compiler'd always clean it up for us. It will, a little, but this is whole levels of shitty beyond that. |
I have to agree with David (get an account!! [:)]). I have used both C (and C++ for that matter) and VB (and VB.Net too), and both have their charms. If I need something really quickly I will use VB.Net, as it's less likely to break with fast, unverified programming. I will also be trying some C# this year I think, just to see how that flows. Drak |
|
C# flows very nicely. I used to favour C++, but now i get the convenience of C# (which is about as convenient as VB.Net). When you need to do something more "traditional" (eg: some fun pointer arithmetic to piss off some auditors - modulus based ring buffers are easily hidden) you can use unchecked { ... } blocks for allowing overflow, and unsafe { ... } blocks for use of pointers and other "fun". Theres also some other classes and statements for dealing with pointers safely in normal code. unsafe/unchecked blocks require full security permission to execute (for obvious reasons). Also my C# tip of 2004: The sealed modifier is used to prevent inheritance of a class. What is undocumented is that sealed can also be used as a modifier to a function, preventing overrides of just that function. |
|
What's the point? It seems to me that the effect can be archieved in more readable and as fast/faster code.
|
|
wow, VB coder with a chip on his shoulder. [8-|]
|
UNRESPONSIBLE? What kind of word is that? Irresponsible please! That's the problem with you C-type programmers, lack of communication skills. A humble VB programmer with a penchant for [the English] language. |
|
hehe... vb and c, good for various things, but usually crap if you are trying to do the same thing.
i stick to C/C++, because I feel it looks a bit better on the resume and if the topic ever arised, I would rather impress an interviewer with knowledge of something OOD. but nowadays, the gap is being bridged, 'specially with VB.NET and C#... is there any difference? they are both compiled into MS IL anyways, just a difference coding preference but you would have to admit, C++ is slightly better than VB, although the difference is not great in many respects, but its often harder to learn to be a good C coder/ |
|
Would the following C++ crap be considered a more concise and ugly method? I'm hoping it works, and assuming in, out are char* and len is the length of in. I'm even nice and allocating the output buffer :D [code language="c#"] Notes: |
|
Spot the extra bloody colon. |
Don't forget that a lot of ppl that visit this site don't have English as their native language (i.e. me [:)]) Anyway - nice piece of code... Guy really should learn: I am really amazed that he already knows the "safe" strncpy function, although he still uses the normal strcpy sometimes... (and no - this is no defending of the code [:D]) For the ppl that say the compiler can optimize this -ERR- wrong [:)] strcmp is a function from some library, the C compiler doesn't know what it does, so it can't optimize string comparisons - it's not a language construct as in many other languages. This site should really organize a contest or smth - rewrite the pieces of code published here in the most optimal way in the same language... Would be fun too see the results... [:D] PS: The formatting in of these replies really sucks... Half-my-ass HTML and some wannabe BB-code? Wrote a nice parser for the latter - but well - it's C eeh... I mean PHP [:D] [;)] |
strg[k] = ' '; This is just so delightful. strncpy(strg, " Copyright ", 11) would have been so much more concise, and much more readable. I'm not even going to comment on the rest. It's just too painfully obvious that this isn't a native C coder. |
|
Since it's part of the standard C library, the compiler is allowed to know what strcmp() does. And many compilers will actually replace the function call with the actual underlying code - for example, VC++ 6 will, if run with /Oi, inline strcmp().
Ah, yes. I actually fire up IE for this forum, since the handling under any normal browser is so bad. When place like LiveJournal can get formatting right, and actually understand threading, using phpBB is a bigger WTF than any code yet posted. |
Code below works (both way algorithms) [code language="c#"]
[/code] |
|
I left the best out: After posting the code to Alex i found this code right after the hex to ascii conversion: out = popen(SENDMAIL_PATH,"w"); |
Indeed. However, trying to optimise round a function call is extremely difficult. If the code can pull the content of the function call inline, then it can (not necessarily will) be able to do a much better job. It need no longer push registers that the function never overwrote anyway. Register colouring can work. If it works really, [li] really hard, it might throw away stuff that turns out not to be required. (Though I think it's on a hiding to nothing with this code.) As far as the strings thing is concerned - well, all the compariosons are against short fixed strings. There is a chance that the intrinsic code could actually just do two byte comparisons rather than a loop. Still, the original code is a total mess. I'd recommend the author look at 'Unicode Demystified' . It contains code that addresses much more complex requirements, with much simpler code, and it might inspire him to write C, rather than VB using C syntax. |
|
Just because some doofus managed to convert his VB script into compilable C, it doesn't make him a C programmer. [:P]
Dead giveaway: "j = j + 2;"? wtf? That's like wearing women's underwear. [:$] Anyway, I think the maximum wtf density is attained in the 256-clause if statement that is a tautology. [:@] I can't stand to read any more. [+o(] |
Probably the dumbest part... I can see myself debugging that for hours and not noticing too ;) |
Agreed ...
Well, this all depends on how you define "hard core". I presume Duff's Device is one of those old C chestnuts that a certain breed of C programmer takes great pleasure in discussing? That must make me not "hard core". Oh well.
Speak for yourself (whoever you are, "anonymous"). I agree that it looks confusing, but it doesn't take that long to work out. If this code compiles, then this must mean that the switch/case statements aren't treated by a C compiler as a construct in the same way the do ... while is. The do ... while compiles independently of the switch/case, and the switch/case is then interpreted as a jump into a particular position in that compiled code - this makes sense, given the default fall through behaviour of C. The switch statement is executed only once, meaning that the first run through the loop is only partial. Given that the address of the destination (to) isn't incremented in the way that the address of the source (from) is, it is probably some kind of serial device. So the net result is that count values are copied from memory starting at location from, to a serial device of some description. I presume they are copied in blocks of eight (first block may be less than eight to give exactly count values overall) for performance reasons? |
|
|
grr, fucking piece of shit forum software.
This isn't phpBB. phpBB doesn't suck NEARLY this bad. Actually I rather like phpBB, after making a few simple modifications to it anyway. Anyway, this is written in ASP, not PHP. That should be your first clue that this isn't phpBB. |
|
Actually its in ASPX. The .Net variant of ASP. Which in itself means nothing as the editing control is javascript/vbscript I guess. Drak |
The reason most bad code is in Visual Basic, is because most of all code is in Visual Basic. "To the first approximation" all programmers are VB programmers. All other languages are in the noise level (or as they put in on "The West Wing" last week "within the margin of error...of not having any support at all")
|
|
Booger...Anonymous again. That last one was me. Isn't this site supposed to auto-logon? |
|
Get the IEView extension for Firefox. It will save you a ton of
frustration with this forum. You only need to use IE if you're quoting though. [:)] |
Ah, thanks for the clarification. I'd ended up trying to find out what the heck BB was (it's very briefly mentioned, with no explanation in the site FAQ) and arrived at the phpBB pages. I then made the assumption that this was using that. I have a friend who works for a certain very large company that happen to run, among other things, a certain two web applications.. One is driven by Python. The other by ASP. One is incredibly successful, and always responsive. The other is godawful slow. They're looking to rewrite the ASP one into Python. And yes, you probably use one of them frequently. |
|
DavidM,
you're on target about Duff's Device. Efficiency is why it does the "blocks of eight" thing with the mod-eight part done first: That way, it only has to check to see if it's done on every eighth byte. The best part about the strncpy() issue is that in the two places where he *should* be using strncpy() but isn't, he *is* using strncpy() for essentially the same thing, on the line immediately preceeding the horrible unrolled gunk. Between that, and "i = i + 2", and a few other items (not least the 256 case sensitive strcmp()s instead of two isxdigit()s), and strcmp()ing "25" etc. when he should've strtol()'d the string once and switched on the integer) -- this poor guy is not a C programmer. |
|
That's a wild assumption. Could be that everything this person ever did
was in C, and that all the training he/she ever got was from one of those "teach yourself C in an afternoon" books. This snippet could as easily be a small sampling of hundreds of megabytes of equally-bad source code. Not a competent C programmer? No. Not a good C programmer? Definitely not. Not a C programmer? Not enough data to draw a conclusion. |
|
You can add 'Not a competent programmer' to that list, and leave out the C. Anyone with some feeling and competence for/in programming could think of a better way to do this, regardless of the language they program in. Drak |
The language has nothing to do with crappy code. |
Re: Who's Hard-Core Now?
2005-01-19 15:21
•
by
ArmchairDissident@mac.com
|
You can. You may not want to - but you can:
Compiles and works just fine. It's the same as Duff's device mentioned elsewhere just - probably - not as useful. Remember that a switch{ case: } construct is just a structured "goto" in C. |
|
Duff's Device
Basically, it's loop unrolling (as done by any optimising compiler), which means the repeat condition gets checked less often, and there are less code jumps for the same number of iterations. It only works if you know how many times it's looping beforehand, but it can make a big difference if the repeated operation is small and done a lot of times (as in here). |
It's just badly posted, look at the C source at the end of the post to see the correct version. It seems this code attempts to change some string into a verbal form of some sort |
|
ArmchairDissident, I think that's not what he meant. There was a left
for (i=0,j=0;iswitch(buff[i]) {
Notice
You are, of course, correct about arbitrary case placement and Duff's Device. Allow me to say, by the way, that this commenting software is
|
| « Prev | Page 1 | Page 2 | Next » |