Archive for August, 2010

Opinion Disclaimer

Caution: Example Code Ahead

Today’s post veers from anything flash specific and goes to the more generic area of example code.  For everything you want learn about in the world of programming there is some example code.  Example code is a great way to see what book authors and blog posters are trying to explain in their posts. I’m a better programmer than a writer so I know how difficult it is to explain some of these concepts without showing code. However, example code has some issues that it is important to be aware of when you use it.

Comments aren’t part of the example

Unless you are reading a book about writitng good code ( I recommend Code Complete by Steve McConnell ) the comments in the code are not there to show you good commenting practice. I could rant on and on how code should be self documenting and be able to be read like a good book but my main complaint with comments in most example code is stuff like this:

// define variable a as an integer and set it to 5
var a:int = 5

Now when you are learning about defining and setting variables this comment is important and that is why this comment is in example code. Unfortunately, I see this all too often in code I’ve had to debug. Code that is straight forward doesn’t need to be commented. In case you don’t know, comments like that in real world code scream amateur and/or I just copied this from the internet somewhere. Moving forward, you might want to make your code as straight forward as possible so you don’t need to comment it.

Best Practices are rarely in example code

Recently I was reading a book on AJAX programming that was trying to show how to use a simple service written in PHP.  To do this they had two input fields in a form where you entered numbers.  The javascript would then send the values of those two fields to a simple PHP webservice that divided the numbers then returned the results. After that the results were parsed to show the answer on the screen.  For the purpose of the book, which was to show how you could use a webservice without being overloaded with other code, this is okay.  In real life, you should just divide the numbers using javascript and leave the webservice out of it.

Also, if you read books and blog posts word for word the authors know that what they are doing isn’t meant for prime time so they will leave a caution warning ( possibly with a cartoony icon ) letting you know this. Please heed their advice if it is there, but since it usually isn’t just realize that example code probably isn’t the best way to handle the problem domain it seems to be solving.

My oh my!

This next section is about a pet peeve of mine, the use of the word “my” in example method and variable names.  For instance, I sometimes run across code like the following:

var myName:String
function myClickHandler( event:Event ):void{
...
}

Unlike the previous examples, I don’t think the reasoning behind this convention in example code is strong enough to even use it there. The reason I don’t like this convention is the readability of code that has to use it .  Using the myName variable as an example, which code appears cleaner and easier to read?

if( employee.myName == 'Jeff' )

or

if( employee.name == 'Jeff' )

I think you’ll agree that the second example, without the redundant prefix is cleaner and easier to read.

The code doesn’t always work

Anyone who has ever tried to copy or [GASP!] cuts and pastes example code has probably figured out that there is a high probability that it won’t work.  There are several possibilities for this from editors who think they know better to code that was only written in a text editor but not tested or even an errant copy and post from the author’s IDE that forgot a semi-colon.

This isn’t a problem in the way that the previous items are a problem with example code. Though it would probably be better if it didn’t occur, its better just to know that your chances of perfectly working code are 50/50. In fact, non-working example code can be a good thing to debug. Especially when you consider a majority of your programming career ( or hobby for that matter ) will probably be taken up with debugging code that you swear should work.

What else?

While the heading for this section might make you think I’m going to discuss the overuse of if-else statements I’m really asking for your opinions on example code.  Am I off base?  Do you have your own issues with example code? Perhaps you want to discuss the overuse of if-else statements in example code or maybe you’d like to see more of them.  Please, comment below and let me know.

[ad#Adobe Banner]
If you liked this post please subscribe to my RSS feed and/or follow me on Twitter. If you only want to see my Flash Friday posts you can follow the subscribe to the Flash Friday feed. How’s that for alliteration :) Until next time keep on coding.

Friday, August 20th, 2010 Flash Friday

What would it take to get to normal?

The other day I was listening to NPR talk about BMI or body mass index with regards to healthiness. I have always poo-pooed BMI because as a former personal trainer I know that it doesn’t take into account actual body fat percentage. For instance, a well conditioned athlete might have enough muscle to be considered obese using BMI while somebody in the ‘normal’ range might actually be skinny-fat and thus too weak to really function on a day to day basis. And, as I looked for a link to the story I was listening to at NPR.org it looks like there were many follow-ups or alternate stories that feel the same way.

BMI is a bogus measurement

However, despite the reality that BMI is a bogus measurement I decided to get real on my personal situation. While I used to be a professional wrestler and a personal trainer, I have been 5 years retired from both and my fitness level is that of a social media game developer( my current profession ) but my eating habits have not changed enough to compensate. So right now I am sitting at 240 pounds which is considered obese by the BMI measurement for a 6 foot tall person.

On the flip side, 220 pounds is the top end of the overweight label for my height and 180 is the top end for the normal range. Its interesting to note that 180 pounds was my weight in High School, probably when I was most active without trying to add muscle. I know that 220 is realistic as I was about 225 when I wrestled. However, is 180 realistic?
[ad#Google Adsense]

Getting real about the numbers

Let’s go through the numbers, keeping in mind I don’t actually know my bodyfat percentage right now.
If I’m at 30% body fat ( which is high for a man but definitely believable ) than I have 168 pounds of lean body mass and if I could somehow lose the weight without losing muscle mass ( a very difficult task – though attainable ) then I would be at 7% body fat. 7% body fat is pretty low, especially for a social media game developer. Am I willing to lose muscle mass, is it still that important to me?

The truth be told, I could have a higher or lower body fat than 30%. If it is higher, 180 could be attainable without losing muscle. If it is lower then I can just kiss some of that muscle goodbye if I want to hit 180.

Do I even want to try?

Do I want to try for 180? That’s a big goal. If I get to 180, will I have done it in a healthy way that I can continue for the rest of my life?

The answer is yes, I do want to make the journey toward 180 pounds and I’m going to use this blog to take you all along the journey with me. I say journey because I know that is more important than the destination. I might find a fork in the path along the way that is better for me and I will share that if I get there. For now, I have a destination and I just have to look through my old maps ( old personal training books ) and possibly get some new ones ( apps for my phone have helped in the past ).  I guess one of those forks will come when I have to decide if losing muscle mass is worth it to me.
[ad#Google Adsense]
If you liked this post please subscribe to myRSS Feed and/or follow me on Twitter. If you only want to read my Wednesday Warrior posts subscribe to the Wednesday Warrior feed. Until next time, thanks for reading.

Tags: , , ,

Wednesday, August 18th, 2010 Wednesday Warrior
Opinion Disclaimer
Add to Google