7 secrets of successful programmers

1. Code for human consumption

It is one of the most pervasive misunderstandings in computing that the source code is for the computer’s consumption. Computers work with low-level binary code, a series of impenetrable 1’s and 0’s or hexadecimal numbers, not the structured high level languages we code in. The reason that these languages were developed was to help the programmer.

In practice, coding for human consumption means coding for clarity first, over efficiency and speed second.

2. Comment often and comment well

The comment is the extreme example of a language element for human consumption. Most compilers will strip the comments from the executable program. The purpose of the comment is to tell you (and any future developer) what the program is intended to do. Write comments with this in mind – and avoid simply restating the code.

Good comment: Disable button to prevent its activation Bad comment: Set cmd = False

A good indication that you have got the level of comment right: could someone understand what your program does if all but the comments were removed?

3. Layout code to increase legibility

Just as it is important for an author to split a book into chapters and paragraphs that aid reading so it is important for the developer to consider the layout of the code and how that can aid readability of the code. In particular any code branch (an IF..THEN…ELSE construction) and any code repetition (a WHILE…END WHILE construction) should be indented so that it is easy to see where they start and end.

4. Expect the unexpected and deal with it

Before you open a file, make sure that the file is present. Before you set focus to a control, make sure that the control is visible and enabled. Try to work out what conditions could cause your code to fail and test for them before they cause the program to fall over.

5. Name your variables to aid readability

There are a number of strategies to variable naming. The key is to be consistent and to be as informative as possible. If you name a variable nMonth, you give the programmer extra information as to what that variable is expected to contain. I personally prefer the Hungarian notation style – but whichever style you use, consistency is the key.

6. Keep your functions and subroutines simple

A function or subroutine should ideally only do one thing. One of the greatest sources of misunderstandings, in my experience, is a subroutine that does a number of different operations. This should be split into separate functions for each different thing it is doing so that these in turn are easy to reuse, and the scope of a code change is easy to understand.

7. Scope functions and variables appropriately

Functions and variables that are only used in one module should not be visible outside that module. Variables that are only used in a function or subroutine should not be visible outside that function or subroutine. This prevents any use of a variable or function outside of where it makes sense to use it.

There are many other hints and tips which can help you become a better programmer, which will make you more efficient and the programs you write more maintainable, but the seven secrets listed above will serve as a good foundation – however high you build upon them.

When God created father’s…

When the good lord was creating fathers, he started with a tall frame. A female angel nearby said,” What kind of father is that? If you are going to make children so close to the ground, why have you put fathers up so high? He won’t be able to shoot marbles without kneeling, tuck a child into bed without bending, or even kiss a child without a lot of stooping”. And God smiled and said, “Yes, but if I make him child size, who would children have to look up to?”

And when god made a father’s hands, they were large and sinewy. The angel shook her head sadly and said,” Large hands are clumsy. They can’t manage diaper pins, small buttons, rubber bands on pony tails or even remove splinters caused by baseball bats”. And God smiled and said,” I know, but they’re large enough to hold everything a small boy empties from his pockets at the end of the day, yet small enough to cup a child’s face.”

And then God molded long, slim legs and broad shoulders. The angel nearly had a heartattack. “Boy, this is the end of the week all right,” she clicked. “ Do you realize you just made a father without a lap? How is he going to pull a child close to him without the kid falling between his legs?”. And God smiled and said, “A mother needs a lap. A father needs strong shoulders to pull a sled, balance a boy on a bicycle or hold a sleepy head on the way home from a circus.”

God was in the middle of creating two of the largest feet anyone had ever seen when the angel could contain herself no longer. “That’s not fair. Do you honestly think those large boats are going to dig out of bed early when the baby cries? Or walk through a small birthday party without crushing atleast three of the guests?” And God smiled and said, “they’ll work. You’ll see. They will support a small child who wants to ride a horse to Ban bury cross or scare off mice at the summer cabin or display shoes that will be a challenge to fill.”

God worked throughout the night, giving the father a few words but a firm, authoritative voice and eyes that saw everything but remained calm and tolerant. Finally, almost as an afterthought, he added tears. Then he turned to the angel and said,”Now, are you satisfied that he can love as much as a mother?”

– Erma Bombeck

When God created Mother’s…

By the time lord made mother’s, he was into the sixth day of working overtime. The angel appeared and said, “Why are you spending so much time on this one?”. And the good lord answered and said, ”Have you read the spec sheet on her? She has to be completely washable, but not plastic; have 200 movable parts, all replaceable; run on black coffee and leftovers; have a lap that can hold three children at one time and that disappears when she stands up; have a kiss that can cure anything from a scrape knee to a broken heart; and have six pairs of hands.”

The angel was astounded at the requirements for this one…”Six pairs of hands ! No way !” said the angel.

The lord replied,”Oh, it’s not the hands that are a problem. It’s the three pairs of eyes that mother’s must have !”

“And that’s on the standard model?”, the angel asked. The lord nodded in agreement, “Yepp, one pair of eyes are to see through the closed door as she asks her children what they are doing even though she already knows. Another pair in the back of her head, are to see what she needs to know even though no one thinks she can. And the third pair are here in the front of her head. They are for looking at an errant child and saying that she understands and loves him or her without even saying a single word.”

The angel tried to stop the lord “This is too much work for one day. Wait until tomorrow to finish.”

“But I cant !, “ the lord protested , “I am so close to finishing this creation that is so close to my own heart. She already heals herself when she is sick and can feed a family of six on a pound of hamburger and can make a nine year old stand in the shower.”

The angel moved closer and touched the woman, “But you have made her so soft,Lord”. “ She is soft”, the lord agreed, “but I have also made her tough. You have no idea what she can endure or accomplish.”

“Will she be able to think?” asked the angel. The lord replied, “Not only will she be able to think, she will also be able to reason, and negotiate.”

The angel then noticed something and reached out and touched the woman’s cheek. “Oops, it looks like you have a leak with this model. I told you that you were trying to out too much into this one.”

“That’s not a leak…” the lord objected. “That’s a tear !”

“What’s the tear for?” the angel asked.

The lord said, “the tear is her way of expressing her joy, her sorrow, her disappointment, her pain, her loneliness, her grief, and her pride.”

The angel was impressed. “You are a genius, lord. You thought of everything for this one.You even created the tear. !”

The lord looked at the angel and smiled and said, “I’m afraid you are wrong again my friend, I created the woman, but she created the tear. !”