Monday, June 9, 2008

Venting

I don't know if anyone read that last post but it sure felt good to vent.

Wednesday, March 26, 2008

Find A way dont fix YOUR way

We've all been there. You get an assignment and you come up with a great way to do it. You sketch it out, your logic makes sense. You write the code and run it and somethings wrong. So you spend hours, days trying to find and fix the flaw in the logic. Why? sometimes it's an emotional investment in what you've created. Sometimes it's for what you convince yourself are pragmatic reasons. You say to yourself "this IS the best way to do it". Other times it's just the thrill of the challenge to MAKE a thing work. I was in this situation yesterday and for two hours I sat, trying to make MY way work. When I finally decided that it was best for everyone that I just made it work, not the best way, not my way, but some way. I had already conceived of a less beautiful less elegant way of accomplishing what I wanted, and it would mean doubling the run time of the script because I would need to loop through my input set twice instead of once. But really, what's the difference between .003 of a second and .006 of a second. This was not a routine that would be run a hundred times a second but one that would be run three or four times a day. I just had to swallow my pride and MAKE IT HAPPEN. So I suggest this to those who are reading this. When you run into one of these situations, swallow yoru pride, and find a way to fix it, don't fix your way.

Wednesday, September 5, 2007

Assignment Vs. Comparison Trip

A common mistake made by both beginner and experienced programmers alike is to use the assignment operator "=" vs. the comparisson operator "==". It happens to everyone now and then and can make debugging a real pain. People tend to see what they're looking for when reading their own code and this can easily be overlooked. Here's an example.


if($x = true){
//do something
}


since the assignment operator was used, the above statement will always be true thus making the condition useless. where the programmer obviously meant to say


if($x == true){
//do something
}


A simple trip to avoid this problem is getting in the habit of reversing the elements of the comparison like this "if(true == $x)". If the programmer then makes the mistake of using the assignment operator the parser
will throw an error since true cannot receive an assignment.


if( true = $x){
//do something
}


if you slip up, you will know immediately and without any manual debugging.
I hope this is useful and saves you time in coding and debugging.