Page 1 of 1
Worst program ever
Posted: Wed Feb 04, 2004 2:29 pm
by Tim
This is probably the worst source code I've ever seen:
http://www.ncplus.net/~jeff-relf/Dif.CPP
Newbies: This is what
not to do.
Can we spot all the mistakes?
Re:Worst program ever
Posted: Wed Feb 04, 2004 2:34 pm
by Therx
Someone needs to tell him that it improves readability to give each command/function its own line and not to try and squeeze everything onto one line.
What does the program do (didn't actually read it just looked)?
Pete
Re:Worst program ever
Posted: Wed Feb 04, 2004 2:40 pm
by Tim
You give it the names of two files on the command line, and it displays the contents of each in a window.
To this guys credit, at least the program basically works.
Re:Worst program ever
Posted: Wed Feb 04, 2004 7:10 pm
by ark
Was this written for that "ugliest working C++ program" contest or whatever it is?
Wow.
If you ask me, there should be a compiler warning generated when something like this appears:
Code: Select all
#pragma warning(disable: 4003 4005 4010 4028 4033 4047 4051 4100 4057 4101 4127 4133 4136 4189 4201 4204 4214 4220 \
4244 4305 4390 4508 4514 4554 4611 4701 4702 4706 4709 4710 4715 4761)
You know, something like:
Code: Select all
Warning (W10000): you disabled a bunch of warnings; your code might suck
Re:Worst program ever
Posted: Wed Feb 04, 2004 7:17 pm
by ark
Code: Select all
_inline void Respond() { while( PeekMessage(&Msg,0,0,0,PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg);
if( Msg.message ==WM_KEYDOWN&& Msg.wParam== 27) exit(1); } }
That's a lot of CPU usage for a program that just displays the contents of two files. I would say this program must have been written in a hurry, but the warning disables kind of counter that one.
Re:Worst program ever
Posted: Thu Feb 05, 2004 7:56 am
by Eero Ränik
Like Joel, I think it was made for the most obfuscated code contest... Or as a practical joke.
Re:Worst program ever
Posted: Thu Feb 05, 2004 11:57 am
by Schol-R-LEA
My impression is that it is generated code, actually, rather than anything anyone actually wrote. Generated by what, I couldn't say.
Re:Worst program ever
Posted: Thu Feb 05, 2004 12:51 pm
by Tim
It's actual, real code! Posted to the newsgroups microsoft.public.win32.programmer.ui and comp.os.linux.advocacy.
You wonder ,
" Was it a contest to see if you could
write the whole thing in 80 lines or less ? "
It is 80 lines , but no ,
I wasn't trying to teach programming techniques ,
I just posted the links for the hell of it .
I never add a lot of whitespace unless
I need to examine a section of code ,
then I always remove it after the section works .
It looks like the guy can write a basic program, just not very clearly.
Re:Worst program ever
Posted: Thu Feb 05, 2004 1:02 pm
by Therx
For people interested in short programs take a look at the attched program I wrote. 89 lines with comment and no line cramming. Its a VERY simple http server
Pete
[attachment deleted by admin]
Re:Worst program ever
Posted: Thu Feb 05, 2004 1:48 pm
by Tim
Nice!
You know, with a small change, you could make this multithreaded and add the ability to serve more than one client at once.
Re:Worst program ever
Posted: Thu Feb 05, 2004 2:14 pm
by Eero Ränik
Very nice server!
Re:Worst program ever
Posted: Thu Feb 05, 2004 3:36 pm
by Therx
You know, with a small change, you could make this multithreaded and add the ability to serve more than one client at once.
I really just did it as a challenge. I wanted to write it in under 100 lines. I've only just actually got it working. It was written 2 years ago and didn't work. I couldn't work out why as it sent the right stuff when I used telnet to check. Then when I looked at it the other day I noticed that at the end of a request I'd put a close() instead of a closesocket(). :-[
Anyone who wants to use it feel free but it would be cool if you could send me what ever you make with it.
Pete
petercalvert AT f2s DOT com
PS Why can't Yabb provide something so that email addresses aren't "spiderable" e.g. Above
Re:Worst program ever
Posted: Sun Feb 08, 2004 12:59 am
by stonedzealot
Schol-R-LEA wrote:
My impression is that it is generated code, actually, rather than anything anyone actually wrote. Generated by what, I couldn't say.
Hahahaha, in my opinion, this should be read in the same tone as: "Clearly there is some supernatural force at work...a force that no man knows."
Re:Worst program ever
Posted: Mon Feb 23, 2004 10:49 am
by vile
You know, you should be careful of those strcpy()'s...
I haven't really looked over your code, but I saw the strcpy()'s, and your program could easilly be subject to a buffer overflow. Use strncpy() instead.