Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Avoiding silly programming mistakes

by tilly (Archbishop)
on Aug 24, 2008 at 06:02 UTC ( #706496=note: print w/ replies, xml ) Need Help??


in reply to Avoiding silly programming mistakes

Dumb mistakes that are caught immediately are not a problem. The figure that I've heard is that on average 1 line in 10 of code as initially typed has a mistake of some sort. That figure isn't unique to programming - it seems to be a fairly standard cognitive failure rate in humans that shows up in everything from errors made in formulas in spreadsheets to typos while writing. And it isn't a problem if most of the time you catch the error almost immediately. (For a similar phenomena think about how often you hit backspace while you're typing.)

The problem seems to be innate. To the best of my knowledge, you can't really reduce the rate of initial errors. Therefore you need to focus on how you catch errors. People have offered a number of suggestions. There are tools. People have mentioned strict.pm and syntax highlighting. There are programming strategies to give you additional cognitive cues. Things like making boolean variables be given names that are yes/no questions which the value is an answer to. The book Code Complete 2 has a lot of very valuable advice on that. There are practices like having good unit tests. And then there is the simple experience of having seen and caught certain mistakes so often that you're just on the lookout for them.

Now there is a funny phenomena. Which is that once you adopt strategies to correct these errors, the frequency with which you make them tends to go up! Why? Well it is because there is a lot that you have to think about during programming. As you get better, you devote less brain power to catching your trivial errors before they are made, and more to keeping track of the "big picture". This is actually a good thing. You see by adopting practices that immediately capture the trivial errors you make them utterly harmless. And the extra attention on the big picture results in better designs, better approaches, better code, and fewer of the really serious errors that could cost you a lot in the long run.

And one of the big picture items to keep track of is your sleep. It is sad, but one of the first things that goes when our mental functioning is impaired is our ability to judge how impaired we are. Which means that when you impair yourself, for instance by sleeping too little, you have no real monitor of how badly impaired you are. And the effects of lack of sleep are pretty serious, particularly for programmers. If you're noticing it, you need more sleep, then trust me, you would benefit a lot from having it.


Comment on Re: Avoiding silly programming mistakes
Re^2: Avoiding silly programming mistakes
by missingthepoint (Friar) on Aug 24, 2008 at 06:13 UTC

    And the effects of lack of sleep are pretty serious, particularly for programmers

    Ewww... Tell me about it. The number of times are legion I've hacked on a piece of code when tired, only to go back the next day after a good sleep and think "What was I thinking?". Unfortunately caffeine just doesn't substitute for sleep when it comes to cognitive function. :)


    email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'
      Isn't it more like "WTF was I thinking?" :)

        Well, that depends on the stupidity of what I wrote. Sometimes, yes :)


        email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'
Re^2: Avoiding silly programming mistakes
by planetscape (Canon) on Aug 24, 2008 at 10:38 UTC
    And one of the big picture items to keep track of is your sleep. It is sad, but one of the first things that goes when our mental functioning is impaired is our ability to judge how impaired we are. Which means that when you impair yourself, for instance by sleeping too little, you have no real monitor of how badly impaired you are. And the effects of lack of sleep are pretty serious, particularly for programmers. If you're noticing it, you need more sleep, then trust me, you would benefit a lot from having it.

    In addition to tilly's very valid points about sleep (I just spent the better part of the last two days getting caught up myself), I'd also like to point out the importance of doing something, anything - walking, running, biking, swimming, whatever works - to get your body moving and blood flowing to your brain. You don't have to be a world-class athelete. You just have to do it. The benefits are more than worth it, and not just to your mental concentration.

    Now, where're my biking shoes?

    HTH,

    planetscape
      Let me support that by pointing out that research has found that regular aerobic exercise results in better short-term memory. Since programmers often have to keep multiple things in short term memory, improvements there are very helpful.

      Note that the effect is very specific to aerobic exercise. It does not happen with, say, weight training. The cause is believed to be that regular aerobic exercise improves blood flow, and the brain responds to blood flow.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://706496]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-08-30 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls