Slashdot Mirror


Programming Mistakes To Avoid

snydeq writes "InfoWorld's Peter Wayner outlines some of the most common programming mistakes and how to avoid them. 'Certain programming practices send the majority of developers reaching for their hair upon opening a file that has been exhibiting too much "character." Spend some time in a bar near any tech company, and you'll hear the howls: Why did the programmer use that antiquated structure? Where was the mechanism for defending against attacks from the Web? Wasn't any thought given to what a noob would do with the program?' Wayner writes. From playing it fast and loose, to delegating too much to frameworks, to relying too heavily on magic boxes, to overdetermining the user experience — each programming pitfall is accompanied by its opposing pair, lending further proof that 'programming may in fact be transforming into an art, one that requires a skilled hand and a creative mind to achieve a happy medium between problematic extremes.'" What common mistakes do you frequently have to deal with?

14 of 394 comments (clear)

  1. Printable version - All on one page by Yuioup · · Score: 5, Informative

    And now for the printable version with all the tips on one page:

    http://infoworld.com/print/145292

    Y

  2. Tests, Manual, Support by programmer. by Barryke · · Score: 5, Insightful

    What common mistakes do you frequently have to deal with?
    - Software only tested by programmer.
    - Manual only written by programmer.
    - Support can't do a day without programmer.

    A good programmer should know when to delegate. Or their boss should. Depends on office culture perhaps.

    --
    Hivemind harvest in progress..
  3. Missing from the article by eagleyes · · Score: 5, Insightful

    The most common programming mistake to avoid: Reading badly written articles about "what programming mistakes to avoid".

  4. Re:do x but not too much! by Chrisq · · Score: 5, Insightful

    Doesn't mistake number 2 contradict number 1? Or am I missing something?

    The whole lot is full of contradictions:

    4: Delegating too much to frameworks 8: Reinventing the wheel
    9: Opening up too much to the user 10: Overdetermining the user experience
    5: Trusting the client 6: Not trusting the client enough

    I think that there is a meta-message, akin to Buddha's middle way. Don't take any rule to extremes.

  5. Re:Programming Mistake #0 by digitig · · Score: 5, Insightful

    True enough. And since every rule has to have a complement, 0a: Assuming that you don't need to learn any of that theory: algorithms, data structures, normalisation and so on

    --
    Quidnam Latine loqui modo coepi?
  6. Programming Mistakes To Avoid by $RANDOMLUSER · · Score: 5, Funny

    1) VB
    2) Perl
    3) Silver bullets
    3) Writing your own "framework".
    4) Using somebody else's "framework".

    --
    No folly is more costly than the folly of intolerant idealism. - Winston Churchill
  7. Re:Mistakes? by Chrisq · · Score: 5, Funny

    I very rarely see programming mistakes.

    Neither do the bad programmers!

  8. Re:#1 - Not managing the pointers and memory yours by dhavleak · · Score: 5, Informative

    #1 - If you are a programmer, BE A PROGRAMMER and manage the pointers and memory allocations yourself. Garbage collection is for little boys. Men deal with it on their own with techniques that work and are efficient.

    So mega-strongly disagree dude. Not saying you shouldn't do heavy lifting when necessary -- just that you should only do it when necessary. Don't re-invent the wheel every time. Frameworks exist that do work for you for a reason. Chose your frameworks well, understand them in depth, and you can do good things. If you "start from the first principles" every time, you end up with a humongous fucking surface of new code -- which is bound to have a nasty bug or three. It comes down to choosing the best tools for the job.

    #2 - Initialize all variables to known values. int i; doesn't cut it. int i=0; does.

    True dat. Lots security pitfalls here too -- not just garden variety bugs.

    #3 - Use descriptive variable names

    So true. Corollary to that: because a variable name is descriptive, don't make wanton assumptions about it.

    #4 - you shouldn't be allowed to program anything new until you've been a maintenance programmer for a few years and seen the crap code that others puke into the world. Your crap code stinks too, BTW.

    I'd modify this to say "always, always, always have a peer-review process". Junior devs are prevented from checking in crap because it gets caught by senior devs. The junior devs also learn quality habits from reviewing senior devs' code. Multiple reviewers is always a good thing. Review your design among the entire team before anyone writes a single line of code. Remember to keep security in mind when reviewing code. Use static analyzers when you're done with the "human" aspect of the review. Apply every imaginable quality bar to your code, and only check it in once it has passed scrutiny.

  9. Re:"Common" mistakes by tudorl · · Score: 5, Funny

    Now that's what I call encapsulation :)

  10. Re:Maintaining code by others are always a nightma by BiggerIsBetter · · Score: 5, Insightful

    There will however always be BAD code by bad programmers. I've taken over Java progress where everything was OOP'ed into hell (as in a bazillion classes more than was needed for the application) and PHP projects which should be OOP'ed but consisted of about 500 files that included each other in a huge confusing net.

    I see this one as a lack-of-experience problem. People have good intentions and want to build scalable, extensible, maintainable code. This is good. Unfortunately however, they're wrong. The apps they're building are small irregardless of the amount of thought they put into them, and they won't have to scale and extend the way they think they might - you don't need interfaces and impls and arbitrary inheritance for everything when the webapp is 4 screens of Spring WebFlow! Sure, if you're building something that warrants it, this is the way to go, but most of aren't building apps that big or flexible. It seems to take time to learn this, and to know when to apply the patterns and when to just build it.

    As a smarter man than I once said, Make things as simple as possible, but no simpler. If you do that, your code will work, it'll be understandable by the next guy, and you'll have a fighting chance of meeting your deadlines.

    --
    Forget thrust, drag, lift and weight. Airplanes fly because of money.
  11. Two Major Mistakes by grcumb · · Score: 5, Funny

    My two most common mistakes:

    1. Variable scoping
    2. Memory leaks
    3. Off-by-one errors
    --
    Crumb's Corollary: Never bring a knife to a bun fight.
  12. Don't get me started by mrjb · · Score: 5, Insightful

    Don't get me started on preventing programming mistakes. If I'd address the most common programming mistakes that I've ran into in the wild and write an article about each of those mistakes at a time, I would end up with a whole book on the matter and would probably call it "Growing Better Software".

    I find the given top 12 list of mistakes a bit weak- I'd be able to avoid all of these and yet write horrible code. My personal recommendation for a top 12 of programming mistakes to avoid would be:

    1. Failing to check function parameters before using them: null pointers, limits, lengths, etc. This will make your program unstable and/or unpredictable.

    2. Spending too little time thinking about and designing the data structure of the application. This will make you get stuck when maintaining/extending your application.

    3. Following every market hype - When the marketing bubble bursts, you'll have to start over again.

    4. Designing user interfaces without actually involving users - You'll be surprised how easy it is to confuse users.

    5. Infinitely deeply nested if/else statements - This will make code absolutely unreadable.

    6. No documentation whatsoever - Who's going to maintain your code after you change jobs?

    7. Ignoring existing, universally accepted standards - so you'll cause interoperability issues or be doomed to either reinvent the wheel.

    8. Hard-coded values/magic numbers - as a result, any change must be made in code rather than allowing power users to configure their own system.

    9. Littering code with global variables - this implies statefulness of code, making it pretty near impossible to predict how a function will behave next time it is called.

    10. Being unaware of the "Big O" order of your algorithms, causing code to be unnecessarily inefficient.

    11. Strong platform dependency: This can shorten the lifetime of your application to whenever the next platform upgrade takes place, or keep you stuck at the current version of the current platform forever.

    12. Thinking you can figure out everything by yourself - In learning by doing, experience can only follow from making mistakes. By getting yourself a mentor or an education, you can actually learn from the mistakes that thousands have made before you.

    13. Stopping at 12.

    --
    Visit http://ringbreak.dnd.utwente.nl/~mrjb/growingbettersoftware to download your free copy of the book
  13. Re:"Common" mistakes by Just+Some+Guy · · Score: 5, Informative

    UK doctors leave 722 objects inside patients in 1 year

    That's actually not the fault of the doctor, except in the "it's his O.R. so anything that happens in it is his responsibility" sense.

    The "circulating" tech or nurse is the non-sterile person who fetches stuff out of cabinets, opens packages, and makes notes like "opened a package of 10 sponges" (typically by making a row of checkmarks on a pre-printed form).

    The "scrub" tech or nurse is the sterile-gowned-and-gloved person standing next to the surgeon who passes instruments, puts knife blades on the scalpel handles, loads the needle drivers, and keeps track of the gazillion tiny pieces to everything. There are so many removable parts because everything has to be able to be broken down into pieces small enough to clean, sterilize, and package, and part of preparing for a surgery is re-assembling all the stuff so it'll be ready if the surgeon needs it.

    The circulators and scrubs work together as a team. The circulator will say stuff like "here's the 10-pack of sponges", and the scrub will relay messages like "I counted them and there are 10 sponges there" or "I opened a package of 5 needles and there are actually 5 needles". The circulator will check off "10 sponges" or "5 needles" or "bolt and wingnut for the retractor" to build a list of everything that has been opened in the room which could possibly fit inside someone.

    At some point, the surgeon will say, "OK, I'm getting ready to close". At this point, "the count" begins. The circulator will ask how many needles the scrub has, and the scrub will answer (including the one that the surgeon is actively using at that moment). If the counts match, the circulator will check off "needles" and move on to sponges, or knife blades, or wingnuts, or whatever else they'd opened earlier. When they're done, the circulator will announce that the count is correct and the surgeon will finish closing, which they're already well into by this point because the count is pretty much always correct.

    Except when it's not.

    The biggest ass-chewing I've ever received in my life was when I was in the Navy and scrubbing for some captain and we couldn't reconcile the number of sponges. One was missing, and the presumption was that it was still inside the patient. After a few minutes of pissed-off-high-ranking-officer-screaming, they wheeled the patient out anyway and prepared to X-ray them to find the missing sponge. Ideally, everyone would stop what they're doing and stand around while we searched, but the realities of surgery are that the anesthesiologist plans the sleeping and waking cycles and you really don't want to start putting them back down into deep anesthesia or keep them down longer than absolutely necessary.

    So, we tore the room apart. We moved cabinets. We dismantled the surgical table. We dumped all the trash - clean and hazardous - onto the floor to dig through it. The captain would periodically stick his head in to ask why the hell we hadn't found the f'ing sponge yet and what the hell was wrong with us and did we know whether this was a courtmarshalling offense.

    Finally, the anesthesia resident - a much lower-ranking officer fresh from med school - sheepishly asked what a sponge looked like. Turns out, one had fallen on the floor during the case and he'd "helped" us keep the room clean by throwing it in the anesthesia trash that he was responsible for.

    As an enlisted person, that was the one time in my career that I actually yelled at an officer (who had the good grace to accept that he'd screwed up and had it coming to him). He went and told the surgeon what happened, X-rays were avoided, courtmarshalls were cancelled, and we scrubbed the room down from ceiling to floor because we'd strewn bloody trash all over the place while digging through it.

    Anyway, so yeah. The counts are ultimately the responsibility of the surgeon, but the surgeon is not the person who actually does the counting - nor could they possibly be expected to without dramatically lengthening the time a patient would have to spend under anesthesia. Behind every object left inside a patient is a scrub and/or circulator who accidentally miscounted or who lied on the count sheet to hide their screwup.

    --
    Dewey, what part of this looks like authorities should be involved?