Some People Should Not Be Allowed To Code

By Sean Hagen

November 2, 2005 at 4:41 AM

Okay. I know I'm not the greatest programmer in the world, but having documentation that actually teaches what it's supposed to helps. My bad English aside, I just started reading through one of the books I recently bought for very cheap. The subject of the current book is C++ programming. When it comes to C++, I've got a pretty good grasp on the language. But there are still certian things that I don't understand very well, like pointers or the standard template library. So I read books to try and improve my understanding of those things I don't know a lot about.

But what's annoying about many programming books, especially C/C++ programming books, is that it is automatically assumed that you are using Windows. Some of the newer books have a blurb here or there about Linux ( or any non-Microsoft operating system ), but for the most part, it's all Windows. Which is annoying at first, especially when the author uses a Windows-only programming library, and I have to figure out how to translate it into Linux-ese. This is especially annoying when it comes to the graphical stuff.

All of that aside though, what really annoys me is when the author of the book glosses over certain basic concepts, or gets too in-depth. Or when the author completly misses the concept when they write a piece of example code. Like this little gem I just stumbled upon:

#include main () {  for ( int count = 0; count <= 20; count += 4 ) {    if ( count < 20 ) {      cout << "The counter variable is " << count << endl;    } else {       cout << "The counter variable is " << count << endl;    }  }}

Okay, lets just ignore the obvious errors ( or if they're not obvious to you, I'll point them out later on ) for now. This is a piece of example code written to introduce the if-else statement. The purpose of the if-else statement is so that you can branch your program. For example, if you wanted to have a specialized greeting program. With the if-else statement, you could have something like this:

if ( name == "Sean" ) { cout << "Hello Sean. You are the greatest!" << endl;} else { cout << "Hello, whoever you are." << endl;}

This little block of code would print out the message "Hello Sean. You are the greatest!" if the variable 'name' is equal to 'Sean'. This is the whole point of the if-else, to allow you to do different things based on different conditions.

So now that I've explained the basic use of the if-else, I can point out the glaring error in the example. No matter what the variable 'count' happens to be, it does the exact same thing. This is a bad thing. Not because it wastes space ( the compiler will notice what has been written, and fix it, but the programmer won't notice ), but because it encourages sloppy coding habits. People who code like this get their pieces of code subbited to the Daily WTF, and that's not a good thing.

Okay, so if you didn't immediatly notice the biggest error in this piece of code, let me point it out to you. It's the line that looks like this: main () {. Why is that an error? Mostly because in C/C++, main() is just another function, which means it has to have a return type. That line should preferably at least look like this: int main(void) {. There are several other ways to write it, but that's the most basic way that you're allowed to write it.

I'm not even going to start with the rest of the errors in the book. Let me just simply say this: never, ever try to learn C++ from a book called "C++". The book was written by Till Jeske, and is part of the "Addison Wesly Nitty Gritty Programming Series". If you ever see this book, either burn it and run, or just run. Seriously.

I just realized that I started writing this entry on Monday. You'd think that between when I started writing this, and now, that I'd have a whole lot to post about. Unfortunatly, my job seems to notice that the end times are near, and has been sucking the life out of me with increased vigor. On the flip side, however, tommorow is my last day. Which means that on Monday, I'll most likely be unemployed. So this weekend I'm going to be sending out a lot of emails, and also handing my resume out to any place that looks like they'd take me. I'm also going to be going to the building that houses CFOX to see about getting a job. I sent them a nice email cover letter with my resume attached, but I haven't heard anything yet. Hopefully, if I go in ( and can actually muster up the courage to step inside the elevator, unlike the past three times I've been there ), I'll be able to showcase myself as the solution to all their website related woes.

There are several good things about me being unemployed though. The first is that I'll finally have time to start working on setting up a better site to host this blog of mine. I want to have things like comments and images, but there are several problems with diaryland. The first is money. If I want comments or images, I have to pay. Actually, come to think of it, that's really the only problem. That and the fact that trying to edit anything I've written is harder than trying to convince someone who believes in Intellegent Design that it's not science. Mostly because of the way the posts are stored here on diaryland. For one thing, every time I go to edit something, all of the character escapes I've put in get replaced. So if I've put something like &gt; so that the quotes from bash.org turn out nicely, it gets turned into > and disapears when I save my edits. Unless I go and change all of them back, which is time consuming and annoying. For the average user of diaryland, I bet this kind of stuff is okay. But for someone like me who occasionally likes to talk about programming or post quotes from bash.org, it is just plain annoying.

I've thought about getting an account at Blogger, but there are several problems with that. I know that if I went with Blogger, I'd get free image hosting and comments on all my posts, but I don't want just a blog. I also want a place I can put up pieces of code I'm working on, as well as a place to put my resume and several other little things I'm working on. In other words, I need more than just a blog, I need a webhost. I've been looking at some of the local webhosts, namely dotEasy and the hosting services provided by Costco. Yes, Costco has webhosting. They even have php and perl 5, hosted on RedHat servers. Wheee!

Or I could just host it myself. That's always an option. But then there's no one else to blame when the server goes belly up. You know, when I get slashdotted or something like that. Because one day I'm going to write an article or post that everyone is going to want to read.

Yeah.

Right.

So since I can't think of anything else to write today, here's a quote from bash.org to distract you while I run away.


#240849
<Patrician|Away> what does your robot do, sam
<bovril> it collects data about the surrounding environment, then discards it and drives into walls

Comments:

RSS

No comments yet, add yours below!

Add Your Comment:
  1. Pick the squirel from the below: