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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||