Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Best and Worst Coding Standards?

Posted by Soulskill on Sun Jul 20, 2008 08:21 AM
from the buffer-overrun dept.
An anonymous reader writes "If you've been hired by a serious software development house, chances are one of your early familiarization tasks was to read company guidelines on coding standards and practices. You've probably been given some basic guidelines, such as gotos being off limits except in specific circumstances, or that code should be indented with tabs rather than spaces, or vice versa. Perhaps you've had some more exotic or less intuitive practices as well; maybe continue or multiple return statements were off-limits. What standards have you found worked well in practice, increasing code readability and maintainability? Which only looked good on paper?"
+ -
story

Related Stories

This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • by AndGodSed (968378) on Sunday July 20 2008, @08:24AM (#24261601) Homepage Journal

    Sound an awful lot like coding in C... no bad coding practice needed...

    • by laejoh (648921) on Sunday July 20 2008, @09:48AM (#24262235)

      Now that we're talking about 'languages that invite bad coding practices'... Well, one of the best programming books I've read is 'Perl Best Practices'. Not only does it list out best practices but it tries to explain (well I might add) why you should code a certain way and why other ways aren't good to follow.

      One of the habits I picked up from 'Perl Best Practices is:

      if (condition) {
      }
      else {
      }

      instead of:

      if (condition) {
      } else {
      }

      The else tends to get 'lost' when just following the closing bracket.

      • by Maxmin (921568) on Sunday July 20 2008, @10:52AM (#24262791)

        "no NO!! Must not put elses near braces, my precious!" - Larry Wall

        I, for one, have never understood Larry's War on Cuddled Elses. It's almost symptomatic of OCD.

        Besides, how is the "else" getting "lost?" I mean, it's only two characters from the left margin! Saves lines too.

        Maybe it's that I prefer reading source that is not so vertically spread out. The more code and logic on the screen, the better. Density factor.

        • by Doctor Crumb (737936) on Sunday July 20 2008, @02:33PM (#24264935) Homepage

          Density is the opposite of readable and maintainable. One of the main aspects of maintainable code is being able to find and change a single line of code quickly and without having to worry about breaking other nearby lines. Having more code per line means it takes that little bit longer to find and is that little bit riskier to change the one line of code. "Lost" in this case is only a minor delay, but when you add that delay up across several thousand bugs (i.e. any project in the Real World), it means you are wasting your time tracking down bugs in dense code rather than adding new features or working on other projects.

          Pop quiz: find and remove the bracketed clause in the above paragraph. Then think about how much faster you would have done that if it had been on its own line. Then think about how much faster you could have done that to 100 different paragraphs. It may not make a difference on the projects you work on, but in something the size of a perl interpreter or a web browser, it makes a huge difference.

          • by telbij (465356) on Sunday July 20 2008, @04:25PM (#24265789)

            Density is the opposite of readable and maintainable.

            Bollocks. It's a tradeoff just like every other debate in the programming world. Sure, Perl gives you the ability to put way to much code on a single line. But the opposite problem of putting loads of white space all over the place is almost as bad.

            The more you spread out the code, the more you have to scroll. White space is valuable when it means something, like to separate discrete tasks within a long function. But the whole


            }
            else {

            thing is just a waste of space. It's one line less of code I can see. I visually parse } else { instantaneously. Similarly, some compound expressions or chained method calls make perfect sense. The right place to break out multiple lines depends on the reader's own cognitive abilities and familiarity with the symbols being manipulated.

            Otherwise
            writing
            like
            this
            would
            be
            much
            easier
            to
            read

              • by telbij (465356) on Sunday July 20 2008, @09:30PM (#24268545)

                I've been a professional developer for 8 years and I've never spent significant time dealing with that bug. I'd rather have the code consistent than have it one way or the other. Developers have strong feelings about these things because of our attention to detail. But the sign of a good programmer is being able to say, "It's not worth my time to even think about this". If it was a clear win one way or the other then of course I'd get on board. But it's not. Being able to see more code on one screen has value.

          • by Maxmin (921568) on Sunday July 20 2008, @05:21PM (#24266245)

            My dear Doctor, readability metrics boil down to personal tastes - subjective, in other words. While perhaps what you choose is even the preference of the majority of coders, it's not mine.

            Advocating for braces and the negatory conjunctive "else" on the same line is not the same as "having more code per line," e.g. more than one statement per line.

            In the responses to the OP, we've if/else on three lines-

            if (...) {
            ...
            } else {
            ...
            }

            -and six lines-

            if (...)
            {
            ...
            }
            else
            {
            ...
            }

            Whilst reading six lines is not a problem for me, I prefer the three line variant, as it means less scrolling over slow ssh connections. Thank goodness we have automagic reformatting IDEs for those who won't accept other formats.

            However -- it is a sorry state of affairs that on /. the replies to an enquiry about "coding standards" end up focusing on code formatting... I'd much rather have been debating architectural design patterns as the response to "coding standards."

            Positions on design patterns, over the last few years, appear to have accreted into two clusters, those for and those against. I am one of those in the "for" camp, where learning the whys and wherefores of a particular set of data structures and classes, and behaviors arising from said structures, determine architecture.

            Those "against" appear, to my reading, to be willing to forgo such learning and accept whatever baked-in design patterns the platform's designers chose.

            Now, on the one hand, I accept that that's the case, as there is an observable stratification of programming ability existing in the world of software developers. One most go with one's strengths, and not everyone is suited to solving the issues architecture.

            On the other hand, if a developer is so inclined, there is still plenty of latitude available when structuring applications.

            Finally, there appears to have been a rise in the strongly anti-design patterns camp - the learning and applying thereof, that is. Most particularly, the anti-Java, pro-Ruby/RoR camp, where seemingly one must accept the baked-in design patterns chosen by the platform's architect, without variation.

            A direct descendent of that camp, the adherents to the prototype.js and scriptaculous libraries, accept the original author's patterns to the point where performance deficits due to overuse of lambda functions are not only accepted, they are ignored.

            That, IMNSHO, is sad comment on the state of software development. Productivity over performance is an awkward choice, to say the least.

      • by xjimhb (234034) on Sunday July 20 2008, @10:54AM (#24262809) Homepage

        Why does everybody do it that way? That is, with the opening paren on the "if" line? I have always found that difficult to read. Why not

        if (something)
        {
            stuff
        }
        else
        {
            other stuff
        }

        or maybe even

        if (something)
            {
                stuff
            }
        else
            {
                other stuff
            }

        This last has always seemed to me to be the most readable, most obvious way to write the code. Can anyone explain why it is not used? (other than some well-known guru prefers the other?)

        • by Zwicky (702757) on Sunday July 20 2008, @11:11AM (#24262971)

          From a personal perspective that happens to tie in with the coding practices at my last company:

          The second example (GNU style) I have found to be quite cumbersome in writing, unless tabs are set to 2 with braces indented once and content twice (company mandated four with one indent for content in the block), in which case I would be frustrated with the extra keypresses involved.

          The first example (Allman style) I used to use until I moved over to Kernighan-Ritchie style (opening brace on same line as control statement, with functions (and classes in OOP languages) braces the exception; these are written in Allman style). This allows me to scrunch more onto the screen vertically.

          FWIW I never liked the '} else {' style of elses but at the same time, I never found it difficult to read so it was never a real issue. It makes sense to me to have the else begin at the same column as the if to which it belongs.

          This [wikipedia.org] may be of interest to you.

        • by CastrTroy (595695) on Sunday July 20 2008, @11:22AM (#24263073) Homepage
          I like the braces on separate lines also. Makes things a lot more readable. Another good idea is to always put the braces in, even when you are only writing a single line. That way when somebody goes to put more code in the if statement, they don't have to remember to add them.
      • by bperkins (12056) on Sunday July 20 2008, @11:28AM (#24263147) Homepage Journal

        So we have a shop that has a whole lot of perl code and they're sent around this book as well as run perlcritic on our checked in code (which pretty much everyone ignores).

        In my couple of years there I've learned a few things.

        1) No one can agree on coding standards

        2) What people can agree on is so watered down that it's not very useful.

        3) The stuff that really causes headaches isn't bad style, it's general insanity. Hardcoded constants and poorly thought out ad-hoc parsers and general brain damage causes a million times more problems than just about anything anyone can describe in a standard.

        That said, in my experience the one thing that almost aways saves me time for anything larger than a couple of lines is to use "use strict."

  • Space Usage (Score:5, Interesting)

    by Nerdfest (867930) on Sunday July 20 2008, @08:30AM (#24261647)
    I've worked where we were supplied a full IDE and a 17" CRT, and the coding standard forced so much white space vertically that you had to basically remember all the code.
    • Re:Space Usage (Score:5, Informative)

      by LordOfLead (1121501) on Sunday July 20 2008, @10:41AM (#24262719) Homepage

      The Linus says:

      "If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program."

      from http://en.wikiquote.org/wiki/Linus_Torvalds [wikiquote.org]

      • by Tony Hoyle (11698) <tmh@nodomain.org> on Sunday July 20 2008, @10:25AM (#24262589) Homepage

        Nah me neither... maybe it's a US thing? It's generally assumed that if you're a half decent programmer you'll follow what is already there and write clear concise code as much as possible.

        One place I was in did try to come up with a coding standard, but it was abandoned as nobody could actually agree on much other than 'don't fuck it up'.

      • Re:Space Usage (Score:5, Interesting)

        by Gorobei (127755) on Sunday July 20 2008, @10:49AM (#24262763)

        I've seen a number of private sector firms with coding standards. Some are just a few pages of common sense rules (naming conventions, etc) while others were book-length horrors created by people so incompetent that management didn't trust them to write code. I've seen requirements forbidding constants in code (correct practice was #define THIRTY_SEVEN 37, believe it or not,) and crazy Hungarian style naming conventions (nothing like several characters of line noise at the end of every function name.

        My current firm's approach is pretty simple:
        1. Write clear, understandable code
        2. Make it look like all the other code in our system
        3. Use the standard IDE
        4. The entire codebase is visible to all developers
        5. If you code does not conform, an annotated screenshot of it will be posted to our main developer chatroom
        6. People will then discuss your code publicly
        7. If the code is truly awful, a senior developer will declare it unacceptable, and delete it from the system

  • by PsyQo (1020321) on Sunday July 20 2008, @08:34AM (#24261671)
    I've always found the Joint Strike Fighter's coding standards document an interesting read. It is available from Bjarne Stroustrup's website [att.com] (pdf)
  • It's easy (Score:5, Funny)

    by krkhan (1071096) on Sunday July 20 2008, @08:40AM (#24261707) Homepage
    First off, I'd suggest printing out a copy of the /. comments, and NOT read it. Burn them, it's a great symbolic gesture.
  • My new standard (Score:5, Interesting)

    by thogard (43403) on Sunday July 20 2008, @08:44AM (#24261729) Homepage

    My new standard comes from a 1950's comp sci book.

    "Programs consists of input, output, processing and storage."

    Lose focus of that and the project will be late, over budget and most likely broken in ways no one will understand for years.

  • by Lucas.Langa (922843) on Sunday July 20 2008, @08:47AM (#24261751) Homepage

    If you are using your computer right, it does not only enable you to do things, it does the boring things for you, automatically.

    Checkstyle is one of the tools in a company toolkit that is often overlooked but in fact VERY handy. It enables you to define a ruleset for your source code, finding stuff which is incompatible with the coding practice in your company/team/project/whatever. Moreover, you can stick it into Eclipse using the free Eclipse-CS plugin, so it will automagically mark the places which need to be change. Last but not least, you can put Checkstyle as an Ant task in your building environment (and in your continous integration toolkit) so commited code that does not conform certain standards does not build.

    As for the rules themselves, we've found these to be the most successful:

    • limit the length of the method to be visible on one 1280x1024 screen; if it's longer it's probably handy to extract smaller methods from it - which will be far more easy to read
    • similarly: set a file length limit (e.g. 1000 lines should be enough for everybody)
    • an upper limit on the allowed number of method parameters seems to be a good idea as well
    • ensure that new code is commented by marking structures which could be javadoced but aren't
    • any naming and formatting convention is better than no convention; Checkstyle can use regular expressions to validate type, variable and other names. It can also check for whitespace constraints, new lines, etc.
    • avoid star, redundant and unused imports
    • enforce or forbid the usage of the tabulator character to have all code clean no matter where you open it
    • warn on redundant modifiers
    • enforce the usage of braces everywhere (e.g. disallow if (something) action; ): no misformatting will hide a trivial but dangerous bug
    • a major one: Checkstyle can warn if it discovers a typical coding problem (of course this has some false positives but better to be on the safe side): double checked locking, lack of hashcode when overriding equals, switch fallthroughs, illegal catches and throws, lack of super.clone() or super.finalize(), etc.
    • you can also constraint the number of returns from methods (we found it to be very useful to set this to 1, using a result variable everywhere else - it's far easier to get hold of the code flow then)
    • we also constraint the if depth and boolean expression complexity to manage the cyclomatic complexity - also for easier reading
    • it's useful to make Eclipse clean up your code on every save: to add "final" where it can, to fix imports, format the code to the specified form, etc.

    Of course, we let developers to add suppresions for the 1% of false positives. In fact, there are very few suppresion rules set.

  • developer buy-in (Score:5, Insightful)

    by Dionysus (12737) on Sunday July 20 2008, @08:48AM (#24261765) Homepage

    Without developer buy-in, whatever coding standards you come up with will be useless. IOW, ask your developers to create the standard together.

  • by hucke (55628) * on Sunday July 20 2008, @09:14AM (#24261927) Homepage

    I worked for a company that was destroyed by a bad coding standard.

    This was a small company, that, back in '96, was awarded the contract for a POS application for a regional store chain, with back-office servers that would be updated nightly by modem.

    The guys who ran the company weren't programmers (though one of them knew enough to be dangerous); they were technical salesmen. They were also big fans of Microsoft, with "MVP" plaques on the walls, and every employee except me having Microsoft certs.

    I worked for them part-time while also working for another company. I advocated Unix (mostly BSDI and SunOS at the time), and always argued with them about why Unix was better (technical superiority vs. potential for big profits).

    When their big project was well underway, they brought me in to do the communications part of it, where the POS terminals would contact one of several servers by modem each night ("why not just ethernet them together, get a dialup PPP connection, and use IP? the interface is so much more reliable..." Request denied).

    The app was Visual Basic, with third-party "custom controls" for things like talking to modems. My part went fairly smoothly, and I was eventually asked to help out with the main application, which was suffering from unexplained crashes. When I looked at the code, I found something... strange.

    For error handling, they had elected to use a program called "VB Rig" (the name came from the rigging used on sailing ships, which prevents a sailor from falling to his death. Sometimes.) What this program did was to examine the source code, and then add error handling boilerplate at the start and end of each and every function. It inserted the exact same error handling code into every function.

    Because the error handler had to be all purpose, it was about 20 lines of code per function - sometimes much larger than the regular part of the function. And, worse, because it was the same for every function, and it made use of the same variable names, that meant either every variable had to be global, or you'd have to declare the ten or so standard variable names at the start of every function (they opted for the "everything is global" approach).

    Which led to things like this (forgive the syntax errors, it's been years since I've touched VB):

    On Error goto my_data_file_read_function_VBRIG_TRAP

    open MyDataFile for writing ...
    goto my_data_file_read_function_VBRIG_CLEANUP

    my_data_file_read_function_VBRIG_TRAP:
    on error 101 'Permission Denied
    delete MyDataFile
    resume
    on error 102 'File Not Found
    MessageBox 'Cannot read ' + MyConfigFile
    resume
    my_data_file_read_function_VBRIG_CLEANUP:
    blah blah
    my_data_file_read_function = SUCCESS ' return

    As you see, the error handling code - which had to be exactly the same for every function - made use of global variables (names like DataFile1, MyFile1, UserName, etc.) to figure out what to do for each error. That meant, that if there was any possibility you might have a "File Not Found", you had to expect the filename where that might happen to be in a particular global variable - say, MyFile1 - and hope that the calling function wasn't using that name too, for the same reasons.

    Naturally, files were being created and deleted at random, and the programmers often spent hours on the phone with the customer trying to figure out why the Access database had disappeared *again*.

    I asked if we could just write the error handling by hand, and use appropriate local variables; or take the standard VBRig error handling and trim out the lines that weren't relevant for a particular function (as subsequent VBRig runs wouldn't touch its code region if it saw that it had been customized).

    Request Denied. "This is our coding standard. We carefully reviewed the options before making the decision to use t

    • by Splab (574204) on Sunday July 20 2008, @09:24AM (#24262025)

      I love abbreviations, not being native English speaker I used to think POS was "piece of shit" since its usually being used when talking about software (failed software).

      (Or the always common "IANAL", well good for you buddy, but we are talking about legal issues here - the arse pounding is for when you get behind bars)

  • Correct focus (Score:5, Insightful)

    by QuietLagoon (813062) on Sunday July 20 2008, @09:15AM (#24261937)
    What standards have you found worked well in practice, increasing code readability and maintainability?

    .

    Coding guidelines are typically justified because, as it goes, most of the time is spent fixing bugs in existing code than writing new code. The guidelines are needed because it helps others to come up to speed quickly while they try to figure out the code in which they have to fix the bug(s).

    I think that is the wrong focus, as it tends to reinforce incorrect behavior, i.e., the writing of buggy code.

    Coding guidelines should focus instead on the techniques that help reduce the number of bugs in code. How is that done? It takes someone (typically a senior person) looking at the the bugs that have been found in the code, categorizing their cause, devising a way to prevent those bugs from occurring, then putting that into the guidelines.

    Keep the focus of the guidelines where it should be: to increase the quality of the software.

  • by Yosho (135835) on Sunday July 20 2008, @09:38AM (#24262131) Homepage

    multiple return statements were off-limits

    Despite the fact that it's not part of the coding standard where I work, I have a few coworkers who take this to the extreme. They surround every single function they write with:
    do{ ... } while(0);
    And then, inside the "do" block, they just put "break" in any place where they would have otherwise put "return." It drives me insane; they insist that having a single exit point from your function makes it easier to debug, but I just don't get it. I've never even seen them use gdb, anyway, so I think that abusing "printf" is their idea of "debugging"...

    One thing in our coding standard that I do like is that all variables that store units must have a unit specification at the end of their name -- in other words, all frequencies might have "Hz" or "MHz", distances might have "m" or "mm", times have "sec" or "msec", and so on. This is really helpful in my field -- it's not uncommon for me to open up a file that I've never looked at before and need to make modifications to it, and if the units everything things are stored in weren't immediately obvious, I'd have to go track down somebody and ask them. The annoying thing here is when people decide not to follow this standard because they think it should be obvious...

    • Re:braces (Score:5, Interesting)

      by Dionysus (12737) on Sunday July 20 2008, @08:43AM (#24261717) Homepage

      If Kernighan, Ritchie [wikipedia.org], and Torvalds [linux.no] does it like that, who am I to do differently.

    • Re:braces (Score:5, Insightful)

      by heffrey (229704) on Sunday July 20 2008, @08:47AM (#24261749)

      It doesn't really matter what you do, so long as everyone on the team does the same thing.

    • Re:braces (Score:5, Interesting)

      by Dachannien (617929) on Sunday July 20 2008, @08:48AM (#24261761)

      I don't like seeing opening braces sharing a line with anything else at all, unless the block gets closed on the same line.


      if(something)
          {
          do_something();
          }
      else
          {
          do_something_else();
          }

      Yeah, it takes a bit more space, but I find it a lot easier to match blocks up when the braces are indented the same amount.

        • Re:braces (Score:5, Interesting)

          by fictionpuss (1136565) on Sunday July 20 2008, @09:00AM (#24261829)

          Well, as long as we're admitting that "readable" is an entirely subjective experience.. I'd have to say that I would find that notation less intuitive than the "} else {" construct.

          It's too similar to consecutive 'if' statements which of course, breaks the logic.

          Also, extending your notation logic fully results in:

          if ( condition )
          {
                  statement1;
          }
          else
          {
                  statement2;
          }

          Which, although a waste of lines, is less confusing than your example.

          • Re:braces (Score:5, Insightful)

            by TheRaven64 (641858) on Sunday July 20 2008, @09:13AM (#24261921) Homepage Journal

            There are other good reasons for putting open braces on their own line. The biggest is that most coding conventions have a maximum line width. If you have an 81-character line, you need to break it. When you are scanning down the code, all you see is a line at one indent level followed by another line indented more - you need to read the entire line to tell whether it's the start of a block or not. With braces on their own lines you can tell just by visual pattern matching where every block starts and finishes.

            While I'm in holy-war territory, I'll also chime in on the tabs versus spaces argument. The tab character has a well-defined semantic meaning. It means 'indent this line / paragraph by one tabulator.' If you are indenting anything there is only one character you should be using - tab. It does not, however, have a fixed width, and should therefore never be used anywhere other than the start of a line or for aligning two lines. If you have to split a function across two lines, you should indent it like this:

            {tab}function(arg1,
            {tab}_________arg2,

            Then, no matter whether the person reading your code thinks tabs should be 1 or 8 characters wide, arg1 and arg2 will always line up. Sadly, vim does not have the ability to distinguish marks used for indenting and marks used for alignment and so this has to be done manually.

          • Re:braces (Score:5, Interesting)

            by Glonoinha (587375) on Sunday July 20 2008, @09:18AM (#24261963) Journal

            Ding ding ding - we have a winner.
            Real coders write code that you can take a ruler from any given close brace and draw a vertical line right up to the matching open brace, every time. Everybody else gets fired.

            Lines are cheap. Time added trying to figure out an obfuscated code structure because somebody wanted to save lines (ie, put the open brace on the same line instead of doing the above) is expensive.

            • Re:braces (Score:5, Interesting)

              by gfxguy (98788) on Sunday July 20 2008, @09:29AM (#24262057)

              That's the way I've always done it, but it seems like most published coding standards don't like it.

              To reiterate: matching braces should line up horizontally AND vertically. It may "waste" lines, but the code is a lot more clear.

              I also, except in some cases (like some class getter/setter methods, where they're just all one after each other and it's obvious what they are), use braces even if it's a single statement that's being executed within. I don't see why code should be inconsistent just because it's a single statement that's being executed.

              I often get berated by other programmers for that style, but the only time I've applied for a job and had to stand at a white board and write code, and then describe my coding style, they seemed to appreciate it.

            • Re:braces (Score:5, Insightful)

              by aj50 (789101) on Sunday July 20 2008, @09:32AM (#24262081)

              Bollocks.

              Draw your line from the closing brace up to the first line with any text on it, that line is the start of your block.

              Having your opening braces on an empty line might be more aesthetically pleasing but has zero advantage in making the code clearer.

              Either way, the most important thing is to have everyone do it the same way, every time.

              • Re:braces (Score:5, Interesting)

                by LuxFX (220822) on Sunday July 20 2008, @09:53AM (#24262299) Homepage Journal

                I've always found this to be clearer.

                Drawing a line up to an opening brace doesn't tell you anything but the constraints of the code block, you then have to take another step to figure out what kind of code block it was.

                If you draw the line up to the first text line then you'll not only know the constrains but you'll know immediately without any further inspection if it was a for block, a while block, a function, etc.

            • Re:braces (Score:5, Funny)

              by russotto (537200) on Sunday July 20 2008, @10:08AM (#24262453) Journal

              Real coders write code that you can take a ruler from any given close brace and draw a vertical line right up to the matching open brace, every time. Everybody else gets fired.

              Messrs Kernighan and Ritchie and their no-necked associates would like to have a word with you out back.

        • Re:braces (Score:5, Interesting)

          by Southpaw018 (793465) * on Sunday July 20 2008, @09:04AM (#24261863) Journal
          That kind of code, when using PHP for templating, can make things much more efficient server side. Remember that anything within PHP tags is parsed by PHP. On a high volume site, even the relatively minuscule difference between passing something straight to the browser and echo("something"); can make a big difference in speed and resources.

          Besides, this is what syntax highlighters were made for. There are very good free ones on every single platform for a reason :p
            • Re:braces (Score:5, Insightful)

              by Southpaw018 (793465) * on Sunday July 20 2008, @09:54AM (#24262305) Journal
              That's what you're SUPPOSED to do. The real world would rather have absolutely nothing to do with any of that.

              In my short experience in the workin' world, I've come across some pretty spectacularly awful implementations of everything under the sun, from production boxes in shambles to network cables wrapped around sweaty water pipes to 2 year old production code passing GET strings straight to the SQL server unmodified (yay nonprofit sector!), and compromising code for a quick and dirty webpage so I can get things running just a bit faster is 1) the least of my worries and 2) a metric fuckton cheaper than new servers (yay nonprofit sector!). :)
        • Re:braces (Score:5, Funny)

          by fictionpuss (1136565) on Sunday July 20 2008, @09:05AM (#24261875)

          True - but at least it keeps thousands of otherwise dangerous PHP developers safely occupied.

      • Re:braces (Score:5, Informative)

        by Haeleth (414428) on Sunday July 20 2008, @10:21AM (#24262559) Journal

        Like many Python evangelists, you seem to have a remarkably limited experience of computer languages.

        Here's a language with no braces:

        IF condition THEN
            statement1
        ELSE
            statement2
        ENDIF

        Here's another:

        (cond (condition statement1)
              (t statement2))

        Here's another:

        if condition then begin
            statement1;
        end else begin
            statement2;
        end;

        Here's another:

        if condition then
          value1
        else
          value2

        or, more extensibly,

        match condition with
          | true -> value1
          | false -> value2

        And the list goes on. Maybe you should try learning some other languages. Broaden your mind a bit. There's a lot out there that isn't Python or C/C++/Java. Some of it is quite interesting.

    • Re:Keep it simple! (Score:5, Insightful)

      by bondsbw (888959) on Sunday July 20 2008, @08:49AM (#24261771)

      Make it "cut and paste" friendly, and as small as possible.

      That's a really bad idea. Cut and paste causes code cloning, which is among the most difficult maintenance problems.

      Code should be designed, when possible, in small chunks (methods, functions, etc.). This keeps the need to think about refactoring to a minimum, since the code is already factored. Well factored code has many other benefits, including easier-to-write unit tests and better understandability.

      I maintain software that was originally written by someone as a prototype and eventually given production status. 4 years later, I am still pulling bugs out that relate to code cloning. Think of the guys who will maintain your software, please.

      • Re:Keep it simple! (Score:5, Insightful)

        by superid (46543) on Sunday July 20 2008, @09:13AM (#24261923) Homepage

        the most egregious bug I think I ever introduced was due to code cloning. It was awful. I did not bother to properly refactor (hey it was 12 years ago) and as a result we ended up with diverging clones that needed to be separately maintained.

      • Re:Keep it simple! (Score:5, Informative)

        by StrawberryFrog (67065) on Sunday July 20 2008, @09:17AM (#24261947) Homepage Journal

        There are several tools that can detect cut and paste code:

        Simian: http://www.redhillconsulting.com.au/products/simian/ [redhillconsulting.com.au]
        PMD: http://pmd.sourceforge.net/ [sourceforge.net]
        DuplicateFinder: http://www.codeplex.com/DuplicateFinder [codeplex.com]

        And probably others

      • by 4D6963 (933028) on Sunday July 20 2008, @09:17AM (#24261957)

        Make it "cut and paste" friendly, and as small as possible.

        Cut and paste causes code cloning, which is among the most difficult maintenance problems. Code should be designed, when possible, in small chunks (methods, functions, etc.).

        Wait.. are you trying to say that copying the same lines of code over and over again must be avoided? So tell me genius, how else would you implement such a function without copying?

        int multiply(int a, int b)
        {
        int x=0;

        if (a==1)
        {
        x+=b;
        }

        if (a==2)
        {
        x+=b;
        x+=b;
        }

        if (a==3)
        {
        x+=b;
        x+=b;
        x+=b;
        }

        // Damn lameness filter, wouldn't let me paste my code in the entirety of its 132,356 lines

        return x;
        }

        • by Haeleth (414428) on Sunday July 20 2008, @09:50AM (#24262255) Journal

          Duh, you so need to learn about this little thing called structured programming, which can totally help cut down on code duplication like that crap.

          Here's a hint:

          int multiply(int a, int b)
          {
              int x = 0;
            loop:
              if (!( a --> 0 )) goto done;
              x += b;
              goto loop;
            done:
              return x;
          }

          See? Much easier to understand than your spaghetti code, and much more maintainable too.

    • by hedronist (233240) * on Sunday July 20 2008, @12:09PM (#24263641)

      Strangely enough, Hungarian worked quite well for the problem it was originally intended to solve.

      I worked at Xerox in the late 70's and my manager was Charles Simonyi, inventor of this notation. The project was BravoX (grandparent of MS Word) and was written in BCPL. BCPL basically has one type: integer. How that integer is treated is purely a function of how you reference it. E.g. fooFirst>>fooNext means "use the variable 'fooFirst' as a pointer to a structure of type FOO, one of whose elements is (from the naming convention) a pointer to some other FOO." Whereas fooFirst+1 adds one to an integer and (almost certainly) yields an invalid point that bill blow up when you try to use it. (It's been 30 years since I wrote anything in it, so I probably screwed up the example.)

      Since there was only one type, the compiler didn't/couldn't perform type checking. Hungarian was a way of putting the type into the name of the variable so that the programmer could perform visual type checking. There were 9 of us on the project and the consistency/readability across the code base was impressive. Any of us could go into anyone else's code and almost immediately see what was going on.

      I still use a light variant of it in my own code, but when in someone else's code I try to stick to their naming/formatting convention.

      Like so many good ideas, it worked well in its original context but became twisted out of shape when used for something never intended/envisioned by the original developers (even though the person doing the twisting was, in fact, the original developer!). Another example of this is the Third Eye Software symbol table format I created for my debugger, CDB, but which was then used and abused by Mips to create a complete piece of crap. What they did still has people swearing at me 20+ years after the fact. (More on this at Third Eye Software and the MIPS symbol table [datahedron.com])