Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Programming

Programming Mistakes To Avoid 394

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?
This discussion has been archived. No new comments can be posted.

Programming Mistakes To Avoid

Comments Filter:
  • by Yuioup ( 452151 ) on Tuesday December 07, 2010 @05:23AM (#34471354)

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

    http://infoworld.com/print/145292 [infoworld.com]

    Y

    • by CountBrass ( 590228 ) on Tuesday December 07, 2010 @06:56AM (#34471766)
      '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.' Bullshit. Programming has always been an art that required skill and a creative mind. The only people who have claimed otherwise have been managers, who would prefer all techies were interchangable cogs, and crap programmers: the gimps and muppets of our trade.
      • by commodore64_love ( 1445365 ) on Tuesday December 07, 2010 @07:04AM (#34471818) Journal

        >>>Programming has always been an art that required skill and a creative mind

        plus logical thinking (like the machine you're programming). It always surprised me when my Professor/Director of Engineering said programming should not be considered a "science" or "engineering". He said they were the equivalent of bus drivers - just human beings running a machine.

        At first I thought, 'Well maybe he has a point' but no not really. Driving a machine is a skill that can be learned in a day or two. Programming a machine requires years - the same amount of time needed to learn any engineering discipline.

         

        • by AmiMoJo ( 196126 )

          I think driving is pretty similar. You can learn it in a few days of intensive training but if you want to be a really good driver you need to stick to best practices and learn how the car itself works and what its limits are.

        • by olau ( 314197 ) on Tuesday December 07, 2010 @11:31AM (#34474920) Homepage

          That's because your professor learnt it in a day or two and now thinks he's a star programmer, while the sad truth is more like he's years from producing anything better than the crap beginners can crank out. As far as I can tell, most professors are at that level when it comes to programming. So none of his co-professors have probably corrected him. I've heard a Ph.d. refuse our explanation of why our SML student project processing strings as lists was slower than gzip (written in C) with "but they have the same time complexity".

          It has the depressing side-effect that people in college are being thought principles that the real star programmers shy away from, while nobody is working on hammering the really important ones into them.

          Of course, there are exceptions to this generalization.

      • And a lot of graphic/physical artist. I've seen many who do graphic arts, drawing and painting, who seems to think that if you are in any computer programming or science field, you have no creativity.

        • by LO0G ( 606364 )

          I had a friend in college [harvard.edu] who got a double major in art and electrical engineering. When I asked her why she was working in such different fields, she responded that to her art and electrical engineering were both forms of art.

          For some reason this has stuck with me for decades (yeah, I'm an old guy).

  • by Barryke ( 772876 ) on Tuesday December 07, 2010 @05:28AM (#34471378) Homepage

    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.

    • by Tridus ( 79566 ) on Tuesday December 07, 2010 @08:24AM (#34472270) Homepage

      Don't think thats the fault of the programmer in a lot of cases. I'd love to have someone in my office to write a manual and do proper QA. But the budget doesn't include those things, and I don't get to set the budget.

      Sometimes the reality is that you either get a program that doesn't have those things, or you try to do those things and don't have enough money to build anything.

      • by Jimmy King ( 828214 ) on Tuesday December 07, 2010 @08:49AM (#34472588) Homepage Journal

        I agree. This is a very big problem for me as management keeps cutting back the tech staff where I work.

        I write the code, I test the code, I write the docs for people. I've tried explaining over and over again that this is terrible. I shouldn't be the final tester. I already think it works or I wouldn't have written it that way and wouldn't be at the point of testing. This affects my testing and causes me to miss things. I also know how it's supposed to work too well and so don't even think to try stupid stuff that users inevitably do which breaks stuff.

        Documentation is similar. I know how it works and how it was intended to work. At times this makes things obvious to me that are not necessarily obvious to someone else and so they may not find their way into the documentation.

    • by Lumpy ( 12016 )

      Unrealistic timetables... Your testing prototype ends up as the shipped code.
      Senior programmer helps on the project... Yay we get old code we have to re-write for him.
      Engineering gives us a craptastic design that we have to program around the limitations or problems in the platform. Causing a kludge that we pray will not unravel after it ships.

      Those three I see nearly monthly.

  • by Anonymous Coward on Tuesday December 07, 2010 @05:32AM (#34471390)

    ...just try to avoid errors and you should be set.

    • by Anonymous Coward on Tuesday December 07, 2010 @10:15AM (#34473688)

      ...just try to avoid errors and you should be set.

      But Warnings are ok. Just no errors. Warnings still compile.

      • by jekewa ( 751500 ) on Tuesday December 07, 2010 @12:34PM (#34475980) Homepage Journal

        I know you're being factitious, but software compiled with "acceptable warnings" may also lead to runtime failures.

        I once had a job writing C++ software where the lead made us write code with zero warnings, turning the compiler to the most strict. Justifiable suppression was allowed (for example, in cases of ambiguous type-casting from library headers). While I thought this was overkill, we were internally hired to help a group whose software was woefully unreliable; turns out they went the other way, turned off all compiler warnings and suppressed some "acceptable" errors. Correcting their errors and compromising on some of their warnings brought the quality of their software to at least a stable level.

        There is a middle ground, but I've chosen to go with the zero-tolerance route on warnings; they're easy to get rid of, and encourage careful and thoughtful use (and even abuses).

        A good rule of thumb is that if your IDE or compiler is complaining about it, you probably left yourself open for a failure.

        Of course, not having any warnings doesn't prevent errors due to bad logic...that's a whole other ball of flame-bait.

  • Until you spend enough time with it, to learn why the original programmer did as he did.

    As I see it, most projects start out with a good structure and the best of intentions, and then comes deadlines and the developer having to juggle several projects at once, and then a shortcut is taken here, then there. And suddenly you end up with a non-documented project where the only person that knows how it works is the original developer.

    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've also had to take over projects where the original developer was using new technology because he thought it would be fun (at the expense of the customer). Having a huge website in PHP/MySQL and then having crucial parts of it in Ruby/PostreSQL is just a maintenance nightmare.
    • All true. My personal favorites are larger, long running projects where all of the above is true and all kinds of undocumented business logic is embedded in the code making a rewrite unfeasable and you have to decide which part of the code is outright sloppy or bad, which parts are feasable and which parts aren't actually being used anymore. Top that off with the original developers being unavailable (either dead or fleeing) and you'd be painting a pretty accurate run-of-the-mill software enviroment.

    • by BiggerIsBetter ( 682164 ) on Tuesday December 07, 2010 @07:09AM (#34471842)

      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.

    • by Savage-Rabbit ( 308260 ) on Tuesday December 07, 2010 @09:49AM (#34473356)

      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.

      Taking over projects fitting those descriptions is never a good idea. They are nothing but pain, it's impossible to resolve the problems with the app and the code unless you opt for a complete rewrite. If, however, you go that route the remaining developers will be pissed off because they wrote the crappy code and you are basically saying that their ugly baby is ... well ... UGLY! What's worse, you are saying it out loud for everybody including the PHBs to hear. Eventually you end up being frustrated, your PHB either caves in to complaints about you and puts you in your place or you get laid off. Unless, of course, you anticipate this and quit before he gets the chance. There is no substitute for writing code properly and designing and planning your application properly no matter how insignificant the application seems to be because you will never know which piece of shit app will take off and scale into something much, much bigger. Myself, I learned this from a friendly lecture I was given by my boss after I handed in my first project on my very first job. He made me rewrite the thing entirely claiming it was better that I learned the value of things like database abstraction and MVC separation right away. He was right.

  • Learing how to do it in the first place.

  • Programming mistake No. 1: Playing it fast and loose
    Failing to shore up the basics is the easiest way to undercut your code. Often this means overlooking how arbitrary user behavior will affect your program. Will the input of a zero find its way into a division operation? Will submitted text be the right length? Have date formats been vetted? Is the username verified against the database? Mistakes in the smallest places cause software to fail.

    Fair enough. So debug while you code. Seems like good advice.

    Programming mistake No. 2: Overcommitting to details
    On the flip side, overly buttoned-up software can slow to a crawl. Checking a few null pointers may not make much difference, but some software is written to be like an obsessive-compulsive who must check that the doors are locked again and again so that sleep never comes.

    Doesn't mistake number 2 contradict number 1? Or am I missing something? I guess he's saying debug while you code, but not too much. After reading the rest I see that that was his algorithm for writing the whole article. Rule 1: do x; Rule 2: But not too much! I didn't really find the article all that useful.

    All programming should be assembly language programming anyway and a lot of his rules don't seem to apply to assembly language programming. R

    • by Barryke ( 772876 ) on Tuesday December 07, 2010 @05:50AM (#34471484) Homepage

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

      Yup. FTA:

      Below you will find the most common programming pitfalls, each of which is accompanied by its opposing pair, lending further proof that programming may in fact be transforming into an art -- ...

    • by Chrisq ( 894406 ) on Tuesday December 07, 2010 @05:52AM (#34471492)

      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.

      • by turbidostato ( 878842 ) on Tuesday December 07, 2010 @07:39AM (#34471996)

        "The whole lot is full of contradictions"

        No, it isn't. It goes "don't do that... but don't fall in the other extreme".

        That's on line with his central idea that programming is "an art, one that requires a skilled hand and a creative mind to achieve a happy medium between problematic extremes".

      • by syousef ( 465911 )

        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.

        Confucious say: This one skitzo mutherfucker

    • Fair enough. So debug while you code. Seems like good advice.

      s/debug/test/

  • by eagleyes ( 737026 ) on Tuesday December 07, 2010 @05:43AM (#34471438)
    The most common programming mistake to avoid: Reading badly written articles about "what programming mistakes to avoid".
  • I very rarely see programming mistakes. There seems to be 2 kinds of programmers.

    - Those who care about what they do and try hard.
    - Those who don't care about what they do and don't try hard

    The later write terrible code, but it is just because they are either lazy or aren't suited to the profession and can't get enthused. Very rarely do you see someone who cares about there work make a big mistake (and if so they are probably just starting out).

    • by Chrisq ( 894406 ) on Tuesday December 07, 2010 @06:30AM (#34471642)

      I very rarely see programming mistakes.

      Neither do the bad programmers!

    • by syousef ( 465911 )

      Very rarely do you see someone who cares about there work make a big mistake (and if so they are probably just starting out).

      Really? I see it all the time from very intelligent but inexperienced programmers. I've seen a few spin their wheels and end up depressed about their whole job.

  • by Voulnet ( 1630793 ) on Tuesday December 07, 2010 @05:57AM (#34471504)
    Programming mistake #0: Believing that your computer degree (Computer Engineering or Computer Science alike) automatically puts your code in a high level of quality.

    Not to bring any academia vs industry argument, but many students miss the idea of a Computer degree with programming courses in it: The degree intentionally doesn't go to details because it needs to give you a background into a broader set of subjects. Industry needs one to be very attentive to details in that one thing he's doing at the moment.
  • "Common" mistakes (Score:5, Insightful)

    by Alex Belits ( 437 ) * on Tuesday December 07, 2010 @05:57AM (#34471506) Homepage

    The only common mistake I see is not firing the programmer who makes any of those "common" mistakes. There is absolutely no reason for any of this shit to be "common" unless "programmers" who make them are uneducated dumbasses who should never be allowed anywhere near software development.

    Now, please, give me the list of "common mistakes" made by surgeons and aircraft engineers, and compare them with this list of amateurish crap.

      • I really could not find much data, but the total number of surgical
        procedures performed in the U.S. per year is around 70 million. I'd expect the UK to have at least 10% of that. That means about 700 lost objects for 7000000 procedures, 1 in 10000. Pretty good track record, although these are not the only mistakes to happen of course.

      • by tudorl ( 841940 ) on Tuesday December 07, 2010 @06:47AM (#34471728)
        Now that's what I call encapsulation :)
      • I would have that patient(*) arrested for trying to steal a complete surgery unit...

        As per TFA (as I only read them once every while, when I read it I quote it), it just states 6 issues (security, user freedom) and says "don't do it too much, don't do it too little"). Useless, because the point is knowing exactly what is too much or too little.

        *: I know it says "patients"... but the joke is worth it..

      • Re:"Common" mistakes (Score:5, Informative)

        by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Tuesday December 07, 2010 @12:32PM (#34475946) Homepage Journal

        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.

    • While I agree with what you say, the problem is that bad programming is largely the result of cultural personality shift.

      Lately, I have been taking some classes on web development... yeah I don't know Photoshop, Illustrator or Flash particularly well -- I like text editors though dreamweaver is growing on me. There is one person in the class who is all about shortcuts. He doesn't want to understand anything, he just wants "results." He's a business man who runs a company that is all about outsourcing. H

  • Pointer typedefs (Score:5, Insightful)

    by QuoteMstr ( 55051 ) <dan.colascione@gmail.com> on Tuesday December 07, 2010 @06:14AM (#34471564)

    Pointer typedefs were a bad idea in the 1980s. They're just terrible today. One pet peeve of mine is this:

    typedef struct _FOO { int Blah; } FOO, *PFOO;

    void
    SomeFunction(const PFOO);

    That const doesn't do what you think it does. There was never a good reason to use pointer typedefs. There is certainly no good reason to do so today. Just say no. If your coding convention disagrees, damn the coding convention.

    • People DO THAT???

    • That const doesn't do what you think it does.

      It never does.

      • That const doesn't do what you think it does.

        It never does.

        Fundamental rules of programming -

        1. Constants aren't.
        2. Variables won't.
    • Pointer typedefs were a bad idea in the 1980s. They're just terrible today. One pet peeve of mine is this: typedef struct _FOO { int Blah; } FOO, *PFOO;

      void SomeFunction(const PFOO);

      That const doesn't do what you think it does. There was never a good reason to use pointer typedefs. There is certainly no good reason to do so today. Just say no. If your coding convention disagrees, damn the coding convention.

      Care to elaborate (on pointer typedefs and the CONST PFOO usage)? Honest question from someone that hasn't touched a C/C++ for the last 12 years and is trying to clear the cob webs.

      • Re:Pointer typedefs (Score:4, Informative)

        by Psychotria ( 953670 ) on Tuesday December 07, 2010 @06:48AM (#34471732)

        Pointer typedefs were a bad idea in the 1980s. They're just terrible today. One pet peeve of mine is this:

        typedef struct _FOO { int Blah; } FOO, *PFOO;

        void
        SomeFunction(const PFOO);

        That const doesn't do what you think it does. There was never a good reason to use pointer typedefs. There is certainly no good reason to do so today. Just say no. If your coding convention disagrees, damn the coding convention.

        Care to elaborate (on pointer typedefs and the CONST PFOO usage)? Honest question from someone that hasn't touched a C/C++ for the last 12 years and is trying to clear the cob webs.

        The pointer is constant... not what it "points to" and the typedef "hides" that

      • Re:Pointer typedefs (Score:5, Informative)

        by $RANDOMLUSER ( 804576 ) on Tuesday December 07, 2010 @06:56AM (#34471762)
        His point was that a PFOO is a POINTER to a struct _FOO, and so when you say void SomeFunction(const PFOO), you're saying that the POINTER is constant, not the thing being pointed to, which is probably not what was intended. Since the definition of PFOO is located elsewhere, probably in another header file, it's easy to get yourself confused as to what data type you're dealing with.
    • The obvious reason you might want a typedef like that is for a mostly-opaque data-structure, where you have several different implementations, some of which require a level of indirection, some of which don't. (The "mostly" in "mostly-opaque" is there to mean that calling code never accesses the type directly, but the type is complete, so the compiler can put it on the stack).

      In short - pointer typedefs are good for the times when you really want to say "this is data of some type, maybe a pointer, maybe a

    • by Arlet ( 29997 )

      My pet peeve is the unnecessary use of the underscore in struct _FOO. I prefer this:

      typedef struct foo { int blah; } foo;

      I hate caps too, except for constants.

    • Comment removed based on user account deletion
  • He gives one example of an attempt to avoid null pointer errors in Java next:

      public String getFirstName(Person person) {
                return person?.getName()?.getGivenName();
            }

    But is it a good idea to use null to mean "no value specified"? What would be better, and what are the tradeoffs? Storing 0 or ""? Storing a special (constant/static) instance object nullValue?

    • by Chrisq ( 894406 )

      He gives one example of an attempt to avoid null pointer errors in Java next:

      public String getFirstName(Person person) { return person?.getName()?.getGivenName(); }

      But is it a good idea to use null to mean "no value specified"? What would be better, and what are the tradeoffs? Storing 0 or ""? Storing a special (constant/static) instance object nullValue?

      I think it is useful to collect the NULLs together to deal with at a higher level - a quick way to deal with a null person, name, or given name identically.
      Scala has a type "None [sanaulla.info]" that does mean no value specified. I haven't got my head over the trade-offs, pros and cons but it seems to work nicely in case statements.

    • Anything as long as it's consistent.

      And "fixing invalid values" is a completely retarded idea to begin with.

  • by $RANDOMLUSER ( 804576 ) on Tuesday December 07, 2010 @06:27AM (#34471628)
    1) VB
    2) Perl
    3) Silver bullets
    3) Writing your own "framework".
    4) Using somebody else's "framework".
    • Whenever yo hear "framework", run like hell.

    • I don't see many problems using a well-defined, well-supported framework you are familiar with.

      Of course, the part of being familiar with it means an overhead that can be important. If you are just going to use it once, maybe it is not worth the time using it (if it is optional). But once you get to know it, many of them are good at solving the issues they were created for...

      If we follow the trend of "frameworks does not serve at anything", we'll be back to programming in assembly soon.

    • If you need a framework - your language is not suitable - Ruby is a scripting language not really designed for web transactions, that's why rails was invented

      If your language allows you to do any of these mistakes ask yourself if you need the power it gives you, if you do then it's your responsibility to not do these, if you can't/won't avoid these use a language that manages it for you ....

  • GOTO... (Score:4, Funny)

    by Ecuador ( 740021 ) on Tuesday December 07, 2010 @06:29AM (#34471634) Homepage

    Is it indecent of me to reminisce on the days of olde when such a topic would simply turn into a lengthy discussion mocking BASIC programmers?

    • Not really. VB grew up (it is now just java with syntactic sugar). PHP, on the other hand, is going back to the 80s of the previous century.
    • You won't believe how many GOTOs I see regularly in our C/C++ sources :(

      • by syousef ( 465911 )

        Worst commerical code snippet I've seen looked something like.

        a *= 0;
        b *= 1;

        Single letter variable names, and code that multiplies one variable by 0 and the other by 1 indicate the programmer was either bored or making a pathetic attempt to keep their job by obfuscating the code.

  • Is this real? (Score:5, Insightful)

    by Psychotria ( 953670 ) on Tuesday December 07, 2010 @06:38AM (#34471684)

    I've not worked as a programmer for, hmm, maybe 15 years and all of this was known way back even before I "retired" from that line of work. Perhaps all these levels of abstraction upon abstraction make things harder to understand. Back in my days these "pitfalls" were obvious because we all (well, not all, but a lot) knew ASM and actually even used it regularly (even inline, *shudder*).

    Someone above mentioned pointer typedefs and gave the example of typedef struct { int Blah; } FOO, *PFOO; (yes I left off the bit before the the opening brace deliberately.) and then suggesting that people don't know that void SomeFunction (const PFOO) {} doesn't behave as expected. Now this could, I suppose, be seen as a failure of the language. But, shit, any idiot who understands the underlying logic can see why that causes problems. Which goes back to my point of maybe all these modern levels of abstraction and getting away from the machine are, in some ways, detrimental.

    Now, get off my lawn. Umm, except I don't have a lawn because I sprayed the growth inducing hormone RoundUp all over it, but that is beside the point. I think.

    • "I've not worked as a programmer for, hmm, maybe 15 years and all of this was known way back even before I "retired" from that line of work."

      Yes: there's an obvious problem with programming and it's that "we" as a guild are not building upon past experience. For the most part, the current generation of programmers are making the same kind of mistakes that where common -and learnt how to avoid, even 20 years ago. Can you imagine, say, aviation if you had to engineer an Airbus 380 all the way from Otto Lili

  • I did went throught the list in TFA and while their "programming mistakes" list is sound, it's all over the place and often doesn't dig down to why should you do or not a certain thing.

    So I decided to put down a list of, low level principles and concerns to consider when doing software. Given my own level of experience and the fact that I'm getting tired of maintining code by people who have never managed to cross the threshold from junior/medior software designer to senior designer, that is the target audi

  • Make sure the code in your article compiles or is even legal syntax. The following is supposedly sample Java code:

    public String getFirstName(Person person) {
    return person?.getName()?.getGivenName();
    }

    WTF?

    • My two questions when reading that:

      1. If there is a null pointer in there, what would the return be?

      2. Would the return be any more useful than the default mode (which would be crash + burn)?

  • Half of these are design mistakes

  • Just add more code! That always makes it better. Closely followed by "It's unreliable/broken" "We've got to rewrite that old xxxx in m$'s new blah-ty-blah framework!".
  • by grcumb ( 781340 ) on Tuesday December 07, 2010 @07:25AM (#34471926) Homepage Journal

    My two most common mistakes:

    1. Variable scoping
    2. Memory leaks
    3. Off-by-one errors
  • by petes_PoV ( 912422 ) on Tuesday December 07, 2010 @07:28AM (#34471944)
    By the time the coding starts, most projects are already doomed. The basic mistakes that occur before any code is written have a far greater effect on the project. While these are almost all outside the control of the programmer, he/she always gets the blame due to the "last person who touched it, broke it" principle. My short list of favourites would be:

    Allowing too many options / features in the design. The classic example being unable to decide whether feature A or B is best, and ducking the issue by including them both

    Assuming 5 working-days of effort can be achieved in a working week. Conveniently forgetting about all the office overheads such as "progress" meetings, timesheet administration, interrupted work, all the other concurrent projects. Even the most efficient, single-threaded operation needs half a working-day per week just for the trivia.

    Following on from that, conveniently forgetting about annual leave commitments, national holidays and the possibility of sickness. If 5 working-days per week is impractical, 12 working-months in a year is downright negligent.

    The tacit assumption that testing will inevitably be followed by reelase - rather than bug-fixing.

    Holding the end-date constant while delaying the start, or presuming that all delays in the specification, design, approval stages can somehow be reclaimed during coding (how: by thining faster?)

  • by rgravina ( 520410 ) on Tuesday December 07, 2010 @07:36AM (#34471978)

    The biggest programming mistakes I've had the displeasure of making, or discovering in others code, almost always centre around one of these two problems:

    1. The code is over-engineered
    2. The code was abstracted before there was even a need for the abstraction.

    I remember when I was less experienced, how thrilled I'd be over code that was clever, solved many problems aside from the one I was trying to solve, and had some clear reusability built in. What a work of art, I thought.... until I eventually realised that much of the extra code I had written didn't get used, the abstracted code was never reused - or even if it was, I couldn't predict how it would be reused and the abstraction was clumsy at best, useless at worst.

    It's sad when this happens - good intentions, but the end result is a lot of waste. I'm embarrassed to look over my earlier code which is like this.. I like to think I do it less now, but the temptation is always there... I'm going to need to do this later anyway... I can just abstract this bit here and reuse it some day in the future...

    My advice now... Don't do it! Just wait until the reuse case comes along, or the new feature request comes along, and *then* do it. You'll know so much more about the problem domain then, or you might avoid days (weeks!) of wasted effort.

  • >> '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.'"

    Its not transforming into it, it's always been an art. And that has got nothing to do with whether its web programming or not.

    The reason that this is even news to some people is that most managers fight hard to bury that fact, because the vast majority of them are one-trick ponies that incorrectly think that everything can and should be

  • by mrjb ( 547783 ) on Tuesday December 07, 2010 @08:48AM (#34472578)
    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.
  • by GodfatherofSoul ( 174979 ) on Tuesday December 07, 2010 @12:59PM (#34476420)

    When we migrated to C++ a while back, my biggest gripe became the number of projects, library, et.al. that weren't documented. I won't name the very popular library, but when I contacted the developers (I was still new with C++ at the time), they told me to "read the headers." Your code is not documentation, no matter how well you comment your functions. There's a subculture out there that I don't get that has the mindset that "it was hard to write, it should be hard to use" (and that's almost a direct quote from a library author). I don't know if it's job security, elitism, nepotism, or what. But, with some projects there's a cold disregard (borderline hostility) towards the people who will actually be using the product.

You will lose an important tape file.

Working...