Welcome to MSDN Blogs Sign in | Join | Help

Computer Science Teacher - Thoughts and Information from Alfred Thompson

Alfred Thompson's blog about teaching computer science at the K-12 level. Alfred was a high school computer science teacher for 8 years. He has also taught grades K-8 as a computer specialist. He has written several textbooks and project books for teaching Visual Basic in high school and middle school. Alfred is the K-12 Computer Science Academic Relations Manager for Microsoft and is trying to be the Microsoft Education Blogger.

Syndication

News


Featured in Education.AllTop.com



TwitterCounter for @alfredtwo




Programming Proverbs 15: Avoid tricks

Tricks are fun. It is often pretty satisfying to add a bit of code that is tricky, difficult or perhaps something that not everyone is going to understand. Well it's fun when it is done but later when the code has to be changed, modified, or worse - debugged its not always so much fun.

Tricks often work because they take advantage of ambiguity or implementation inconsistencies. or they rely on some deep understanding of low level details. The problem comes into play when those features change. For example a trick that takes advantage of overflows in a 16 bit word will break when the application moves to a 32 bit computer. Or a trick that takes advantage of a loop checking a value at the bottom even though the specification calls for it to be checked at the top of the loop will fail when a compiler that correctly implements the specification comes out. I actually know of cases where that latter problem happened!

There is a reason things are called tricks after all.

Tricks also make maintaining and debugging more difficult. Programmers really need to think about the person who will maintain their code. Most coding happens to existing code that someone else has written. If the next programmer doesn't know the trick they may very well have trouble working with your code.

Of course if you can't avoid using a trick at least comment it well. Explain it in detail so the next programmer to look at it will have a fighting chance to figure it out.

This is the fifteenth in a series of posts based on the book Programming Proverbs by Henry Ledgard. The index for the series is an earlier post and discussion of the list as a whole is taking place in the comments there. Comments on this "proverb" are of course very welcome here.

Published Friday, April 13, 2007 2:17 AM by Alfred Thompson

Comments

# Interesting Finds: April 13, 2007 @ Friday, April 13, 2007 8:56 AM

Jason Haley

New Comments to this post are disabled
Page view tracker