- 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
Admin
C/C++ = 1, C != 0. Of course, the value of C has been increased by one (barring overflow).
Admin
Worserer than failure!
Admin
Fired...
You did that TODAY? What? It ONLY took you a few hours? What will you do for the next few weeks?
Admin
I bet Alex will be happy to preinstall the winning submission.
Admin
Admin
From the sounds of this you also need a wood table.
Admin
I'm just going to upload the exact same template back. The WTF is that I didn't code anything, it's still all TODO's! Now that's dysfunctional.
devin (sir_flexalot - the WTF of this post is I'm registered but not signed in!)
Admin
All you have to do is write it in bad APL, then write a bad APL interpreter in C or C++ and hardcode the code to be interpreted into it. I'm not entering as I'm tired of C and C++.
Admin
As for the contest, man, I have so many good ideas...
So download it. It's free as in, uh, drugs.
Welcome to English. We sometimes use the '/' character, or 'slash', to abbreviate either 'and' or 'or'.
Admin
But saying C/C++ is like saying Apple/Elephant
They're completely different. Might as well say Perl/COBOL.
So which is it? C? or C++?
If it's either, then use "or" which more correctly implies that you have a choice of two different languages, rather than implying that C and C++ are so similar as to be indistinguishable.
Java and C# are far more similar than C and C++
Admin
I suppose your analogy is not completely worthless... provided the elephant has just eaten the apple in question.
Admin
No they're NOT completely different! Almost all valid C code is valid C++ code. You can't say that about your Perl/COBOL example in either direction.
It's true that they are diverging, but they will remain very tightly related for some time.
I'll agree about that, but I've also seen stuff like C++/Java, which I still think is perfectly fine and yet in some sense far more egregious than C/C++.
Admin
For the testing machine, what is the minimum spec (particularly RAM) that it should run on to test?
Even though compile time may be easy and short, what is the cut off for load time?
Admin
IMO writing "C/C++" is a sign that the person who wrotes it knows neither C nor C++ well enough to know that they're not the same language.
But yeah, maybe I should start writing Java/C#. While I don't really know either of those two languages, I once read someone (just a few comments ago) claiming they were similar, so that makes it OK, right?
Admin
This is true, but largely because of malloc. I bet that if C++ allowed implicit conversions from void* to other pointer types, a third to a half of existing, non-trivial C programs would compile fine. Add in allowance for implicit declarations and half of the rest would compile. Almost no one uses C99 features that aren't already in C++ (e.g. // comments or for(int i=0;...)) or most compiler extensions (long long).
When the language differences can nearly be counted on your fingers, saying that C and C++ are "completely different" is a vast overstatement.
If you could substitute "or" or "and" in for the slash, sure.
Admin
I beat you to it, only I wasn't able to get to the template- it was 404ed - so I submitted the 404 with a .zip extension. I'll claim that "the archive was corrupted, let me resend" and get back to Alex with a real version several months after the contest is over.
Admin
A bet I'd be more than happy to take.
I take it you pulled that statistic right out of your lower rear? :)
Hopefully noone is using "for(int i=0;;)" because that's just plain poor programming. C99 added a few things from C++ which tend to make source code a mess and/or unreadable, but luckily not many use it (and those who do are mostly C++ programmers who refer to themselves as C/C++ programmers).
I tried taking a non-trivial C application and compiling it with a C++ compiler. Not one single file compiled, and I gave up after C++-ifying a handful of files.
Some of the problems I encountered:
Implicit casts between different pointer types are not allowed in C++. Any reasonable C compiler will warn about unrelated types, though.
Doesn't work in C++. String literals are const in C++.
Doesn't work in C++ either.
And that's without even trying.
Please note that I am not the person who claimed they were "completely different", however I do not think they're the same language either, not by a far stretch. Just because they share a part of the syntax does NOT make them the same, or compatible, languages.
I don't agree with Bjarne Stroustrup often. In fact, the first time I've even partiall agreed with him was when I found this quote of his:
I agree that writing "C/C++" is braindead. Most people do it in this way: "Languages I know: Visual Basic, Java, C/C++." That's just wrong.
Where I don't agree with Bjarne is that he thinks it is mostly C programmers who write "C/C++." In my experience, it is mostly C++ programmers who never learned C and just once got told that "a C++ compiler will compile any C++ program. C++ is a superset of C." Thus they think that since they learned C++, they also know C, so they know C/C++!
So why is it that so many people can figure out how to write "or" or "and" between any other language, but not C and C++? I'd say it's because most of them simply don't know what they're talking about.
Admin
Yep
I would argue exactly the opposite.
Perhaps its because my background (if you can't tell...) is mostly C++, but I think that declaring your variable in the loop like that when you can is both better practice than outside of the loop and more readable.
I can support the first statement with actual reasons (it limits the scope of variables and puts them near their use), but I suspect the latter is just personal preference. (For that matter, the former reasons are probably largely preference.)
Okay, so I didn't think that those sorts of pointer casts would be used that much. I probably should have loosened my statement before to say that if C++ allowed unrelated pointer casts to the degree that C does, instead of just from void*. Though I guess that still probably wouldn't have given me a wide enough girth to make me correct, so I concede that point.
Ah, sorry about the misquote. I have a habit of not really looking at who says things, which has both good and bad consequences. (Probably mostly bad...)
I will make one last argument to try to support my position, which is that if you are somewhat but not terribly careful (probably the biggest concession would be the need to cast out of malloc), it should be possible to write non-trivial code that sticks to the intersection of the languages while losing almost nothing from C. (Though I guess I am a bit more wary about making this statement than I would have been a couple hours ago, as I wonder if there are reasons why people use what I would consider unsafe practices like random pointer casts regularly enough that it would cause a noticeable problem compiling existing code as C++...)
In that sense, C and C++ ARE a lot more related than any two other language I can think of off the top of my head.
I would agree that there it would be better separated, at least if the person didn't deliberately mean that they have used the limited part of C++ that largely overlaps with C, in the sense that Stroustrup meant.
But I do think that there are plenty of places that C/C++ would be fine. This article is borderline IMO, more because of the "the language" than the C/C++.
Admin
BTW, for the record, I just looked and my resume says "C and C++" ;-)
Admin
What kind of failed abortion are you? Could you imagine that it is a blessing to work as a programmer for 25 years, bringing food on the table and never having to touch the clusterfuck called Windows? Why the fuck should someone taint his clean soul for a crappy contest?
Go back to licking Bills arse and stop annoying the real programmers.
Admin
Sorry, that's not enough to solve the problem. Once you got the result, you also need a printer to print the result, have the robot arm place it on a wooden table, take a snapshot with the webcam, post it on a web server, download the image from the web server, preferably using web services, OCR the image to get the result and then return the result.
You have to think enterprisey.
Admin
No, oh no no no, it's definitely < 1 provided C > 0.
Admin
Yeah, but for prize there is macbook or sony, I don't want to have any of them. I don't like mac's and sony is "teh evil corporation".
Admin
If you win, I'll give you a ThinkPad in exchange for one of them.
Hopes he doesn't ask how old it is
Admin
I had a buddy that wrote his own calculator. It didnt compile (HAving more errors than LOC, about 3-4 times as many errors as it had lines actually) so, what did he do? He picks up the phone and calls me to come and "look at some code". My hair DIDNT go white, but I am pretty sure I am gonna go bald a full 10 years earlier because of that code.
It did a lot of wonderfully fucked up things, and once I actually got it to compile (Beating on it with a sledgehammer more or less until the compile errors went away and there were only like 70 or so serious warnings left). It miscalculated stuff if you put numbers in in "the wrong way", it used strings to do calculation, and well, it had indentation, but uhm. Not like you'd expect. ;) It was a real mess, and I still remember it fondly, and I have been planning to make my own version of it just to do something horrendous. This might be a good time. ;)
Admin
-Passes all of Test Cases
Okay, it looked all fine until this point. But what's the point of a WTF contest if the program has to pass all test cases? I thought it should be buggy.
I thought about making a program that runs C:\WINDOWS\system32\calc.exe (assumes an absolute path of course), then takes a screenshot and scans for the result. But if it has to pass test cases then I guess that idea is out the window.
Admin
I don't see a requirement that the program must give the calculation results within the judges' lifetime.
How do the judges determine whether the calculator actually completes the testcases, in the case the program actually performs quadratically or worse?
Admin
His point being that said search was slow to the point of uselessness, if you'd read the full article...
Admin
And the specifics being: (To add to this)
Admin
Obviously the original posters are complete numptys for not reading the whole article, as there's a GTK equivalent to the Win32 code. However, on the dual booting front, can you tell me how to dual boot Windows on my Sun workstation as I don't feel the need to blow several hundred quid on a PeeCee?
Admin
Why no Java/C#? They would be the easiest languages to do a simple GUI in, and the tools are much more straightforward to set up.
Admin
Re: The Worse Than Failure Programming Contest 2007-04-24 15:36 • by [email protected] Come on, let me do it in C#. Pretty please?
An idea for WTF: Implement the CLR and C# compiler in C/C++, and then implement the solution in C#. I reckon this counts as a "clever" solution.
ok.
Admin
It seems to me you might get a head start on some excellently WTF code by writing Windows code without a Windows machine available.
Admin
He probably wants to guarantee that the code submitted won't contain malicious malware components such as virii, trojans and adware which could potentially steal intellectual property from his machine.
Restricting the competition to a windows codebase - ie a commercially verified codebase - eliminates the possibility of open source code being used which is well known to be rife with the above concerns.
Admin
Admin
Well :D Ive wasted some time now to get this to compile under VS2005 express with no luck :D It kompiles but wont link so I think Ill sit out until the GTK one arrives and do it in my cozy linux :)
Admin
I figure that my being one the the 15% who don't use C/C++ is a real advantage here...
My bugs will be authentic! =)
Admin
Hee! Dumat nada ne brõgat. Read the manual and what ya know, to compile this with VS 2005 express you will need to add kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib to linkers aditional deps for the skeleton project. the gude tells you to add this to the default project template but that does nothing for an existing prject...
Admin
Wrong.
C++ is a postincrement, meaning that it's evaluated and then incremented.
So therefore C/C++ is equal to 1, except when C is 0.
Admin
You think you could get Joel Spolsky to call the winner and give their code review on the phone using harsh language?
Admin
My point of view is that variables should only be declared at the beginning of a scope and before any statements. This IMO makes it much easier to read through code you don't know. Uncertain of what type something is? Well, just scroll up to the beginning of the scope and you will find the declaration. Also if you use more than one loop, declaring i multiple times is just silly.
I do realise that C99 considers "for(" the beginning of a new scope, but I completely disagree with C99 here. C99 allows declaration of variables anywhere anyway, which I also completely diagree with. It's just promoting sloppy programming.
To be fair, the thing I tried to compile was Quake, which is very far from being the most beautiful code. In fact the Quake source code is fairly ugly if you ask me.
Another problem I forgot to mention is that Quake has a "typedef enum { false, true } qboolean;" definition which also clashes with C++ ;)
Code I write does not do unrelated implicit pointer casts since I consider it bad style. Indeed if C code compiles with -Wall without warnings, there's a good chance the code won't need too many changes to compile with a C++ compiler.
Related? Yes. But not enough to write "C/C++."
One of my biggest problems with writing it like this is that many (most?) C++ programmers make awful C programmers. Looking at C code written by someone knowing C++, you don't have to look for many seconds to find the first memory leak or lack of error checking.
Especially bad is error checking. The typical C++ programmer does absolutely no error checking at all, which is just proven again and again every time I start working on a new project at work (which usually means I end up working with new people). Another thing I see scaringly often by C++-programmers-turned-C is something like:
And then after a while, someone taps me on the shoulder, asks me if I know why the new operator would be crashing and if it is a bug in the operating system. Of course the new that's crashing is the one after the code I wrote.
I'm still trying to think of a single place where writing "C/C++" would be OK... Unless you were trying to unify the two languages into a new language, that is.
Admin
What everybody really wants to know, but doesn't want to say out loud, is: what does OMGWTF stand for? Sure we want to know, but only in a perverse "after I find out I'll be sorry" kind of way. I'm guessing it's something like:
Ooops Me Goof it's Worse Than a Failure
Maybe somebody else knows for sure.
Admin
Admin
awwwwwww yeah.... use the GUI for basic I/O only (user enters digits, reads result). The calculations are done in a console window however, instead of passing the variables back through to the GUI class, the GUI runs a screen scrape method on the console window to get the results.
or better yet,instructs the user to take a screenshot of the results window, print it, put the printout on a wooden table....
Admin
And, it you had, it would have compiled under C & C++.
No, actually that does. The Standard committee had to hold their nose as they hacked the Standard to get it to work, but that is allowable.
So, basically, you're saying that C is a different langauge from C++ because C++ won't let you get away with incredibly bad programming practices you shouldn't be doing in the first place.
So, let's re-phrase the original statement -- "Most WELL-WRITTEN C code is compilable be a C++ compiler."
Admin
See, I think personal preference. I think it's easier to find things if they are near their uses. If the function is short, it doesn't make much difference; if the function is long, it means that you have less chance of scrolling and also that the block of declarations is likely pretty sizable. In either case, if you're using an IDE then there's no issue figuring out where the declaration is, as there's a "go to declaration" action. Heck, Visual Studio will show you the type of the variable the mouse is over in a tool tip.
In addition, "declare anywhere" also often/usually allows you to initialize the variable at the point of declaration, something you can rarely do in C, which reduces the chance of using an uninitialized or improperly initialized variable. And this doesn't affect C, but it also makes RAII a lot more useful by letting you use it at any block level.
Eh, I guess we disagree.
Does remind me of like a, by now, probably third-hand anecdote though. This one guy my friend knows was interviewing for faculty positions probably about a decade ago, and one of the places was at UT Austin. He gets to the department, and some of the profs start essentially apologizing to him for what was apparently fairly unpleasant behavior on the part of Edsger Dijkstra. For instance, they warned him that Dijkstra didn't like people anthropomorphizing programs, so at one point during his talk he said "the program wants to do this.... sorry, the programmer wants the program to do this".
But on one of his slides he had something like "x/y" (not as a division). Dijkstra raised his hand and asked "what does x slash y mean"? And this guy says "it means x or y, but if I had written that out then it would have wrapped to the next line, and I hate that!"
Admin
Let's try to pay attention here --- The first refers to a trademark; the second, to copyrights. They are incompatible.
And while we are pointing out problems with the name of the contest, I guess I should get nit=-picky and point out that it should be "The Olympics of Misguided Geeks at Worse Than Failure Programming Contest."
"Olympiad" actually refers to a period of time, specifically 4 years, during which there is one Olympics.
Admin
And a wooden table, don't forget the wooden table.
Admin
At least the last non-broken version of GCC doesn't warn about implicit signed/unsigned casts.
Bingo, and if I didn't, it wouldn't. And that was (part of) my original point.
Right, it actually does compile. The code that had the problem looked like this:
Now I don't know if that's a compiler bug or really intended in C++
No, I'm saying that C is a different language from C++ because while they're syntactically similar (though not identical), the way the two languages are used, especially when it comes to allocation, error handling and standard libraries, means that C knowledge can't just be transferred into C++ knowledge and C++ knowledge can't just be transferred into C knowledge. You need to learn both languages, and thus they're distinct.
Well, I can extend that. Any well written C++ program will be compilable with a C compiler.
When your definition of a well written C program is something that compiles with a C++ compiler, well, then the argument is lost before it even started.
C++ has a lot of "features" over C which makes code much harder to read, much harder to maintain and overall puts the code in a lot worse condition. Though I don't expect you to agree.