ScottMeg.com

May 30, 2007

How to code

Filed under: Life, Ramblings, Rants — Scott @ 7:50 pm

(via Slashdot)How to Keep Your Code From Destroying You

It is always good to see a short story on how to code better.

Mr Vogel’s tips(my comments)

    Tip 1: Comment like a smart person.

I don’t like comments and I only comment a section when I’m forced to do something tricky or unusual. Comments tend to get out of sync with the code and in the end the code is the truth, the whole truth and nothing but the truth. In general I prefer well named and well constructed code. The code should tell the story.

    Tip 2: Use #define a lot. No, a LOT.

This is basic. Hard-coding any values into your code will return to bite you. Enums are great if your language supports them.

    Tip 3: Don’t use variable names that will mock you.

Clear, Simple, Meaningful. And try to keep them 5-12chars or so long. Shorter and they tend to be hard to search for and longer mangle your formatting. Never even think about using I or O they look too much like 1 and 0.

    Tip 4: Do error checking. You make errors. Yes, you.

Yea so. Don’t worry about it. The last thing your code needs is for every function to start with a bunch of range checks. Unless you are doing input or interface processing, general validation is a waste. Validate when you need to validate. If a call ass-plodes when I send it null, why did I send it null. Generally you kinda know that if a method takes an object as a parameter it probably needs a non-null object. When you create the object, check that it really got created. Not very productive passing a useless object around now is it.

    Tip 5: “Premature optimization is the root of all evil.” – Donald Knuth

This is a good one. Rarely is what you think slow actually the thing that is making it slow. Write clean, clear, simple code. If its slow, run it through a profiler or even instrument it yourself. Find out where it is slow. Figure out why. Then address the problem. Guessing is for amateurs.

    Tip 6: Don’t be too clever by half.

Stupid is as stupid does. Simple works. Clever takes work. Clever works less than simple and requires more fixes, more testing, more tweaks, and gives more headaches. Guess which is more clever? The problem is that clever is more fun at the start… “The first one is free.”

My tips:

1) Get a great editor. Either spend the time and actually learn emacs or go out and buy SlickEdit. You’re a programmer not a bricklayer! Get the tools you need. They save you time, energy and frustration and let you code with out all the the muss and fuss.
Use your editor’s features. Learn search, tagging, use references, go directly to definitions, find all in project. Figure out regular expressions. Learn to block cut. File/multi-file Diff is your friend.

2) Source control. Its not coding right? Wrong! Sometimes going back is the fastest way forward. Source control saves lives.

3) KISS. Keep it simple simple. If you can’t think of a simple way, get help.

4) Always keep it working. There is nothing worse than a broken application. Lots of small changes beat the one big one.

5) Test, test, test. Automated regression tests rock. Test before, test after, test well.

6) Good formatting and good names mean more than you know. Choose wisely and don’t be afraid of search and replace. When the meaning changes, change the name. Think of a better name, change the name.

7) Methods/function should be short (generally a page or less) and do one thing.

8) Cut/paste is the tool of the Devil. Don’t do it. Make a common function. It really sucks making the same change in 20 places across 16 files. And then there is all the retesting…

9) Give/ask for help. Sometimes you just need a fresh set of eyes. The more you help others the easier it is to ask for help.

10) Always try to write positive tests. Negative conditionals wear out the brain. (Just ask De Morgan or Meg)

May 28, 2007

Memorial Day

Filed under: Holidays, Ramblings — Scott @ 5:13 pm

Day Is Done,
Gone the Sun,
From the Earth,
From the Hill,
From the Sky,
All Is Well,
Safely Rest,
God Is Nigh

-the words for Taps

Taps’ history

Memorial day

Filed under: Holidays, Ramblings, Rants — Scott @ 9:51 am


from daybyday

Thank you to all who served. We remember.

May 27, 2007

The.Best.Game.Ever.

Filed under: Favorites, Life, Ramblings — Scott @ 10:14 am

Way back in college I had a Mac se and picked up a puzzle game “The Fool’s Errand.” Never before or since I have every played such a great game with so many puzzles. Believe me I’ve looked. On a whim I googled the games title today and to my great surprise I found the game along with a mac emulator that lets it run on my pc.

Fool's errand
Click to go to site

After the weeks and late nights my college dorm-mates and I spent solving all these puzzles, I’m looking forward to solving all them again with Meg.

If you like puzzles check it out. The emulator has some ‘character’ but don’t let it reduce the pure coolness of the game. [Update: We found it best to set your screen resolution to vga]

Thanks to the author (Cliff Johnson) for making it available for free.

May 26, 2007

Lionesses , crocodiles , buffalo… oh my

Filed under: Ramblings — Scott @ 11:57 am

Youtube video
You don’t see that everyday.

Older Posts »

Powered by WordPress