Archive for October, 2007

Portal

Wednesday, October 31st, 2007

Nothing I can say about Portal hasn’t already been said before. Just stop reading now if you’ve read anything at all. However, if you’ve not heard of Portal, then read on…

I played Portal last night. It’s a little game included in Valve’s new Orange Box ($50, includes 5 games). It’s one of the best games I have ever played in my entire life ever.

I set out at 10pm to play the first few levels. I stopped at 1:30am having beaten the game.

I laughed (a lot) and I cried (not really, but there was a really sad moment when I had to burn a cube with hearts on it that they referred to as my “companion cube”, and the game was so good that I actually felt sad like I was loosing a friend).

The whole time you are basically like a lab rat. There is this computer voice that talks to you. You learn to trust it at first, as it helps guide you through your tasks. But then you learn not to trust it because it is a liar.

After a while you get the feeling that you are no longer playing the game, but that the game is playing you. It tries to psyche you out and get you to fail not only by making the tasks hard, but by telling you that you are no good, and that you are not smart enough, and that the task is impossible.

It is amazing.

Oh, the object of the game is that you have a gun that makes two portals. You can shoot most surfaces and then walk in one portal and thus out the other. So if you are on one side of a room that has a fire in the middle, and you want to get to the other side of the room, you would shoot the wall next to you and the wall across from you (on the other side of the fire) and walk through the portal on your side and thus out the portal on the other side.

Buy the game, you won’t be disappointed. It’s absolutely amazing. Actually, it’s not. Don’t buy it. It sucks. (there, now your expectations will be low and it will be even better).

If you’re going to code badly… do it with style!

Monday, October 29th, 2007

Please, for the sake of “the next guy” (or yourself a month down the line) tab format your code. Especially if you aren’t that “great” a programmer and your 1240 line file is a mass of spaghetti if statements.

If you have a nasty mess of if statements, there is just no easier way than to tab format it. However, no tab formatting is better than a little tab formatting. Take this for instance:

if(this == that){

 if(that == this){

 	Do this

 	Do that

 	if(this == that){

 		Do this

 	}else{

 		Do that

 	}

 	Do this

 	if(this)

 		Do that

 	if(that){

 		Do this

 	}

 }else{

 	if(this == that){

 		Do this

 		Do that

 	}else{

 		if(this)

 			Do that

 		if(this)

 			Do that

 		if(this == that){

 			Do this

 		}else{

 			Do that

 		}

 	}

 	if (this == that)

 		Do that

 }

 if (this == that)

 	Do this

}

It’s a mess, but at least it’s readable. If you ever do anything that looks like the above, you have almost definitely done something wrong. You probably should have used some sort of multidimensional array, or stored some stuff in a DB and done a good SELECT statement.

But if the word “multi-dimensional array” sounds like a sci-fi weapon to you, and you can’t function without if statements, then please tab them.

If you don’t tab your code blocks consistently you will end up with this:

if(this == that){
if(that == this){
	Do this
	Do that
if(this == that){
	Do this
}else{
		Do that
	}
Do this
		if(this)
			Do that
	if(that){
			Do this
		}
}else{
if(this == that){
	Do this
Do that
		}else{
	if(this)
		Do that
if(this)
Do that
	if(this == that){
		Do this
}else{
	Do that
		}
	}
if (this == that)
	Do that
	}
if (this == that)
Do this
	}

I DEFY you to be able to read that code. It’s insanity, and will drive any sane person to the brink of delirium.

If you don’t tab them, that’s OK (but not optimal). It’s better than tabbing inconsistently. But please put brackets on EVERY if statement. Yes, all of them. Even if it’s just one line. I know you don’t have to, but just do it. There is just no good reason not to. One good reason to do it is that when you come back in a month and add a second line to that if statement, if you forget to add brackets at that point then that second line will always execute, and thus a bug is born. Make it fail safe.

Now, if you inherit some horrible quasi-tabbed code (like the bunch shown above) you do have some options.

A bad (but better than nothing) option is to open it up in an IDE, highlight it all and hit SHIFT+TAB until there is no formatting (then you could even go through and tab it all if you can figure it out).

A good option is PHP Developer (and many other IDEs) which will show you where the opening and closing brackets for a bracket set are. Aptana (which is basically eclipse) does not. Textpad does not (Although you can highlight an opening bracket and hit Ctrl+m to see the closing one). Dreamweaver does (I think. I believe it will actually re-format your code for you).

For those of you newbs out there learning to code for the first time, use an IDE like Textpad or Dreamweaver and set it to help you out with your formatting (STOP USING NOTEPAD!!!!). In Textpad this is as simple as clicking Configure>Preferences>Document Classes>[Click your programming language] then select “Automatically Indent Blocks”. If you use another IDE figure it out and then do it and be consistent. There is almost nothing I can think of style-wise that is more detrimental to success than tabbing your blocks of code. It’s one of the first steps to becoming a “good” programmer. I won’t say it’s what separates the men from the boys, but maybe the boys from the babys.

The Importance of a Tasks List

Friday, October 26th, 2007

If you are feeling frustrated on a project, or if you find yourself blogging/reading blogs (or something else) instead of working, you might consider that perhaps you have lost (or never even had to begin with) your direction.

On page 95 in Step 5 of her book “10 Steps to Successfull Project Management”, Lou Russell summarized research by Michael Ayers which detailed a few reasons why people resist work. Aside from the obvious ones like “The project doesn’t interest them”, “The project doesn’t need them” and “The project goes against their values”, there were two reasons that interested me.

These two reasons (in my oppinion) are very closely related:

1. The project seems impossible
2. The person doesn’t know what they are supposed to be doing

If you don’t know what you are supposed to be doing, the project is going to seem impossible.

If you set out to accomplish a task, usually all you have in mind is the end goal. Say for example you decide you are going to make some cookies. You know what you want. You want to savor the sweet gooey goodness of some moist fresh from the oven chocolate chip cookies. But if you don’t know what you are supposed to do to get them, the project will seem impossible.

You may wander around the kitchen for a while, opening the oven door and looking inside hoping they will appear. If you’re like me, you would probably focus on something you know, and get more and more granular with that subject until you have lost complete site of the project you started, and focus entirely on something you do know. You will end up building a replica of the oven, or inventing a new kind of spatula, or perhaps making a peanut butter and jelly sandwich before you even realize that you have come no closer to accomplishing your goal.

It’s easier to just ignore what you don’t know and focus on what you do. Your avoidance might just go so far as to lead you out of the kitchen entirely. You could end up watching tv on the couch, or playing ball in the yard, or just going to the store with a vague notion of buying some cookies as a pretense.

Stop. Just stop right there. Sit down, get a piece of paper out, get a cook-book, get the oven manual, make a plan. Don’t spend too much time on it, but spend just enough to get you going. Focus on the parts you don’t know, go large scale on the parts you do. You don’t need to detail exactly how you need to use your thumb and fore-finger to turn clockwise the nob marked “oven” to such and such degrees, just say “turn on oven to such and such degrees”. However to get those cookies really mixed up you may need to detail a tricky wrist flip. But don’t spend three hours on a plan for a project that should take 20 minutes.

In order to make the impossible seem possible, you need to know what you are supposed to be doing. You can’t know what you are supposed to be doing unless you have a plan. A tasks list. So next time you find yourself blogging, or surfing, or gazing out the window, stop and think, “Why am I procrastinating/avoiding?”. It may just be as simple as you don’t have a plan.