Slashdot Mirror


What Workplace Coding Practices Do You Use?

Agent_9191 asks: "Recently I've been promoted to what essentially amounts to a project lead role for every project we do, in house. Since my company has run for the past 35+ years with no form of central IT department, there has been no standards put into place for developers to abide by. One of my tasks is to set up standards in how projects will be implemented and produced. Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code. I've come across some documents in this area from a few sources (of course can't remember them off the top of my head). What practices/standards do you use in your workplace?"

682 comments

  1. Comments by Gyga · · Score: 5, Insightful

    Tell them to use comments in code, and be sure that they make them good comments.

    --
    I don't preview or spellcheck.
    1. Re:Comments by mopslik · · Score: 5, Informative

      ...be sure that they make them good comments.

      And make sure they update comments if changes necessitate it. There's nothing worse than reading through a function's description, complete with well-documented inputs/outputs/conditions/etc. and finding out that those things no longer apply because somebody changed a 1 to a 2.

    2. Re:Comments by PunkOfLinux · · Score: 0

      Yeah. It's a lot easier to understand the code when there ARE comments. Even a person who knows relatively little about programming can understand what does what if the comments are good. For example: if x==456 then //checks for conditional x and executes code if x is true - this is not a good comment if x==456 then //checks to see if x is equal to 456. If it is, then the code within is executed -this is a good, easy to understand comment.

    3. Re:Comments by Threni · · Score: 3, Insightful

      > somebody changed a 1 to a 2

      You shouldn't be using magic numbers anyway - use a #define so that the comments and code stay the same regardless of what the value happens to be.

      Instead of

      function(1);

      try

      #define LOAD_DATA 1

      function(LOAD_DATA);

      Then you don't need to care what LOAD_DATA is.

    4. Re:Comments by Py+to+the+Wiz · · Score: 5, Insightful

      "if x==456 then //checks for conditional x and executes code if x is true - this is not a good comment if x==456 then //checks to see if x is equal to 456."

      Actually, IMHO, those are bad comments. Too much commenting, while not as bad as too little commenting, is still a problem. Writing too many comments is not only time consuming for the developer, but it makes it harder to find the important comments in the sea of crap. Also, if the program is modified, all the comments must be changed as well. This can be a tedious and time consuming process for large projects.

      Personally, I try to use comments for parts in the code that might be confusing. Even for a novice programmer, code like if(x == 456) is self-explanatory, no comments are needed. But complicated statements involving many different variables from different parts of the file may be confusing, and likewise merit comments. Also, comments with input/output or precondition/postcondition for functions might not be a bad idea either.

      Use comments when you need them, but don't write so many comments that they become useless.

      --
      Fight the fall of slashdot by supporting PlayfullyClever in your sig.
    5. Re:Comments by Mr2cents · · Score: 1

      While you're at it, try out some documantation extraction tools, like javadoc, ccdoc, or others.

      --
      "It's too bad that stupidity isn't painful." - Anton LaVey
    6. Re:Comments by Seraphim1982 · · Score: 3, Insightful

      I would say both of those are bad comments. Neither of them tells me something that a very basic understanding of the language wouldn't tell me.
      I would say a good comment (that is, a comment that I would find useful) for that piece of code would tell you why the statement was important, what is it going to accomplish, and if needed why was it writen the way it was. For your code my questions when reading it would be "why 456?" and "what is going to happen in the following block(s) of code?".

    7. Re:Comments by republican+gourd · · Score: 5, Insightful

      Has anybody written an IDE plugin yet to sign comments? You could for instance have a hash that uniquely identifies comment lines 10-20 and code lines 30-70 as the a 'set' of data that is required to match. Then if the hash of either section changes, flag it as a problem until the hash is regenerated.

    8. Re:Comments by jomegat · · Score: 5, Insightful
      BOTH of those comments are bad. If a person knows relatively little about programming, he shouldn't be in a position to modify your code. If they don't know what an "if" statement does, they have no business mucking around in my code anyhow.

      Comments should concentrate on "why" not on "what." A machine can figure out "what," so a programmer should be able to do that too (eventually). No machine has a clue as to "why" though.

      Any time I'm reading through my code and I can't remember why I did something, it's a red flag - that needs a comment. If the code doesn't look like it's needed, but it really is, you need to put in a comment explaining why it's there.

      "What" comments should be reserved for the top of a function or largish body of code.

      --

      In theory, practice and theory are the same. In practice, they're not.

    9. Re:Comments by dorkygeek · · Score: 5, Informative
      For example:
      if x==456 then //checks for conditional x and executes code if x is true
      - this is not a good comment
      if x==456 then //checks to see if x is equal to 456. If it is, then the code within is executed
      -this is a good, easy to understand comment.

      Is this supposed to be a joke??! Both of them are worst comments, because they only formulate in english what the code already says by itself. Everyone can see that this is an if-statement, everyone is able to identify the condition, and everyone knows the semantics of an if-statement.

      A good comment is not describing what is done (since everybody can see that from the code itself), a good comment describes why something is done, or what the overall objective of the statement is.

      For example:

      if (x == 456) { // Check if step motor reached final position. If yes, halt motor, otherwise step forward.

      This is ways more useful. Even more useful would be to already use self-describing symbol names in the code itself, like

      if (currentPosition == finalPosition) { ...
      --
      Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
    10. Re:Comments by PunkOfLinux · · Score: 1

      I was simply using them as EXAMPLES. For christ's sake. They were only used because I couldn't come up with something better. Good god...

    11. Re:Comments by joe_bruin · · Score: 4, Insightful

      Our coding standard is a little like this:
      Write clean code that can be easily understood by reading it. That is, good variable and function names, try not to make any absurdly complicated statements, and have your comments explain the logic of the operations. As for style, try to stick with the style that the original author started with. And finally, all people who use Hungarian notation are locked in the basement and given menial tasks until they repent their sinful ways.

      I hope this helps.

    12. Re:Comments by assert(0) · · Score: 1

      I, for one, find your ideas intriguing / interesting and wish to subscribe to your newsletter / journal.

      --
      (founded 95,000,000 yrs ago, very space opera)
    13. Re:Comments by NemoX · · Score: 3, Interesting

      Visual Studio has one called "Ghost Doc" that we use. Also, microsoft has some macros you can download that will create documents for constructors and for any exception within a method. Using these two together, and you have a pretty standardized comment collection that can be compiled by NDoc (the .NET version of JDoc for Java). I have a really good one for Eclipse, also, but can't remember it of the top of my head.

    14. Re:Comments by kers · · Score: 0, Troll

      Not only are you using no-existant instructions, you also forgot to declare the line numbers.

    15. Re:Comments by OzRoy · · Score: 2, Insightful

      This is something that seems to be very common in commenting. Comments are not there to describe every line of code. Any programmer can see what the code is. A good comment should explain *why* it is that. It should explain what the input is, and what the final output should be.

      I looked at that if statement and wanted to know why 486? Why does it execute that block if x is 486? That is what the comment should do.

      That said I really need to comment my own code better than I do :)

    16. Re:Comments by kuom · · Score: 1

      The standard at my work place is Robodoc, because we use a variety of languages, and since robodoc supports a lot of languages, our developers only need to learn one style of comments, and apply it to every language. The output (HTML) is not as pretty as JavaDoc, but good enough...

    17. Re:Comments by JWW · · Score: 1

      Yeah, you nailed it! Espicially that part about Hungarian notation.

      But really the thing you really got right is that is more important to follow reasonable guidlines and take responsibility for your projects. I would like to add that creating a checklist of procedures and rules won't help your company write better code, it will just add busywork for your developers.

    18. Re:Comments by naibas · · Score: 5, Informative
      Both of them are worst comments, because they only formulate in english what the code already says by itself. Everyone can see that this is an if-statement, everyone is able to identify the condition, and everyone knows the semantics of an if-statement.

      A good comment is not describing what is done (since everybody can see that from the code itself), a good comment describes why something is done, or what the overall objective of the statement is.

      Amen to that.

      In addition to the original comments being redundant, there's also the issue of the code and the comments getting out of sync...

      The company I work for just wrote up a formal coding standard, which includes everything from a guide to our internal hungarian notation, indentation guidelines, and even which C++ features/paradigms are supported, frowned upon, or not allowed. All the coders got a chance to send in feedback before it was finalized, and we even ended up with a list of recommended reading on the subject, including:

      • Sutter & Alexandrescu's C++ Coding Standards,
      • Meyer's Effective C++,
      • Meyer's More Effective C++, and
      • McConnell's Code Complete.

      The idea is to keep the code readable and maintainable with the least amount of re-invention of the wheel. With good coding practices, it's easier to avoid bugs in your own code and spot them in others (reviews are also a big plus on both counts). And it gets any religious battles out of the way up front, so you don't have to waste time bickering later on.

    19. Re:Comments by Webmoth · · Score: 5, Insightful

      Write your comments first, then code to match the comments. This way, you are forced to clearly define the input, output, variables and algorithms that will be used in the code BEFORE you start coding. When it's clear in your mind, the coding becomes easier and less confusing; and you have an outline to follow to make sure you don't forget something.

      If you write the code first, then annotate, you fall into two traps: "What the heck was that variable for?" forgetfulness, and "It works so stop messing with it" laziness.

      --
      Give me my freedom, and I'll take care of my own security, thank you.
    20. Re:Comments by B3ryllium · · Score: 1

      insertCommentRegardingHungarianNotationWithNestedH umorousCommentAndAdditionalJibeAboutSexualOrientat ionOfParentPoster(&unclosetedOutputStream);

    21. Re:Comments by Anonymous Coward · · Score: 0

      If you must post an example, use one that elucidates, not aggravates.

    22. Re:Comments by Helios1182 · · Score: 2, Interesting

      If using Java, make sure they use Javadoc compatible comments for every class and method.

    23. Re:Comments by Anonymous Coward · · Score: 0

      they were shitty examples, that's all

    24. Re:Comments by geekoid · · Score: 1

      Amen.

      AS a tiny addedum, I would reference the document that says that 456 is the final position. When working with mechanicals, this little tidbit can be a lifesaver... literally.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    25. Re:Comments by iabervon · · Score: 4, Funny

      I prefer:

      if x==456 then //checks to see if x is equal to 256. If it is, then the code within is executed

      That way, there's less chance for confusion if the code gets modified in the future.

    26. Re:Comments by BobearQSI · · Score: 4, Interesting

      There is lots more to coding standards than just comments and style. Where I work, portability and maintainence are of high concern too. Certain rules, like no hard-coded values such as 563, allow for much better code maintainence. Other rules, like in C/C++ never using an int for any value other than 0-127, and never using a char for anything other than text characters, allow for code portability. These are just some of the rules. If your product is designed for one environment, you may have different coding standards. In the past, we have gotten together as a software team and reviewed other standards found online and combined the likes and the like-nots to create our own, tailored for our industry and requirements.

      Style is good for readability and also for consistency. Requiring spaces before and after operators like = and + help in reading complex lines. Parens () help also. Setting requirements for function bracing (or what goes on a line, depending on the language), and tabbing help multiple programmers understand and easily see the program flow of others.

      Anyone who protests that they like their own style better because they can read it eaiser (while everyone else can't) shouldn't be working for you. Team players are needed. We've resolved many such arguments satisfactorily in the past by simply putting it to a vote. And those team players gracefully accepted the majority.

    27. Re:Comments by CausticPuppy · · Score: 5, Insightful

      Our coding standard is a little like this:
      Write clean code that can be easily understood by reading it. That is, good variable and function names, try not to make any absurdly complicated statements, and have your comments explain the logic of the operations. As for style, try to stick with the style that the original author started with. And finally, all people who use Hungarian notation are locked in the basement and given menial tasks until they repent their sinful ways


      Well that's a good start, with good intentions, but you need to have a standard definition of what constitutes good function names and good variable names. If you have 5 different programmers on a project, you'll have 5 different opinions on what good names are.

      Make sure your coding standards are DOCUMENTED.

      If it's a java project, the best source would be Sun's java coding standards. A very useful tool for this is Checkstyle. You can decide which rules to enforce (some of the ones enabled by default are more annoying than anything) but if you take the time to get your code to where Checkstyle likes it, you'd be amazed how easy it is for humans to read.

      As for my department, we use CVS for version control.
      Every time code is checked into CVS, it is formatted by Jalopy. So, it'll look nice and neat the next time it's checked out.
      Also, we have a script that does nightly builds, and then emails the result to everybody on the team. So if you checked in something that breaks the build, everybody knows about it the following morning. :-)

      We have a regular release schedule. All work is done on the main CVS branch, but when it's time for a code freeze, the new version is branched off and tagged in CVS. During QA testing, bugs are fixed in the branch and the mainline. New features are only added to the mainline.

      When we are ready to deploy, we tag the release in CVS. The deployment script checks the tag out of CVS, builds it, and packages everything up into the relevant .ear files which Operations can then take.

      This is all a very strict process, but things rarely fall through the cracks this way. If you don't have any processes in place now, it's best to implement them a step at a time. Get everybody used to working with CVS or some other version control, get them used to the notion of tagging and branching, and make sure there's actually a document detailing whatever processes you have.

      And lastly, have code reviews every week or two. Review a different person's code each time and make sure everybody on the team is allowed to have input. If you're not at the coding stage yet, have design reviews.

      --
      -CausticPuppy "Of all the people I know, you're certainly one of them." -Somebody I don't know
    28. Re:Comments by multipartmixed · · Score: 2, Funny

      Out of curiosity, what kind of platforms do you code for? Even my commodore 64 had 16-bit ints.

      --

      Do daemons dream of electric sleep()?
    29. Re:Comments by BrynM · · Score: 2, Insightful
      Write your comments first, then code to match the comments.
      This is why Design Documents are so important. For those sitting there thinking "// checks if x == y then proceeds" is a good comment, the rest of us call this "comment first" idea "planning". It has been working well for coding since the begining and has worked for other things for centuries if not millenia. The most frightening thing to think when handed old code is "My god! They never had more than a meeting of planning for this pile!" Bad or after the fact comments betray a lack of planning every time. Not commenting is almost a downright admission.

      When I see code like this, I have turned to my current boss/client and said "You didn't plan this thing very well at all did you?" on many occasions. That question always gets a look of guilt quicker than two teens with no clothes on when her dad walks in. When you explain how you noticed so quickly, you can see the look of "How did I get here? Do I know what I'm doing?" wash over their face a few times over as they think of everything else they are in charge of in the same light... and wonder if their mistakes are always that obvious to others. I remember one PHB wo implemented a "Code Review" the very next day. Fun! Sad, sadistic, pitiful fun - but still fun sometimes.

      I wish I had mod points for you Webmoth. You hit the nail on the head dead square. Even countersunk it a little.

      --
      US Democracy:The best person for the job (among These pre-selected choices...)
    30. Re:Comments by Anonymous Coward · · Score: 4, Insightful

      Don't do weekly code reviews. Instead, make it a checkin requirement: in order to check in any code, no matter how inconsequential, it has to be reviewed by at least one other dev who knows what the code is doing.
      Also, have a simple set of automated test scripts and require that every change must build and pass all of the scripts before being checked in. Also have a more in-depth set of test scripts that are run on a regular basis, and make sure that failures are fixed. Finally, make sure that you have a test org in charge of maintaining the scripts and adding new ones, so that your code doesn't become 'immune' to your tests.

    31. Re:Comments by ZeldorBlat · · Score: 1

      There are even tools out there that document code for you:

      http://www.cenqua.com/commentator/

    32. Re:Comments by Anonymous Coward · · Score: 4, Insightful

      I used to have that feeling about Hungarian too. Until i read Joel's view of how Hungarian is meant to be . There are definitely some times when it is a Good Thing. Not for your str_ThisIsString variables, but to put you in a mindset so that you know whats going on. Its not something to use everywhere (maybe 5-10% of your variables will need it), but if you put it where its needed, its something that definitely helps code maintainability.

    33. Re:Comments by pushf+popf · · Score: 1

      Tell them that it has to be clean and simple enough that it can be fixed by someone who didn't write it, at 3am. Then put them on call for a few months. Make them justify every piece of technology, since each one is a potential failure and costs money to maintain. Although I'm certain to get drawn and quartered for this, Java isn't the answer to every programming task in the world. If something takes 200 lines of code and a few days in one language, and 100 lines of code, 4 different server products and a dozen external libraries in another, chances re you're using the wrong language and platform.

    34. Re:Comments by GlassHeart · · Score: 3, Interesting
      Well that's a good start, with good intentions, but you need to have a standard definition of what constitutes good function names and good variable names. If you have 5 different programmers on a project, you'll have 5 different opinions on what good names are.

      So what if they are not all uniformly named? Has anybody actually seen a code base where it's possible to call a random function in a class without looking at documentation or the header file? As long as it's an informative name - and code reviews should flag bad ones - you should save your fight for something that actually matters.

      Guidelines on naming, on the other hand, is a great idea. Clubbing smart developers over the head for this is pointless.

      if you take the time to get your code to where Checkstyle likes it, you'd be amazed how easy it is for humans to read.

      One of the myths of software engineering, IMO, is that code is hard to read. For a competent programmer, code is *not* hard to read, in the sense that it's pretty easy to figure out what the code is doing. The problem is what the code is attempting to do, and possibly why. This is why brace styles, spaces versus tabs, and other "low level" coding standards do very little except to annoy. I've worked at several companies, each with different coding conventions, and I follow most of them. Unfortunately, I've found little relationship between maintainability and adherence to coding standards.

    35. Re:Comments by Tim+Browse · · Score: 2, Insightful
      Even for a novice programmer, code like if(x == 456) is self-explanatory, no comments are needed.

      You're right - how could it be possible not to know what that code is doing? (The rule is, the only magic numbers allowed are -1, 0, and 1. 456 is right out.)

      But then again, don't worry, everything should be clear, right? :)

    36. Re:Comments by lbernba · · Score: 1, Funny

      did you notice that the comment does not match the code?
      or is there some spot in the universe where x==456 will check to see if x is equal to 256?

    37. Re:Comments by drxenos · · Score: 2, Insightful

      0-127??? Why? The standard guarantees that int is at least 16 bits.

      --


      Anonymous Cowards suck.
    38. Re:Comments by Hognoxious · · Score: 3, Funny

      Er, like WHOOOSH or something.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    39. Re:Comments by egardner4 · · Score: 1

      Hear, Hear! I couldn't have said it better myself. Every place I've worked over the last 19 years has had a similar policy. We've come up with a small set of simple rules focused on readability as well as correctness. I can't remember a time where anyone agreed with every rule but we all followed them.

      Readability is important both for the person writing the code initially as well as others that follow as maintainers of the code. Most people don't think of correctness as playing a role in coding standards but that's naive. When I coded in C we had a rule to use compound statements (i.e. with braces) for the bodies of all control statements even if the body only contained a single statement. It's too easy for someone to add another line to the block without noticing the lack of braces. This can lead to any number of critical errors.

    40. Re:Comments by Glonoinha · · Score: 1

      In the past five years I have YET to see a Javadoc output that doesn't completely suck ass. Ever.
      If Javadoc is the best you can do for support documentation, just include the source code in the jar file so we can figure out what the code is doing.

      In other words, if source code documentation isn't worth doing well (by hand, while you still remember the original intent) - it isn't worth doing at all.

      --
      Glonoinha the MebiByte Slayer
    41. Re:Comments by zeath · · Score: 1

      Sutter's Exceptional C++ is similar to the Effective series and is also quite good.

    42. Re:Comments by Anonymous Coward · · Score: 0

      I work for a small IT company, ~20 developers and for the last ~5 years I've played a part in deciding Coding Standards. I'm now the Development Services Manager and do this sort of thing a lot still. Technology is always changing.
      We have a coding standard docs for
            1. C#, i.e. variable names/declarions, methods, and even white space, Pascal vs. camel, etc.
            2. SQL, i.e. Stored procedures, SP templates, naming, aliasing, etc.
            3. Developer DOs and DONTs, i.e. Never use "*" in a select, refrain from cursors/temp tables, No .ToUpper() for string comparisons, etc.
            4. Best Practices doc for Code Repository (StarTeam), Windows services, Web Services, etc.
            5. Process flow docs for each client's application
            6. To ensure compliance we use FxCop, Daily Code reviews, code templates, etc.

      There's much more to this! I would recommend starting with someone's published coding standards and changing them as you see fit from there.

      Good luck!

    43. Re:Comments by swillden · · Score: 4, Funny
      if (x == 456) { // Check if step motor reached final position. If yes, halt motor, otherwise step

      That line still contains an example of one of my biggest pet peeves... the use of magic numbers. Okay, so the comment explains what 456 is, but not why and makes no provision for managing changes. What if a new design had a stepper motor whose final position was 256?

      Magic numbers are a reality, of course, especially when dealing with hardware. But if there's no way for the code to dynamically determine the values, the very least you can do is to define a symbolic constant, and collect the constant definitions together in one place. For example:

      #define FOUR_HUNDRED_FIFTY_SIX 456

      // ...

      if (x == FOUR_HUNDRED_FIFTY_SIX) { // Check if step motor reached final position

      See how much better that is? And if the value changed to, say 100, all you have to do is modify the constant definition in one place, like:

      #define FOUR_HUNDRED_FIFTY_SIX 100

      Really, a little extra work up front goes a long way.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    44. Re:Comments by Anonymous Coward · · Score: 0

      And tell them what good comments are.

      "Every one" "knows" that "good comments" are "essential".

      No one adds them.

      I think many people don't really consider the meaning of the term "good comment".
      And I think many coding standard writers don't consider or explain what it is they actually want and why - because of course to them is is "obvious" ( no resource is less common than "common sense").
      Which of course makes it hard for the coders to give them what they want - even if the coders really want to.
      Be explicit and provide examples.

      Eg what are you (or the code) doing, why are you doing it, what are the expected inputs, what are the known flaws and error conditions. etc.

      Give examples of code and good and bad comments in your style guide/coding standard. Explain why teh good one s are fgood and the bad ones are bad.

      If you think all the suggested inclusions are obvious then why do you need to write coding standards?

      People still won't do it, but they'll have less excuses for not doing it and you'll have better pretext for kicking there lazy asses until they do what you need them to do.

    45. Re:Comments by el+cisne · · Score: 1, Funny

      HA!!! YOU were the guy who wrote this code I am having to work on now!!! ;-)

    46. Re:Comments by Anonymous Coward · · Score: 0

      No, even if that was 'just an example', you would have comments that explained the code, not the obvious steps they represent. You are explaining your purpose, not the language, to the reader.

      You provided an example of a terrible comment, claiming it was a good one. Exactly what is exemplary about that?

      if x == 486 { // If CPU is an 80486, check for a co-processor.

    47. Re:Comments by gordo3000 · · Score: 1

      um... wouldn't it be a lot easier to name the variable "final_position" and then have the #define statement so that gets changed, rather than reading four hundred fifty-six and having to remember it doesn't actually equal that??

      just personal preference, but I hate it when people name a variable with a number, it feels just like a magic number when I read code.

    48. Re:Comments by zerocool^ · · Score: 1


      You're really into job security, aren't you?

      --
      sig?
    49. Re:Comments by Philodoxx · · Score: 4, Insightful

      It's important to comment "if x==456 then..." if it is not readily apparent why x might contain that value. having a comment of "// check to see if x is 456" is counter productive, you're right. A comment like "// x having the value of 456 indicates that the previous operation failed because the CPU burst into flames" is useful, and can help programmers decipher huge decision structures.

      --
      Oh, a lesson in history from Mr. I'm my own grandpa.
    50. Re:Comments by Simonetta · · Score: 2, Interesting

      Anyone who protests that they like their own style better because they can read it easier (while everyone else can't) shouldn't be working for you.

          Maybe instead these people can be requested to write programs that reformat the written code from their style to the company standard style. They should do this, of course, on their own time at home.

          No magic numbers in the code is a good idea. Especially for embedded systems code where there are lots of configuration registers in the microcontrollers to set up.
      For example, avoid constructions like:

          ldi config, 0x28 ; LoaD Immediate Value into register
      instead use:
          ldi config, (1 bit5goodname) | (1 bit3goodname)

          I'm always encouraging people on embedded coding sites to do this.

          Running the comments through a spell checker is a good idea. If you can get the language environment to separate the comments from the active code and feed the comments alone into a good spell checker. I haven't seen any compiler yet that does this, but it should be too hard to set up a text filter program for it. A least no one in your company will be embarrassed by simple misspelled words in the comments. Great for your H1-B people also who are using English as a second or third language and haven't mastered the unusual spelling of thousands of common English words.

          I'm also becoming a strong believer in Talking Documentation. Get a high quality Speech-To-Text converter program and a fast PC. Place this PC next to the development PC with the source code. Start the Sp-to-Tx and the source code listing. Describe in words the entire listing as if there were someone there who was endlessly fascinated by the code and you. Take hours if you need too. Save the text file of the transcribed dictated documentation with the source. Don't be concerned about formatting and paragraphs or even coherence. If needed, someone can do all that later. It's important just to have the detailed dictation text that describes the source. It seems strange, but it does work as a documentation technique.

          Don't forget to spell check your own stuff too.

    51. Re:Comments by Parham · · Score: 1
      I understood what you were getting at, but as stated, the example was just a weak one to justify your point. I think the above threads were just saying that over-commenting (such as an intuitive if-statement) or obvious commenting, is a poor thing to do and just takes up extra space and may clutter up code.

      What hasn't been mentioned yet is how to insert comments into code. In-line comments and comments can also be poorly written. For example, if you use an in-line comment but it drags too far out, it may make code look ugly. Then there are people that do these:
      if (x) { //this is code
      ........ //that will do perform some
      ........ //task if x is set
      Which I think also tends to look terribly ugly when it's done too much. I'm curious how people comment (not what they comment).
    52. Re:Comments by bigNuns · · Score: 1

      nonsense... planning ahead does not equal comments in your code... planning ahead, as you mentioned at first, can be in many forms, and hopefully takes place long before you open up your favorite text editor to write some code... if i have created (or been handed) good specs i can start writing clean and decent code without writing it all out in comments first... nor do i need to comment every single little bit of code... you being able to look at code and make such a call based on a lack of comments is silly and just shows a bit of arrogance.

      just because someone doesnt comment their code does not make it unplanned, it just makes it (possibly) harder for you to understand. i would rather have code that is easy to read and is well planned (i.e. variable and method names that make sense, logical structure) without comments than crappy code loaded with comments... dont get me wrong, comments are all well and good, but the lack of them do not show a lack of planning... i dont doubt the situation you described has happened, but i do doubt you will always be right in such a scenario...

      --
      .................... ...mmm farm fresh...
    53. Re:Comments by Al+Dimond · · Score: 1

      Whoa there... your comment isn't exactly a work of art either: it makes the line longer than 80 characters without a line break.

      Some people say "an 80-character width limit? Maybe in the 80s!" But a few super long lines in the middle of code, which mostly contains nice short lines, are really hard to read. 80 characters for whatever reason seems to be a nice width to read. Gives enough variance in line lengths to allow you to quickly scan code structures and have room for different indenting levels (as long as you don't set up your indention like a damn fool), while avoiding those pesky super-long lines that either wrap around to the next line or force you to scroll over (depending upon editor settings).

      (plus it means you can :vsp two files if you have a decent monitor, which is a big plus.)

    54. Re:Comments by Anonymous Coward · · Score: 0

      #define FOUR_HUNDRED_FIFTY_SIX 100

          I hope that was a mistake ...
          Try naming it:

      #define FINAL_MOTOR_POSITION

          instead.

    55. Re:Comments by Spacejock · · Score: 1

      At my workplace, it's "It if Runs, it's Right"

    56. Re:Comments by Anonymous Coward · · Score: 0

      i think you're pretty much right.

      i would say that comments should explain why the code is made the way it is, not really what it does

      kind of like instead of saying "//checks to see if x is equal to 456"
      you could say "//if x is equal to 456, we've reached the end of the list and need to get a new list" or something like that.

    57. Re:Comments by Red+Flayer · · Score: 1

      " Tell them to use comments in code, and be sure that they make them good comments."

      I find that a user-moderated comment system works well for me in my workplace :)

      --
      "Trolls they were, but filled with the evil will of their master: a fell race..." -- J.R.R. Tolkien on Olog-hai
    58. Re:Comments by NilObject · · Score: 5, Interesting

      The best advice I ever got was to write "why", not "what" a piece of code does.

      // Increment counter
      counter++;

      See? Completely useless. Let's try again:

      // We've processed one more message
      counter++;

      Ah, much better! Any Computer Science peon knows that "counter++" increments counter. What they might not know is why. Those simple bits of "why" comments can make reading code so much easier.

      Organizational comments (those that delineate what chunks of code inside of a method do) can be helpful, too. (Ex: "// Normalize string", "Encode string", "Send String") They make narrowing in on a particular "task" performed in a method even easier.

      Other than that, however, the biggest and most persistent and most annoying problem I have is poorly-engineered code. Some people just do not know how to apply their college degrees. I wish CS degrees had a bigger emphasis in software engineering. Would you hire an architect who couldn't design anything bigger than a porta-potty? Why does the CS industry get away with doing the same thing?

    59. Re:Comments by chachacha · · Score: 5, Insightful
      Agreed.

      People forget that code itself is a language. And usually a much more clear and logical one than English. Requirements docs are for explaining complex business processes and code itself explains most of what is going on. That is not to say that comments are not important, but when they exist I want them to be there for a reason. Anyone reading your code is assumed to be conversive, if not fluent in the code language, so comments should explain things such as:

      • strange idioms (ie. select((select(FH), $|++)[0]); // autoflush FH)
      • reasons for non-obvious choices of algorithms (ie. // we're not using an FFT here because ...)
      • intended input/output (a "comment preamble" to a method such as generated by VisualStudio. This is extremely useful for someone following a stack trace.)
      • candidates for refactoring (ie. // this method can now be collapsed/condensed ...)
      • pitfalls that are likely to trip up an intermediate developer
      • (many other valid reasons exist)


      Comments that merely "translate" basic code language into english are at the very least useless and often harmful: they bloat the filesize, obfuscate executable lines (I have deleted blocks of apparent comments only to find that unit tests are subsequently failing - the reason? - a single line of executable was buried between 2 dozen lines of commented out code), increase the burden on the maintainer and/or reader who must sort out the important details from the quotes laid down by Capt. Obvious.
      --
      I do like programming things that work super quickly, especially when they work super quickly, super quickly.
    60. Re:Comments by roystgnr · · Score: 5, Funny

      Even for a novice programmer, code like if(x == 456) is self-explanatory, no comments are needed.

      You're right - how could it be possible not to know what that code is doing? (The rule is, the only magic numbers allowed are -1, 0, and 1. 456 is right out.)


      Okay, but that's going to get really hard to debug!

      if (x == (1+1)*(1+1+1+1)*((1+1+1+1)*(1+1+1+1)*(1+1+1+1)-(1+ 1+1+1+1+1+1)))

    61. Re:Comments by Coryoth · · Score: 1

      And make sure they update comments if changes necessitate it. There's nothing worse than reading through a function's description, complete with well-documented inputs/outputs/conditions/etc. and finding out that those things no longer apply because somebody changed a 1 to a 2.

      That's why it's nice to have some formal semantics for inputs, outputs and conditions so that the documentation can be easily and automatically converted to, say, unittests. Take, for instance, JML which provides semantics for commenting your functions in a way that

      (1) Can be used to generate automatic runtime checks for debugging
      (2) Can be automatically included in your documentation
      (3) Can be used to automatically generate JUnit unit tests

      If you change the code but not the comment in a way that means it no longer behaves as the comment indicates... well the code will fail the unit test.

      Even little things like Python's doctest module can be kind of nice, ensuring that the docstrings still represent the code they are meant to be documenting.

      Jedidiah.

    62. Re:Comments by shobadobs · · Score: 2, Insightful

      I've never understood all this hokery. You only have to obey one simple rule.

      The general theory of coding practices: Don't be a moron.

    63. Re:Comments by Anonymous Coward · · Score: 0

      Unfortunately programmers know that good comments mean less job security. If you are the only one that understands the code, you can't be fired!

    64. Re:Comments by swillden · · Score: 1
      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    65. Re:Comments by Jeremi · · Score: 1
      80 characters for whatever reason seems to be a nice width to read


      Not for me -- shorter lines may be prettier, but they mean that fewer lines can be shown at once in my text-editor window at the same time. That means that with code limited to 80 columns or less, I end up constantly scrolling up and down in the code, which is annoying and tedious -- like trying to fix an engine while viewing it through a periscope.


      So given that both short lines and long lines have their downsides, and that "80 characters" feels like an arbitrary number chosen for obsolete historical reasons, I prefer to just make my lines however long they need to be to do what they need to do, and not force-insert line breaks at any pre-specified regular intervals.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    66. Re:Comments by BrynM · · Score: 2, Insightful
      nonsense... planning ahead does not equal comments in your code... planning ahead, as you mentioned at first, can be in many forms, and hopefully takes place long before you open up your favorite text editor to write some code...
      If you have prelimary docs, then just open them in a text editor and cut-n-paste from them as you go. How hard is that? Don't tell me you're one of those who writes a design doc, only looks at it rarely and imagines "I remember it all" (I'm hoping you're not, you seem smarter than that). That's not planning, that's getting the general meetings out of the way then running away to code off the cuff.

      Referencing the documents that the PHB/customer helped write also makes your comments easier for them to understand. Not to mention something the PHB/customer is actually happy to look at (gasp!). It usually makes for better and more consistant documentation - especially if you add in minor "this is for that" line comments where needed.

      When it comes down to it, it's actually a lazier way to go in some respects even. It's been a huge time saver and a check against feature creep for me in many cases. Try it and you may never go back.

      --
      US Democracy:The best person for the job (among These pre-selected choices...)
    67. Re:Comments by Retric · · Score: 1

      IMO a lot of coding practices tend to make things less clear.

      Would you rather a bunch of simple lines like:

      boolean GoodNameA = (Name.length < maxNameLength)
      boolean GoodNameA = (Name.length > 0)
      boolean temp2 = (Fark.length < maxNameLength) && (Fark.length > 0)
      boolean temp3 = (Logo.length < maxNameLength) && (Logo.length > 0)

      if ((GoodNameA ) && (GoodNameB) {
        if (Temp2){
          if (Temp3){
          ...
          }
        }

      ...
      }

      Or a clear compound line which shows you the context for all those simple lines so you can see what's going on.

      if ((Name.length < maxNameLength) && (Name.length > 0){

        if(Fark.length < maxNameLength) && (Fark.length > 0)
          (Logo.length < maxNameLength) && (Logo.length > 0)){
           ...
        }
        ...
      }

      I think it's a good idea to use a tool like Jalopy to keep some consistent basic style, but a little code review goes a long way to keeping things clear.  Just the idea that someone is going to look at the source code keeps most coders from doing anything that's all that ugly.  So while a few coding ideas like "No magic numbers" is a good idea I think it's best to let the code fit the style of the problem not some exacting standard.  Coders have enough ways to waste time without giving them boring takes to procrastinate about.

    68. Re:Comments by th4tGuy() · · Score: 2, Insightful

      Agreed...

      And I would consider attempting to get in the habit of putting the number / constant first. If you accidently drop an = from ==, it will be a compiler error. The other way around can be maddening to hunt down and correct... although a good IDE will at least give you a warning.
      EX:

      #define UPPER_BOUND 456

      if(x == UPPER_BOUND) do_something_useful();
      if(x = UPPER_BOUND) assign_upper_bound_to_x(); and_always_evaluate_to_true();

      if(UPPER_BOUND = x) compiler_error(); //!

      --
      -- As soon as I have an interesting sig, you'll be among the first to know!
    69. Re:Comments by IllForgetMyNickSoonA · · Score: 1

      I'm not a friend of a hungarian notation. It's OK to prepend a "p" to a pointer, for it is always nice to recognize a pointer at once (that's why I hate those C++ 'references'), but everything going beyond that brings as good nothing, while introducing a *lot* of work when you decide to change the type of the variable.

      Where I work, the rule is "if you like it, use it, if you don't - don't use it, but you HAVE to be consistent within a compilation unit."

      Besides, what would a "pointer to unsigned short 'sy'" look like in hungarian notation? :-)

    70. Re:Comments by lourensc · · Score: 3, Insightful

      if (x == 456)
      {
      ...;
      }
      this is bad code and no amount of commenting is going to fix it. It begs 2 questions; What is x and why 465? I would recode it as something like this that makes the purpose clear enough that no comments are needed:

      const int screenWidth = 456;

      if(xCoordinate == screenWidth)
      {
      ...;
      }

      this way I type more code but less comments.

    71. Re:Comments by Anonymous Coward · · Score: 0
      Actually I'd rather you not duplicate code all over the place.
      boolean nameok (string name) {
        return 0 < name.length && name.length < maxNameLength;
      }
      ...
       
      if (nameok (Name)) {
        if (nameok (Fark) && nameok (Logo)) {
      ...
        }
      ...
      }
      p.s. I don't do Java, so don't complain if this isn't the right syntax/paradigm.
    72. Re:Comments by IllForgetMyNickSoonA · · Score: 1

      Oh, I forgot to mention, that the most supporters of the hungarian notation in my group have changed their minds over the years. Nowadays, only one of them seems to be sticking to the notation, and that's more out of a habit (as he says).

    73. Re:Comments by Anonymous Coward · · Score: 0

      Some shit-for-brains modded this overrated, but it's not, it's dead on, instead of trying to come up with and remember all kinds of little rules, how about just stopping for a second and taking one step back and thinking for just a moment what it is you're doing and trying to accomplish, and then make sure what and how you're doing it makes sense.

    74. Re:Comments by shinghei · · Score: 3, Informative

      But the generated document is only as good as the comment itself, isn't it? Correct me if I am wrong, I don't think any of the tools that you mentioned can generate any intelligent comment. What good is the comment "The openSocket method throws a SocketException"?

    75. Re:Comments by CyanDisaster · · Score: 1

      ...At my workplace, it's "It if Runs, it's Right"...

      And at my workplace, it's "If it runs, I've managed to crap out the right code somewhere between the countless distractions." My boss expects me to program PHP scripts for websites while dealing with customers, computers, and phone calls. Getting a significant block of code done without distractions is virtually impossible. Even though I manage to come in under/on budget, the actual timeframe between starting and finishing a project is much longer than is necessary.

      As for commenting my code, it depends on where I'm at with my project. Usually at the start of it, my comments are fairly clear, though as the project drags on, the more I'm inclined to not even bother with them. Between pressure from the boss and a distaste for the project, I'll forego the comments and hope that the code is self explanatory...

      Hope be with ye,
      Cyan

    76. Re:Comments by weicco · · Score: 4, Funny

      Oh yes, comments. Well we use comments as version/history information. We have every code file and project file on a single samba-shared volume. When somebody wants to change something he/she shouts "I'M OPENING THE FILE X, DON'T TOUCH IT NOW" and he/she has done modifications he/she adds very informative comment somewhere in the file (name/date/what was done), saves file back to disk and yells "OK, FILE X IS FREE NOW"

      Documents... There is no documents. Who needs those anyways? It's much more fun to code something when you really don't have any idea what its supposed to do.

      Test plans? Nah, waste of time I say!

      Testing? Well, somebody runs it and if it doesn't crash, it works.

      I must say I'm in the best damn work place ever! And now if you please, I'll go and find some ethernet cabel to strangle myself.

      --
      You don't know what you don't know.
    77. Re:Comments by zardo · · Score: 2, Insightful
      It's called test driven development, some people do it without even thinking about it, everyone else is a bad programmer. By documenting your thought process, you help other programmers mature. That's the jist of it.

      In addition to everything others have mentioned, for web development you need a good deployment system to compliment subversion or CVS or whatever you use for version control. As far as planning goes, always start with the data model, that is my best advise. Come up with the most versatile data model you can, try to plan for everything, don't just add columns to your existing tables as you go along (or try not to at least). Using a program like inkscape, omnigraffle, or visio can be handy for this, although it takes a bit of practice to come up with useful diagrams.

      Usually the data model is the easiest part of the application to convey visually and will lead to the quickest understanding by newcomers. It's usually the first thing I start with when I'm familiarizing myself with something new, whether or not there is good documentation, I'll look in the database first.

    78. Re:Comments by Bill+Dog · · Score: 1

      Besides, what would a "pointer to unsigned short 'sy'" look like in hungarian notation? :-)

      We get it. But if it's so damn important that you had to use an unsigned short, and couldn't just use an int, don't you think it should be documented so people don't come along and overflow it or assign or compare negative values with it?

      --
      Attention zealots and haters: 00100 00100
    79. Re:Comments by Shokac · · Score: 1
      Write your comments first, then code to match the comments. This way, you are forced to clearly define the input, output, variables and algorithms that will be used in the code BEFORE you start coding. When it's clear in your mind, the coding becomes easier and less confusing; and you have an outline to follow to make sure you don't forget something.


      First : Mod parent up (informative) Secound : This is called pseudocode programming. First write down what should be done, then start coding, not other way around.
    80. Re:Comments by Bill+Dog · · Score: 1

      Sure, you can write your comments first, although don't write them as comments, write them as function names. That is, when you go to code a function, think about the steps that need to be accomplished, and make each a descriptively-named subroutine call. Then your function comments itself, which it should. Save actual commenting for things that can't be said in code.

      --
      Attention zealots and haters: 00100 00100
    81. Re:Comments by Anonymous Coward · · Score: 0
      // Increment counter
          counter++;
      See? Completely useless.

      Not so fast, bud ..
      obscure_class * counter;
      int operator ++ (obscure_class *);
      .. ha ? :-)

      On other hand the code with overloaded ++ for a class pointer won't
      likely to have any comments to begin with ..

    82. Re:Comments by chachacha · · Score: 4, Interesting
      But even that can be rewritten as
      const int SCREEN_WIDTH = 456;
      if (SCREEN_WIDTH == xCoordinate) { ...
      Using the constant on the left hand side of an equality test such as this will cause a compile-time error if you accidentally type
      const int SCREEN_WIDTH = 456;
      if (SCREEN_WIDTH = xCoordinate) { ...
      Come on, we've all done it. ;)
      --
      I do like programming things that work super quickly, especially when they work super quickly, super quickly.
    83. Re:Comments by stoborrobots · · Score: 1

      I'm not a friend of a hungarian notation.

      Neither was I until I read Joel's take on it... After that, the correct use of Hungarian Notation seems to be a much better idea... I can also see how pointless the dark-side of Hungarian is...

      I think there should be more style-guides emphasizing the appropriate use of Hungarian...

    84. Re:Comments by RobbieGee · · Score: 1

      I know where you're going, but on a serious note I'd call it pSy or p_sy, or rather something like pSystem or p_system or other descriptive name. I don't see any point in using hungarian notation to indicate the variable type.

      For PHP scripting, I use HN to indicate wether a variable is 'safe' or 'unsafe' for a database query using an 's' and 'us' prefix. I have standardized on a set of very few notations I use throughout the code and I don't see anything wrong with that. The problem is when people use it without knowing why, or out of old habit.

      --
      If you get this, we're 10 of a kind.
    85. Re:Comments by Anonymous Coward · · Score: 0

      Even better:

          processed_messages++;

    86. Re:Comments by kastberg · · Score: 1

      Atleast you're following a known model;

      The Theorem Theorem: If If Then Then

    87. Re:Comments by Bill+Dog · · Score: 1

      As long as you never need a dead tree version of your code. Hard copy doesn't scroll horizontally, it wraps, making following the code indentation more difficult.

      I can use the mouse scroll wheel or the page up/down keys to quickly scroll vertically through code. Having to scroll right so that most of the code and its indentation is out of view just slows me down.

      --
      Attention zealots and haters: 00100 00100
    88. Re:Comments by Anonymous Coward · · Score: 0

      Ha fucking ha. If Linus had invented Hungarian Notation you'd all be masturbating over it right now.

    89. Re:Comments by TeRanEX · · Score: 1
      Tell them to use comments in code, and be sure that they make them good comments.
      IMHO this is wrong. You should tell them to refactor their code. If they do it correctly, the code will be readable without any comment. In refactoring terms a comment is a code-smell. It may seem strange to not write comments, however i know this works perfectly well since this is how we do it at work... (and our code is very readable). Also it avoid to have out-of-date documentation, since your code is your documentation.
    90. Re:Comments by iangoldby · · Score: 1

      And finally, all people who use Hungarian notation are locked in the basement and given menial tasks until they repent their sinful ways.

      Don't forget that there is a difference between 'system hungarian' and 'apps hungarian'.

      System Hungarian I agree is a waste of time. The compiler already knows the types of each variable.

      Application Hungarian - the original intention of the inventor, Charles Simonyi - though is another matter entirely and seems quite sensible.

    91. Re:Comments by iangoldby · · Score: 1

      in order to check in any code, no matter how inconsequential, it has to be reviewed by at least one other dev

      That's a great way to ensure that developers delay checking in their code until they absolutely have to.

      If you've never lost code due to a disk crash or had to roll back some edits, you won't realise what a bad idea this is.

    92. Re:Comments by CountBrass · · Score: 1, Insightful

      You are so lucky you don't work for me, I'd demote on the spot if you produced crap like that for me.

      --
      Bad analogies are like waxing a monkey with a rainbow.
    93. Re:Comments by JulesLt · · Score: 3, Informative

      Which is why we would say :
      1) Don't use variable names like x, use something that indicates the meaning of the variable - so maybe in this case lErrorStatus
      2) Don't hardcode magic values, use a meaningful constant - which also means only one point in code needs to be changed if we switch CPU and find there is a different on-fire code

      Then we get

      if lErrorStatus == CPU_ON_FIRE then

      Which I think is pretty self-explanatory.

      One thing that isn't clear yet is whether this bit of code is sitting in a little function or part of a big block - i.e. what it's going to do on the 'then'.
      Now at some future point we might find ourselves needing to check CPU_GETTING_QUITE_HOT. So we will still have to impact all occurrences of
      lErrorStatus == CPU_ON_FIRE to add an extra test.
      This leads to

      3) Encapsulate tests in meaningfully named BOOLEAN functions.

      I'd say it is swings and roundabouts as to whether (3) is worth the effort.

      If the _cpu_on_fire(ErrorStatus) test is just done once, then we've had to go to a lot of effort to encapsulate a single line of code (as the expression is already boolean). If it is used >1 times it is definitely worth wrapping, ditto if the expression is complex - just to make sure developers get into the habit, as much as to protect against any change. (I think it's better to get into a slightly more time-consuming habit of doing the right thing and break it occasionally, than into the habit of doing the quickest thing and having to think to do the right thing).

      The other principle that points to (3) is the one that blocks of code should be 'readable' and if possible a block should fit on one page - i.e. when you have an
      if . . then . . .else . . end structure and the bodies of all the elements are large then each should be a procedure/method itself.
      Again, _cpu_on_fire(ErrorStatus) isn't a good example as we'd be replacing one line with one line.

      However, if you have a standard logging mechanism (say log4j), and template code for functions/methods, you can use this encapsulation to record the fact that the test occurred, input and output values, rather than leaving it to the individual developer to remember to add logging before their 'if' and on each conditional path.

      --
      'Capitalists of the world, unite! Oh ... you have' (League Against Tedium)
    94. Re:Comments by Anonymous Coward · · Score: 0

      A comment like "// x having the value of 456 indicates that the previous operation failed because the CPU burst into flames" is useful, and can help programmers decipher huge decision structures.

      That comment is not useful. It's papering over bad code. 456 should've been a symbolic constant with a self-descriptive name. No comment needed.

      Many comments are like that - bandaids for badly written code.

      When I see new code to maintain I groan if the comment density is too high - it's often an indication of a programmer who doesn't know what the hell they're doing. Bugs de jour.

    95. Re:Comments by jrumney · · Score: 1

      Perhaps most important is to comment what 456 means (or better - use a named constant). It looks like some magic number, why was it chosen?

    96. Re:Comments by cogg · · Score: 1
      Using the constant on the left hand side of an equality test such as this will cause a compile-time error if[...]
      Better at compile-time than run time - not that I'm justifying any errors!
      --
      "Never 'clear the air'. Instead, investigate all the subtle nuances of the word 'fester'." - R. Candappa
    97. Re:Comments by KlausBreuer · · Score: 1

      "Every time code is checked into CVS, it is formatted by Jalopy."

      Aaargh!
      A terrible idea I've seen happen myself. See, code formatting does not mean slavishly sticking exactly to very detailed specifications (as a utility would do it), but also making sure that the code is very easy to read.

      While most code should be formatted according to certain rules (and preferably the same rules by everybody), some code pieces may be a *lot* more readable when formatted just slightly differently.
      Certain parts of a long SQL command neatly aligned under each other. Difficult case statements written and commented in a different way. Peculiar if then else else commands aligned differently, according to the functions called, with their parameters aligned (to show how only the third parameter differs). Things like that.

      And a tool like Jalopy screws this up and irritates everybody - I'd advise against it.

      --
      Free PC version of ChipWits at http://www.breueronline.de/klaus/chipwits/
    98. Re:Comments by Heembo · · Score: 1

      If they use Java, make em use Java (right) and also make the core developers publish their code and best practices on the intranet so the new developers can see the in house libraries that your team uses. Good shops write proprietary wrappers around third party libs so they can be swapped out - especially security libraries.

      --
      Horns are really just a broken halo.
    99. Re:Comments by Anonymous Coward · · Score: 0

      Besides, what would a "pointer to unsigned short 'sy'" look like in hungarian notation? :-)

      pnSy

      I guess the joke is funnier if you use pure Microsoft-style Hungarian notation instead of a modified form though.

    100. Re:Comments by mooingyak · · Score: 1

      Not always. Sometimes you need to do something that looks really ass-backwards, and that may take a bit of commenting.

      The database we use has an extremely poor query planner. It gets tripped on the weirdest things. In particular, we have a table that has indices on 3 different fields. On a table of approx 1.2 million records, one of those fields has a very low variation, one has moderate variation, and one of them has high variation.

      So search by field 1, and you'll need to scan 200K records.
      Search by field 2, and you'll need to scan 30K records.
      Search by field 3, and you'll need to scan 100 or fewer records.

      The database ALWAYS searches by the second one, no matter how we rephrase the query. We can't change the indices (for reasons not worth getting into here), so we had to work around it some other way.

      I eventually wrote some code that used the database to query ONLY by the 3rd field, then manually scanned the result set to filter out the records that didn't meet the conditions for the other two fields.

      The code I wrote was clear in what it did, but without knowing the background, someone would probably look at it and wonder what the hell was wrong with me and why didn't I just use SQL, since that's the exact thing it's designed to do.

      I put in a comment block describing the case above, along with some references to performance research (it cut down execution time from over 9 hours to about 5 minutes).

      The important thing is in knowing what actually needs a comment.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    101. Re:Comments by Anonymous Coward · · Score: 0

      Comparison against constaints should have the constant on the left side.

      if (MY_456_CONSTANT == x);

      Isn't likely to be accidentally stored, whereas

      if (x = MY_456_CONSTANT);

      Would happily store a value into 'x' in many languages. This simple change lets the compiler catch it. I have hundreds of other style solutions learned over decades of coding. Don't get me started on memory management and all the simple techniques that very few coders use - 'cause I'm not that stupid - or so they think. Basically, code to take advantage of compiler checks.

      Coding style is critical, maintenance is key, fast is secondary and should be addressed "later." Oh, developers should have the slowest machines so they write more efficient code.

      1 more thing. 1 highly qualified developer can easily replace 5 newbies. Pay your good developers about double the "going rate" and don't make them work with college boys or overseas newbies hired on a street corner because they need bodies.

    102. Re:Comments by fgb · · Score: 3, Insightful

      I get really irritated when developers check in code with sections commented out. If the code is no longer relevant - delete it! If you really need to get it back, get it from a previous version in the source control system.

    103. Re:Comments by TeRanEX · · Score: 1
      Not always. Sometimes you need to do something that looks really ass-backwards, and that may take a bit of commenting.
      Yes indeed that's true. Sometimes you have to use hacks etc because of external libraries etc which can't modified. Then comments are good. In those cases we always start our comments with 'WHY:' or 'HACK:' to clearly indicate the reason for the comment.
    104. Re:Comments by swillden · · Score: 1

      You are so lucky you don't work for me

      Lucky? I suppose that's one way to look at it. I would consider myself to be *unlucky* to work for someone with no ability to recognize a joke.

      Or maybe you're playing, and I'm the one not catching the subtle cues? nahh....

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    105. Re:Comments by gronofer · · Score: 1

      It's what happens if you put technical questions to a vote instead of finding the right answer.

    106. Re:Comments by nickos · · Score: 1

      "Anyone who protests that they like their own style better because they can read it eaiser (while everyone else can't) shouldn't be working for you. Team players are needed."

      You know, I used to agree with this. That is, until I joined a company where the (ancient) code standard was to use 2 spaces to indent. As a result of this stupidity many developers use tabs, and the result is that we have 2 different styles.

    107. Re:Comments by slackbits · · Score: 2, Insightful

      >Using the constant on the left hand side of an equality test such as
      >this will cause a compile-time error if you accidentally type
      >const int SCREEN_WIDTH = 456;
      >if (SCREEN_WIDTH = xCoordinate) { ...

      It depends on the language. Any language that has a boolean type is going to give a compile time error to xCoordinate = SCREEN_WIDTH. The only time it will not is if you write if (something = true). But then again that comes down to bad code.

    108. Re:Comments by istartedi · · Score: 1

      //gack.
      if (456==x)
          {
          printf("I will not accidently assign x\n");
          }

      --
      For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
    109. Re:Comments by Anonymous Coward · · Score: 0

      Is that not his point?

    110. Re:Comments by Anonymous Coward · · Score: 0

      Standards? I use a Standard Keyboard. That way everyone can read the code.

    111. Re:Comments by jlencion · · Score: 1

      CakePHP, a rapid development framework for PHP, has a pretty decent guide of coding standards. It is short and might be a good place to start.

      --
      Joe Lencioni | Shifting Pixel
    112. Re:Comments by arkanes · · Score: 2, Insightful
      None of the above, because you're likely to be using these sorts of checks a lot of times, in multiple places. Write functions (make them inline or macros if performance is what freaks you out) with descriptive names that perform these checks.
      if (name.FitsInBuffer() && name.length > 0)
      for example. Of course, in this particular case it'd be better to move the maxLength checks into whatever class name is and throw exceptions. These kind of long repetetive checks are prime breeding ground for typos and brainfarts that introduce rare bugs, because the repetetive nature of the code makes your eyes skip over small inconsistencies.
      if(Fark.length < maxNameLength) && (Fark.length > 0)
      (repeat 10 lines checking different variables)
      (Logo.length < minNameLength) && (Logo.length > 0)){
    113. Re:Comments by Ors · · Score: 2, Funny

      The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.

      -- FORTRAN manual for Xerox Computers

    114. Re:Comments by Jakeypants · · Score: 1

      Man, Hungarian notation drives me up the wall. A few of the developers where I work insist on bringing it to the data layer. It's bad enough in languages where variables are strongly typed, but in the database, when the table reads like "strusername, intnumber, datdate, struserlastname," I start tearing my hair out. For fuck's sake, strings aren't even a datatype!

      Can you imagine if people advActually vrbTalked prepLike nnThis?

    115. Re:Comments by Mxyzptlk · · Score: 1

      Wow, that really is 456. Oh my God, I really feel like a nerd for verifying that...

    116. Re:Comments by MemeRot · · Score: 1

      I love hungarian notation, especially when dealing with typeless scripting languages. A good descriptive variable or function name saves a lot of maintenance headaches down the road. With a strongly typed language the preceding int, str, etc is redundant, but the descriptive names never are.

    117. Re:Comments by LifesABeach · · Score: 1

      Just one question. What's 'x'?

    118. Re:Comments by MemeRot · · Score: 1

      Um, I don't think your code is ever going to make it to the next statement.

      if x == CPU_BURST_INTO_FLAMES {
            print 'ah fuck, why bother this will never even print'
      }

      One comment I have - NEVER write code that says
      } else {
              Debug 'This should never happen'
      }

      I've literally seen that exact same debug message in 3 different companies. And yes, it DID happen at all 3 places.

    119. Re:Comments by nyri · · Score: 1

      code like if(x == 456) is self-explanatory, no comments are needed.

      No it's not. "456" should be commented:
      if(x == 456) // file not found error

      Or better yet, a variable should be used instead:
      final static int ERROR_FILE_NOT_FOUND;
      .
      .
      .
      if(x == ERROR_FILE_NOT_FOUND)

    120. Re:Comments by UnknownSoldier · · Score: 1
      Commenting
      ==========

      If you use proper descriptive variable names, you don't need comments 50% of the time! Why? Because if you can't name something properly, chances are, you probably don't understand the problem fully.

      Another good idea, is that many people use "notes" in the code that you can search for, such as:

      // TODO: ...
      // BUG: ...
      // FIXME: ...

      Here are few examples with commentary:
      int nBitsPerPixel; // Look ma, no comment is even needed!
      int bpp; // Bits Per Pixel -- plus now I need to remember what the hell "bpp" stands for. Sure this one isn't TOO bad, but this is NOT FUN when people invent their own non-standard acronyms.

      Callback_Mouse(); // Gee, I wonder, is this a Callback??
      mouse(); // who calls me? and what does it do? Set or Get mouse paramaters??

      Any half-decent editor will have auto-completion, so typing in long names are a thing of the past. Plus you don't have to remember _cryptic_ abbreviations. Dealing with Unix's naming convention is bad enough, don't make me deal with it in code too. (What, someone couldn't think to use the names: /user /temp, instead of the inconsistent: /usr /var ??)

      Coding Standards
      ================

      Whatever standard you pick, PICK ONE. A bad standard is better then no standard at all. and The nice thing about standards, is that there are so many to choose from.

      When dealing with Physics or Math calculations, it always very handy to keep track of the "units". On the HP calculators, they use "_{units}". i.e. 299792458_m/s. In code, this isn't practical -- as the code tends to become too verbose. It would also be great if we could see the "scope" -- local, global without extra clutter. What kind of system could we design/use that is practical?

      Now note that when you take a standard to the logical extreme, you end up with something impractical. Applied to this domain of programming we find that absolute abonimation called Hungarian notation, micro-managing every little detail. (Do you really need to clutter up the variable naming detailing the internals if a string is zero-terminationed?? NO!!)

      However, if you use something more PRACTICAL, you end up with a very nice, compact, naming schema.

      Prefix
      a arrays / tables
      b bool / flag
      i iterators, along with the object type. i.e. iWord
      n number of, or size of. i.e. nWords, nBytes, nBits,
      r reference (not really needed, but some people like them.)
      p pointer (handy with pSrc, pDst, pTmp to indicate the direction of the data flow.)
      g global (together, with '_', you can tell the "scope" of a variable, or function.)
      s static (usually indicates singleton pattern.)
      _ member variable. (some use m_, but that just clutters up the code with a redundant character. Postfix '_' is also in fashion these days. Use whatever floats your boat.)

      Postfix
      _ argument is modified. (Traditionaly, "Out" was used, but that clutters up the code. "In" is also redundant, as a) everyone should be using "const" correctness, and b) everything is "In" )

      And since I'm dealing with math so much I usually add in:
      v vector
      m matrix

      // along with operator overloading, this shows one doesn't need silly verbose

    121. Re:Comments by Retric · · Score: 1

      Ok it was a bad example, but I am trying to point out that being overly verbose in code can lead to bugs.  I have taken 20+ pages of somewhat buggy source code and condenced it down to 2-3 pages of clear but somewhat complex code and found a lot of simple bugs that are from somone spliting things up and then forgeting what's going on.

      The point was "spliting a conditional's logic from the conditional is not realy inherently helpfull". I see a lot of :

      if (someDataType.isValid()) {

      }

      Which is fine if you use isValid is used all over the place, but in cases where somone overloads ifValid a few times and then has a bug somewhere it's not realy helpfull.  IMO the only reason to have a function do something is if your going to use it in several places or it's over 1/3 a page of code that does some clear and independent function.

      IMO a line of code should be a clear thought such as "if (odd condtion is going on) { do something}"

      When you write

      Boolean DBready= ((DBcon != null)&&(DBcon.isValid())&&(DBcon.isReady))
      if (DBready){
      }

      you have lost something because overtime people will start adding lines between DBready and the if so it becomes harder to follow what's going on.

      I have also seen where a bunch of those type of checks are at the top of a code block so that they can throw a try block if something is wrong, but they don't document that their code is doing this.  So they have section where they assign a bunch of boolean values with their value. (each of which is only used once)  Which makes it harder to follow AND buggy if things are moved around.

    122. Re:Comments by Boing · · Score: 2, Insightful

      I agree with you, even inasfar as to say that I think putting constants on the left side is a good habit. However, there is a hit to readability when you do it that way. English speakers read left-to-right, and the subject nearly always precedes the object in a sentence. "if (5 == x)" may keep you from doing accidental assignments, but it also reads the same way "red is my car" would. For me, that means another second or two of parsing it in my head, which breaks the flow of my code review.

    123. Re:Comments by UnknownSoldier · · Score: 1

      > I get really irritated when developers check in code with sections commented out. If the code is no longer relevant - delete it! If you really need to get it back, get it from a previous version in the source control system.

      I assume you're not talking about #if ... #endif sections.

      How many times has code been cleaned up, and ended up broken? It's a PITA to:
      (1) rename / resave the current version as "new"
      (2) fetch the old one
      (3) diff
      When it is easier to read the "old" and "new" code, intermingled.

      Sometimes the old code is left in, as a "fallback" -- since the new code is still in a state of flux, and hasn't been thorougly tested. A good example is optimizing a function, piece-wise. I found it best to:
      (1) have complete copy of the original function commented out
      (2) have a "working" copy (or is that "not-yet-working" ? ;-) of the new function, with commented parts of the original that are in the state of being converted.

      But yea, once the stability has settled down and the new code is working, I agree. Nuke the old sucker. Unfortunately, once code is checked in, people tend to forget about it. "It's working, right? Why clean up cruft?" lol.

      --
      /. sucks @$$ for posting code snippets "Your comment has too few characters per line" ??
      /. eats extra whitespace in "code" -- any workarounds?

    124. Re:Comments by maxwell+demon · · Score: 1

      FOUR_HUNDRED_FIFTY_SIX is a bad name, because it still doesn't tell you anything about the value. Better use a descriptive name like MAGIC_VALUE or VALUE_THAT_WORKS.

      Of course x should get a better name, too. what is x? Well, I guess it's a variable, but then, it could also be a macro expanding to whatever. Therefore an improved version could look like this:

      if (variable == MAGIC_VALUE) // check if step motor reached final position

      Now it's clear what's going on: You compare a variable with a magic value in order to find out if the step motor has reached its final position.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    125. Re:Comments by maxwell+demon · · Score: 2, Interesting

      Why do you consider indenting by 2 spaces as stupidity?
      And how can the result of this rule be that developers use tabs?

      --
      The Tao of math: The numbers you can count are not the real numbers.
    126. Re:Comments by Philodoxx · · Score: 1

      I was discussing the quality of the comment, not the quality of the code. I agree that meaningful variable names, and appropriate named constants go a long way to improve the readability of code. Sometimes even with descriptive variables, how the system got to that state can be confusing to somebody who is looking at the program for the first time.

      --
      Oh, a lesson in history from Mr. I'm my own grandpa.
    127. Re:Comments by Anonymous Coward · · Score: 0

      In general, I agree with the parent post, but I must say I disagree on the self-explanatory symbols. Yes, it seems like a good idea on paper, but if the project eventually becomes complex, think of a programmer trying to step in. Rather than having a constant right there that tells him the final value, and a comment telling him what that constant is for, he must dig through to try and find the values of the symbols to understand the code. For an example, check just about anything in the Linux kernel.

    128. Re:Comments by chris_eineke · · Score: 1

      $ cat > constant.c
      #include

      int const foobar = 1;

      int main(void)
      {
                      int qwertz = 1;

                      if (qwertz = foobar)
                                      ;
                      return 0;
      }^D
      $ gcc -Wall constant.c
      constant.c: In function `main':
      constant.c:9: warning: suggest parentheses around assignment used as truth value

      --
      "All you have to do is be fragile and grateful. So stay the underdog." Chuck Palahniuk, Choke
    129. Re:Comments by IllForgetMyNickSoonA · · Score: 1

      Great link, thank you very much! I never realized there is another kind of HN beside the dark-side HN (I'm a UNIX type of guy, HN never really took off in the UNIX world - at least not to the same extent as in the MS world).

    130. Re:Comments by Jeremi · · Score: 1
      As long as you never need a dead tree version of your code. Hard copy doesn't scroll horizontally, it wraps, making following the code indentation more difficult.


      Very true. Fortunately I have never felt the need for a dead tree copy of my code -- the medium's lack of a search feature makes it next to useless. ;^)


      Having to scroll right so that most of the code and its indentation is out of view just slows me down.


      This isn't a problem if you use an editor like vi, which wraps too-long lines around on screen. I agree that it can be quite annoying on editors that just truncate too-long lines and force you to scroll right and left.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    131. Re:Comments by Anonymous Coward · · Score: 0

      " Write your comments first, then code to match the comments"

      Do you REALLY do this? Come on, you can tell the truth.

      It sounds good in theory, but time is better spent modeling, then writing comments

    132. Re:Comments by Anonymous Coward · · Score: 0

      that does not necessarily make code any better. Sometimes it adds clutter. It also adds confusion since the define is somewhere else on your screen. It may also lead to trouble because you may think that LOAD_DATA is equal to something else when debugging. On my compiler, i cannot popup on a define to see its value. Also, LOAD_DATA may be much too generic of a term for another person to associate and remember what it belongs to.

    133. Re:Comments by P3NIS_CLEAVER · · Score: 0

      Thats why you would use FLAME_BURSTING_CEILING as a constant.

      --
      Please sign petition to restore sanity to our banking system!!!

      http://financialpetition.org/
    134. Re:Comments by fahrbot-bot · · Score: 1
      I love hungarian notation, ...
      - MemeRot $live{free} || die "";

      I'm just askin', but shouldn't your sig be:
      MemeRot $live{boolFree} || die "";

      :-)

      --
      It must have been something you assimilated. . . .
    135. Re:Comments by M4N14C · · Score: 0

      Software engineering isnt always the answer. I've met people with masters degrees in software engineering that could design impressive systems and diagrams, but none of it makes sense. There will always be some Computer Scientists that cant design a large system. But from what I've seen there are plenty of software engineers that couldnt design hello world if they had to.

    136. Re:Comments by dubl-u · · Score: 1

      Correct me if I am wrong, I don't think any of the tools that you mentioned can generate any intelligent comment.

      You are absolutely right. When reviewing code bases or taking on code from other developers, comments like this are worse then useless. I can already see the exception declaration right there. And since the programmers are used to ignoring the useless auto-generated comments, when they change the code they just blow on by the comment, taking it from useless to actively misleading.

      I think you can generate nice documentation from information embedded in the code; JavaDoc proves that well. But generating comments in the code from data in the code is just retarded; the only problem it solves is a gotta-have-comments checklist item.

    137. Re:Comments by Anonymous Coward · · Score: 0

      Your conception was a mistake.

    138. Re:Comments by Surt · · Score: 1

      Yeah I found that interesting too. When I did work where portability was a serious concern we always used typedefs. We had a standard header that would define types such as
      s16, u32, s8

      etc. The first job of porting was to port that header and guarantee that the data types on the target platform were at least as many bits as advertised, and matched the (s)igned or (u)nsigned property.

      Basically you were forbidden to use any native types in the remainder of the app. That system worked pretty well, we were able to do ports with trivial effort to 4 different architectures.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    139. Re:Comments by stereo_Barryo · · Score: 1

      I thought that it was a better idea to use constants rather than #define since debuggers couldn't handle the #defines and you would be missing some important feedback.

    140. Re:Comments by matfud · · Score: 1

      > in order to check in any code, no matter how inconsequential, it has to be reviewed by at least one other dev

      This is very good advice.

      Disk crashes or roll backs are a function of your VCS. The process I follow is that code is commited to the VCS in a sub stream. It can then be reviewed by a coworker who can, if they think it is OK, commit it to the main stream. This way disk crashes are not a problem. Roll backs are also fairly trivial if you commit your code regularly to your private stream (or use a IDE that integrates local revision control).

      Also raided disks for developers is a good idea to work around those inconvienient disk crashes when you have't commited recently.

    141. Re:Comments by Tower · · Score: 1

      Right, and this is why multi-stage development tools are handy. Where you have:

      a user stage - where you make changes
      a current stage - where you can check things in/out of, but aren't part of the shipped code

      a build stage - where the code can be promoted to after the review

      That way, you have your code checked in to the (backed up) server and are able to test/review it there, without committing that code to anything resembling permanent.

      --
      "It's tough to be bilingual when you get hit in the head."
    142. Re:Comments by MemeRot · · Score: 1

      Beats me, I stole it from someone else on slashdot years ago. I haven't used perl since 1999, and live{free} certainly looks better.

    143. Re:Comments by bobbyjack · · Score: 1

      Totally agree - I hate reading code like that. If you can be disciplined enough to reverse the natural order of things, you can sure as hell be disciplined enough to remember to use ==.

    144. Re:Comments by naibas · · Score: 1
      Besides, what would a "pointer to unsigned short 'sy'" look like in hungarian notation? :-)

      In our system, it would be "pn" for a pointer to a generic integer. You could change the type to long*, int*, unsigned char*, whatever, and it would still be a pointer to a generic integer. We don't use hungarian to put an explicit type to a variable. We use it to describe the type of data that that variable is expected to hold. This works for use because we also discourage variable reuse within a block of code.

      So something like this:

      float g;
      g = radSomeAngle;
      ...
      g = sSomeLength;
      ...


      should instead look like this:

      float rad = radSomeAngle;
      ...
      float s = sSomeLength;
      ...

      C++ class names usually end up being the basis for a new Hungarian prefix, so in those cases, we are explicitly typing out variables. And if it comes to it, there are editors that can keep the task of renaming from totally agony. I believe Source Insight has a context sensitive (c++ class/namespace/scope/etc) project wide renaming capability, which would make it a one step process.

      This works well for what we do. If you are working in a situation where it doesn't make sense, then don't use it. I don't mean to push Hungarian, because I can understand it's not for everyone. That's just part of what works for us, and thus it's part of our enforced coding standard.
    145. Re:Comments by elknco1 · · Score: 1

      yea but that example's compiler dependent. while the GP's example will result in an error on every C/C++ compiler. well, any "correct" one anyways. Visual C++'s compiler didn't give me a warning when I compiled your example..

    146. Re:Comments by Anonymous Coward · · Score: 0

      Oh, very well, here goes yet another likely violation of an NDA:
      Have a single-command build process that your devs can run every night to build everything they could possibly need in the morning. Now, have that build command have the side-effect of backing up everything the dev checked out of VCS to some other server, that is itself backed up daily. Result? Code backup server crashes => who cares, it didn't have anything that the devs don't already have, and is backed up anyway. Dev machine crashes => sucks to be them, but at least they didn't lose more than half a day's work on average if they were diligent in building everything every night.
      So, now you need to consider, what is more important to you:
      A: improved code quality, because every dev tests their code and is much less likely to check in "temporary junk" that never gets removed because they're too busy or just plain forget about it.
      B: well, I was going to say devs not losing work, but if they crash, they're going to lose work anyway, even if they do check in all their yet-undiscovered bugs every night.

      Then again, if your org consists of devs who'd delay checking their code as much as possible just because they have to do that bit of extra work to assure quality, maybe you really are better off if they don't check in...

    147. Re:Comments by peetm · · Score: 1
      For example:
      if(x==456)
      Or
      if(456==x)
      No problem when someone gets = and == confused.
      --
      @peetm
    148. Re:Comments by peetm · · Score: 1

      >>never using an int for any value other than 0-127

      Does this mean that you're writing programs that *only* use 0-127 then?

      I seem to remember something in the standards that said a char might be as big as an int, and that a long int might be as big as an 'ordinary' int too. So, to be strictly portable, you should only rely on there being 8 bits in a long - I also seem to remember that a char has at least 8 bits in the standard?

      --
      @peetm
    149. Re:Comments by saxonhawthorn · · Score: 1

      FWIW my own practice is to comment every line, then add a summary at the end of each minor and major section of code which tells the reader what that section does. That way he can scan quickly through the summaries and get a feel for how it all works before diving in at line level. Putting all those summaries at the same point on the screen so that he can move from one to another by just hitting also helps a lot (but assumes that screen configs are all the same of course).

    150. Re:Comments by nickos · · Score: 1

      I think the consenus at my company is that 2 spaces makes it hard to see the difference between different levels of indentation. Perhaps this was enough to push the coders who prefered hard tabs into abandoning the standard.

      Personally I'm also a member of the hard tab faction, and I think it makes good sense to use 1 tab character to represent 1 level of indentation. Users can then make it look and/or behave like as many spaces as they like in their editor. Problems only occur if users use tabs for anything other than indenting.

    151. Re:Comments by maxwell+demon · · Score: 1

      I never have problems to immediatly spot two-space indentation. But maybe it depends also on other parts of the coding standards. For example, I usually put the opening brace on a line of it's own (the only exception is if the closing brace is in the same line, which can be useful for empty and one-statement functions), which causes indented blocks to be separated from unindented by an almost-empty line.

      Larger spacing makes the effective line length shorter (I keep my lines below 80 characters, so it will not wrap in non-resized editor and terminal windows), which leads to more many-line statements (if you use descriptive variable names, even relatively simple expressions can get quite long), which I again consider less readable.

      Hard tabs can make it problematic to align certain parts of a statement relative to each other (e.g. aligning arguments to functions so that they line up nicely). Also, changing the tab width from the default of 8 might break non-program texts like tables of data, while 8 space indentation is IMHO clearly too much. And with non-standard tabs, you'll have to remember to set the tab width everywhere (on the editor, when using less on the command line, on printing, ...)

      If the relevant systems had a simple and consistent way of setting file-type specific tab spacing globally for each user, then using tabs might be practicable. With the existing systems, it IMHO isn't.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    152. Re:Comments by Chr0nik · · Score: 0

      Make sure that the decimal point is in the right place when you funnel that $0.00001 from every intertrode transaction to an offshore account.

      Otherwise you might end up in a federal "f!ck me in the ass" prison.

      --


      ... what did you expect, something profound?
    153. Re:Comments by NemoX · · Score: 1

      That is correct, to an extent. In C# .NET for example, there is no way to know what exceptions a method throws, without looking at the code it self. Whereas, in Java, it is declared as part of the method signature. So, this is actually helpful in C#, especially when throwing custom exceptions (e.g. InvalidStoreLocationException, or something to that nature), but a similar tool for a language such as Java, has little, if any, merit.

      The generated code is a helping tool, and is only as good as you naming convention of your method. So if your method is named S1, the comment generator is worthless. So, it really helps with your naming convention of your methods, and is only good for jump starting your documentation. But, used properly, it is a great aid but by no means a complete substitute, as you already pointed out.

    154. Re:Comments by Anonymous Coward · · Score: 0

      guess who is not a team player.

    155. Re:Comments by lilmouse · · Score: 1
      "What" comments should be reserved for the top of a function or largish body of code.
      And Perl. Don't forget Perl!

      Perl has enough ways to do things that even if you're totally comfortable using one method, another person might have been coding Perl for years, solving the same problem as you, and *never* seen what the hell you're doing.

      You also have to remember that not all code is meant only to be accessible to at least intermediate programmers. If you supply comments such that even a mostly-illiterate person can modify your code, then they can. This may be useful in certain situations - e.g., writing scripts for non-programmers to use. If you have comments that read:

      # This is where we set the default directory
      # Change this value, make sure you don't use \ - change them all to /

      then someone can change it without breaking it and coming to you asking "I need to change the directory...fix it..."

      --LWM

      PS. Did I mention Perl?

      This is my favorite bit, from Bugzilla's source code:

      # This handles bug a, comment b type stuff. Because we're using /g
      # we have to do this in one pattern, and so this is semi-messy.
      # Also, we can't use $bug_re?$comment_re? because that will match the
      # empty string
      my $bug_re = qr/bug\s*\#?\s*(\d+)/i;
      my $comment_re = qr/comment\s*\#?\s*(\d+)/i;
      $text =~ s~\b($bug_re(?:\s*,?\s*$comment_re)?|$comment_re)
                          ~ # We have several choices. $1 here is the link, and $2-4 are set
                              # depending on which part matched
                                (defined($2) ? GetBugLink($2,$1,$3) :
                                  "$1")
                          ~egox;

      Working that one out even when you know what it does is a chore!
    156. Re:Comments by IllForgetMyNickSoonA · · Score: 1

      I see your point. However, my position is that you *always* have to *know* the type of the variable you are using. And the only way to *know* (as opposed to "believe to know, based on a prefix added by an unknown co-worker at some point in time") is to look it up in the declaration section.

      On a somewhat less related note: there are a lot of areas where using unsigned short really is preferred to using an int (think embedded programming).

    157. Re:Comments by IllForgetMyNickSoonA · · Score: 1

      If it works for you - great! Personally, I think a development process which too much relies on luxury tools is a bad development process. That's only my opinion, of course, based on experience and observations I made so far, not on hard facts. YMMV.

    158. Re:Comments by Ninja+Programmer · · Score: 1
      English speakers read left-to-right, and the subject nearly always precedes the object in a sentence. "if (5 == x)" may keep you from doing accidental assignments, but it also reads the same way "red is my car" would.
      If you have an intuitive problem with the way that reads, its not the problem with the code, its a problem with your intuition. The test of "My car is red" translates to if (car.color == red) which is the same as if (red == car.color) or "the color of my car is red" or "red is the color of my car". Its the same -- your perception of a difference is in of itself a likely source of bugs .

      The idea of putting constants on the left side (and using const as a parameter or value attribute whenever possible) is a technique that only has upside (ignoring programmers with "intuition failures").
    159. Re:Comments by Bill+Dog · · Score: 1

      I don't feel super strongly about Hungarian notation either way, so I'm not dickering about that, but I would just point out that I think your argument, that it shouldn't be used because the variable prefix can get out of sync with the var's actual data type, is the same argument some people put forth for being against commenting their code (i.e. they can get out of sync). So while I don't throw an absolute hissy when I see code that's not commented or Hungarianized (like some Slashdotters evidently do when they see code that is HN-ed), I think it's in general slightly less desirable.

      --
      Attention zealots and haters: 00100 00100
    160. Re:Comments by Al+Dimond · · Score: 1

      80 may be obsolete, historical and arbitrary, but it's something that will work for just about everyone. Few people have terminals narrower than 80, and most editors default to start up at 80. If I write my code at 80, anyone that wants to read it can without having to mess with anything.

      Besides, how often do you write code with nothing else on the screen? If one window of code takes only half the screen, the other half can be used on another window full of code (which is often very useful, and a much more efficeint use of space than showing the ends of a few long lines) or documentation. 80 works nicely for this on most systems with decent monitors and reasonable font sizes (i.e. not the gvim default on Windows... yuck...)

    161. Re:Comments by IllForgetMyNickSoonA · · Score: 1

      Very good point, that with the anti-comment crowd. Never thought of it... :-)

    162. Re:Comments by Boing · · Score: 1
      My point is that the "intuition failures" are basically universal among english speaking programmers. Your example, "red is the color of my car" may technically be understandable but requires extra processing because of its nonstandard ordering.

      So basically, you're saying putting constants on the left is a technique that only has an upside (ignoring the downside).

    163. Re:Comments by Dstarr · · Score: 1

      Did I miss a smiley face? Somewhere?
      How about

      #define MOTOR_STOP_POS 456

          if (shaft_pos == MOTOR_STOP_POS)

      Surely you were kidding about

      #define FOUR_HUNDRED_FIFTY_SIX 100

    164. Re:Comments by Anonymous Coward · · Score: 0

      Reduce the number of languages. If you can settle on one, that's not going to get better.

      AS per XP:

      1. Do not use comments. Make the code readable, use intention revealing names. Use short methods. Class comments are ok.
      2. Unit tests your code.
      3. Write code in pairs.
      4. Release often.
      5. Use one integration machine.
      6. Use acceptance tests to know when the project is feature complete.
      7. Write user stories (functional specs written informally) in small cards. Tear the card when the user story is implemented (the corresponding acceptance tests should pass).
      8. Use an standup meeting at the beggining of the day so that everyone says what they are doing, what problems they have found, etc. Standup because the meeting is short.
      9. Open bay area. No cubes.
      10. Continuous integration.
      11. User in the room, available 100% of the time.
      12. No overtime.

    165. Re:Comments by nickos · · Score: 1

      I'm admittedly a bit unusual in that I prefer to use a proportional font for my coding. I think that if I'm going to spend all day looking at text it should be as quick and easy to read as possible. Of course, this makes any attempt to line up tables of data or align arguments to functions impossible, but I think that's a price worth paying. I also find that much more text fits on a line, so perhaps this is less of an issue.

      My rule then is that the first whitespace on a line (indenting) should be hard tabs and all other whitespace should just be one space (although I wont change multiple spaces in other peoples files). Perhaps one day an editor will be smart enough to line some things up according to context (without inserting extra characters) but I've yet to see anything like that so far (and I'm not sure that such a feature would be desirable).

      I've also noted that people who use spaces for indenting tend to have different preferences for how many to use depending on which platform they started coding on. For example coders from a Unix background will typically prefer 8 spaces while Windows users often prefer 4. The use of hard tabs in code makes this a non-issue as they can be converted to the users preferred number of spaces on loading of the file and converted back into tabs upon saving.

    166. Re:Comments by maxwell+demon · · Score: 1

      Well, if you use proportional font, I understand that you don't spot two-space indentation. Proportional font spaces are usually much smaller than fixed font spaces. However, I very much depend on the ability of lining up certain things to each other (esp. function arguments), therefore proportional fonts will not work too well for me.

      The auto-indenting editor would not be sufficient, because there's still the problem of saving changed code. Unless of course you say the code may well be saved in any form as long as it looks nice on the editor. But then, the editor is hardly the only program you use with the code, there's also e.g. things like less, version control (esp. in diffs changes in whitespace can cause lots of visual clutter), and finally if your compiler gives error messages with column information, you pretty much want the columns in your editor to match the columns reported by the compiler (BTW another place where tabs can hurt).

      Auto-converting spaces into tabs on saving will also kill alignments if you view with another tab size than what you saved with. After all, the editor cannot distinguish spaces used for indenting from spaces used for alignment.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    167. Re:Comments by nickos · · Score: 1

      Fair points. I've seen too many files with, for example, 7 or 9 spaces used accidentally when 8 was the standard to convince me though. It seems the only problem with hard tabs is when non leading whitespace is used to align text, so perhaps we need another way of interpreting hard tabs. Hmm...

    168. Re:Comments by nickos · · Score: 1

      Ahh, found this link

      I liked these posts:

      Why are we arguing about this? Isn't what we really want a source code editor that understands the semantics behind the source text? Why waste bytes on tabs and/or spaces when the editor could figure out how to display code based simply on the placement of curly braces?

      and

      The main problem with using tabs occurs when statements are spread across more than one line (to horizontally align parameters in long function calls, etc.). If someone views the code with a different tab width setting, the horizontal alignment is undone.

      One solution is to use tabs for the block indentation, and then use spaces for any additional indentation that is internal to the block. That way, each programmer can have his own preference for how wide each indent level should be, without messing up any of the line-stuff-up readibility efforts.

    169. Re:Comments by maxwell+demon · · Score: 1
      Another problem is that it doesn't fit well with additional indentation/prefixing from outside tools (e.g. diff, or quoting in emails/usenet). After all, a tab is not equivalent to n spaces, but it's equivalent to as many spaces as needed to get to the next tab stop.
      For example, take a simple tool which adds line numbers. And, say, the original code looks like
      void foo()
      {
          bar();
      }
      Then if you have used spaces, the tool will give you:
      1: void foo()
      2: {
      3: bar();
      4: }
      However if you used tab indentation with a 4-space tab size, it will instead look like:
      1: void foo()
      2: {
      3: bar();
      4: }
      That's because the program now begins at column 3, but the first tab stop is still at column 4, which is just one space away. Now I think you'll agree that this result is, well, not really optimal.

      And of course if the number of errors with 8 space indentation convinces me of anything, then it's that 8 space indentation is just too much. But that's probably because I'm convinced of that anyway :-) Note that for 2 space indentation, the probability of doing 1 of 3 spaces on accident without recognicing it is quite low, because the relative difference is large (half an indentation level).
      --
      The Tao of math: The numbers you can count are not the real numbers.
    170. Re:Comments by maxwell+demon · · Score: 1
      Damn, slashdot ate my spaces!
      Ok, here's my example again, this time with underscores instead of spaces:
      Original code:
      void foo()
      {
      ____bar();
      }
      Code with line numbers, assuming space indentation
      1: void foo()
      2: {
      3: ____bar();
      4: }
      Code with line numbers, assuming tab indentation (tab spacing of 4):
      1: void foo()
      2: {
      3: _bar();
      4: }
      --
      The Tao of math: The numbers you can count are not the real numbers.
    171. Re:Comments by maxwell+demon · · Score: 1
      The problem of course is that the editor can only indent based on syntax, which will be fine in most cases, but not in all of them. For example, my "n plus 1/2" loops generally look like this (underscores used for spaces, to prevent slashdot from eating them:
      while (true)
      {
      __code();
      if (condition) break;
      __morecode();
      }
      Note that the if line is not indented because it logically belongs to the loop structure. I doubt that an on-the-fly auto-indenting editor would let me do that. Of course an auto-indenting editor feature which just changes the text and allows me to manually change it afterwards is a different point (and I indeed do use the xemacs auto-indentation). And another problem, of course, is that the editor is by far not the only tool you use to look at source code. And I'd bet that even the editor would usually be confused by prefixed source code (e.g. diff output).

      The idea of using tabs only for block-indentation solves the relative alignment problem, but doesn't solve any of the other problems. It doesn't solve the problem that there isn't a global setting of the tab stop, but only settings local to the respective tools. It doesn't solve the problem that not every file is a program, and setting tab stops to anything but the default of 8 might break viewing non-program material. And it certainly doesn't solve the problem that a tab, by design, is not equivalent to a fixed series of spaces (or to a fixed amount of horizontal space), leading to problems with prefixing.
      --
      The Tao of math: The numbers you can count are not the real numbers.
    172. Re:Comments by nickos · · Score: 1

      Good point. I'm used to graphical diff tools, so I'd never thought of this.

      So even if someone creates a clever way of interpreting hard tabs, problems will still exist unless someone patches the terminal progs :(

    173. Re:Comments by Fulcrum+of+Evil · · Score: 1
      How many times has code been cleaned up, and ended up broken? It's a PITA to:
      (1) rename / resave the current version as "new"
      (2) fetch the old one
      (3) diff
      When it is easier to read the "old" and "new" code, intermingled.

      Learn how to use your code versioner - cvs diff -r1 -r2 file is really simple.

      Sometimes the old code is left in, as a "fallback" -- since the new code is still in a state of flux, and hasn't been thorougly tested.

      And this is why god invented branches. If the code isn't stable, don't put it in mainline.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    174. Re:Comments by Fulcrum+of+Evil · · Score: 1

      One comment I have - NEVER write code that says [...] 'This should never happen.

      Why not? That implies you've got a serious bug.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    175. Re:Comments by Fulcrum+of+Evil · · Score: 1

      That's a great way to ensure that developers delay checking in their code until they absolutely have to.

      I've never had a problem - it takes all of an hour or two while I do other things.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
  2. Joel on Software by Marxist+Hacker+42 · · Score: 4, Informative

    Has several excellent articles on the subject This is about as good of a starting place as any.

    --
    SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    1. Re:Joel on Software by ajdavis · · Score: 5, Interesting

      Yeah, but Joel's an ass. Have any of his worshippers here on /. actually *used* something written by Fog Creek or whatever? FogBUGZ, a web-based bugtracker, seems to be his one claim to fame, & it's terribly mediocre. I mean, mostly it works, but the search function doesn't, the UI is inconsistent, & while you can define filters (such as, "my open priority-1 bugs"), you can't share them, which makes them nearly useless. Joel writes a good spiel, but when it comes to coding, his company ain't the shit.

      Plus, he argues passionately for paying programmers well & giving them exciting projects, but in at least two cases he hired interns to start his company's most interesting apps.

      Dude needs to work on his street cred.

    2. Re:Joel on Software by bwags · · Score: 0

      Go ahead a buy his book book JOEL ON SOFTWARE (ISBN: 1-59059-389-8) for everyone on your programming team. While you are at it, buy one for management too. It makes for a great read and is extremely useful. HIGHLY RECOMMEDED!

    3. Re:Joel on Software by hackwrench · · Score: 1

      I'm not sure what he meant by grease being "everywhere". Grease should just be on the parts that need to be greased, and nowhere else. I don't know what he means by "yellowing", but rust? Seems to me that if something's rusty, something's wrong. Reading his clarification on the paint, if the heat is causing the paint to turn yellow, the oven should never have been painted with that paint to begin with.

    4. Re:Joel on Software by keltor · · Score: 1

      There's another person who the OSS community loves to talk about, but have you ever used Yahoo! Stores? (even before it was totally changed)

    5. Re:Joel on Software by Jack+Tanner · · Score: 1

      Yeah, that's great as far as coding standards go. The moral of that article is "some coding standards are actually meaningful and useful". But it's also very easy to create coding standards that are just nauseating.

      Most importantly, keep in mind that whatever standards you come up with better stand up over time. Eventually, they'll be being used by a young generation of poli sci majors. It's not the standards, it's who's applying them.

    6. Re:Joel on Software by eddy+the+lip · · Score: 1

      Thanks for that painful reminder. I have no handy strong drink.

      --

      This is the voice of World Control. I bring you Peace.

    7. Re:Joel on Software by halfnerd · · Score: 1

      I'll second this, even if the articles as basically freely available on his home page. The book has more polish to it.

    8. Re:Joel on Software by mariox19 · · Score: 1

      Creating new applications is speculative and brings in no money, unless you create good applications, in which case the money comes in long afterwards. Most likely he couldn't take his staff away from the jobs he had them doing, and it would make no sense to hire more programmers for work that would not be producing a "sure thing."

      I know nothing about FogBUGZ, so maybe it does suck. But, I don't think it's a contradiction to argue for paying programmers well and to use interns the way he does. (I'll bet the paid programmers end up doing a lot of work on the new products the interns create, after they go back to school.

      --

      quiquid id est, timeo puellas et oscula dantes.

    9. Re:Joel on Software by Anonymous Coward · · Score: 1, Insightful

      His best skill is self-promotion.

    10. Re:Joel on Software by measterbrook · · Score: 2, Insightful

      > Plus, he argues passionately for paying programmers well & giving them exciting projects, but in at least two cases he hired interns to start his company's most interesting apps.

      That is because Joel has fallen into the legacy vs new trap.
      Legacy code is difficult to maintain and only your best and most experienced programmers can work on it without either braking it, making it worse, or doing it very very slow. In comparison, writing new code _seems_ relativily easy (can you hear the alarm bells?).

      So if you have to put your best programmers on the legacy code, everyone else gets to write the new code ... badly (but you don't realise this until maintanance time). The new code becomes legacy code, which requires your best programmers, which leaves the rest for the new new code. And the cycle continues.

      There is no easy answer, pair programming helps, but requires more staff. Not many managers understand the "pay a bit more now, collect the big reward later" way this works. Good experienced programmers are expensive, young inexperienced progammers are cheap if you only consider how much you pay them (and not how much you have to pay to sort out the mess later using your expensive experienced programmers).

      It works for me - I make a living out of fixing bad legacy code. I don't get to work on the sexy new projects, the youngsters do, creating my future employment needs... and so the cycle continues...

    11. Re:Joel on Software by Anonymous Coward · · Score: 0

      I have a suggestion:
      Use existing standards that other people have thought long and hard about... Innovate/modify once those ideas are understood... Feel free to GPL your code...

    12. Re:Joel on Software by Anonymous Coward · · Score: 0

      thank god someone else sees that this joel guy sucks.

      he's not insightful, and because he worked on excel or something at one time in the past and now wants to run an office with fancy chairs and well paid programmers, he's a god.

      no, he's not. he sucks. pragmattic programmer? good. joel? suck.

    13. Re:Joel on Software by Jakeypants · · Score: 1

      Have you ever looked at the source, too? It's a maze of include files. That, and, at least in the MySQL version, there's no referrential integrity in the database.

    14. Re:Joel on Software by pebs · · Score: 1

      Yeah, but Joel's an ass.
      [...]
      Dude needs to work on his street cred.

      He worked at Microsoft as a program manger for the Excel development team (I believe had some other positions as well there). That's his street cred, and also one of the reasons he's popular among Microsofties. Why Slashdotters like him I'm not sure, maybe his article How Microsoft Lost the API War earned him some fans.

      Although he's written a few good articles here and there (but not recently), I do agree that he's an ass.

      --
      #!/
  3. Help people play to their strengths etc.... by FyRE666 · · Score: 4, Interesting

    If you really are starting from ground zero, I'd suggest setting up a repository such as SVN as a good first step. Couple this with a good template to set up standard locations for documentation directories alongside the code trunk and branches (and any other resources your projects requires (images, sound other media). Make sure everyone uses the repo - even if you have to spend a day leading people through it - you'll save time later. This also ensures your projects are backed up (so long as everyone checks in at the end of the day at least), and screwups - such as deleting the wrong directories and forgetting about it for weeks can be reversed.

    Obviously there are other issues such as naming conventions, useful comments etc, which are often neglected in small projects, but become more important as more people work together without wars breaking out!

    Find out your teams individual strengths and preferences - there's no point trying to hammer everyone into the same mould - some people will naturally gravitate toward, and excel at certain tasks. It's important for efficiency and general happiness that this is taken into account when allocating resources to a project.

  4. Project Automation by Anonymous Coward · · Score: 1, Informative

    If you haven't been doing these things, pick up "Pragmatic Project Automation". It may not specifically address coding standards, but it definately will help you get some standards around processes.

    1. Re:Project Automation by swimmar132 · · Score: 1

      Along those lines, get Ship It, another book in the same Pragmatic Programmer series.

      Honest. Get it.

  5. Evolutionary Prototyping by PIPBoy3000 · · Score: 4, Insightful

    In my job as a web developer in a healthcare system, I'm all about evolutionary prototyping and other interative methods. There's a handful of big projects where we take a more traditional waterfall approach, but even then it's highly modified.

    It's nearly impossible for me to get final specifications from a user until they've actually seen something. Paper is okay in a pinch, but a semi-functioning web application is worth a thousand meetings.

    1. Re:Evolutionary Prototyping by inKubus · · Score: 1

      Yeah, I do that too. Just hack together the most basic answer to the problem without worrying about the details, document heavily, send in the analysts and make corrections, rinse and repeat.

      --
      Cool! Amazing Toys.
    2. Re:Evolutionary Prototyping by OzRoy · · Score: 1

      I work for a small company making web based apps as well and I pretty much am the development team apart from occasional part timers. I've always worked this way and I'm pretty much self taught so I would probably suck at any real project leadership and the way I work is probably very wrong, but this is how I usually aproach my systems.

      1) Fast prototype the system. Get a version out as quick as I can that will meet all the basic requirements.
      2) Use the system for a while and get lots of feedback about what is right, what is wrong, how is the interface good or bad.
      3) Start version 2 by droping the system completely and starting again from scratch.
      4) Using everything I learnt from version 1 get a new version coded properly that only does what the first version does. So version 2 is pretty much the same as version 1 feature wise, just better coded, and better user interface. Then build slowly from there adding the requested features.

      It's worked pretty well for me, the only problem is the prototype versions often gets used much longer than they really should be.

    3. Re:Evolutionary Prototyping by ScentCone · · Score: 3, Interesting

      It's nearly impossible for me to get final specifications from a user until they've actually seen something. Paper is okay in a pinch, but a semi-functioning web application is worth a thousand meetings.

      What's amazing is that you can say that in two sentences, and most web developers here will completely get what you mean... and that traditional managers (of developers) will get incredible hives and seriously rethink your annual bonus for uttering such heresy.

      My favorite flavor of Not Getting This are the managers or customers that want you to mock up some screen shots for discussion, and are happy to pay for you to do so in Visio, or a paint program, etc... but if you instead actually whip together some HTML-based forms (much of which can eventually go towards further prototyping or actual use), you've opened the door to arguments over charges for having "jumped the gun" on the programming cycle. Never mind that I can produce conceptual mockups that actually render on a browser faster than by most any other means. But since a cheesy little pull-down-generating server-side script is "programming," there's PHB-fodder about having already done dev work before all of the requirements are described. Oh well. I'd rather write off a chunk of the project's proceeds than try to hammer out all of the requirements on paper first. In real life, with projects that must go from "I saw this thing when I checked out at Amazon" to being functionally bolted onto an existing web presence in a matter of a dozen man-hours, that's frequently impossible.

      --
      Don't disappoint your bird dog. Go to the range.
    4. Re:Evolutionary Prototyping by open_source_dweeb · · Score: 2, Insightful

      But since a cheesy little pull-down-generating server-side script is "programming," there's PHB-fodder about having already done dev work before all of the requirements are described.

      The flip side of this is that after showing marketing a semi-functional prototype that is pretty close to what they are looking for, there is often a tendency to assume that the project is near the code-complete phase and that a majority of the resources can be reallocated elsewhere. Just leave a couple of developers on the project to polish up the code and the installation program ... then ship it!

      Because of this, I usually like to leave an obvious (from the UI perspective) piece of functionality missing from the functional prototypes. This makes it clear to the management and marketing types that there is more work to be done. They don't really care that the prototype is non-scalable and has the web server making direct database calls, whereas the real implementation would need the web server going through middle-tier business components, data access layers, etc.

    5. Re:Evolutionary Prototyping by Anonymous Coward · · Score: 0

      >My favorite flavor of Not Getting This are the managers or customers that want you to mock up some screen shots for discussion, and are happy to pay for you to do so in Visio, or a paint program, etc.. ... Never mind that I can produce conceptual mockups that actually render on a browser faster than by most any other means.

      Simple solution: HTML + screenshot. It's a win-win situation as long sa you don't tell them how you did it.

    6. Re:Evolutionary Prototyping by dtfinch · · Score: 1

      Hence the real world model:

      1) Fast prototype the system. Get a version out as quick as I can that will meet all the basic requirements.
      2) It works! Client likes it, wonders why they should pay you to write it a second time, without adding any features.

    7. Re:Evolutionary Prototyping by OzRoy · · Score: 1

      The trick is to make sure there is a small detail about the system that is absolute crap and a real bitch to use. Then you say to them that you can't fix it and have to rewrite the whole thing as the real version.

  6. My boss doesn't care by b0lt · · Score: 3, Funny

    I like to think of it as "don't ask, don't tell" :D

    --
    got sig?
    1. Re:My boss doesn't care by dubl-u · · Score: 2, Insightful

      And the original poster should consider the benefits of something nearly that loose.

      Don't arbitrarily set up standards. Ask people what problems they have. Tell people what problems you're facing (e.g., you need to be able to move people more easily between projects). Then ask the developers who don't have those problems what they do. Feel free to toss in your own suggestions, too. But let them talk first. And let the developers decide how to do the work as long as they address your needs.

      Remember that you're not working in some Taylorist 1930s factory where you have to specify every motion. Creative work, which is what your developers are doing, is utterly different than factory work. (See the book Artful Making for more info on that.) Treat them like professionals and they'll act like professionals.

  7. Standards by zutroy · · Score: 1, Funny

    For every conditional, you chug a beer.
    For every loop, you chug a beer.

    And, of course, for every save, you do a shot of tequila.

    1. Re:Standards by xao+gypsie · · Score: 1

      no no no, that only works when you are going for the 'most creative code' contest. otherwise the standard protocol involves electroshock therapy, like on ghostbusters.

      --


      xao
      http://TheHillforum.hopto.org
    2. Re:Standards by blank89 · · Score: 2, Funny

      int beersOnTheWall = 99;
      while(beersOnTheWall>0) {
         me.chugBeer();
         beersOnTheWall--;
         System.out.println(beersOnTheWall + " bottles of beer on the wall...");
         }

    3. Re:Standards by JuzzFunky · · Score: 1

      Every time you break the build you have to buy a round of beers!

      --
      Unexpect the expected!
    4. Re:Standards by lpangelrob · · Score: 1
      Yeah, standards are great.....we've got lots of them :-)


      We've gone a step further and simplified all our standards down to one. I'm pretty sure the one we use now is... Spaghetti.

    5. Re:Standards by joelito_pr · · Score: 1

      Better yet:
      #include <iostream>
      #define NO_BEERS 0
      void DrinkBeer(void);
      int main(void)
      {
              int beersOnTheWall = 99;
              for(beersOnTheWall; beersOnTheWall > NO_BEERS; beersOnTheWall -= 1)
                      DrinkBeer();
              std::cout << "Oops, No beers left, better get some you drunken bastard" << endl;
              return 0;
      }

    6. Re:Standards by maxwell+demon · · Score: 1

      #include <iostream>
      #include <stdlib>
      #include <deque>
      #include "beer.h"

      int const initial_number_of_bottles = 99;

      std::deque<bottle_of_beer> wall(initial_number_of_bottles, bottle_of_beer::full_bottle())

      int main()
      {
        while (!wall.empty())
        {
          bottle_of_beer current_beer = wall.front();
          wall.pop_front();
          current_beer.drink();
        }
        std::cout << "Oops, no beers left, better get some you drunken bastard!" << std::endl;
        return EXIT_SUCCESS;
      }

      --
      The Tao of math: The numbers you can count are not the real numbers.
    7. Re:Standards by maxwell+demon · · Score: 1

      Previewed twice, and still an error: <stdlib> should of course be <cstdlib> (or at least <stdlib.h>)

      --
      The Tao of math: The numbers you can count are not the real numbers.
    8. Re:Standards by blank89 · · Score: 1

      //...or for web based application//
      $bottles_on_wall = 99;
      while($bottles_on_wall>0) {
         echo $bottles_on_wall." of beer on the wall, ".$bottles_on_wall." bottles of beer.";
         $bottles_on_wall--;
         echo "Take one down and pass it around, ".$bottles_on_wall." bottles of beer on the wall.";
         }
      mysql_connect(beer.com,beer,b33r1sgo0d);
      @mys ql_select_db(bartender) or die("Database Error");
      $result=mysql_query("UPDATE users SET drunk='true' WHERE session='$session'");
      mysql_close();

    9. Re:Standards by nate+nice · · Score: 1

      Yeah that's my favorite standard.

      Most systems are designed poorly and not made modular enough to be easily extended. So, when a new feature needs to be put in it gets crammed into other things and before you know it you have all types of functionality co-mingling and things are a mess. Of course, there is no documentation.

      Most places have way too many MIS types who don't really understand software design or anything. Just programming...and poor programming at that because they don't know of a design pattern or what OOP really is, etc. Many CS folk suffer from this as well. Really, not many people can design a system come to think of it....

      Ahh well, ya get paid none the less.

      --
      "If you are a dreamer, a wisher, a liar, A hope-er, a pray-er, a magic bean buyer ..."
  8. Unrealistic expectations by TheNarrator · · Score: 3, Insightful
    Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.


    Unless you are dealing with trivial projects it will take more than a couple of hours to figure out the code. Even the best documented open source and commercial projects take a few days to figure out.

    1. Re:Unrealistic expectations by netruner · · Score: 1

      Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.

      Unless you are dealing with trivial projects it will take more than a couple of hours to figure out the code. Even the best documented open source and commercial projects take a few days to figure out.


      Not if you don't care how much you trash the code. Getting something to "work" can be done relatively quickly. Keeping a maintainable piece of code from getting mucked up takes some effort. I see this all the time where I work. The code we have is large (millions of sloc) and people take the OP's path. It now takes over a year before a new developer can even do quick fixes and making it maintainable usually involves a rewrite of a large section of code - if it's even possible. Another problem that this mentaility creates is recurring bugs (I fixed it a month ago, why is it back?). This is because nobody has any idea what anyone else is doing because the code is so hacked up and the architecture is so broken down that people's band-aid fixes are undoing each other.

      --



      DISCLAIMER: This post was not checked for speling and grammar- if you complain- you're a whiner
  9. GOOD code review; Chief Designer at every inspecti by mekkab · · Score: 4, Insightful

    At every inspection; and of course example code for everyone to mimic the coding style.

    And good unit test drivers.

    Awesome commentary (both at the top of a package outlining the entire low-level design and at the algorithm level) goes without saying.

    Oh yeah, and run spell on your code. I mean, really!

    --
    In the future, I would want to not be isolated from my friends in the Space Station.
  10. Looking for magic? by YrWrstNtmr · · Score: 4, Insightful
    Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.

    That is a pipedream. Any project of significant size will require some immersion before a new proj member can get his hands around the particular bit he's trying code/solve.

    Standards can be good, but they're not magical. Unless you're trying to generate a group of little robots, everyone has a slightly different style.

    1. Re:Looking for magic? by waldomaniac · · Score: 2, Insightful
      Good call. Waste a couple of hours?... How many hours are you going to want to spend on the standardization process? And enforcing it? Beware the tools of micro-management... standardization, time-keeping, the dark side are these... Personally, I'm down with the tagline I saw one time:
      Comments should be banned - it was hard to write, it should be hard to understand.
    2. Re:Looking for magic? by boriente · · Score: 1

      Standards won't help you figure out code. But they will allow you to go in expecting to see a uniform organization of a project, program etc. Our site uses a standard naming convention, even so far as using standard abbreviations. Each program, class, method etc must be preceded by a comment block. A good idea is to develop a set of templates for the types of objects you may require. We have a standards committee that establishes, reviews and amends standard practices. At a minimum publish a set of standards/guidelines. Then require that all code be subjected to a code review. You'll be surprised how quickly the code will be up to standard. In addition code reviews will often point out areas of ambiguity in the standard or offer opportunities to add/change a standard. As for comments, we use VBCommenter. It a plug in for .net. It automatically generates a comment block for methods, properties etc. It will also generate an xml file that, when bundled with the DLL, will provide tooltips. Once you realize that your comments are being used as tooltips via Intellisense, you tend to keep your comments up to date and meaningful. Code reviews also tend to enforce this.

    3. Re:Looking for magic? by Sigl · · Score: 1
      I'm totally on your side with this one. Let's talk about all the benefits of no code standards. When I dig into some code and find some problems I like being able to tell who wrote it by the characteristics of the code so I can go make fun of them directly. Also, when I get stuck at a point writing code I know is poor I can just start coding in someone elses style. Makes it hard for them to trace back to me.

      Yup, I'm all for no coding standards.

  11. We use by Anonymous Coward · · Score: 0

    Drunken Style®.

  12. A Good Coffee Break by JoeShmoe950 · · Score: 2, Interesting

    This doesn't directly answer the question, but a nice big break in the middle of the day helps me get myself on track easily. After a few hours of coding, I may start to slow down. If I just take an hour (eat lunch, walk around a little), my brain clears, and I come back fully productive. My work place allows this, and I'm not sure how many others do.

    1. Re:A Good Coffee Break by dorkygeek · · Score: 1
      That's what's called midnight snack, no?

      --
      Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
    2. Re:A Good Coffee Break by Eberlin · · Score: 2, Insightful

      A good break in general will clear the mind often enough to get unstuck on some problem. Coffee is optional. I often find that walking around (even just in the room) with a stress-ball, and talking aloud to myself will reveal solutions that wouldn't have otherwise shown up if I were buried too deep in the code.

      That and something to scribble on. Either lots of paper or a whiteboard. Whiteboards are cool for getting your thoughts organized. Unfortunately you can't make printouts afterwards...but a good digital camera snapshot of a whiteboard will give you enough to remind you of what you thought up.

      The general hint -- give yourself some time to step back from the problem. There are times when it's good to bury yourself in the code and times when it's better to think things through away from the code.

  13. Doesn't matter by Anonymous Coward · · Score: 1, Interesting

    Every place I've ever worked has had coding standards, and at none of them were they ever followed. There was never any difficulty telling who wrote what by how they styled their code. Efforts to enforce coding styles by management never succeeded.

  14. Standardize on a good language. by Anonymous Coward · · Score: 2, Funny

    The importance of a single language standard can't be overstated. Ever since my company switched to LOGO I can understand my co-workers' code at a glance.

  15. Couple of hours by Mr.+Underbridge · · Score: 1
    jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.

    Must be a simple project if you can switch projects and figure things out in a couple of hours. Lucky if it isn't a couple of days.

  16. One Solution by Anonymous Coward · · Score: 1, Funny

    Outsource them all.

  17. Let your staff decide by Anonymous Coward · · Score: 0

    Assuming you have in house developers, rather than outsourcing everything, You should let your staff (or a committee of them) set the priorities for the development of standards, what standards to use, and review the stndards regularly (annually or so).

    They know how they want to work, and also know what bugs them most, so they should set the standards and priorities (with you to guide them).

  18. implementing standards is the easy part by the_mighty_cornhole · · Score: 0

    implementing standards is the easy part...having people follow them is the hard part hopefully you don't work with a bunch of close-minded morons...if you do its gonna be hard to have everyone follow them...if people see and buy into the value that standards offer... it will be a hell of a lot easier.

  19. GOOMOALMWIP/GOOMCALMWIP by Martin+Blank · · Score: 2, Insightful

    Get Out Of My Office And Let Me Work In Peace

    or

    Get Out Of My Cubicle And Let Me Work In Peace

    This applies mostly to the people that come in and have to inform me of their new cat, girlfriend, boyfriend, computer, game, TV, kitchen, car, shoes, and/or midlife crisis (and that's just the top of the list).

    A request on the part of the devs under your control: Don't implement a new paradigm every time one comes out. From extreme programming to agile programming, from scrums to design workshops, find something that works in your particular case and stick to it. Your employees will thank you for it (at least in the long run by not planning your demise in the parking lot after the fifth methodology change that quarter).

    --
    You can never go home again... but I guess you can shop there.
    1. Re:GOOMOALMWIP/GOOMCALMWIP by Anonymous Coward · · Score: 0

      I'm with you there.
      "conversations" should happen at lunch time or the walk back to the parking lot.

      Let me add.
      Do not IM me and expect me to reply instantly. It's called Instant Messenger, not Instant Response.
      IM topics that recieve especially slow responses are as follows:
      -I don't feel well
      -I just finished coding this, can you test it...now?
      -How's your personal life
      -This is happening in my personal life
      -Did you see this SlashDot article? YES! I DID! I have it in RSS feeds...you know that!
      -Check out this front page article from take your pick(USA Today, CNN, FoxNews, etc.)

      Don't get me wrong, I care...but I care more about getting my work done.

    2. Re:GOOMOALMWIP/GOOMCALMWIP by Trogre · · Score: 1

      Yes but don't get too anti-social.

      An environment where people connect and get along is generally a happier and more productive one.

      But when I'm Deep Into The Code, I certainly don't want to be disturbed by office politics, what cool toy the geek down the hallway has bought, or who's playing rugby after work. That's when you may want to invest in a do-not-disturb OAR [On A Roll] sign for your door or cubicle wall, or ITZ [In The Zone] if you prefer.

      --
      "Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
    3. Re:GOOMOALMWIP/GOOMCALMWIP by Anonymous Coward · · Score: 0

      Wish I had mod points!

  20. loose standards are best by Anonymous Coward · · Score: 1, Insightful

    If you dont allow people to code the way they naturally can, don't expect any amazing code or new ideas. Their code may also have bugs. Don't buy all the standardizaion hype.

    So if you are going to have standards make sure they are loose, and pertain mostly to external interfaces etc. requiring comments or code descriptions or something. I am telling you the worst thing for a project is frustrated programmers because they will make shortcuts in the code. Trust your developers ..u shouldnt be hiring 'em if you arent going to be trusting 'em.

  21. What a question! by cmburns69 · · Score: 1

    At our workplace, we have very few (if any) standard practices.

    1) We don't all develop in the same place (some use their HD, and some use a shared drive, some develop over FTP).

    2) We don't use the same editors (Textpad, UltraEdit, Homesite, etc).

    3) We don't use the same tab settings (Some use tabs, others use spaces).

    4) We don't use the same methodologies (Using PHP as an example: Some prefer $_GET while others prefer to enable globals).

    Part of the problem is because we came from different backgrounds (Some delhi people, some PHP, some home-taught, etc), but the biggest reason is that we usually don't work on each others code. A couple years ago, we decided as a department to start using some specific coding standards. These didn't last very long, because the company culture has always been one of one-on-one projects, and team-based development simply does not happen.

    If you want to implement coding standards in a place where there have been none before, be prepared for blowback from the "grunts". They have been doing it their way, and they are used to it. They probably don't see any reason to change.

    The only way for this to be successful is if you either have the power to enforce, or if you can have them catch the vision. At our place of work, I was the only one with a vision.

    Good luck to you!

    --
    Online Starcraft RPG? At
    Dietary fiber is like asynchronous IO-- Non-blocking!
    1. Re:What a question! by masklinn · · Score: 1
      others prefer to enable globals

      How come they haven't been terminated yet?

      --
      "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
    2. Re:What a question! by geekoid · · Score: 2, Insightful

      I would write people up, and see that it was reflected in there perfomance review.

      You work for me, you do it my way. If you think your way is better, present it to me and tell me why. "Cause it's the way I do it " doesn't count.
      I'll train you, I'l give you time to set up your editor so it automates whatever you need automating. I'll mentor you, have other developers mentor you. But there is a line where I expect the developer to be up to speed.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    3. Re:What a question! by chromatic · · Score: 3, Funny

      Perhaps someone broke in and fixed the code.

  22. Works for some companies not others. by jellomizer · · Score: 2, Interesting

    First language try to choose languages that work well on multiple platforms with at most a recompile. Languages like PHP, Python, Ruby, are Good. If you have to use .NET try to make your programs compatible with Mono. Even if you are using a Windows network and don't plan to switch anytime soon working with platform independent language give you the ability to better negotiate with MS for licensing price because your 3rd party apps will cheaply move over to the new platform. Also programs designed to be platform independent tend to migrate a lot easier to new versions of the OS. Avoid using and single platform library or other 3rd partly libraries unless you really need them. If they stop development you could be stuck.

    Second have a Good Data Warehouse try to use Rational Database servers that support Stored Procedures and Triggers, which is dependable. MySQL 5, PostGreSQL, MSSQL, Oracle are all good choices. I would put money to give all the DataBase Servers some good specs and conversly I would put all the data manipulation into Stored Procedures and Stored Functions. Also when creating them give them a prefix to show that they are your companies specialized functions and not built in the Database Server. The Database should give you the data they way that is most convenient for you to use. The reasoning for this is that it normally reduce network traffic to the SQL Server, and allow porting applications to different languages and platforms easier because the data format part is still complete.

    Third use have all your apps on your intranet be web based. first it eases deployment and also allows desktops to be upgraded without killing the app every security patch.

    So if you make a all your Apps Web Based with the bulk of the calculations on the Database server and having the Web Language handle the User Interface, and depending on you size of you apps a 3 or 4th tear with custom libraries for standardized uses of Interface and data a.

    --
    If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    1. Re:Works for some companies not others. by Anonymous Coward · · Score: 0

      hmm, so use a portable language to keep from being tied down to one platform, but then use stored procedures to do all the DML, thereby tying you down to one DB?

      which is it?

    2. Re:Works for some companies not others. by jellomizer · · Score: 1

      Working with SQL on many different DB I found there differences are relatively minor. But the real advantage, is that you can update your software to different platforms and let the old DB Server still run. And if you get a Different DB server then you will need to change the Procedures around slightly (With minor to moderate effort, many of the commands are similar) But if you didn't put all the logic in stored procedures then you will need to go into all your code and check all you programs database calls.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
  23. Indentation by Aundy · · Score: 0

    Well of course commenting, good function/variable names are essential, but also i find that it helps alot to keep the way you indent the same. For example before I learned python i used C++ and since indentation was not necessary mine was horrible. Then after learning python I came back to some code that I had made before in C++, and since in python you need to have proper indentation I found it very hard to find my way around the code. I had to go through the whole thing and change the indentation before I could figure out what the code was doing.

  24. Our style! by Doug+Tanner · · Score: 2, Informative

    I work for one of Activision's subsidiaries and this is what we use:

    int* gpiGlobalInt;

    int FunClass::GetSize(int _iArg1, bool _bArg2)
    {
        bool bBool;
        float* pfFloat;
        static int siStaticInt;

        for(;;)
        {
        }
    }

    Seems to work out well enough.

    1. Re:Our style! by Anonymous Coward · · Score: 0

      ...thankful I don't work for ActiVision....

    2. Re:Our style! by Anonymous Coward · · Score: 0

      Identifiers with leading underscores may be reserved, so you should never use them. See H. Sutter's "Exceptional C++", item 20.

    3. Re:Our style! by Doug+Tanner · · Score: 1

      Can you give some examples?

    4. Re:Our style! by Anonymous Coward · · Score: 0

      You put the openning braces on the wrong lines.

    5. Re:Our style! by geekoid · · Score: 1

      Man, that is horrible. You should be modded +1 funny.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    6. Re:Our style! by martin-boundary · · Score: 1

      That explains a lot, thanks! I was wondering why it took forever to load the last game I bought from them. There's the problem: infinite loop in GetSize() call! Duh!

    7. Re:Our style! by Anonymous Coward · · Score: 0

      I belive he is trying to demonstrate the naming conventions they use for their variables.

    8. Re:Our style! by Anonymous Coward · · Score: 0

      As the GP (who is not me) correctly claimed, identifiers with leading underscores are reserved. Of course, being a professional C programmer, you should already know this. I know Win32 defines _read(), _strnicmp(), _utime(), and others. Here's a short sample of underscore identifiers extracted from my libc.

      _init _itoa _itoa_base_table _itoa_lower_digits _itoa_upper_digits _itowa _itowa_lower_digits _itowa_upper_digits

    9. Re:Our style! by Anonymous Coward · · Score: 0

      You adopt a coding style that was designed by Zoology department?

      Aarrrghhhhhhh!!!!!!!!!!!!!!!!!!!!!!!

      The Indian Hill coding style specification.

    10. Re:Our style! by cwry · · Score: 1
      You are correct that it's a good rule of thumb to just never use identifiers that start with an underscore, but there are exceptions.

      From http://web.archive.org/web/20040209031039/http://o akroadsystems.com/tech/c-predef.htm#Groups:

      Respect that first entry in the table below: never make up any identifier that starts with an underscore.

      (Actually, you can legally use an identifier that starts with an underscore if the second character is a lower-case letter or a digit, and the identifier is used inside a function or a function prototype or as a structure member or label. Easier just not to use leading underscores!)

      The parent post uses them inside a function and the second character is lower-case.

    11. Re:Our style! by destuxor · · Score: 1
      Oh yeah?
      int parseInt (char * myString)
      {
      char * p = myString;
      int x = 0;
      while (* p != '\0')
      {
      x += 10 * x + ( * p ) - '0';
      p++;
      }
      return x;
      }
      This is something I used to drop into every C project I wrote.
    12. Re:Our style! by Anonymous Coward · · Score: 0

      identifiers with leading underscores are reserved

      Not necessarily. _[_A-Z] is reserved everywhere. _.* is just reserved at file scope. I always just recommend not using any leading underscores, though, so you don't have to remember what is OK and what's not.

      Disclaimer: This applies to C, I don't know anything about C++.

    13. Re:Our style! by Emil+Brink · · Score: 1

      ... and then you learned about strtol() and stopped, right? Why the copying of the argument to a local variable p, by the way? And why isn't the argument const? And why not stop on the first non-decimal digit?

      --
      main(O){10<putchar(4^--O?77-(15&5128 >>4*O):10)&&main(2+O);}
    14. Re:Our style! by destuxor · · Score: 1
      Right.
      It wasn't programmed exactly that way, I just typed something out, and forgot what the inequality I actually used was. In practice I used (something like)
      while ((* setting_pos <= '9') && (* setting_pos >= '0')) {
      x = (10 * x) + (* setting_pos) - '0';
      setting_pos++;
      }
      The idea behind copying the arguement to a local variable was to increment the pointer with no risk of loosing the original string...of course that was silly now that I think about it. Like you said, having a const arguement would solve that little problem.
      Anyways, I've made enough of a fool of myself for today already.
  25. We promote/hire the most incompetent by Anonymous Coward · · Score: 0

    They do have expensive fancy pieces of paper prooving they can memorize things only.

    Besides, cleaning up from their constant bumbling affords me the ability to ignore coding practices. There are bigger piles of shit to clean up!

  26. WHAT Standards? by thepropain · · Score: 3, Funny

    I'm all self-taught, so I have my own style which others tell me is impossible to make heads or tails of. The standard is: the boss promises stuff to our clients, and I have to whip it out [snicker] as fast as possible. Doesn't leave much time to make easy on those who would come after me. I jokingly call the mess of code I have to make JOB SECURITY.

    --
    "You know you're narcissistic when you quote yourself in your sigs." -- PRoPAiN!
    1. Re:WHAT Standards? by Anonymous Coward · · Score: 0

      My coding standards involve a standardized shot of vodka on the hour, every hour. That's how I get my versions on.

    2. Re:WHAT Standards? by xero314 · · Score: 1

      If you're serious you make self-taught developers look bad, I now realize why have to work so damn hard to beat of degreed pros. I have worked with alot of people that have had that Job Security belief. Let me clarify, I have cleaned up after those people that have the Job Security belief while they cleaned out their desks. A boss would have to be blind or an idiot to let someone write code that can't be understood by the next developer. Of course a good boss wouldn't be making unrealistic promisses to their clients.

  27. None... by xquark · · Score: 1

    As simple as that he he he he he :)

    --
    Arash Partow's Philosophy: Be a person who knows what they don't know, and not a person who doesn't know.
  28. Coding Practices by Billosaur · · Score: 5, Insightful
    Here a just a few things that come to mind:
    1. Version Control - find a VC system everyone can agree and use it religiously, whether for scripts, programs, or even web docs. I've use CVS mainly, with a little Perforce, and Subversion is good so I hear.
    2. Coding Standards - depending on how many and what type of languages you have, you'll want to develop standards for how code will be laid out and documented that will make sense and also make it easy for somebody to move from one code base to another with as little trouble as possible. You can be as detailed as like, right down to conventions for naming subroutines and indentation, but don't get carried away or you'll stifle creativity.
    3. Documentation - not just documenting code (which any programmer should be doing reflexively), but documenting system flows and procedures. It doesn't hurt to throw together text docs on your more important scripts/programs, outlining where they live, how they're run, etc.
    4. The Brain Book - there's nothing I hate more than starting a new job and having to learn all those server names, IP addresses, what I'm supposed to have access to, where in the directory tree the stuff I works on live, what types of DBs we use and their versions, etc. So I developed the Brain Book, where I would write these things down as I learned them, to have a point of reference. It's a good idea to do this for all your major projects, so as new people come on, they can spend less time learning their way around and more time coding.
    5. Code Review - everybody's coding style is different and sometimes they don't mesh well or there are divergent opinions on how a particular task should be coded out. Get your programmers together in a room and hash things out as a group. It will provide everyone with a say and may open up some people's eyes to new ways of doing things.
    --
    GetOuttaMySpace - The Anti-Social Network
    1. Re:Coding Practices by bigtrike · · Score: 1

      The Brain Book - there's nothing I hate more than starting a new job and having to learn all those server names, IP addresses, what I'm supposed to have access to, where in the directory tree the stuff I works on live, what types of DBs we use and their versions, etc. So I developed the Brain Book, where I would write these things down as I learned them, to have a point of reference. It's a good idea to do this for all your major projects, so as new people come on, they can spend less time learning their way around and more time coding.

      The wiki feature of trac is excellent for this because it can be collaboratively maintained. The excellent subversion integration is also a plus.

    2. Re:Coding Practices by Anonymous Coward · · Score: 0

      I just want to add something to the Code Reviews section here. We have an interesting little way of making sure that people outside the project review the code, and not just show up and sit there like a log. At the beginning of every project (new feature/new product) someone that is not assigned to work on that project in any way is assigned to be the 'lead reviewer'.

      The lead reviewer is responsible for making sure the correct people are at the reviews (not responsible for calling the review, but when one is called making sure the right people show up [usually Architect, Teamlead, 2 project developers and 1-2 random developers]), making sure everything is reviewed, determining if the reviews are valid and complete etc. The lead reviewer does not worry about requirements, the Teamlead on the project is responsible for checking that requirements are met. It allows us to have at least one reviewer focused on What it does, and another reviewer focused on How it does it.

      It guarantees that someone who isn't staring at the code all the time has a good general idea about how the code is organized and can provide a comprehensive review it. If something bad were to happen to one of the coders, the lead reviewer could step in, pick up the requirements and assume the developer role without too much difficulty.

      I work in a mixed C++ (Unix) & .NET shop. For .NET, some syntax must be checked with FxCop, we have defined a set of rules that must pass BEFORE a review is even called. We don't enforce every rule, but it helps get rid of a lot of 'minor' nit-pick issues before reviews even start. We have documentation describing coding styles for both languages, they list recommended ways of writting common functions, general error handling practices etc... We also list reference books for OO Programming/Class Design, UML Design and Requirement Analysis in every design document. It works out very well for our shop.

    3. Re:Coding Practices by Anonymous Coward · · Score: 0

      s/Brain Book/Wiki/g

    4. Re:Coding Practices by raarky · · Score: 1

      I'd like to strongly second DOCUMENTATION as a major item.

      Theres nothing more annoying in the world then inheriting someone else's code to find out that there is no documenation on how they implemented their solution.

      Comments are fine but they dont describe the architecture of the program, what servers are used, who the contact people are, what the business goals of the app are and more.

      document, document, document!

      The days of the adhoc hacker are gone. coding is a "profession" and should be treated like all other business initiatives.

    5. Re:Coding Practices by sbenj · · Score: 1

      These are all great suggestions. I've worked for a pretty wide variety of places over the last few years, and often even the most basic stuff is left hanging (I once walked into a project with 10 developers and no version control). In an environment like that, even instituting VC is a real victory.
      Brain Book- I love your idea of a "brain book". I've never seen such a thing, always wanted one. In just about every place I've worked this is knowledge one accumulates through attrition and then lives forever on crumpled sticky notes and "that email from last month I know is here from Fred".
      Code review-great, only seen in one place.
      I'd add one extra idea to this- At a small shop I worked in we began a series of weekly self-education meetings - each week a rotating member of the group would pick some development subject (any subject of their choosing) and talk about it for about 30 minutes. This gave everyone a bit of a way to stay on top of things but also got people to buy into the idea of continuous improvement for themselves.

    6. Re:Coding Practices by Anonymous Coward · · Score: 0

      Yes, I like the idea of Brain Book. Better still, if the Brain Book is online and accessible by everyone. I have witnessed how the use of wiki sites which, over time, developed into many sections containing useful information that is well used by everyone and enhanced productivity. Typical sections are System Help, Development Platform FAQ, Project specific queries and many others. It is especially helpful to new comers, and interesting enough, it earns a lot of respect from them too !

    7. Re:Coding Practices by QuestorTapes · · Score: 1

      > 1. Version Control - find a VC system everyone can agree and use it
      > religiously, whether for scripts, programs, or even web docs. I've use
      > CVS mainly, with a little Perforce, and Subversion is good so I hear.

      Also, since the shop has never had an IT department, make sure everyone knows -how- to use an RCS. I had a project a couple of years back where one guy didn't use the RCS. After a few times I badgereed him to check in, we talked and I discovered he didn't really understand version control. So I spent some time teaching him.

      > 4. The Brain Book - there's nothing I hate more than starting a new
      > job and having to learn all those server names, IP addresses, what I'm
      > supposed to have access to, where in the directory tree the stuff I
      > works on live, what types of DBs we use and their versions, etc. So I
      > developed the Brain Book, where I would write these things down as I
      > learned them, to have a point of reference. It's a good idea to do this
      > for all your major projects, so as new people come on, they can spend
      > less time learning their way around and more time coding.

      We do this as part of an orientation package. Server names, standard share points, who is in charge of what, standard test logins to use, etc. Put it in a document, print it out for everyone new.

      > 5. Code Review - everybody's coding style is different and sometimes
      > they don't mesh well or there are divergent opinions on how a particular
      > task should be coded out. Get your programmers together in a room and
      > hash things out as a group. It will provide everyone with a say and may
      > open up some people's eyes to new ways of doing things.

      Very good advice; this also smooths out problems where any convention is just as good as the next, as long as everyone is consistent. Hashing this out as a group prevents cases where 9 people are asked to change the perfectly acceptable way they do things to conform to the lone other guy's ideas.

    8. Re:Coding Practices by MarkGriz · · Score: 1

      Jack Ganssle is widely respected in the Embedded Development world, and has an excellent Coding Standards manual on his website (it's an MSWord doc). While it's geared specifically to coding for embedded systems, much of what is in there applies to coding in general.

      --
      Beauty is in the eye of the beerholder.
    9. Re:Coding Practices by Anonymous Coward · · Score: 0

      Good advice - just a few things I would add:

      - Keep functions/methods short, no more than a screenful per function. If it is longer than that, it deserves to be broken up into smaller, descriptively named chunks.

      - Get tools that make refactoring easy and use them to keeps things simple. Refactoring lets you correct smaller archtectural mistakes without losing too much hair.

      - Adopt a naming convention for // FIXME comments, so they can easily be found.

      - When in doubt, throw it out! Don't be afraid to throw away crap code and rewrite it. In the long term this is usually the better choice.

      - It is usually better to optimize for simplictiy/maintainability than performance. Processors get faster over time, maintenance gets harder.

  29. Specs, reviews & tools are the real key by VisualVoice · · Score: 2, Insightful

    From my experience managing many multi-million line code projects for many years, its the tools (source control, bug system, langauges) and a standard documentation templates (market requirements doc, product requirements doc and detailed design document, unit test document) that are more important to standardize than coding guidlines. Sure everyone should follow a good variable naming convention (hungarian or equivalent) and heavily comment each function's purpose, but beyond that you can waste a lot of team time on arguing about idententation, and micro-commenting guidelines.

    Also key is a standard process of developer peer reviews. All developers should have peers review specs. New or mediocre developers should have their code peer reviewed. Proven developers can be excused the code review but not the spec review.

  30. Project Management by LoaTao · · Score: 2, Informative

    You seem to be asking more about the basics of Project Management than specific tools. For a fair overview of the subject try this in Wikipedia. The grand-daddy of Project Management for software development is SEI-CMM.

    --
    The smartest man in the whole, wide world really don't know that much. - Mose Allison
    1. Re:Project Management by greginnj · · Score: 1

      Absolutely -- good idea on Wikipedia; I checked out that article before I saw your link to it.

      Also (VERY IMPORTANT) you do not mention if you are in a publicly-held company. (Don't laugh, gang; even relatively small companies of a few hundred people can be thinly-traded but publicly held).

      If your company is public or planning to go public in the next few years, talk to your internal auditor, CFO, Controller, whoever -- IT Development Standards are part of the typical Sarbanes-Oxley audit.

      Explain to whoever named you to this position that if any of your development touches on financial app support (yes, this includes Excel macros) you should be formalizing your procedures, and it takes a few years to get this stuff right.

      Get them to spring for a few good books on project management (and make sure they include documentation templates and business process forms).

      Get them to spring for a Project Management Institute membership for you ( http://www.pmi.org/ ). Coding standards should be the least of your worries!

      --
      Read the best of all of Slash: seenonslash.com
  31. Project Management first, then everything else by Pasajero · · Score: 0

    Use top to bottom approach:

    First of all, have some formal project management training, at lest to get the basics. With this, you will be able to come up with a simple methodology for project requests/paycback/negotiation/scope/development/te sting/release. Then work your way down putting measurable controls where needed on each step of the process.

    I have done what you are doing now, and these where the first steps I took when facing a lot of teams with a lot of possibilities on "this is how we run a project" ways to do things.

  32. Experience counts by canuck57 · · Score: 3, Insightful

    My suggestion is get someone who has done this in a structured and successful environment. Otherwise developers will roll you over and your projects will be late, over budget and buggy.

    I have seen it so many times where an internal inexperienced person jumps in the saddle without mentorship and guidance in the areas of software development (NT or UNIX) and systems management not native to the environment. And I have seen how long companies suffer with the problems created by this and how much it costs companies in the end. It makes a $1000 per hour consultant look cheap.

    A good example is code management. Very few IT shops have it. Why? No one wants to know who checked in the buggy code! But few developers want such tools, especially the microwave generation. But at least when your caffeine isn't good enough and they move on you will know where the source code is.

    Sounds simple? Not really, there are hundreds of issues like the one above. And it can't be taught quickly.

    So get a consultant for 6 to 12 months that has done this, listen and learn and you will be off to a fast start.

    1. Re:Experience counts by ph1ll · · Score: 1
      So get a consultant for 6 to 12 months that has done this, listen and learn and you will be off to a fast start.

      Expecting honesty and commitment from a consultant is like expecting love from a prostitute - I'm sure it happens but generally they're only in it for the money.

      Talking to people in the developer community is a far better way of getting good advice and it's free.

      --
      --- "We've always been at war with Eastasia."
    2. Re:Experience counts by Anonymous Coward · · Score: 0

      Talking to people in the developer community is a far better way of getting good advice and it's free.

      The wolves watching the hen house comes to mind.

      For a lot of things though it is good to consult "professional" developers however the policies and framework of the operations is a management responsibilitiy. Developers often want to skip planning, engineering and business analysis and skip straight to coding. Testing is viewed as an option then the environment is medocre at best.

  33. We use this by Sexy+Commando · · Score: 1

    We use agile programming methods.

  34. code complete has some good things to say by blackcoot · · Score: 5, Informative

    on this particular subject. i believe code complete 2 came out "reasonably recently". that said, were this my task, i'd say the following:

    1) document things thoroughly using a tool like doxygen. there is no excuse for interfaces not to be thoroughly documented
    2) adopt a standard naming convention. in java, this is easy -- just use the default. in other languages, you'll probably have to make your own up.
    3) pick an indentation style. it really doesn't matter which since tools like indent can convert between them almost painlessly. all code that goes into the repository is run through indent to put it into a standard format
    4) require that code compile cleanly with no warnings at the most anal retentive compiler settings before it can be checked in unless there are good reasons to ignore the compiler warnings
    5) average devs are only able to commit to the "head" fork (or equivalent in your sccs). the code is not committed to the "real" fork until it passes whatever tests you have
    6) incorporate tools like valgrind into your testing cycle --- they should come back largely clean. if they don't, things need to be fixed unless there's a really good reason not to.
    7) people who check in code which breaks cvs or, upon a code review, are found to not sufficiently adhere to your guidelines owe their dev group donuts.

    1. Re:code complete has some good things to say by masklinn · · Score: 2, Insightful
      3) pick an indentation style. it really doesn't matter which since tools like indent can convert between them almost painlessly. all code that goes into the repository is run through indent to put it into a standard format 4) require that code compile cleanly with no warnings at the most anal retentive compiler settings before it can be checked in unless there are good reasons to ignore the compiler warnings 5) average devs are only able to commit to the "head" fork (or equivalent in your sccs). the code is not committed to the "real" fork until it passes whatever tests you have

      5 is not that required since most modern version control tools are able to run scripts on your data before/after the commits.

      In that case, the indentation cleaning, compile test and full unit-testing of the modified application could be done automagically at commit, with commit refused if code doesn't seamlessly compile or if any unit test fails (any code change would also, naturally, require the concurrent commit of the modified unit tests for the code).

      --
      "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
    2. Re:code complete has some good things to say by Q2Serpent · · Score: 1

      This only works for the smallest of projects - imagine if a CVS commit took 5 hours while waiting for the new code to build and another hour while waiting for some tools to check over coding standards and static analysis? Hah! Ignoring the non-atomic nature of CVS and the race conditions that will happen, I'm not waiting 4 hours per check-in!

      A better idea is to run these things nightly, with automatic notifications going to the appropriate parties.

    3. Re:code complete has some good things to say by masklinn · · Score: 1
      5 hours while waiting for the new code to build

      Duh, you're not supposed to rebuild the whole project every time

      --
      "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
    4. Re:code complete has some good things to say by tanguyr · · Score: 1

      7) people who check in code which breaks cvs or, upon a code review, are found to not sufficiently adhere to your guidelines owe their dev group donuts.

      We have a little garden gnome statue for this: he lives on the desk of the latest person to have messed up. We even do a little procession through the workplace to bring him to his new abode.

      --
      #!/usr/bin/english
    5. Re:code complete has some good things to say by Q2Serpent · · Score: 1

      What if I checked in a header file that is included in many places? What if the build runs the testcases?

      The point is that even for a CVS check-in to take 5 minutes is absurd.

  35. Pottery Barn rule by lanced · · Score: 1, Insightful

    The pottery barn rule comes to mind: you break it, it is yours. Or at least that's the way it is when I am tweaking the legacy code.

    My boss on the other hand, it's more like the bull in china shop. Heck if I know how he got in there, but I know there is going to be heck to pay in the morning.

  36. Documentation and Planning by inKubus · · Score: 1

    These are pretty obvious, but documentation and planning are something you need to stress.

    Documentation is the most important, from business rules and operating procedures (this code gets backed up at this time every night) to the code itself. As a project manager, your job is to build a little box for the developers to work in. You want to make sure that all the important stuff is just a simple list of stuff to follow so they can concentrate on coding. Programmers are generally not good at scheduling or remembering to do mundane daily tasks. Get that stuff straight and you'll solve 50% of your day to day problems.

    Planning is important. Make sure that there's a good plan that everyone's following. Plan naming conventions and folder/file systems for your code. Then, everyone knows where to look if they need to find something. Simple organization is important. As far as actual development, you need to have a broad plan for the goal of the project, what general steps need to be taken (initial planning, module coding, testing, beta, release, maintain) and do them in that order. You don't need to get crazy with project planning software either; what you want is results, not to dictate how the results occur.

    To that line, this box you're building has to be open enough that your developers aren't too constrained to innovate. This means you have to make it kindof a fun challenge to document the code, plan the project, etc. Don't make it seem like it's some chore to document. Force them to pass their code around for a few weeks to work out the bugs; don't wait until you have to. Or start with some dumb easy project that is a small part of the larger problem, and make everyone do one little piece of the planning, then pass it to the other people.

    Anyway, this stuff is pretty obvious management stuff. I can tell you that in my 6+ years of business experience with coding and coders, the most important thing is having naming conventions for your files and folders. It seems obvious but when you get a new developer in, he's not going to understand Module3.CreditWidget.x3.1211.c when it could just say "NumberVerifier.CreditCard.c".

    The military logistics people have good ideas for that sort of stuff:

    -A data element name consists of a prime word, a class word, and modifiers.
    -A prime word is the noun designation given to an entity identified in a data model. For example,
    a company may need to maintain information about customers, so an entity "Customer" could exist. The prime word for this entity would be called "Customer." The prime word identifies the object to which the data element refers.
    -Prime Word Modifier. Prime word modifiers are adjectives that further refine and categorize the
    prime word. They designate the name of a data subentity in the data model and distinguish it from other subentities of the same data entity. They are needed to distinguish that data subcategory from other subcategories of data represented by the data entity. For example, a company may be interested in information about two distinct groups of customers, "Retail Customers" and "Wholesale Customers." The prime word modifiers "Retail" and "Wholesale" are used to distinguish between these two types of customers
    - class word is a noun that prescribes a definition for a general category of data. A class
    word designates the category of data into which a data element fits. Examples of class words are: "Code," "Name," and "Quantity."

    Etc.

    Check out Department of Defense Data Element Standardization Procedures

    Good luck.

    --
    Cool! Amazing Toys.
  37. Mushroom Management by ad0gg · · Score: 1

    At my former job we used this mushroom management with great success. While people quit or get laid off we ended up with Lava Flow. And it ended up with my favorite practice called "down by the river eating government cheese".

    --

    Have you ever been to a turkish prison?

  38. You're fighting an uphill battle by Anonymous Coward · · Score: 0
    I've been working for a State government agency now for 3.5 years. No development standards to speak of. We have no formal procedure for launching a project, conducting/managing a project, or deploying and reporting on the project. Developers waste a lot of time reinventing the wheel and learning other people's code bases for maintenance projects. There are still many people who even refuse to see the value of a source code and documentation repository.

    My thought is that you have just accepted a practically impossible task. If you don't have unwavering support from management, you'll fail. If you can't somehow get people who've been doing their job for 35+ years without standards to WANT to do it WITH standards, you'll fail.

    Expect endless argument about what standards there should be and how far they should go. Expect that no one will be satisfied with your testimony about a proposed standard having worked well for you in the past -- everyone else will deny that your "standards" are solutions to the problems of project maintainability. Expect complaints that "we've never had to do this before" even if you know it's a good idea. Finally, expect it will take a LOT longer than you want it to.

    If there's one piece of advice I can give you, it is: start with the very basics, work to expand them slowly, and pick your battles carefully.

    Good luck, you're going to need it.

    1. Re:You're fighting an uphill battle by thsths · · Score: 1

      > Expect that no one will be satisfied with your testimony about a proposed standard having worked well for you in the past -- everyone else will deny that your "standards" are solutions to the problems of project maintainability.

      That's partly because developers are smart: they know that what works good for you is not necessarily good for them. So if you want a standard that is successful, you have to get the developers involved in creating it. Just putting something down "by force of power" is so 1930s :-)

  39. there are three by geekoid · · Score: 1

    Comments:
              concise comments.

    Clarity:
              Use readable and properly discriptive names. Avoid using hard to read code because it makes it faster. Processor are fast,and compilers re pretty damn good. The only exception is code write on top of the machine, But then you should commented well.
    Consistency:
    Apply the details to all developers. Meaning if you decide to to use 3 spaces for every indentation, be sure all the developers use it. If you use a common IDE, then it should be trivial to make the look consistant.

    I'm a big fan of code reviews. It spreads the knowledge around, makes the developer interact, helps ensure consistency, and is a good way to be sure the project is on target. Too many times I've seen wrtitting a tool to help with a project, become the project.

    The reason why I becames a fan of code reviews is a long and tedious story...so here goes:

    I was leading a team of 4 developers. about 8 weeks before the project was do, I decided to do code reviews. 4 weeks later It was this developers turn. He doesn't show up to work, or the next day, or the next day. I had HR call him, but never got a returned call. At this point I get on his computer and start searching. The only code I found was learning code. Clearly this 'experienced developer' had no experience at all. The team came together and we managed to get his work done, and the project released on time. Saved the bank 100 million dollars. They gave us a football.
    I ran into him years later, it seems a dot com where he was the lead developer had gone belly up when they couldn't deliver.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  40. Example programs... by hackwrench · · Score: 1

    When I started out programming I went to the example programs, and ever since then when I want to learn something new I find example programs. Have your programmers write example programs that demonstrate what they expect their code to do. This can also prove useful for unit testing.

  41. infinite number of monkeys by MMHere · · Score: 1

    I've hired an infinite number of monkeys, and seated them at an infinite number of PCs running Eclipse (with File->Quit disabled).

    I expect them to have finished writing my code for me by Monday.

    1. Re:infinite number of monkeys by Anonymous Coward · · Score: 0

      If you've got an infinite number of monkeys and an infinite number of computers, it should be ready in an infinitesimal amount of time, even assuming a uniform or even nonuniform distribution of keypresses from now to infinity.

    2. Re:infinite number of monkeys by Anonymous Coward · · Score: 0

      Hey, with the next Eclipse stable build, all you'll need is ctrl-space.
      Unless you're equipped with the ./ standard metallic headwear of course.

  42. Standards by shoemakc · · Score: 3, Funny

    Yeah, standards are great.....we've got lots of them :-)

    -Chris

    --
    --an unbreakable toy is useful for breaking other toys--
  43. UP by chadseld · · Score: 1

    I'm a huge fan of the Unified Process. Note that UP focuses on the software development process, and not the project management process. Also: Set up a Subversion server, use Trac, and put daily announcements on the start page wiki (or similar). Unit Test your code, and make sure to use Javadoc/Headerdoc.

  44. Coding Standards :: E_Not_Enough_Info by lloy0076 · · Score: 1

    Well, coding standards can be very complex to very simple not to mention they're language independent. A coding standard for Perl would almost certainly be different to one for C - simple example, Perl doesn't have /* and */ so mentioning them in a Perl coding standard doesn't make a lot of sense.

    Here's some advice though:

    1. Take a top down approach and a bottom up approach at the same time

          - What are your broad goals and what do you want your standards to do?
          - What standards already exist in the organisation?

    2. Remember, you need to win the hearts and minds of your teams to change

          - Sure you can be PHB and say "Thou shalt", but unhappy coders write unhappy code
          - Listen to your team and get their feedback

    3. Don't make wholesale changes because "you can"

          - Otherwise you might end up making things worse

    Out of all these three points, if you want to effect change, maintain respect and have coders who you can still herd about, point 2 is probably the most important...in fact, if you have the time and support to do it, getting your programming team to formulate the standards FOR YOU will mean they're more likely to actually follow them because they OWN them :)

    HTH

  45. Test Driven Development by Anonymous Coward · · Score: 0

    Test Driven Development. It's the easiest way to end up with good code and tests that support you when you make changes. And, we all know that we will make changes :-)

  46. Documentation, convention, version control by Roach · · Score: 1

    Contract developers and new programmers joining an organization, especially a small organization, appreciate thorough documentation of processes and modules from an overview down to details on each specific component. Legacy engineers tend to hate documenting so it may require some effort.

    OOP helps resolve issues of efficient use of code so that development efforts aren't wasted on modules that may already exist created by previous developers no longer with an organization. A clear naming schema and again, documentation on each class and how it works is very helpful.

    Structured programming practices. Documented code. Standards such as variable naming conventions and efforts to maintain code uniformity.

    I personally like Version Control with Subversion, we use it in our China office and everything there takes very well to it.

    We have learned a lot from our China operation for the organization I am with. They make extensive use of Wiki's too. This lends itself well to the documentation task.

    I believe the rest is management style and your corporate culture.

  47. Write code that works by georgewad · · Score: 1

    That's what my old boss told us to do.
    Also, "If you can't finish it by the deadline, work faster."
    fsking brain surgeon.

    --
    Karma: It's not just a good idea. It's the law.
  48. Programming Standards by clockwise_music · · Score: 5, Insightful
    In no particular order:

    1. Get a development database, a testing database and production database. Yes, you need all three.

    2. Write a few docs explaining each system. Make these are detailed as you possibly can. (This will save you weeks in the long term)

    3. Use software revision control. CVS, VSS, whatever, use one.

    4. Use a bug tracker. BugZilla, Jira, CityDesk, whatever, use one.

    5. Use whatever coding standards the language reckons you should. If java, use sun's standards. If microsoft, use their standards.

    6. Write automated unit tests. I don't care if you're not an agile or XP developer, write unit tests. Check out Junit, or Nunit, or just write your own.

    7. Setup some code so that you can check out ALL code from the source code repository and compile it by ONE COMMAND. Eg, "make" or "ant" or "maven" or whatever. This will take time but is worth it.

    8. Have a naming standard for database tables. This will make your life SOOOO much easier.

    9. Read thedailywtf.com and don't do anything that is posted there.

    10. Write specs for your new developers. Please write specs for your new developers. Don't just say to them 'fix this up'.

    11. Make sure code isn't hard-coded to a particular directory. Everyone does this. Fix it. (Might be part of step 7)

    12. Create your own standard config files.

    13. Have code reviewed by peers. Don't be a bastard but be nice when picking on people's code.

    14. As mentioned, comment your code but use the language standard. Java - javadocs, Perl - perldocs, etc. These are cool, but don't get too carried away. Nothing can replace a good spec.

    15. Ignore what most people say on Slashdot. (Except for me, of course).

    That'll keep you busy for a couple of months! Doing thiswill make you well on the way to having a pretty high level of coding quality. Most companies don't do all of them. Good luck.
    1. Re:Programming Standards by Anonymous Coward · · Score: 0

      Good starting points with the exception of: "If microsoft, use their standards."

      Setup your programming environment as agnostic (non-Microsoft) as possible, and follow real standards. If management pushes you to do it, push back.

    2. Re:Programming Standards by RetroGeek · · Score: 4, Interesting

      1.a Get a test application server and production application server. Yes, you need both. The development server would be the developers workstation.
      6.a Formalize the testing process by people other than the original developers.
      6.b Write test cases.
      6.c Do regression testing. Especially for "transperant to the user" changes.
      8.a Have a naming standard for table columns. This will make your life SOOOO much easier.
      11.a Where you do need hardcoded directories, externalize the locations in configuration files.

      --

      - - - - - - - - - - -
      I am a programmer. I am paid to produce syntax not grammar. Deal with it.
    3. Re:Programming Standards by NemoX · · Score: 2, Interesting

      Great post. Some additions...

      1. Use a code reviewer like FxCop for .NET stuff. You can build custom rules that your team decides on, and apply them to each program.

      2. Automate as much as possible with things like Ant or NAnt. The less people do, the less room for errors or discrepancies from project to project.

      3. Use something like Cruise Control .NET which will tie everything together, run coverage reports, automate builds, etc.

      4. Make a Utility library so that they have a common place to get repetative processes. (e.g. we have one that validates whether a number and address is a valid store for our company; it is used in 75% of our programs, but only coded once.) You could incorporate some common error handling like log4net or log4j into the utility.

    4. Re:Programming Standards by dorkygeek · · Score: 1

      Pretty neat list.

      I personally think that transparency is one of the key principles. Use a central repository where everyone can look at each others' code, use a central bug tracking facility, and call people by name who checked in code which broke things (something which e.g. XP proposes). With that you can ensure that people are aware of their responsibility for things they did, and others know whom to contact if the breakage was intended and they needed to adjust their own modules.

      If you have a tool which integrates all this into a single workflow, the better (e.g. Eclipse with Bugzilla plug-in, etc.).

      Of course, if you only have one person per project and you're not planning to change this scheme in near future, you can save yourself some of the overhead.

      --
      Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
    5. Re:Programming Standards by mobilebuddha · · Score: 1

      "Get a development database, a testing database and production database. Yes, you need all three"

      what parent meant is:
      1) get a development environment, testing environment and a production environment.

      what parent realllly meant to say is:
      1) get a development environment - (a server) where developers can freely push changes into and do their limited unit test and their own "regression" tests.

      2) get a QA environment - (a server) where your QA team (hopefully you have one) are the only one who can push changes into this box. have an issue/enhancement tracking system (there are many free ones out there) so you can track what goes in.

      3) get a pre-production environment - (a server) where it is -always- only 1 version ahead of your production. no one should have access to this machine except folks who are responsible for pushing things into production(IT team). if something gets pushed into this merely for testing, the IT team is responsible to undo the push immediately after the test is done.

      4) get a production environment - (a server) where this is your production code resides. no one has write access to this box except IT team. IT team is not allowed to touch this box except in dire emergencies and during normal production push window (once a week -> once a yr depending on your development lifecycle). during the production push window, you copy everything from pre-production into production.

      most of the corporations that i've dealt with do the following:
      1) rational clearquest for development of enhancements, version tracking
      2) remedy for IT or production support related issues.

      also, they have another environment sitting between QA and the "pre-production", it's for all of the changes that get passed by QA but not yet ready to be pushed into production during your next push cycle.

      hope that helps!

    6. Re:Programming Standards by Tim+Browse · · Score: 2, Interesting

      Something else I've found useful (which I think I got from a McConnell or Maguire book) is the idea of priorities in your coding, which should be part of your coding standards. That is, take a set of features/aspects of code like this:

      • CPU Efficiency
      • Memory/storage Efficiency
      • Maintainability
      • Portability
      • Correctness
      • Testability
      • Robustness
      • etc.

      ...and then put them in order of priority for each project you work on. The order will vary depending on the project, but a lot of coders will program with the same priority list in mind no matter what they are working on (e.g. obsessing about efficiency above all else) unless you actually tell them what the priorities should be.

      Making the list and putting it in order just puts it on everyone's radar. I have at times had the list taped to the edge of my screen, so when I come up against a design decision, I check the list for guidance.

    7. Re:Programming Standards by swthomas55 · · Score: 2, Interesting

      Amen!

      In 30+ years of coding, I've used many different "standards". I've come to the realization that the details of the standard are unimportant -- what's important is that you have one.

      Personally, I find "hungarian" variable names painful to behold. But if I'm working on code that used them originally, I'll try to make myself be consistent with the existing style.

      Indenting and white space standards are totally unimportant with a good IDE. In Eclipse, hit control-shift-f to make it look the way you want it to.

      Commenting is more problematic. I've gone from heavily commented to no-comment XP programming. I've settled down into a "minimal comment" regime. I try to write code that doesn't need comments by using short functions with meaningful variable, method, and class names. But where a comment can inject additional clarity, or where the code is necessarily obscure, then a comment can really help. (And by obscure, I don't mean "obfusticated" -- I mean code that is handling some bizarre real-world circumstance that most code readers probably would not think of.) Use your judgement. Ask yourself "if I came back to this code in a year, what bits would I be confused about." Then clarify that code. If it can't be further clarified, write a comment.

      As for "javadoc" or "pod", I think that it is essential if you're writing code that will be used in "binary" form by others. Try using something like DOM or Spring without documentation and see how far you get! But Javadoc for the sake of meeting some metric ("all public methods must have Javadoc") is purely silly. Even when I was working on a strict XP team that enforced a "no comments" discipline, we put Javadoc on a couple of methods. We found ourselves continually going back to read the code to answer questions such as "is this index 0-based or 1-based?" A simple Javadoc comment stating "index is 1-based" saved many minutes of coding time.

      Practice test-first writing. It's weird the first several times you do it, but at least for me, the more I do it, the more comfortable it feels. You can't always do it, I'll be the first to admit. But if I never write a line of code that doesn't have a test motivating it, I have a lot more confidence that the resulting code is going to do what I intend it to do. On the flip side, if I can't think of a test case that requires some particular "if branch", then maybe I don't really need to write that line of code.

      Get a coverage tool and use it. Don't blindly try for ~100% coverage (you'll never get it anyway), but it can point out bits of code that are undertested.

      In addition to "writing specs for new developers", pair a new developer with an experienced developer for a few weeks. Just a couple of hours a day will transfer the group practices much faster than any document will. IMO, this works best when the experienced developer is the "navigator" and the new developer has his or her hands on the keyboard, "driving." Doing == Learning. Watching == Boredom and Distraction. As an experienced developer, this is really hard for me -- I want to drive -- but it really does work.

      Practice group ownership of code. Don't let any individual piece of code belong to a single person -- in the sense that only one person understands it and only one person is "allowed" to touch it. Not only can this save you when the "guru" leaves, but it helps to prevent wheel-reinvention and accretion of "ugly code". It encourages the attitude of "if it's broken, and I'm working on it now, then it's my responsibility to fix it."

      Frequent integration in a multi-developer shop is essential. Don't let each developer work alone for a month or maybe even a week without reintegrating the code.

      A bunch of this sounds very XP-ish. That's because XP is not a new thing. XP is a combination of good practices all "turned up to 11." We tried XP for about a year and had mixed results -- out of 4 projects, one was successful, one was an utter and complete failure, one was mothballed

    8. Re:Programming Standards by buck_wild · · Score: 1

      "Use a central repository where everyone can look at each others' code"

      Certainly not saying it's the best, but an application we successfully use it called MKS Integrity. Developers check out modules they need to modify, and everything is safe, secure, and tracked.

      In my shop, we've even automated most application rollouts.

      --
      If all you have is a hammer, everything looks like a nail.
    9. Re:Programming Standards by iabervon · · Score: 1

      Ideally, get everybody development databases. Oracle basically lets you have them for free, and a small database on each workstation. If you can't run the complete system under single-user load on a workstation, there's no way you'll get it to run in production, unless you're Google.

      If you expect unit tests to fail (especially common with XP, where you write tests for code you haven't implemented), make sure that reports don't list them as being a problem, because this just hides unexpected failures.

      Language coding standards generally leave a bunch of flexibility. Eliminate all flexibility in your coding standards. There are better and worse options to choose, but non-uniformity is even worse than GNU^W^W^W^Wthe worst of all.

      Don't comment your code. Comment your data structures. People can see what your code does by reading it (and can see what it should be doing by reading the spec). Your data structures just sit there and can be misinterpreted. Once you've explained in detail what your data means, you can comment tricky bits of code.

      Use symbolic constants. If there are any two things which match by more than coincidence, you're missing a constant, and you're going to be in trouble when one of them changes. This includes comments.

    10. Re:Programming Standards by Mycroft_514 · · Score: 1

      >Get a development database, a testing database and production database. Yes, you need all three.

      Depending on the shop size, you might need more than that. Our current plan calls for 5, and that might not be enough.

      >Have a naming standard for database tables. This will make your life SOOOO much easier.

      And rule one of this standard is that no table, nor any column in any table may use a reserved word as a name. Trust me on this one, it will make your life SOOOO much easier.

    11. Re:Programming Standards by SebNukem · · Score: 1

      OMFG:

      3. Use software revision control... VSS

      Read:

      3. Use software revision control except VSS. Stay clear of VSS if you want to keep your job and your life.

    12. Re:Programming Standards by Anonymous Coward · · Score: 0

      OMFG, good luck with 7th grade next year.

    13. Re:Programming Standards by Anonymous Coward · · Score: 0

      Cruise Control - thanks for the heads up! Theres currently a minor war/bitchfest going on where I work which would be prevented by software like that...

    14. Re:Programming Standards by aug24 · · Score: 1

      An excellent list to which I would add only one comment:

      Do not let your coders make assumptions. If the spec is unclear they *must* go back to the business analyst and get it make clear.

      J.

      --
      You're only jealous cos the little penguins are talking to me.
    15. Re:Programming Standards by zztong · · Score: 1

      Just one change...

      Quote: "1.a Get a test application server and production application server. Yes, you need both. The development server would be the developers workstation."

      Get a development server, test server, and production server. You'll need all three. The seperate development and test servers allow your staff to be working on bugs while folks are testing a release. I think it's completely acceptable for each developer to have their own development server assuming a desktop machine is capable of the load. It may be that was already assumed by those giving the earlier advice.

    16. Re:Programming Standards by CrazedWalrus · · Score: 1

      Get a development database, a testing database and production database. Yes, you need all three.

      A development database for EACH DEVELOPER is almost a must for large code bases and large development teams. Nothing is more frustrating than having someone clobber your test data because they're working on a related system, or finding out you've done the clobbering to someone else.

      Use software revision control. CVS, VSS, whatever, use one.

      Try to use one that isn't *MASSIVE* overkill for your situation. We have ClearCase here, but we only use it for functions easily provided by CVS. Unfortunately, it's orders of magnitude slower and more complicated, making simple code changes a chore.

      Read thedailywtf.com and don't do anything that is posted there.

      Heh. Agreed. I knew I hated Hungarian notation, but didn't realize that a) it has a name, and b) I'm not the only one, before I started reading that site.

      Write specs for your new developers. Please write specs for your new developers. Don't just say to them 'fix this up'.

      Indeed. That shouldn't just apply to 'new' developers as in 'just out of college'. Remember that any system is confusing to someone looking at it for the first time. More experienced people can generally make sense of things faster, but 'faster' might still mean two days instead of a week. For a system of any size, I think it usually takes a good six months to really start feeling comfortable, and usually years to become intimately familiar with. Developers may be a dime a dozen nowadays, but developers who understand your system and business aren't.

      I could start a related rant here about the importance of reducing turnover, but the above summarizes it pretty well.

      Create your own standard config files.

      In fact, standardize your configuration system and write APIs for it for your shop's major languages. Make this a no-brainer.

      In fact, I would advocate doing this for all major operations, in case the standard or methods change. For instance, connecting to a database. Make one module that you call that will return a connected database handle for you. Use it for everything that needs a database connection.

      Why? Think about those upcoming security audits... changes to how you store your passwords, moving to using kerberos to authenticate instead of passwords, changing database vendor, etc. Change the abstraction module, and you move everything. Changing duplicated logic in hundreds of programs is a nightmare.

      Hope this helps.

    17. Re:Programming Standards by Programmer_In_Traini · · Score: 1

      Amen bro - especially true for #15 - lots of peeps are just karma whores :)

      --
      If you look like your passport photo, you're too ill to travel. - Will Kommen
    18. Re:Programming Standards by 4of12 · · Score: 1

      This all sounds like good advice from someone who understands the value of these practices.

      But, if I might, there is a higher level Meta stage that needs attention.

      In my experience, there are tons of opinions and and tons of vendors with Solutions © to these kinds of problems. And, yes, there is some value in that advice and in those solutions. That's not enough.

      It's incredibly important that your staff see that value, understand it, and are willing to put up with the costs (time, hassle, learning) with whatever system you use.

      There's nothing more tiresome that getting a notification to attend a meeting where the New Coding Practices will be rammed down your throat for 3 hours. As if the high level decision makers are sufficiently in-touch with life in the trenches to understand the issues, much less dictate the answer of how to do the work.

      [Apologies for the ranting]. My suggestion is to get the people in the trenches to meet together and come up with suggestions themselves. They can explain to each other the value of certain practices, the uselessness of Vendor Y's product, etc. In the process of coming up with a set of standard practices, they will buy in to the decision and practice because they have helped to define it (and they are less likely to include things in the definition that are onerous or stupid). Believe me, the worker bees really know what gets in their way and what helps their productivity. They have strong opinions about it and can convince people why certain practices apply or don't apply to your particular line of business.

      By assigning your staff to help define, recommend and select the policies and any helper applications, commercial or FOSS, in-house, etc. you'll be in a lot better shape during the actual implementation of those polices.

      --
      "Provided by the management for your protection."
    19. Re:Programming Standards by RetroGeek · · Score: 1

      The problem with having a common development server is that if you code something that causes a crash, then you take down the common server. Running a personal server allows these little gaffes to be fixed without affecting other people.

      Performance is not really an issue (just need RAM, lots of RAM). If a query takes 1-2 seconds, so what? One user, one query. I use an old 400MHz machine, which was surplus. It has 1G of RAM, but only a 20G hard drive. It runs both the application code (Tomcat/Java/JSP) and the database server (MS SQL).

      Now the test server and definately the production server need to be up to spec, as they will need to handle load.

      BTW, this setup processes pages (from first servlet start to the final JSP) in under 0.3 seconds. The test server does the same page in under 0.05 seconds. The production server is under the millisecond range and does not show a time except under heavy load.

      --

      - - - - - - - - - - -
      I am a programmer. I am paid to produce syntax not grammar. Deal with it.
    20. Re:Programming Standards by SebNukem · · Score: 1

      Thanks. You should take the spot in the back while I seat in the front of the class. See you there.

    21. Re:Programming Standards by malloc · · Score: 1

      Use software revision control. CVS, VSS, whatever, use one.

      VSS! Please, for the love of all that is pure and holy, not VSS! Use something that won't destroy label/tag history simply by a user having their system time incorrect. Use something that won't corrupt your data when the network hickups. Use something that isn't open to corruption the moment a user gets infected with a virus. Use something that supports proper release branching. But please, not VSS!

      (A good alternative is Subversion.) -Malloc

      --
      ___________________ I want to be free()!
    22. Re:Programming Standards by starbuck5250 · · Score: 1

      One way to make this process more palatable is to consider implementing it from the ground up, not imposing it from the top down. That is, unless you intend literally to have code police physically approve every line of code, it'll work better if the programming staff buy into the concepts noted above. Said concepts being Good Ideas indeed.

      Peer review can go a long way to developing working standards that YOUR programmers want to use in YOUR shop. You won't be revisiting existing code to go make it conform to The New Way, so your programmers will be living with old and new side by side for quite a while.
          --buck

    23. Re:Programming Standards by Nevyn · · Score: 1
      Don't blindly try for ~100% coverage (you'll never get it anyway)

      Neer, neeer ... *cough*, sorry about that. Of course, I also have a monetary reward for remote holes in my webserver ... so I'm probably not that normal :)).

      --
      ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
  49. Doxygen by segfault7375 · · Score: 2, Informative

    One word.. doxygen. I had been working on a program by myself for a few years and was really the only one who knew the guts of it. We got a new person on it so I could move on to other things, and rather than spending a week or two showing her what she needed to know, I spent a few days adding doxygen comments to the project, and she was able to read the generated documentation for herself and picked it up in no time. It plugs in to Visual Studio very nicely if you use that, and if not, you can easily write a batch file to update your documentation. I just can't say enough good things about this tool. If you can get your developers in the habit of documenting in the doxygen format, your documentation will basically write itself.

    Segfault

    1. Re:Doxygen by Anonymous Coward · · Score: 0

      I second that. Get the programmers to adopt good commenting habits that'll export well using Doxygen and you're golden. Once you get into the habit of placing clean, concise and descriptive 'header' comments before functions, next to members, and so on, the codes becomes insanely readable and Doxygen will produce awesome documentation for it.

      Clear automated documentation is absolutely invaluable. But it does mean you have drill into the programmers' heads to adopt a particular style of commenting that Doxygen (or whatever else tool exists) recognizes.

  50. We don't need no coding standards! by MythoBeast · · Score: 2, Informative
    Ok, so the subject is misleading. As a C++ contractor with about 15 years of experience in a broad variety of shops, I've been exposed to quite a lot of different coding standards, from severely strict where they told me where and when I can use the spacebar, to the completely non-existent. Of all of them, I have found the GNU coding standards to be the best balance between the flexible and the legible.

    A few other details that I'd like to add. K&R braces were invented, not by K&R but by the guys who typeset their book. It is a severe roadbump to try and read code where the braces are at the end of an if statement instead of vertically alligned.

    Try spinal alignment for variables. Most people align their variables like this:


    int something;
    void somethingelse;
    longobjectname theThirdThing;

    Those with more of a clue align them so that you can find the variable name easily in a mess of them:

    int something;
    void *somethingelse;
    longobjectname theThirdThing;

    This puts some major space in some cases between names and short type declarations. Try aligning them like this:

    ...........int..something;
    ..........void.*some thingElse;
    longobjectname..theThirdThing;



    The problem with this technique is that, if you ever post your code on Slashdot, you'll have to replace spaces with dots and spend fifteen minutes trying to get it to render correctly because SD doesn't support a simple PRE tag.

    Other tidbits that have helped. camelNotation rules. Don't use hungarian notation, it doesn't work in a severely object oriented enviornment. Instead, preceed your variables with a single letter that tells you where it's declared. l for local, m for member (of a class or struct), g for global, that kind of thing. I've seen "my" used for member and "the" used for static very effectively, also, but stick to one.

    Most of all, good luck. Remember that a lot of people's beliefs in this matter have no foundation except for what they've been doing for years. I have faith in my standards simply because I've seen what happens when you don't follow them, and that's mostly confusion.

    --
    Wake up - the future is arriving faster than you think.
    1. Re:We don't need no coding standards! by Jerf · · Score: 1
      The problem with this technique is that, if you ever post your code on Slashdot, you'll have to replace spaces with dots and spend fifteen minutes trying to get it to render correctly because SD doesn't support a simple PRE tag.

      <ecode>
      .
                int something;
                void *some thingElse;
      longobjectname theThirdThing;
      But it's quirky and you always have to preview when using it. In this case, it was eating the spaces on the first line. That's what the period is for, to be the first line. (There used to be a comment on the posting page about the tag, but now I don't see one; it's just listed without explanation at the end of the "allowed HTML" list.)

      Oh, and I've grown to really, really dislike that style. We use Perl, but you still get the basic equivalent when initializing vars: my $Whatever = 'initial'; I'm still not sure why I dislike it. Maybe just because it's a pain to type.
    2. Re:We don't need no coding standards! by MythoBeast · · Score: 1

      It's still displayed wrong in your post. There should be two spaces between the type and the variable if there is no pointer or reference indicator (* or &). This keeps first characters aligned for alphabetic identification. Also, your int is aligned with the beginning of the void on the second line instead of the end, like longobjectname is.

      Thanks for the tip about the period as the first line. That'll be helpful in the future.

      I'm still not sure why I dislike it. Maybe just because it's a pain to type.

      I can't disagree that this is a drawback. My philosophy, though, is that I type something once, but wind up reviewing it several times thereafter. Typing it correctly doesn't cost me nearly as much time as having to sort through mis-aligned variables looking for the one I need to adjust.

      --
      Wake up - the future is arriving faster than you think.
  51. High quality management. by Xzzy · · Score: 1

    > I've come across some documents in this area from a few sources (of course can't remember them off the top of my head).

    Uh, then might I suggest holding off on pressing the submit button for a few minutes while you go find them? Can just imagine this new project lead in meetings. "Well guys I was going to unveil our new features, but I can't remember what they are off the top of my head."

    Little preparation goes a long way.

  52. That's Like Scrum... by Greyfox · · Score: 2, Insightful
    Scrum and Code Reviews are all well and good but people who've never done that before don't know what to expect, so they tend to be all over the place with their comments. This leads to code reviews where your code is nitpicked over every little thing and scrum meetings that grow and grow until they take 2 hours out of every day to complete. Neither of these things are beneficial to productivity.

    I find that a good standard for code reviews is to assume that the programmer knows what he's doing and I don't try to push my political agenda in them. If you want to have a passionate argument about hungarian notation or putting braces around if statements that only execute a single line of code, the code review is not the place to do so. If you think a data structure he used isn't up to the volume of data you'll be running through the system, THAT's something to bring up in the code review.

    You can require comments in your code all you want, but I find that you inevitably get something like this: "a++; /* Add 1 to a */" With no indication anywhere of what A is or why you would be incrementing it there. I would propose power stapling the offending programmers in such cases, until they learn not to do that anymore. I would say remedial English classes, but even I am not THAT sadistic.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

    1. Re:That's Like Scrum... by mekkab · · Score: 1

      This is why you need a Chief Designer who pretty much runs the show. Since they are at every inspection the become a human cross reference. The good inspectors/good-inspectors-to-be will learn by example.

      Process falls apart in the people; if you've got one person imposing their standards at every inspection you get consistency.

      You can argue that this is micromanaging; thats fine, argue all you want. But our 30 person team is kicking the ass of my old 8 person team in terms of consistency and quality. And its all because of this one guy.

      --
      In the future, I would want to not be isolated from my friends in the Space Station.
    2. Re:That's Like Scrum... by Anonymous Coward · · Score: 1, Interesting

      Sorry, but I have to interject here.

      > But our 30 person team is kicking the ass of my old 8 person team in terms of consistency and quality. And its all because of this one guy.

      WTH? A 30 person team SHOULD kick the ass of an 8 person team. Worst case: You have 8 guys coding and 22 guys doing nothing. If one person is responsible for making a 30 man team better than an 8 man team, then they should fire the other 29 of you guys and let him work in peace. Hah. Either that or maybe he's tricked you into thinking you're actually doing work, but instead he just has you staying out of his way.

      I didn't really intend for this to be a personal attack when I started it, but it sure seems to have turned into one. Sorry about that. For all I know, you're just as productive as that guy. Maybe you ARE that guy.

      The original point was that you'd have to be horribly mismanaged to for a 30 person team to do worse than an 8 person team. Maybe you meant 80?

    3. Re:That's Like Scrum... by Anonymous Coward · · Score: 0

      > Sorry, but I have to interject here.

      I think you missed his point, and have obviously never been in project management. There is far more overhead in "micromanaging" 30 people than just 8 when only /one/ person does it. So you would naturally infer that the 30 man team would be bloated and cumbered by procedure, right? The key words were efficiency and productivity. Focus on those for a sec, ok?

      Now imagine /one/ person managing that 8 person team and then scale those procedures/methods to a 30, 40, 100, or whatever you want size team. Typically (and that's the key word there, typically) a smaller leaner team is /more/ efficient. However, if you refine the process to a certain point (which he is trying to illustrate here), you can scale that method up and actually /gain/ productivity. That's a very very important concept and holy grail all managers labor over daily. Clearer? If you still fail to see his point, get used to "developer" on your business cards. You're in for the long haul...

  53. If I could set the rules.... by Big+Smirk · · Score: 1

    1) Every project of significance would have a serious requirements document. By that I don't mean heavy on details, but enough there so that everyone know _why_ we are doing what we are doing. Identify stakeholders, customers etc. Vision statement!

    2) Every project will have a preliminary design review. Take the requirements, interpret them, come up with a 'solution' and give a presentation to all the stake holders (or representative stakeholders) and make sure that they understand what they are going to get. Don't just e-mail this around and say "If you have any comments make them now or forever hold your peace"

    3) Once the code starts comming together, a critical design review. This is for the technical people. Again, no e-mailing. This is a boring meeting where you pick the brains of experts to make sure you have your bases covered.

    4) I'm not big on coding standards. A loose one that governs naming and maybe indentation. I would add perhaps a template for things like header files etc. Maybe the standard copyright notice.

    5) Up front, think about unit testing. Having working on a project where the only way you could unit test was to litterally include/link in _all_ the libraries (a hell of a make file) I would think that 'modular' should be in the volcabulary early on.

    6) All projects need a follow up plan. Software people need to observe, in the field, how their product works. Hearing about complaints once they've been raised high enough is not effect learning. For me, just recently found out that since one of my dialog boxes was too complicated (it had too much backup information) it was simply being ignored... The title "Database Exception" and the first line "Failed to update database" was being lost (and ignored) in the noise. I would have found out later when the data was all coorupted... fortunately I caught it early. Rather than fixing the code, I instituted a policy of training and beatings for those that didn't comply (in case you were curious).

    --
    TODO: create/find/steal funny sig.
  54. Peer Review Often by ear1grey · · Score: 2, Insightful

    Establish regular peer reviews: regular, as in daily; and not just when the library is finished and ready for delivery.

    Peer reviews encourage developers to describe what they're doing and why they're doing it (not just conceptually, but at the code level) so deeper awareness of whole systems is fostered.

    This can lead to projects with less redundancy, and greater integration. It also helps ensure that code will pass any human driven acceptance tests that the commisioning agent may stipulate.

    An additional benefit is that utilisation estimates are improved because as developers get better at describing what they're doing, they become better at describing what they plan/need to do.

    The canny manager will schedule the peer-review session 30 mins before lunch, recognizing that it gives developers something to discuss as a group whilst eating.

    1. Re:Peer Review Often by johnkoer · · Score: 1

      I agree with this 100%. Depending on the size of your company every day may be a little much, but once a week is a must.

      I have found that many developers write better code when they think it is going to be peer review, because they don't want to look like idiots in front of co-workers. It changes things from:

      int x;
      int realval;

      realval=10; //Get number of hours
      x=realval*3;

      to

      int iNumberofHours;
      int iActualNumber;
      int iSalesmanFactor;

      iActualNumber = 10;
      iSalesmanFactor = 3; //Determine how long the project will take based on the actual number of hours and multiply //that by BS factor, i.e. the amount of BS this particular salesman usually spews.
      iNumberofHours = iActualNumber * iSalesmanFactor;

  55. 35 years says a lot... by clambake · · Score: 1, Insightful

    I dunno, there aren't too many software companies been around 35 years and still going strong. I'd say go with what's been working. The best "coding standards" are: simplicty, adaptability and readability.

    Let programers do what they want. When somone complains that XYZ is hard to read, then it's his job to refactor that code into something that is easy for him to read. Assuming you have the tests you should have written, he'ss have no trouble doing this. If the tests aren't there, then write the tests first so you know if you broke what's already there.

    Don't comment your code. Make the code so damn readable that a comment is superfluos.

    Above all, don't make rules you can't break on a whim, but do make rules as you find them helpful. Go with what feels right until it stops feeling right and then fix it.

    The first person who says something unhelpful as "your code doesn't comform to our company mandated brace alignment standard" gets fired, but only after he's shown what a modern IDE looks like and how well it autoformats the code to any brace standard he cares to think of.

    1. Re:35 years says a lot... by Agent_9191 · · Score: 1

      That's just it. We're not a software company. We're a private college that has such a specific business process (and CEO wanting software that's custom fit to the company, rather than the company to the software) that we have to customize or build our own systems. Many times it's been "Oh, we need this done" and whatever IT person that is closest to them at the time saying "OK, we have this software on hand so we'll use that" and then that system becomes a "critical" non-critical system. It also meant the same business logic being redone over several languages and rarely were they all updated at the same time. I beg to differ on the "let programmers do what they want" attitude. With job turn over and needing to get helping eyes in on projects, attempting to figure out what's going on is a waste of resources. The project that I originally joined the company to work on had (from what I heard) 7 different developers on the project (when it really needed about 20). I can tell who added what code because of different ways things were handled. One developer used recordsets whenever and where ever possible. Another used global variables and never had functions take any parameters. Another had the tendency to keep indenting to the point that you had to scroll horizontally further than you did vertically. *I* have no problem slogging through the mess of code, but it still takes me at least a day to figure out what a program is doing before I can even attempt to fix it. That's after looking at this code base for a year. But that's still a full day wasted on other tasks that can be accomplished. A vast majority of the time the fix takes 5 minutes. So 1 day of decoding = 5 minutes to fix. That isn't a very efficient formula and this has become the norm for the company, yet they wonder why the programmers can't get anything done.

  56. Standards? Practices? by Anonymous Coward · · Score: 0

    None. Boss decides at will, changes mind every other day, cow orkers feel numb. Anybody anything to offer, career-wise?

  57. document functions/classes by dindi · · Score: 1

    Force the programmers not just to comment the code, but to write usable docs for classes and functions.

    Some programmers do not have to understand what's in, just to call a function ... this is pretty much "everyone knows" but pretty much missing from many places ...

    Technically sometimes you spend days just to figure the mess out until you can even start typing a line, while with decent docs, you can start fast....

    Also diagrams, flowcharts and the like might help others to see thru a system faster...

    I mostly worked as a sysadmin, but even at relatively large installations I sometimes missed a simple network map..... I remember at least 2 places where my work started manually discovering (mean, room by room, flashlight in hand, cable end to cable end between routers, hubs, firewalls) what the hell was happening at the place.....

    The funniest (or most sad) was when I found a firewall at a new place, connected into itself. The "admin genius" kept the owners beleive that they are protected by a firewall, while in fact it was just connected to a hub with all 3 interfaces, default config 10.0.0.1-2-3......

    I have also been to a place, where 3 programmers/designers (web project) worked on a project for half a year (no docs, no nada, no software) and all they did was surfing the net and waiting for it to turn out.

    This is a bit extreme, but actually no one noticed, as management had no clue how long it took what they did, until we estimated it 4-5 days of work for a team of 2 max. I don't know if I felt sorry for them at the end, but the whole office got fired alltogether 3 days later.

    My point is: make them document what they do, that also tells if they do anything at all (in case you have a non tech manager, or you are not in their field).

  58. I feel your pain by Anonymous Coward · · Score: 0

    I'm a year into a job that sounds very similar to what you're describing. I took some advice from friends and instated some of the following procedures:

    1) Meet with the relevant stakeholders in the new project. Come up with a detailed list of requirements.

    2) Meet with the staff who will be implementing this project, go over the requirements and come up with a rough estimate of the time and resources required to complete EACH requirement. This estimate can be plus or minus 50%. Identify areas that will require additional research or testing in order to refine the resource estimates.

    3) Meet with the stakeholders again, go over the time/resource estimates. Deal with any ambiguity in the requirements and get their buy off on the current estimates for time and resources.

    4) Meet again with the development staff, spec out the entire project with milestones and completion estimates ( this estimate can be plus or minus 10% ).

    5) Codify the requirements and the specs for the project into a single document. Include all time and resource estimates. Have the stakeholders (including any relevant middle or upper managers) each sign this document with the understanding that any deviation from the requirements will immediately void all estimates.

    I realize that this seems top-heavy with meetings, but once you've gone through it a few times you'll see why its necessary. Having all the stakeholders agree to the requirements and their estimates will protect your staff from scope-creep and unreasonable deadline changes. You'll also find that the more you plan in advance, the easier the implementation will be and the more robust the end result is likely to be.

  59. Worry about what not to do, too by Rocketboy · · Score: 5, Insightful
    Many (many) moons ago I worked for an IT manager who's explicit instruction was, "don't use arrays." He didn't understand them and, therefore, they were bad.

    The moral of the story?
     

    A. You are not the font of wisdom. If very lucky, you are the point of the pen. Rule carefully.

    B. Don't make standards based on what you learned in school. Base them on what you learned in real life.

    C. If an Old Fart tells you that one of your edicts is stupid, don't assume that they're resistant to change just for the sake of being crotchety. Maybe they learned something useful over all those years and all those lines of code.

    1. Re:Worry about what not to do, too by donnz · · Score: 1

      To comment or moderate, that is the question...

      I won't tell you again, don't use arrays.

      Let me see if I can put it another way,

      Arrays are bad.

      --
      -- Free software on every PC on every desk
    2. Re:Worry about what not to do, too by johnkoer · · Score: 1

      Momma said Arrays are the devil.

      Momma also said Arrays are ornary because they have all those mallocs and no frees.

    3. Re:Worry about what not to do, too by Creepy · · Score: 1

      Interesting that you mention arrays - ages ago I had to switch my school taught coding style from creating C arrays to using malloc calls because traditional C arrays are defined in the stack and I'd end up with stack overflow errors. I don't do much C coding these days (and have no idea if that is still true), but when I do code C I always use malloc for that reason.

      Anyhow, my point is that even though the malloc'd blob is still an array for all intents and purposes, a stack allocated array can be bad - especially if you're allocating a large amount of space, so it's possible (though not likely) that your IT manager wasn't a complete moron.

      Incidentally, the coding style I was taught in school was bad in many, many ways. Monolithic at a time when Modular should have been taught and I was never taught good header format for C (e.g. #ifndef __HEADER__ #define __HEADER__ #endif) to name a couple of things, though I'm sure I could think of more. They did dock me points any time I didn't follow format conventions, comment my code, or indent properly, so at least I did learn something (like how to use formatting tools ;).

    4. Re:Worry about what not to do, too by Anonymous Coward · · Score: 0

      Wrong, they're ornary because of their medula oblongata.

    5. Re:Worry about what not to do, too by LadyLucky · · Score: 1
      There's also a nugget in there for you aspiring development manager types - how to get buy in to your new coding standards. Since most developers don't wake up in the morning prepared to be awe inspired by your latest writings and edicts from on high, it's important to them to feel included in the process, like they own it.

      Then your best bet is to include them in the process of building the standards. Perhaps sit down with each person and get some ideas, and collate them together, and pull everyone into a single meeting, with a set time limit to discuss each sugestion. 80 character line limit? Yes or no? Your devs should decide. Sometimes they will make the wrong decision, so that's where you come in along the way to poke the conversation with careful questions in the right direction.

      Win Win!

      --
      dominionrd.blogspot.com - Restaurants on
  60. Well I don't know.. but by Anonymous Coward · · Score: 0

    Use python.

    Then you automatically get the code standard. Well, if you are going to be strict of it, you will have to set some *standard* too but, usually many of python codes have very similar way of coding style unlike C or C++ that should have to be explicitly defined. Above mentioned PHP isn't such a good choice since it sucks.

    If you are going to use ALL linux or ALL windows, platform independent isn't such a big concern anyway so you don't have to consider mono if you are going to use .NET which is suck anyway.

    You can have C extensions with python. When C only to be used, it is pretty much of suck but when it's used with python you get very clean structure of code since you will code it with C when only it's bottlenecked. There's good optimizer/profiler called psyco. And many numerous such extensions.

    What makes python so structured is, it's almost *configurable* structure, not being compositable. So you already have a basic structure, only you change the small pieces even it seems like making a graphical theme of a skinable applications.
    Since everyone already know about middle picture, people only have to read the big part and super-little part(C extensions). Middle part is defined, and little part is configurable thus it's standard.

  61. Waste a couple of hours? by dlaur · · Score: 1
    Sorry, but it is going to take a lot more than a couple hours for any programmer to jump in and figure out the code for any non-trivial program no matter how conventionally it is coded. The statement (which I am taking too literally) is wishful thinking.

    I get the point though, coding standards are critical so that people aren't confused when they look at someone else's code and it is following completely different conventions. It doesn't matter which coding standard you use as long as everyone agrees with it. Try to create consensus on the conventions and allow them to evolve. Forcing things down peoples' throats won't work.

    Focus on getting peer reviews into your process as early as possible - like the same day the code is written - maybe even at the same time the code is written. If you wait too long to review code, the author gets a little attached to it and often too defensive. Constructive criticism is more easily accepted before someone has traveled a long road and doesn't want to backtrack.

  62. We have been implementing Project Management by Gonarat · · Score: 1

    We have been dealing with this in our organization. In the past, we have been programming by the seat of our pants -- we get requirements, program what we think our Customers want, do a little testing, then throw it into production, then wonder why we have problems in the middle of the night.

    Sarbanes-Oxley plus the competition is putting an end to this method of coding. In the past year, we have hired real Project Managers and have begun doing real Project Management.

    We now require a Functional Systems Design (FSD), a document that details what the customer wants at a high level. A Computer Systems Design (CSD) document is then written. This document is the actual design of the system that Developers and Programmers use to design the system, design and build databases, and determine what programs need to be written and computer system(s) (PC, Mainframe, Unix)they will live on. Once the programs are written and unit tested, we have a QA department to do real testing. We currently use Microsoft Project, TrackRecord (a Compuware defect tracking tool), and Bugzilla (an open source tracking tool) to track what has been done, what defects we have run into, and how they were resolved.

    We still have a long way to go, and have faced opposition from some Managers, but support from Upper Management (and auditors) has helped to pave the way.

    Implementing change is tough, but it is starting to pay off in better designed and implemented software which helps keeps our customers around (which means no layoffs, at least for now). Getting requirements in writing is a big help when it comes to analysis and design -- it by no means eliminates problems, but it sure does help reduce them.

    --
    Beware of Sleestak
    1. Re:We have been implementing Project Management by chris_eineke · · Score: 1
      we have a QA department to do real testing.
      Hold it right there. Quality assurance isn't the right place for testing. That's what the test team is for.
      --
      "All you have to do is be fragile and grateful. So stay the underdog." Chuck Palahniuk, Choke
    2. Re:We have been implementing Project Management by Gonarat · · Score: 1

      Our QA department is the test team where I work. IT is required to do unit testing and some system testing, but our QA serves as an independent testing unit that both tests the particular change and does full regression testing. The idea (at least at our shop) is that QA catches anything that the programmer may have missed, and any changes made don't foul up anything else in the system.

      We are still developing and refining our development cycle but positive results have already been seen in the projects that have gone through QA.

      --
      Beware of Sleestak
  63. Standards by umbrellasd · · Score: 3, Insightful
    Current place we have a corporate naming convention document which addresses the various environments that we work with. Formatting conventions are unspecified, so everyone in our group does what they want to do. I typically use an indenting scheme that is pretty standard for most .NET articles that I read or code that I encounter (because much of my work is .NET). For the most part, we just focus on being consistent to our own approaches and the most important thing is being accepting of different ways of doing it.

    I think the most important policy is to slap the guy that says, "I like tabs more than spaces" or "I don't like the way you indent" or "I hate the way you put spaces around ('s".

    Honestly? These people have too much free time. People use a variety of conventions and I've seen pretty much all of them. As a senior developer, I just take everyone's idiosyncracies in stride, even when they name variables retarded things like: n, vt, pkq, and rsptln.

    If I can deduce what they are doing easily, it is no problem. If I cannot, I make them explain it. If they are not around anymore, problem solved. I rewrite or have their stuff rewritten in a good way, since the stuff was 99% likely to be utter crap anyway, and move on without a moments hesitation.

    I've worked on a lot of large codebases and I've never encountered this idea of, OMG this code is so archaic that I cannot possibly decipher this person's intent--and believe me, I've worked on some crazy ancient crap. My obligatory developer arrogrance leads me to state that people that cannot figure out code because of coding conventions are weak developers. Anyone that has slogged through the convoluted "efficiency" of Knuth or the a,b,c,i,j,k madness of Wirth can figure shit out.

    So anyway, if you have the authority and your people are actually willing to go along with a standard without a huge hullabaloo, then just pick any standard (you'll get way more mileage from just sticking to a consistent convention no matter what it is). If people are going to make a big deal of it and it is difficult to enforce, just deal with it individually and tell people to write sane things. Their coworkers will provide quite good feedback if they are producing shit, and that's where you really need to step into your lead role and work out a resolution.

    One of your best tools for a standard is to create automation to enforce it. Get yourself some prettyprint scripts that you have run on all source that is checked in--in fact, get your developers the same tool so they can run it on what they check out to print it the way they like it. (Of course, you only want to check the source in with the standard pretty printing or diffs become atrocious, but that's technical stuff for a different discussion.)

    Bottom line is that whatever you can automate in the way of conventions is a win because then it's completely automatic, difficult to bicker about (two coworkers can't very well bicker at each other when it's the prettyprinter's fault, so they can only come to you and you have authority to resolve the issue right quick, whereas they could just engage each other in an endlessly unproductive slugfest if they are coding by the convention of their opinion), and if people want a change it goes through you and you have a strong argument for--"if it isn't broke, don't fix it".

    Kind of a ramble, but after many years this is my take on standards. Use a convention if it is convenient. If not, play it a bit more loose, but be firm on snuffing out those annoying neverending debate situations.

    That said, one factor that is relevant is the type of work you are doing. I'm assuming from what you said that you have some flexibility to structure as you like. If for instance you were subject to government or other agency auditing (my current company is), then the loose method is not going to fly, but on the other hand, you would probably already know what conventions you needed becaus

  64. Monkey Reporting In by Anonymous Coward · · Score: 0

    I just checked in code that crashes eclipse on File/Open. All the other monkeys opened it. Now what?

  65. the best standard by Anonymous Coward · · Score: 0

    Hire developers who know what a brace means, regardless of whether it's at the end of the if statement, or on the next line.

  66. coding standards take time too by icepick72 · · Score: 1
    so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code

    From my limited experience, if they don't have to jump into the code to figure it out, they have to instead jump into the documemtation and correlate it with the code. It's time consuming in another way. At least the programmer doesn't have to re-learn so many things, and can instead focus on the more high level stuff faster.

    The more coding standards you have, the more time consuming coding can potentially become. For example, for vertical apps, the more structured (or layered) the app is, the more understandable it is, but it takes longer than normal to code through the layers even after you understand it (compared to not having all the layers and structure in place). Layers tend to make everything within them look similar, more often than not, because each layer has a more specific purpose -- that's good. However when you run into limitations of the many layers, you have a lot more planning to do create a solution that's efficient AND still uses the layers properly. At this point you normally want to start taking shortcuts, but that just starts eating away at the original foundations.

    A library of common data structures is good. E.g. .NET strongly-typed data sets in the data layer. Or maybe the Microsoft Enterprise Library for some pre-made, commonly-used enterprise class patterns that you can extend and use. This means developers don't have to re-invent the wheel.

    Of course my story is not done yet, so time will tell the outcome of the coding standards pool I find myself swimming in right now ...

  67. #defun is sooo 70s... by PaulBu · · Score: 3, Informative

    enum is your friend!

    enum {LOAD_DATA, SAVE_DATA, DESTROY_DATA} ...

    Paul B.
    P.S. And of course my all-caps enum values were considered too lame by lameness filter... ;-(

    1. Re:#defun is sooo 70s... by Bill+Dog · · Score: 2, Informative

      And enum values in all ucase are sooo 80's! ;-)

      enum DataAction
      {
              eLoadData,
              eSaveData,
              eDestroyData
      };

      --
      Attention zealots and haters: 00100 00100
    2. Re:#defun is sooo 70s... by The+Swirve · · Score: 1

      And don't forget the "hack" everyone uses if enums don't cut it:
      enum {eStandardArraySize = 32}

    3. Re:#defun is sooo 70s... by goonerw · · Score: 4, Funny

      And Hungarian notation is soo 90's ;-)

      --
      LOAD ".SIG"
      PRESS PLAY ON TAPE
    4. Re:#defun is sooo 70s... by CountBrass · · Score: 1

      I hope you guys aren't relying on your programming skills to earn a living. loadData(...); saveData(...); destroyData(...); Your monsters "it does everything" function was bad practice 30 years ago!

      --
      Bad analogies are like waxing a monkey with a rainbow.
    5. Re:#defun is sooo 70s... by Threni · · Score: 1

      > Re:#defun is sooo 70s...

      I never mentioned `defun`, whatever that is. I'm talking about C, so it's perhaps unsuprising that it features `70's` features, what with that being the decade it was created!

      Finally, enum is overkill when you don't have range of related values. It's perfect for your example but not for a bunch of one-offs.

    6. Re:#defun is sooo 70s... by Stele · · Score: 1

      Enums only give you integer constants.

      If you need other types of constants, you should prefer using "static const TYPE VAR;".

      Let the compiler help when it can.

    7. Re:#defun is sooo 70s... by somersault · · Score: 1

      you have to have somewhere where you actually call the functions. The enums there may be menu options used to decide which of 3 functions to run, etc. ;)

      --
      which is totally what she said
    8. Re:#defun is sooo 70s... by Fembot · · Score: 2, Funny

      LOAD_DATA + SAVE_DATA == DESTROY_DATA??

      (Yes, that's compiler implementation specific, I know...)

      Alan

    9. Re:#defun is sooo 70s... by Threni · · Score: 1

      > I hope you guys aren't relying on your programming skills to earn a living.

      Afraid so! At least it'll keep you in maintainance for a few more years. Don't worry, someone will trust you to write your very own program sooner or later. Although even your maintainance skills need polishing up, because...

      >loadData(...); saveData(...); destroyData(...); Your monsters "it does everything" function was
      >bad practice 30 years ago! ...what makes you think it's an "it does everything" function? It could be just writing an error to a log file, or noting what to undo when the program terminates. If you're maintaining code, it's best to *see*, and not just assume, what it's actually doing.

    10. Re:#defun is sooo 70s... by Anonymous Coward · · Score: 0

      And Hungarian notation is soo 90's ;-)

      Don't you mean: "cAnd ajHungarian nNotation vIs ajSoo n90's e:-)"?

    11. Re:#defun is sooo 70s... by vidnet · · Score: 1

      Hungarian notation is only lame when misused: http://www.joelonsoftware.com/articles/Wrong.html

    12. Re:#defun is sooo 70s... by goonerw · · Score: 1

      That's a nice read. Thanks.

      --
      LOAD ".SIG"
      PRESS PLAY ON TAPE
  68. Dilbert by RedNovember · · Score: 2, Funny

    heh

    --
    "MY APOCALYPTIC TENOR HAS NOT BEEN DISPELLED!" - T-Rex, qwantz.com
    1. Re:Dilbert by MarkGriz · · Score: 1

      Since the author doesn't have any coding practices in place, this one might be more useful.

      --
      Beauty is in the eye of the beerholder.
  69. Geek minds by eric.t.f.bat · · Score: 4, Insightful

    The best description I've ever come up with for the Geek mindset is this: a Geek can hold a complex structure in her head and manipulate it with ease. A History Geek can hold the structure of a historical event and see motivations and causes from every angle; a Carpentry Geek can plan an entire piece of woodwork and see every cut and join vividly; a Programming Geek can hold a program's structure and its data and event flows and manipulate it as an idea.

    Someone commented that the difference between Microsoft and Google is that Microsoft programmers are holding concepts the size of "If...Then...Else" and Google programmers are holding concepts the size of Bayesian filtering; thus, Google's Geeks are better at making big, coherent plans without getting lost in the details. It's not 100% true across the board, but it's an insight.

    As a Project Manager, then, your job is to:

    1. Allow your Geeks to transfer the concepts from the screen/page/whiteboard into their heads; and

    2. Allow your Geeks to hold those ideas easily once they've got them.

    Step 1 is a bandwidth issue: make the "inputs" more efficient by, for example, giving all of them dual-head monitors and high speed printers, so they can get lots of code into a usable format for reading (some of us prefer printouts; others just need vi/Emacs and a flicker-free monitor). Step 2 is a quality issue: Geeks who have to hide in headphones or run away to the park to read because of ringing phones and nagging managers are NOT going to be able to do their job.

    And with any data pipe, throughput is more a function of time rather than pressure. So your dream of getting your programmers up to speed in minimum time really is -- pardon the pun -- a pipe dream. They won't be any use to you if they don't have the time to learn the systems they're working on.

    --
    I have discovered a truly remarkable .sig block which this margin is too small to conta
    1. Re:Geek minds by Aceticon · · Score: 1

      Although i agree with your points i find that your sugestions are simplistic and you are missing "Step 3 - Allow your Geeks to clearly communicate those ideas". After all, the inputs for Step 1 don't come out of thin air.

      For any application that outlives their creator's career period in that position/company, new people will be constantly cycled through all the steps as the application needs to be fixed or extended. This makes it important to leave things set for the "next generation". This part of the process is actually what the original poster is asking about IMHO.

      In complex systems, reading the code to find out the architecture of the system is the last resource option - simply put, no mater how fast your printers or how big/abundant your screens, going through tens of thousands of lines of code is a very inneficient way to figure out how a complicated application works.

      Even in smaller sized applications, code reading to figure out the design is a slow and error prone process - if you ever been faced with having to do short fixes on somebody else's (undocumented) application and later having the chance to become familiar with it, you will find that your first couple of fixes probably didn't quite fit the design of the application (ie, they look like hacks). Any application that gets fixed/extended by several unconnected developers will tend to become unmaintaineable spaghetti. This can often be avoided with a simple design document, often just 2 or 3 graphics and a couple of lines of text. Similarly, some simple code and code-documentation standaards enforced in Step 3 will really increase the efficiency of Step 1.

    2. Re:Geek minds by StrawberryFrog · · Score: 1

      Someone commented that the difference between Microsoft and Google is that Microsoft programmers are holding concepts the size of "If...Then...Else" and Google programmers are holding concepts the size of Bayesian filtering;

      Seeing as you're insulting the mental abilities Microsoft's staff here, how many MS employees have you actually met and what did you think of thier grasp of abstract concepts?

      --

      My Karma: ran over your Dogma
      StrawberryFrog

  70. Moral Code... by hackwrench · · Score: 1

    My moral code is iterative, but the moral code of most of the people I encounter is not.

  71. I recommend the Mercury project model by ralphbecket · · Score: 2, Insightful

    Mercury is an industrial strength, state-of-the-art
    compiler for a declarative programming language
    comprising some half a million lines of code. The
    project has been running for over ten years with
    multiple developers working at any given time, some
    of which are in different locations.

    Key aspects of the development model are:

    (1) Use a good source code control system (we use cvs,
    but are considering svn).

    (2) Add at least one test case for every piece of
    functionality you add to the system and for every bug
    that is discovered during use.

    (3) Use a robust, automated build-and-test system.

    (4) All code changes should (a) compile, (b) not break
    any test cases, and (c) -this is vital- pass peer
    review on a mailing list.

    (5) All code should be adequately documented. Every
    change should be accompanied by a log message explaining
    the rationale for the change and what the changes were
    and a unified source code diff.

    (6) Have a common coding standard for things like
    naming, layout, commenting, and preferred idioms.
    Shoot any coders that use more than 79 columns in
    their code.
    Avoid complexity and cleverness unless it is absolutely
    warranted.

    (7) Code should check all error conditions. Exceptions
    are rarely a good error reporting mechanism.

    (8) Have nightly builds and test runs.

    (9) Your watchwords should be discipline, cleanliness,
    simplicity.

    -- Ralph

  72. Best process is no process by daviddisco · · Score: 1

    For small operations, less than seven people, establishing up front standards and processes just get in the way. Just get the rudimentaries such as source control, automated builds etc up and running and adapt when neccesary. If you have any problems swivel your chair and ask the relevant person. When you notice the same problem coming up again and again create a policy to avoid that problem.

  73. Two absolute MUST standards... by Anonymous Coward · · Score: 0

    Use a centrifugal chiller for any load over 300 tons.

    AND

    If you finish the pot, you have to make the next.

    That should cover it. Wait, what is coding again?

  74. None needed by Anonymous Coward · · Score: 0

    If they have survived 35+ years doing whatever they are doing it doesn't sound like they need your advice.

  75. Never comment! by Billly+Gates · · Score: 5, Funny

    Its for wussies!

    -USe tons and tons of goto statements.

    -Make sure you use particular letters capped for variables of different types to make them more confusing for the losers who can't read the code and remember what each one was.

    - always make calls by reference using pointers as arguments. Don't use call by values.

    - Hell user other pointers that use other pointers to make things more interesting. Reassign them all over the place

    - Never use a three tier model when developing client/server apps. This only creates redundancy and gets in the way of solving the problem.

    - When linking to a database always use vendor specific extensions and avoid a database layer using something like odbc. It makes use of the advanced feature set by the particular RDBMS.

    - Be a man! Show how much you know perl. Alot of one linners can save tons of time with exotic line switches

    Oh last... make tons of money and gain job security because no one in Earth will be able to understand or work on your projects after doing all of these things. Enjoy

    1. Re:Never comment! by MagicMerlin · · Score: 2, Interesting
      - Never use a three tier model when developing client/server apps. This only creates redundancy and gets in the way of solving the problem - When linking to a database always use vendor specific extensions and avoid a database layer using something like odbc. It makes use of the advanced feature set by the particular RDBMS


      umm, it sounds to me like you are one of legions of 'application level' programmers. the separation of an application into 'tiers' (which have no real formal definition) just obscures data contraints into a maze of levels of code. Totally unnecessary...the closer your constraints are to the actual data the cleaner and more maintainalbe your application will be.

      Very few applications need to be portable across databases. If you pick a good database (PostgreSQL), there is little reason to port. Application languages (ruby, c++, COBOL, Java, etc etc etc) are a dime a dozen and will be switched and/or mixed a dozen times over the lifetime of a enterprise app.
    2. Re:Never comment! by yerdaddie · · Score: 1

      "Avoid the advice of the sucessful, they do not want you in their company."

    3. Re:Never comment! by Anonymous Coward · · Score: 0
      • Micro-optimize early and often. Clever use of pointers and pre/post inc/dec operators can easily produce the world's fastest bubble sort implementation.
      • While you're at it, optimize all error paths.
      • Speaking of error paths, every module/component should use unique error reporting mechanisms. Does an API return 0 on failure? Or !0, or <0, or SOME_DISTINGUISHED_VALUE? Guessing is fun and productive!
      • When in doubt, thrown in another level of indirection. This is especially important at the architectural level. Can't decide on which OS-neutral toolkit to use? Create your own abstraction layer under which you can plug multiple OS-neutral toolkits!
      • Memory is cheap -- use all you want, you can always buy more.
      • The performance and behavior of the private test network in your office will always "scale down" to the corporate network and the Internet. Hey, the net is plenty fast -- why bother writing nasty code to coalesce data before sending? Just send 1000's of little tiny packets.
      • Along the same lines, always assume UDP is reliable. It's always reliable on the private test network, why wouldn't it be reliable on the corporate network or the Internet?
      </sarcasm>
    4. Re:Never comment! by Billly+Gates · · Score: 1

      Neither.

      I am a wannabe in college. But I have seen mess porting older software when I was in IT in the post .com crash.

      I agree on over-engineering. I was privledged to hear a speaker from the superlinux beowulf project speak at my local LUG about how budgets get overkilled for simple things.... he loved to make fun of garden.com which has a system that can handle more transactions than ebay but has a profit of $15 million?? Yikes

      But the three tier model is needed for apps that are expected to grow and be used for a very large time. Or that is what I was taught?

      After reading about the expensive licensing of ms-sql server and oracle I can see why having a system that is more upgradable is nice. Otherwise it would take a long time and a big budget to get rid of scattered vendor specific code.

      But if its for a small intranet site for a branch office then I wouldn't care if I were developing it.

    5. Re:Never comment! by cerberusss · · Score: 1
      -USe tons and tons of goto statements.

      GOTO is out of fashion. COMEFROM is much, much more advanced. Just one statement can bring a whole codebase to its knees.

      --
      8 of 13 people found this answer helpful. Did you?
    6. Re:Never comment! by Creepy · · Score: 1

      heh - mostly true - but not always

      I've seen C code that uses tons and tons of goto statements to implement exception handling, so just because they're out of fashion doesn't necessarily mean they're completely bad. My C teacher, like most of 'em, taught me never to use goto, and I think I've used them once in my personal code (mainly to see how they work), but seeing tons of goto statements isn't a sign that it's bad code.

      exotic perl calls have their uses, too, but don't expect anyone to maintain them. I use them for maintenance work on my directories and some cgi handling, but I don't share this stuff with others.

      job security is fleeting - they'll just hire 5 coders in India to decode or rewrite your bad code and fire you anyway.

  76. Ahahahahaaa... heh... Snrrrrrkkk. Kidding, right? by pla · · Score: 5, Informative

    without wasting a couple hours just to figure out the code.

    A couple hours???

    Look, no offense, but you either only deal in "toy" code, or you have such high expectation that you will fail, and quite spectacularly.

    A new coder, even an experienced one, takes days or even weeks after coming into an existing project before he can contribute anything but the most trivial of changes. For a truly massive project, or one that requires intimate domain-specific knowledge in a niche industry, extend that to months.

    If you can find a way to get an unfamiliar newcomer up to speed on any "real" project in a matter of hours, consider your talents wasted in your current position.

  77. Extreme programming? by openglx · · Score: 1

    Bah, extreme programming isn't as good as the coding practice we started at our lab: SUICIDAL EXTREME PROGRAMMING!

    Code for weeks, without even trying to compile. When you think your code is good enough, start compiling and fixing it. Well, it is working yet... :D

  78. Coding Standards, and others by MidKnight · · Score: 1

    Right now I'm more concerned about trying to set up coding standards...

    Coding Standards? A good thing. Which ones? Doesn't really matter. Read Ken Arnold's Style is Substance for a good opinion. His point is that you shouldn't spend any time arguing about which style is best; just pick one of the few well-documented standards and enforce it as heavily as possible.

    ... so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.

    Unless we're talking about really well designed, really well documented and really well commented code, this sounds like a pipe dream to me. Maybe I'm just not skillful enough, but attempting to absorb any non-trival amount of code that was written by someone else is going to take a few hours. You're better off assuming that will be the case.

    As far as general software development practices, I think you have two viable choices:

    1. Pick one of the popular Agile development methodologies; my first choice would be Scrum, but they all have common goals. Read a book or two on it so you get the idea. Then, go hire a consultant to help you run a Scrum project with one team. After you've done it all the way through once, you can probably run it yourself & expand the # of teams using it.
    2. Read a whole bunch of books on software development process, and don't limit yourself to the Agile methodologies. Document your favorite concepts, and why you think they'd work in your environment. With the help of a small group (3 people max), come up with your own process that is loosely based on your research. There is obviously a fair amount of risk here though: lots of smart people have spent many, many years trying to solve this problem, so be careful.

    The one thing you shouldn't do is quickly review a few random articles, pull out a couple of the buzzwords, then never think about it again. The number of development groups out there that say they're following a certain process when they're really just winging it is astounding....

    Oh, and take all suggestions from strangers on Slashdot with a big, chunky grain of salt :)

    --Mid

  79. Fundamental coding truths by WiMoose · · Score: 5, Insightful

    In addition to some of the suggestions made so far I would add a good automatic regression-test system which runs every night, and reports problems (build failures or result diffs). I've made mine so they "find the guilty" (whoever committed code since the last good regresstion test).

    I recently put together a list of Fundamental Coding Truths after musing about this topic and why it was so hard to plan software development:

    1. Software is not at its core a collection of a few clever algorithms.
          Rather, it is primarily (in the ways that matter) a huge collection of arbitrary
          choices and random implementation details.

          The algorithms that consititute the mathematical/logical basis of a piece of software
          are an important, but very small (eg: 1%) and relatively very simple part
          of the overall code.

    2. Code complexity is pretty much exclusively determined by the (combinatorial)
          number of interactions between pieces. Each interaction requires at least one decision
          and usually many more.

    3. Because of #1 and #2, deep, intimate familiarity with the code (this vast
          collection of implementation details) is only ever fully knowable to the original
          author(s) who made these uncountably many, mostly arbitrary decisions.
          (Familiarity by secondary authors/maintainers comes primarily from
            re-writting sections of code.)

    4. Because of #3, programmers are not interchangeable. The efficiency with
          which a person can navigate the code, implement or even imagine changes
          is almost entirely determined by how familiar they are with these many, many small
          details. The ratio of efficiencies between a primary author and another
          equally talented coder is very large (eg: 100). Because of this, the original
          authors of a section of code are usually the only ones who are ever able to efficiently
          modify or restructure it. This becomes rapidly more true as the the size and
          complexity of the code increases.

    5. Because of the complexity of code (the number of interactions and interdependencies),
          debugging and maintenance constitutes the vast majority (eg: 99.9%) of the work
          required by a piece of software over its life.

    6. Because of the complexity of code (number of interactions between components), it is
            very hard, if not impossible, to predict with any accuracy what will be involved in implementing
            a given change. Even for original authors, unintented side effects are almost inevitable, and
            the primary determinant of the length and difficulty of a task lies in finding and rectifying
            unintented consequences or unforseen interactions. Because of this, the uncertainty in the time
            it will take to execute a change is very large.
          (eg: 10x range in 95% confidence limit of time estimate, say 1 day-2weeks).

    7. Because of the complexity of code, bugs are an inevitable byproduct of writing code. It is hard
            to predict how long it will take to find and repair bugs as that depends on how many side effects are
            involved, which is not known until the repair is done and "fully tested". The only way to avoid bugs
            completely is to not write code. There are things that can minimize bugs or speed up finding/fixing
            them, but they will always exist.

    1. Re:Fundamental coding truths by Eivind+Eklund · · Score: 1

      Point 1 and 2 are fundamentals.

      Point 3 will often seem right, yet it's not. For good pieces of software, it is possible for another programmer to have more familiarity with a piece of code than the original author. This happens regularly in large projects that live long.

      Point 4 is right and wrong. Programmers aren't interchangeable, yet the difference between an original author and a new programmer does not have to be significant. In the circles I move, it's actually not that uncommon for a different programmer to be *more* effective than the original author, just due to plain being a better coder.

      5. is an exaggeration, except for very low quality code. Except if you see writing a program as maintenance on the blank file, and extensions thereof.

      6. is sort of true, depending on what "any accuracy" means. It's usually possible to predict within +-30% for a decent codebase after estimation training and environment calibration. Ie, you have to estimate a ton of times, you have to have a decent codebase, and you have to measure how far off your estimates are (finding the correct expansion factor for your environment).

      And I totally agree with your last point :)

      Eivind.

      --
      Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
    2. Re:Fundamental coding truths by Bellum+Aeternus · · Score: 1
      I have to disagree with #4. There are a ton of good APIs out there that are easy for an outside programmer to come in and use. If you build your code with the concepts that

      • You will not be the one to maintain it
      • You're writting an API that will be tied together
      • You're not the world's greatest coder
      Your source doesn't need to be locked into one developer. I hate to see it, but see M$DN's stuff for .NET to see ease of reference with an understandable API to see exactly what I mean (warning not FireFox friendly - sadly).
      --
      - I voted for Nintendo and against Bush
  80. wrong by geekoid · · Score: 1

    May not make sense to a different person.
    You may need these developers on a different project later and want to use a Jr. to maintain your code.
    In fact, I would say you need to watch the standards more closley because a small group is more likly to make assumptions.

    NOt to imply you need draconian standards, but just letting coders ' do there thing' usually goes very bad in the long run.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  81. Wrong Priorities by BlueBoxSW.com · · Score: 0

    I'm sorry, but I think you might have the wrong priorities here. Coming up with standard coding practices should only be your first concern if bad coding practices led to the creation of you new position. Still then, I wouldn't start there.

    You've got to realize that your company just added a layer of management, and therefore, complexity, to every in-house project. You should be most concerned with not doing anything that overly complicates the internal development process. Like a doctor, your motto should be "do no harm".

    Second you've got to find out what the real problems are (and I will bet you real money, it's not a lack of comments in code, although, they are important, yes). Is the real problem that management can't get realistic information about active projects? Is it that the company is spending too much on maintaining proprietary stuff when they can buy an off the shelf solution? Is it that they're spending too much on off the shelf solutions when they could be developing better solutions in-house?

    These are the question you should be asking first, not looking at coding standards.

  82. I have a producer wash my BMW once a week. by Anonymous Coward · · Score: 0

    Because, my argument was, if I have to wash my car then I'm not coding. The general manager agrees, now an AP gets the keys and six bucks every Friday afternoon.

  83. Whitespace by Anonymous Coward · · Score: 0

    Make sure you use plenty of whitespace. Put blank lines between functions. Don't put numerous statements on one line.

    In C (C++, etc), always use {} around the bodies of loops/conditionals. Too many times I've seen people add more code to the "body", without adding in the necessary {} around it. When they test it, it often works anyway because they test the "true" condition and not the false, or the false condition still "mostly" works right.

    Comment major blocks. It helps break a function into smaller logical blocks, making them easier to understand.

    No silly comments. The "you won't understand this" comment is often wrapped around bad code, and isn't helpful anyway. Add comments to help me understand it, not to be silly.

    Use consistant indenting. Also don't indent based on the length of the loop/conditional statement. If the loop is modified, you don't want to have to spend a lot of time re-indenting the code.

    Periodically go through the code and remove "#if 0" (or related) when it is used to comment out sections that were re-written, but the old code was left in, in case the new code wasn't any better. It ends up as useless clutter.

  84. Variables... by SeanMon · · Score: 1

    name them well, and the code becomes drastically more readable. Don't use ambiguous abbreveations. Set up a system for naming functions based on what they do. Also, in C++, include the variable names in function prototypes, even though they are ignored by the compiler.

    bool descriptiveFunctionName ( int lowerBound, int upperBound ); // Returns true if ... False if ...

    By naming functions and variables clearly, less comments are required to completely explain what a variable/function does.

    --
    "Scud Storm!" -- Jeremy of PurePwnage.com
  85. subject by Anonymous Coward · · Score: 0

    "Without wasting a couple of hours"?

    It is a joke.

  86. Thats horrible! by geekoid · · Score: 1

    "Let programers do what they want. "
    thats great, assuming they all want to do it the same way.

    "When somone complains that XYZ is hard to read, then it's his job to refactor that code into something that is easy for him to read."

    well done, now you have developers constintly changing the same code. there goes stability.

    "
    Don't comment your code. Make the code so damn readable that a comment is superfluos"

    not possible in the real world. No matter how well you code, it can never catch the intent of what you are writing. Only by stating intent can someone know if there is a problem.

    "Above all, don't make rules you can't break on a whim, but do make rules as you find them helpful. Go with what feels right until it stops feeling right and then fix it."

    there's a great way to waste time and money. 'Feels right' isn't the same to everyone.

    "The first person who says something unhelpful as "your code doesn't comform to our company mandated brace alignment standard" gets fired, but only after he's shown what a modern IDE looks like and how well it autoformats the code to any brace standard he cares to think of."

    how about you get fired for being too damn stupid to set up your IDE to conform? Other tools besides your IDE may be looking at that code.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    1. Re:Thats horrible! by clambake · · Score: 1

      Two years with no bugs, new features rolled out every week says it works well...

    2. Re:Thats horrible! by ClosedSource · · Score: 1

      "Let programers do what they want. "
      "thats great, assuming they all want to do it the same way."

      Why should they all do it the same way? The argument typically advanced by those promoting coding standards is that they make the code easier to understand. If a programmer is going to be scratching his head because he's unfamiliar with the naming convention, he's certainly not going to be able handle C/C++ pointers or Java generics.

      In truth understandability is really just an excuse. The main motivation for coding standards are power and a compulsive need to produce order where none is required. In practice, a manager or the "alpha" programmer dictates the bulk of the standard that everyone else has to live with. It's very rare that the process is democratic.

    3. Re:Thats horrible! by Lio · · Score: 1
      I have to disagree here: although there are coding standards out there that do not help a coder to understand foreign code, most rules can only help and will never prevent someone from effectively dealing with the code. The essentials are:
      • A name or identifier shall only consist of US English words and digits.
      • Comments shall be made in US English.
      • There shall be a header at the beginning of each source file, containing the author, scope (project), version, status, last modification date and time
      • If parts of the code (including comments) is not made by the original owner of a document, there shall be a comments including the name of that personBlock shall be indented
      There are several other rules that help preventing common coding errors (e.g. do not use else-clauses without brackets), but they are of minor importance IMHO. Lio
  87. For the comment author only by derek_farn · · Score: 1
    A few other details that I'd like to add. K&R braces were invented, not by K&R but by the guys who typeset their book.

    Do you have a citation for the source of this statement?

    It is a severe roadbump to try and read code where the braces are at the end of an if statement instead of vertically alligned.

    I agree.

    Did you intentionally give a nonexistent web url?

    When will /. provide a method of contacting a comment submittor that does not require posting a comment or the author supplying a public address?

    1. Re:For the comment author only by Hognoxious · · Score: 1
      Did you intentionally give a nonexistent web url?
      It just lives up to its name, that's all.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    2. Re:For the comment author only by MythoBeast · · Score: 1

      >> K&R braces were invented, not by K&R but by the guys who typeset their book.

      Do you have a citation for the source of this statement?

      Not on the web, unfortunately. That statement came from a periodical that has been lost to me for a while now.

      id you intentionally give a nonexistent web url?

      Which one? The one for the GNU coding standard? It works fine for me.

      --
      Wake up - the future is arriving faster than you think.
  88. Coding Standards by NiftyNick · · Score: 2, Informative

    I know what you mean about coding standards. I have worked in so many places and have been asked "Do you have any coding standards that we can use". So instead of carrying around stacks of documents, I have placed them all on one site. Go to Delphi Coding Standards this is a Delphi coding standard I follow, but I'm sure you can apply it to all languages as required.

    1. Re:Coding standards by truedfx · · Score: 1

      Use whitespace for readability. Code like if(strlen(obj.getname())" is legal, but it's a lot harder to read than "if ( strlen( obj.getname() ) ".

      A more important change, IMO, would be to make it:

      if(strlen(obj.getname()) != 0)

      It also makes it easier to distinguish functions ("f(x)") from control structures ("if ( x )").

      Which are, at least to me, just as easily spotted by the opening brace, or the changed indentation on the next line. Or by the font change for the keyword with any decent editor.

    2. Re:Coding standards by Todd+Knarr · · Score: 1

      Which are, at least to me, just as easily spotted by the opening brace, or the changed indentation on the next line. Or by the font change for the keyword with any decent editor.

      And grep or regexp search in Emacs recognize font changes how? :) The distinction is as much for "make it easy to programmatically find all occurrences of a call to f(...) without getting false hits on "if ( ... )"" as it is for "let a human pick out the if statements".

    3. Re:Coding standards by truedfx · · Score: 1

      That one's easy - just search for \f(.

    4. Re:Coding standards by truedfx · · Score: 1

      Or rather, \<f(... I should've previewed the message, I forgot about HTML.

    5. Re:Coding standards by lznancy · · Score: 1

      I like the idea of source controlled designs. Having an index on the project name defining both the source controlled code and the designs ties it together without wasting time maintaining links in each module.

  89. Ideal workplace by pmv · · Score: 2, Interesting

    I'm sure many others here have already gone on and on about coding practices, so I'll go in other important directions.

    Beanbags. Very useful. Especially when you've got those incredibly stubborn bugs, and feeling careless and jumping about and falling. *grin*

    Food and drinks (coffee). Increases productivity greatly.

    I've also appreciated how the QA team is ideally located in separate offices from devel. Things get pretty messy. :)

  90. Check-in policy by TheUnknown · · Score: 1

    It is not exactly a coding standard but sort of related. My department used to have a policy of no check-ins until you are submitted to the test : building a small (~20 pieces) Lego toy. You could even use the instructions if you couldn't figure it out :-)

    You only passed the test once your boss thought you were ready.

  91. Even better: CPAMAP by gerf · · Score: 2, Funny

    (copy paste as much as possible)

    1. Re:Even better: CPAMAP by Anonymous Coward · · Score: 0

      Ah, so you're the guy who cuts and pastes and changes one or two characters with each paste.
      Your 10k line code "dump" was rewritten from scratch and is only about 1k lines now.
      (and yes, we have a guy who does this where I work, and I think he's about 65 million years old).

    2. Re:Even better: CPAMAP by Anonymous Coward · · Score: 0

      duh, how else do you think I got my CS degree? Hello World still has me stumped.

  92. For .Net, here is what we use by cyberjessy · · Score: 4, Informative

    C# - The C# Coding Style Guide, Mike Krueger(SharpDevelop). This is probably the most widely used one (Novell). It largely agrees with Microsoft's internal coding standards, with a few exceptions.
        VB - .Net Coding Standards, part of the SDK. This is not comprehensive though, like the C# doc mentioned above.

    Version Control -
        Server: Subversion + Apache
        Client: Tortoise SVN (Excellent) [We also use Perforce, CVS, VSS(Commercial apps)]
    Continuous Integration - Cruise Control.Net
    Intranet, Knowledge Management - DotNetNuke (www.dotnetnuke.com)
    Project Management - dotProject (PHP) (www.dotproject.com), MS Project
    Unit Testing - NUnit (www.nunit.org)

    --
    Life is just a conviction.
  93. A few obvious ones by avarame · · Score: 1

    1. Everything in source control. Everything.
    1.1 Source control on RAID.
    1.2 Occasional offsite backups.

    2. Get everyone on the same page as far as who's going to do what, and how the parts will talk to each other, before anybody writes a line of code.

    3. Never add manpower unless:
    3.1 ... they have needed expertise, and no one else can learn it on schedule.
    3.2 ... someone else is leaving.
    3.3 ... you JUST shipped the last version and have plenty of time to bring the new folks up to speed.

    4. (This is a more personal-level tip) No AIM, no IRC, no email while coding.

    5. Use Ruby. Or Python, even.

    --
    Save time now so you can waste it later
  94. Software Carpentry by Anonymous Coward · · Score: 0

    Have your developers read this fantastic set of course pages:
    http://osl.iu.edu/~lums/swc/

    The course is sponsored by the python foundation, so there's a lot of python embedded. Still, its one of the best and most complete collection of best practices and resources I've come across.

  95. DO-178B by Anonymous Coward · · Score: 0

    It's most certainly not a quick/easy answer, but if you write-up your own plans/procedure/standards based on the guidance it contains, and then have competent people follow them (and audits that verify this are pretty much required), you'll most likely produce a very good software product. That said, it will also almost certainly take longer and cost you more because of this additional overhead. I work for the FAA, and their perspective is that this is a required expense since a failure at the wrong time could have very serious consequences, but I suspect a subset would still be useful in most environments (if nothing else, you'll probably reduce your long-term maintenance costs on large/complex projects).

  96. Coding Style by Anonymous Coward · · Score: 2, Insightful

    This is a subject near and dear to my heart. I have a history of coding in small shops, from 1 to 7 programmers. I currently work with two other programmers at a company that has had 4 programmers before us that are no longer available to us. My coding style is very different than my coworkers'. My code is very dense, with few comments, because I believe the code is the comment, and frankly, I think if a compiler can understand it I should be able to also. But that's not important here. I think it is useful that we all have different coding styles. In an environment like mine that has only a few players we learn each others style and know who did what just by the way it looks. It's also nice to see where one person has modified another person's routine.

    I love good variable names and statements of purpose and all that, but I think pure conformity is counter productive. Whatever guidelines you put in place, if you allow for some differintiation between authors it will help with the debugging later.

  97. If using C++... by Anonymous Coward · · Score: 0

    1) Use standard containers (e.g., STL or boost data structures) and algorithms as much as possible.
    2) Use smart pointers whenever dealing with dynamically allocated data (auto_ptr, shared_ptr, shared_array, etc.)
    3) Use a standard, easy-to-use error checking mechanism for error checking during development (assert or a custom version thereof). Make it easy to comment out for the finished product.
    4) Use a standard, robust method to handle error conditions in finished code. Don't confuse these errors with development phase errors (see point 3). It's not nice when a finished app just crashes and spits incomprehensible garbage on the console.
    5) Devise a standard way to handle input errors. Either use C++ exceptions consistently, or have functions return error codes. Try to stick to one method or the other.
    6) Look into using SVN instead of CVS (this applies to all languages).
    7) Insert geeky jokes into the comments whenever appropriate. ;)

  98. Standards are irrelevant by dpbsmith · · Score: 2, Insightful

    It's funny. I work very closely with two other programmers, although we work on almost disjoint bodies of code. Our coding styles vary widely. One of us uses Hungarian notation, one of us does not, one sometimes does and sometimes doesn't. We use different indentation styles, different nesting styles, different personal styles for naming variables.

    And you know what? None of us have any trouble at all reading or maintaining each other's code.

    Why? Because we're good programmers; because we _care_ about what we are doing, we take a long-term approach, and management judges us by our long-term track record and doesn't look over our shoulders micromanaging how many spaces we indent.

    And we all write LOTS of comments, but we comment the things that need to be commented, not just pro-forma and CYA stuff.

  99. The Pragmatic Programmer by RhettD · · Score: 1

    Read The Pragmatic Programmer. If I ever start a company, this is going to be required reading for every employee.

  100. duh... by Anonymous Coward · · Score: 0

    RAD Dude! Nuff said.

  101. You want documentation, not coding standards. by oneiros27 · · Score: 2, Insightful
    Don't get me wrong, coding standards help too, but by the question:
    Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code
    I couldn't care less if people are using tabs / 2 space indents / cuddled elses / whatever formatting crap.

    Even how you name your variables vs. functions vs. methods vs. objects has very little to do with being able to jump into a project, so long as people are consistent. What's more important, is to maintain good documentation, so that someone has some clue what the relevent files are, and what the overall logic was in how the program / general modules / etc are laid out.

    No one is going to be able to jump in and start modifying code on a moment's notice. On a large project, spread across multiple developers, it might take a week or more for someone to have a grasp of what needs to be done, why it's being done the way it is, and what the implications are to change things to the way that they think is better. (I consider unit tests to be a form of documentation -- given a specific input, I expect the given result)

      And let's not forget the whole mythical man month -- tossing in another developer at the wrong time may screw up the existing developers if they get pestered by the newbie. That's why I try to keep documentation explaining what the purpose of the project is, known outstanding issues, how the program is laid out, all of those sorts of things that a new developer would need, should I get reassigned, fired, given extra help, or just give up and decide to quit.

    A ticket tracking system, and some centralized documentation repository (might be a wiki for multi-person projects) can really help you get a handle on these sorts of things.

    If you want actual programming tips ... take a look at Damian Conway's Best Practices article for perl.com (or his book) ... much of it applies to more languages than just Perl.
    --
    Build it, and they will come^Hplain.
  102. Doxygen by everphilski · · Score: 2, Informative

    In C++ we use Doxygen. Basically as you write comments inline you use a few shorthand markers (kinda like HTML tags, sorta, not really) to tell Doxygen what to pick up. Generates pretty good documentation and graphical class charts, etc. Works pretty slick, Doxygen is then pure HTML + png documentation of your code.

    -everphilski-

  103. The controversial location of the braces by sammy.lin · · Score: 1
    The one standard I remember reading is the fact that they wanted the braces on a new line
    int main()
    {

    return 0;

    }
    and NOT
    int main(){
    return 0;
    }
    This is something you learn when you first start writing code so its a preference thing. The engineer put it loud and clear that he wanted it this way, to avoid controversy.
    Along with useful variable names, method signatures and plenty of comments where needed. It really doesnt matter to me, Im not Visual Studio does it by default ;)
  104. Excellent Book by weegreenblobbie · · Score: 2, Informative

    I have recently aquired the book "C++ Coding Standards - 101 Rules, Guidelines, and Best Practices." ISBN 0321113586 or http://www.amazon.com/gp/product/0321113586/103-00 42056-9954216?v=glance&n=283155/

  105. Our coding practices: by Jeian · · Score: 1

    Mountain Dew and coffee, mainly.

  106. Coding standards by El+Cabri · · Score: 2, Interesting

    Coding standards are language standard, or language specifications.
    A developer who does not understand any piece of code does not understand the language and hence is incompetent.
    Of course one can write obfuscated code, and developers should be encouraged not to. If your developers are not capable of writing meaningful code in a language, change the language, change the developers, or as a last resort change careers, your company stinks.
    Setting coding standards would be the same as restricting the English language to a subset in which, for example, George W Bush would be capable of forming a meaningful and consistent sentence.

  107. my take by tuj · · Score: 1

    Don't mandate Hungarian notation; what a waste.

    Keep procedures short and simple and use a lot of them.

    Don't repeat code when possible.

    Comment where things really are confusing, but don't waste comments on things like /* this loop counts from 0 to x */

    Don't nest if statments too deep, and when you do nest them, don't put 400 lines of code between the if and the next else. Use functions.

    Use preprocessors to let the compiler work for you, but don't put ifdef's inside your actual code if possible.

    Get a good set of base functionality and let everyone utilize it. Its a lot easier to optimize 10 functions than it is to consolidate 5 versions of those 10 different functions and fix all the code.

  108. My personal favorites are ... by Anonymous Coward · · Score: 0

    a) Use lots of goto statements
    b) make sure not to check buffer lengths
    c) put knock knock jokes in my comments
    d) name my variables after dragon ballz characters

    Oh btw work for Microsoft and on the windows vista development team.

  109. Re:Comments lie by rs79 · · Score: 2, Insightful

    " and finding out that those things no longer apply because somebody changed a 1 to a 2."

    Comments lie. Code never lies.

    --
    Need Mercedes parts ?
  110. You don't have to come up with anything... by Lairdsville · · Score: 2, Insightful
    If your company has been doing development for 35+ years in multiple projects, there is certainly a body of knowedge and culture of development that has evolved over the life of the company. I doubt that you could just 'come up' with anything better yourself, so I think your goal would be most effectively achieved by collecting and organising the information that you have all about you.

    I achieved a similar thing in my company by setting up a wiki (I started with Twiki and then we changed to Confluence) with a basic skeleton that I wanted have fleshed out. I even got our developers to define the skeleton, they all knew what we needed, code guidelines, review methods, development procedures etc. Now all I have to do is spread the word about the existence of the wiki and watch it emerge!

  111. Top 10 by careysb · · Score: 1

    I've worked on several "standards" documents and I've found that they are mostly ignored because there are too many items. After you compile your list of items you want to control whittle the list down to the top ten that you expect people to know and follow and that you are willing to enforce in code walk-throughs. (You do code walk-throughs don't you?) Another suggestion is to let the developers vote on some of the items, they are usually more willing to follow conventions if they have some input and feel that there is a consensus.

  112. Project Management by mchawi · · Score: 1

    Everyone has pointed out most of the stuff you need to know from the development side. CMM and CMMI will give you most of the project standards you need - pick up a starter book and in about a day you'll get the basics. Maybe something like Information Technology Project Management by Kathy Schwalbe - very generic. The big key to take from here is to get the proper scope before starting and have everyone sign-off at the beginning of what they expect and at the end that you satisfied their criteria. Nothing else anyone said here will matter if you don't do those two things.

    Secondly I come at this from the support side, because our developers write stuff and dump it on us. We also have developers that document the program and spend a day with the support team going over how to use it effectively - showing them tips and tricks. So the best code can be viewed as a failure if the users and support staff start knocking it because they don't know what they're doing. If you get them up to speed though, they'll support you 100%.

    In both cases the key factor is public relations and cya. The larger the company you work for the more you need to worry about things like that unfortunately.

  113. Don't overdo it by snitmo · · Score: 1
    I'm sure the 100 comments before me provide very good advice. I probably don't have much new information to add.

    However, I would like to say this. From my software engineering experience (which includes big companies, medium sized ones and startups), too much emphasis on coding style, development process, code reviews, bug tracking systems, naming convention, etc., may hurt the team's productivity.

    To do everything perfectly, engineers need to spend time indenting code, changing variable names, making sure correct information is in the bug tracking system, waiting for somebody's code review, etc. That adds a lot of hours to development time, in addition to the time to actually develop software. You may also need to hire a manager to make sure everything is OK.

    Worse yet, if too much focus was put on to such things, the team's mentality may eventually shift to "let's code everything right and clean", rather than "let's develop something great and innovative and help our customers". That's not a winning formula.

    So my advice is, learn the current infrastructures your teams have. Chances are they already have some kind of systems and they may be fine to a certain degree. Listen to your engineers, the lowest level ones included, on what is broken and should be improved. Fix only the broken things that are hurting productivity. Fix them in the least intrusive manner. Sometimes, the laziest engineering manager is the best one.

    Good luck and let us know how things go.

  114. Magic Numbers by Anonymous Coward · · Score: 1, Funny

    Magic numbers are the worst thing you could ever put into code. They are even worse than hungarian notation...

    1. Re:Magic Numbers by WushuJim · · Score: 2, Insightful

      In addition to that, don't hard code values into variable names such as making a timer variable called fifteenSecondTimer.

  115. You need only Version Control System by Anonymous Coward · · Score: 0

    You need only Version Control System, this is the only one thing that matters.
    It can be CVS, SVN, ClearCase...
    You have to use it religiously.

    Insisting on coding standards assumes that you treat programmers as they are idiots. If not strictly enforced the coding standards will be just ignored.

  116. Code Complete by pigwin32 · · Score: 3, Informative

    Steve McConnell's Code Complete is an excellent source for coding standards and a good read for any developer. I don't agree with everything in the book but it is comprehensive. Ignore that it's published by Microsoft Press, it's a good one.

  117. Why not ask your co-workers? by Anonymous Coward · · Score: 0

    It might go over better than dictating.

  118. Don't just worry about coding pratices... by megalogeek · · Score: 2, Informative

    You should also worry about development practices. Just having good coding pratices will not gain you much in the way of robust and easily changed systems. Having good development pratices will.

    Specifically, I'm referring to having a complete system of specifying the requirements for any system. Too many coders these days start a project by hacking up the first thing they think is necessary, then the second, then the third, etc. While this ends up working out for most small projects, big projects can quickly become unweildy. Not to mention, if you bring in a new developer after years of working like this, the learning curve for that developer is very steep.

    Enter Hatley & Pirbhai's Strategies for Real-Time System Specification. In this book, the authors outline a set of strategies for developing complicated systems and making them as robust as possible. Now, you may be thingking "Who are these guys and why should I care what they have to say?" Well, they used to work at Boeing and they developed their strategies while working on designing a plane. (I think it was the 777, but I could me wrong.)

    You should definately read the book, but the strategies they present basically boil down to defining the whole system from the perspective of what, how and when--separately. Here's how it works:

    • Specify what the system does - This means starting at the top and drilling down until you get down to individual tasks that do one thing.
    • Specify how each task will be implemented - This is where you write the code, develop the hardware and such thing.
    • Specify when (and how often) each task needs to run - If you find some task can't be completed as often as you like, it's easy to go back to the implementation and find a new way to do it.

    This may seem like overkill, but it's not. I've been working like this for a few years at college now and it has huge advantages. Development tends to go faster, problems can be fixed faster and--most importantly I think--new developers can sit down with the specifications and get up to speed very quickly.

    Overall, I think using strategies like Hatley and Pirhbai have developed is far more important than all the coding practices and code commenting in the world.

    Of course, YMMV, etc.

    --James
  119. Focus on the management of the project first... by Anonymous Coward · · Score: 0

    Coding styles are one thing. Version control is another. But you need to step even further back if you are managing the entire development process. What am I coding? What are the requirements? How will my design fufill the requirements? Without answering these questions, all the proper coding in the world won't matter. Your boss/customer will want their requirements met, and if you aren't managing the development efforts from the beginning incorporating a solid design, you've failed before you write your first bracket. Being a development lead is one thing, being a project lead is another. If you aren't responsible for the project aspects, make sure somebody is.

  120. Be a nazi! by Now.Imperfect · · Score: 0

    comments everything.
    segment everything, make sure the code has distinguishable parts.

  121. Jack Ganssle: Excellent Resource! by Anonymous Coward · · Score: 0

    Less of a specific approach and more of a "this guy can help you learn about your options" is Jack Ganssle (website: http://www.ganssle.com/ )

    He focuses on firmware, so its not highlevel application stuff, but if your lowlevel his insight and suggestions are pretty useful. The core of his work is presented in lectures he gives, both publicly and privately for specific companies.

    He also writes monthly for Embedded Programming, normally something funny but with a serious point. And to cap it all, he's a pretty nice guy.

    Check it out, see what you think. He helped me improve my coding and my team quite a bit.

    1. Re:Jack Ganssle: Excellent Resource! by antispam_ben · · Score: 1

      Anonymous Coward wrote: ... And to cap it all, he's a pretty nice guy.

      Jack, that's not you, is it?

      --
      Tag lost or not installed.
    2. Re:Jack Ganssle: Excellent Resource! by jackganssle · · Score: 1
      Nope! But I appreciate the post.

      Jack

  122. My way, darn it! by amigabill · · Score: 1

    That's 4-space indents, and spaces not tabs. Function and file headers, file headers basically for what the entire program does (not big ones, mostly perl or Cadence skill language scripting), and intelligent as I can comments of what I'm doing and more importantly WHY I'm doing it, so I can make sense of it myself long after I've forgotten what was going through my mind at the time.

    My company doesn't really have any "standards", and most people don't format much at all and rarely, RARELY, comment anything whatsoever. The first thing I do when getting into someone else's code is to reformat it to my personal indentation style, as I get a better view of code flow with 4-space indents than single-space indents. I think single-space indents are pretty much meaningless as it's hard to follow without really paying attention to it, and sometimes you want to get a feel for where you are at a glance instead of at a study session.

    I wish there was some company requirements, but we're electrical engineers not "real" programmers, and I guess no one else in the office cares if they can read their own code 6 months later.

  123. For what? by cheezit · · Score: 1

    You mention "a couple of hours" for a developer to get up to speed? So what? You want to add incremental work to every trained developer's workday so that you can save a little bit of a newbie's time?

    The reality is that company that treat developers as interchangeable modules that can pump out standardized units of effort get crappy results. Regression to the mean and all that. Everyone wishes the "other guys" would conform to standards, but there are real reasons that cookie cutter code is not at the top of the list of success factors for a good project.

    The best thing you can do is to identify your key lead developers, keep them happy, and make sure they are doing a halfway reasonable job of spreading the knowledge around. Oh, and recognize that if they leave you will take a hit. It comes with the territory.

    The alternative is to use process and standards as a club to force conformity, which will make your shop into a place that most folks with talent don't want to work.

    --
    Premature optimization is the root of all evil
    1. Re:For what? by leftCoaster · · Score: 1
      The reality is that company that treat developers as interchangeable modules

      Too true. However, common layouts of code make it easier for developers of all stripes to read code and get an overall idea of how the code flows.
      Having worked with a team that used all manner of indentation I can tell you that when an if block doesn't line up start to end, it is difficult to tell where to look for code flow.

      The best thing you can do is to identify your key lead developers, keep them happy

      Again a true statement. However, there is always a situation where the lead developer will leave. It makes a lot of sense to cross polinate. Eliminate the single source of all knowledge about your project or any critical piece of it. Code reviews help a lot. Senior folk find errors in code and junior folk learn from constructive criticism. The trick is to promote reviews not as a place to put people down, but as a place to teach/mentor. It's not an easy task to foster this environment, but the benfits are truly impressive.

      The alternative is to use process and standards as a club to force conformity

      Granted, I (perhaps like others) have a problem with authority forcing this kind of thing down my throat. However, with a bit of explanation for the reasons for the standards, I think most developers will understand the value and adopt and adapt.

    2. Re:For what? by cheezit · · Score: 1

      Formats can be a challenge for vi users, granted (and I'm sometimes one of them). But any modern editor can make those types of cosmetic issues go away with a couple of clicks to reformat.

      The more difficult issues are ones of style and syntax (why did this guy use a bitfield and masks instead of an array of booleans? why does this method return a -1 for failure but that one returns 0?). Trying to drive consistency through standards is tough because if the standards are comprehensive enough to address all this stuff, then it should be possible to feed the standards into an expert programmer application and fire your staff. Nobody does that (and survives) so let's not get hung up on standards as the panacea.

      Absolutely agreed on code reviews, and it brings up what I think is key---the human element. You will never make a bad developer into a good one through standards---but you have a good shot at improving their skills by talking through their code with them.

      --
      Premature optimization is the root of all evil
  124. Re:Comments lie by Lehk228 · · Score: 5, Informative
    Comments lie. Code never lies.
    I beg to differ
    --
    Snowden and Manning are heroes.
  125. Least worry by Anonymous Coward · · Score: 1, Interesting

    In my experience, the last thing that people that worry about coding practices should worry about, are coding practices.

    Unless you have procedures in place for testing, deployment, version control, code sharing, change request system and more, then those are bigger concerns than how you indent your code and what naming conventions to use.

    I'm not saying that coding practices aren't good. Just that you likely will achieve better productivity by focusing on other things.

    If you are hiring, make sure that you hire a seasoned software engineer and not a code monkey next time. If you aren't hiring, then research the web for ways to improve how your team builds software. What is best for you will differ quite a bit depending on your exact situation.

    If you want code practices, then focus on "best practices" or patterns over cosmetic rules. Try to centralize code that support common patterns, such as error handling, database access, GUI components and so on.

    Think about it this way. Your team can only absorb a certain amount of improvements. How much this is depends on the individuals on your team and how well you are able to introduce these new things. Think about the improvements that you want to make and prioritize them.

    Man, this ended up sounding like I think I'm the best thing since sliced bread. I'll post anon.

  126. Question about Hungarian Notation by Create+an+Account · · Score: 1

    I apologize if this is a stupid question (I am an MBA) but what is wrong with Hungarian Notation? I thought it was supposed to help people keep variable and object types clear? What am I missing? Thanks.

    1. Re:Question about Hungarian Notation by Lehk228 · · Score: 2, Interesting

      Hungarian notation puts an unenforced comment into every variable name.

      the problem is not when you look at intPositionSensorReading but rather when it has been changed to a decimal, or when you need to change it to a decimal suddenly you are either wasting time editing every piece of code using that variable. or you cause incorrect comments to be all over the code.

      IFF VB would enforce and automate hungarian notation as an option it would be useful (i use VB as the example because it is the only place i have run into Hungarian Notaiton)

      More HERE

      --
      Snowden and Manning are heroes.
    2. Re:Question about Hungarian Notation by Create+an+Account · · Score: 0, Redundant

      Oh. Well, thanks.

    3. Re:Question about Hungarian Notation by joe_bruin · · Score: 5, Insightful

      Hungarian notation has its (extremely limited) uses.  The reality is that it turns code into garbage.  Go ahead, read aloud the lines of code below.

      // the old c style
      if(cur == last) rec->tag = name;

      // camel case
      if(currentKey == lastEntry) Record->keyTag = userName;

      // hungarian
      if(iCurrentKey == iLastEntry) prRecord->m_pszKeyTag = pszUserName;

      Now imagine discussing them with your coworker.  Imagine thinking in your head "What should I do if prRecord->m_pszKeyTag is NULL?"  Humans are good at symbolic manipulation.  Giving something a name makes it easier to deal with.  Giving something a label that cannot be easily manipulated in language (spoken or in your head) severely hampers the ability to think it through.

      The argument for Hungarian is usually "but it lets you know what the variables are".  This is the maintainance programmer argument.    This argument rarely makes sense in reality, unless some very bad programming is involved.  First of all, if you do not understand the current code you are about to modify, you should *not* be modifying it.  If your maintainance programmer is just going to have a look at two lines of code, add a third in the middle, and hope for the best then you are truly fucked.  He has obviously not understood the code enough to know what the consequences of the modification will be.  The reality is, if your current logic unit is such a monstrosity that looking up the types of your variables is a burden, and your variable names are so poor that it is insufficient to infer at least a basic understanding of what is going on without having to resort to prepending types, you should probably step away from the keyboard, turn off your computer, and tell your boss that you had an epiphany and will be pursuing a career in French fry development.

    4. Re:Question about Hungarian Notation by Bwerf · · Score: 1

      In a way VB does enforce and automate it. Not by changing the code, but rather by providing information about a variable(type on variables, more on methods) when you do mouseover on it. I like that the info is there but doesn't clutter my code.

      I haven't used VB in a long time, so I don't know if it's doing this atm, but I assume so since the VS C++ editor does it.

      --
      If noone rtfa, then what's the slashdot effect?
    5. Re:Question about Hungarian Notation by Anonymous Coward · · Score: 0

      and your variable names are so poor that it is insufficient to infer at least a basic understanding of what is going on without having to resort to prepending types

      Hence the value of all prefixed notation: even those people who shout that Hungarian is bad (usually because of its connotations with Microsoft, and no other reason), will stil use some form of formatting to show more information about the variable that a simple name.

      eg. Camel case says you should capitalise variables according to some rules - eg. lowerCamelCase is used for member variables, and UpperCamelCase for classes. Similarly, some people prefix variables with m_ for class members. These are all notations, Hungarian is just another one of them.

      These ar ejust one of many techniques that help you work. Looking up every variable to see if it is a string, primitive, or object can be a real nuisance. If you can see right there in front of you what type it is (using hungarian, or an editor's tool), then you are instantly more productive, and will make less errors. Regardless of what you think *should* be best practice, anything that helps you (or more importantly, someone else) understand code is good, and should be promoted.

      The maintenance programmer argument, BTW, is that the original developer "should fix his own damn, crock of crap code that has these bugs in it, why do I get all this useless, convoluted, look-how-clever-I-am rubbish that I have to figure out what it is supposed to do and fix" :)

    6. Re:Question about Hungarian Notation by gbjbaanb · · Score: 1

      if(cur == last) rec->tag = name

      We've just had a bug reported, sometimes the tag name stops printing correctly, it starts printing garbage values.

      If you'd used hungarian, you'd have seen that the pointer assignment to the tag variable was not an actual string copy. Of course, without that you have to go find which class rec is an object of, (being very careful with the inheritance heirarchy), to find that it is a char* and not the string class other, similar, classes in your code (that has been modified over time.... experienced programmers know what I'm saying here) use regularly. :)

      (of course, use hungarian, but then changing the type but not the variable name is just as bad)

    7. Re:Question about Hungarian Notation by gronofer · · Score: 1

      You can't write software without looking things up. You need to look up function definitions and semantics, you need to look up structure definitions. Even if Hungarian manages to avoid a small percentage of these lookups, it's not enough to justify turning the code into unreadable crap, in my opinion.

    8. Re:Question about Hungarian Notation by pooly7 · · Score: 1

      Talking about Hungarian notation, You haven't seen the worse.
      Function name with prefix for the return value ! Yes, like a gorry :
      int nGetHostByName(char *szHost, int nNamelen);
      Surely once, one guy in this company will think about writing as well the variable types in the function name !
      How usefull !
      (They should just hire _better_ programmer)

      http://www.joelonsoftware.com/articles/Wrong.html

    9. Re:Question about Hungarian Notation by MemeRot · · Score: 1

      This is less of an issue with typed languages, but in scripting languages the preceding int is the only place you can tell what the variable is supposed to hold. Is UserID an int? A varchar(255)? intUserID is clear. Also, it only takes ~30 seconds with any decent editor with find/replace to type in find:intPosition replace:fltPosition. Doing so keeps your comments consistent with the code. Leaving off the int/flt means that when you're running a debugger, you don't have any idea whether 123.4 is a valid value or indicates an error, which can be very helpful.

    10. Re:Question about Hungarian Notation by P3NIS_CLEAVER · · Score: 1, Insightful

      Tight scoping of variables negates the need for HN.

      --
      Please sign petition to restore sanity to our banking system!!!

      http://financialpetition.org/
    11. Re:Question about Hungarian Notation by ColdSam · · Score: 2, Insightful
      I rarely use Hungarian, but your reason for not using it is awfully contrived. In your example how would you ask the question using your own naming convention?

      "What should I do if open paren capital R ecord dash greater than capital K ey capital T ag equals equals null close paren?"

      If we used Hungarian and I were to ask the question of a coworker, I would of course leave off all the crap (unless it were relevant). Humans are good at that and Hungarian notation makes it pretty easy to spot the "real" name (just skip everything until you get to the first capitalized letter).

      You may have a point if you are instructing a coworker in what to type into his editor, but if that's the case you probably have bigger problems with your development team.

    12. Re:Question about Hungarian Notation by wft_rtfa · · Score: 1

      I agree that hungarian notation is generally bad. However, it can be useful for some purposes. As for GUI programming you may have a label a textbox, and a variable all for something like price that the user enters.

      TextBox txtPrice; Label lblPrice; float price;

      However, I think postfixes are easier to read. Hungarion notation isn't that bad for GUI objects.

      --
      :-] :0 :-> :-| :->
  127. coding standards? by Anonymous Coward · · Score: 0

    Coding standards??? HAHAHAHAHAHAHAHAHAHAHA!!!! Coding standards... hehe... that's a good one.

    Let's see, I'm an independant contractor & while nowhere near the best, I feel that I'm more competent than the average coder- I'd say 90% of the companies I've contracted myself out to the code ranges from incompetent to criminally insane. I can actually group this into two subcategories further- coders who have no skills with relational database theory background, and DBAs with no coding background- and then there's the odd web programmer with neither.

    My advice (the worst vice)- keep your comments simple & to the point (just like your code should be) AND don't create two different variables with the same value and use them arbitrarily. Yea, you know who you are.

  128. uGh... by HermanAB · · Score: 1, Flamebait

    nUthinG wOrse tHan hUngArian nOtashioN. You only need to look at typical MS Windows code to understand why Hungarian notation is a really, really bad idea.

    --
    Oh well, what the hell...
    1. Re:uGh... by Anonymous Coward · · Score: 0

      Thank you for that detailed, carefully reasoned out thesis. With such a comprehensive, sound argument so expertly put forth, I succumb to your masterful powers of logic and am undeniably utterly convinced.

    2. Re:uGh... by CountBrass · · Score: 1

      Heh, newbie. Some environments only allowed 2 letter variable names so: A, AA, AB, AC I think beats Hungarian by a long way.

      --
      Bad analogies are like waxing a monkey with a rainbow.
    3. Re:uGh... by HermanAB · · Score: 1

      Hmm, you have never actually written any wIndoze code have you?

      The problem is that many of the carefully chosen hUngarian prefixes in the wIndows API were defined way back when the X86 processor had long and short pointers, segments and a 16 bit accumulator. With the advent of 32 bit and 64 bit processors, these things became totally meaningless.

      #include <windows.h>

      int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, i
      nt nCmdShow)
      {
      DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINDIALOG), NULL, (DLGPROC) DialogFunc);
      }

      static int InitializeApp(HWND hDlg, WPARAM wParam, LPARAM lParam)
      {
      }

      Especially these meaningless things:
      LPSTR lpCmdLine
      WPARAM wParam
      LPARAM lParam

      Carefully defined pRefixes for long's, words, ints, all became meaningless, since the architecture of the pRocessors changed and wIndows now runs on various machines from 16 to 64 bit. Clearly, mIcrosoft thought that the X86 pRocessor is going to be the be-all and and-all of computing and never expected their wIndows API to be used for 20 years.

      So, if you are really fAvouring hUngarian nOtation, think carefully wHether technology is going to stand still for the lIfetime of your pRoject...

      --
      Oh well, what the hell...
    4. Re:uGh... by Lonath · · Score: 1

      I don't like using a lot of prefixing, but I've found that using the "m" in front of data members like mFoo, mName, mThis, mThat is REALLY nice since then you can pass in parameters to methods like foo, name, this, that and you can easily tell what belongs to *this and what came from someplace else.

    5. Re:uGh... by chris_eineke · · Score: 1

      I think it is CodeWeavers who do something like this:

      int foobar(int* outSum, int inFirst, int inSecond)
      { /* ... */
      }

      I started to use this naming style. It works pretty good.

      --
      "All you have to do is be fragile and grateful. So stay the underdog." Chuck Palahniuk, Choke
  129. Worst versioning system ever by charlesbakerharris · · Score: 1

    We use Accurev. Don't *EVER* use Accurev. It's the worst piece of software I've ever seen written.

    1. Re:Worst versioning system ever by Anonymous Coward · · Score: 0

      When I saw the title, I wondered if the parent uses AccuRev. And he does! We use it too. Most of us reeeeealy hate it. It's not without strengths but it gets in my way far too much and is horrifically slow.
       
      Then there's the built-in issue tracker. OMG. That truly is garbage.

  130. Pragmatic by dividius · · Score: 3, Informative

    Read and apply the Pragmatic Programmer.

  131. vmware, revisioning system by tlacuache · · Score: 1

    Two things that have helped me a ton as a developer:

    1. A good revisioning system. Being able to look back at a previous version of a piece of source code, compare revisions, etc., is a big help, as is being able to manage branches for easy concurrent development of different versions.

    2. Invest in some VMWare licenses. You can set up standard development or build environments so everybody's working from the same page. Also, using snapshots is a HUGE boon for debugging. When something crashes or otherwise doesn't work, you can run through it again in exactly the same state, over and over, until you find the problem.

  132. Watch Your Cornhole by krisamico · · Score: 2, Interesting

    I see a lot of comments in this thread about coding practices and the like. That is fine, but I think you would do well to think about practices that matter more. You have indicated that your environment really doesn't offer much of an IT infrastructure, which means that you will more than likely play an appreciable role in many of the following processes: requirements management, quality, change management, project management. There may be many instances of your behavior causing projects to succeed or fail, and they will have nothing to do with whether your people are commenting their code.

    If you can, put together a process that specifies how all of you can define a product, start a project (get a suit to sign off on it too), deal with changes in requirements without tanking the project, assure quality, and ship. The code will take care of itself because it is the only thing you will have a decent amount of control over. Everything else is cross-functional, which adds a great deal of difficulty -- hence the need for policy.

    Just remember the "ship" part. Don't get stuck too long in defining a process because none exist which are universally indicated, completely effective, or free from ruinous meddling and circumvention. Worry more about what can keep you from shipping and try to set a policy that will prevent those things.

    And most of all, watch your cornhole -- technical leads are sh*t magnets.

  133. Three Coding Best Practices by DanielMarkham · · Score: 1

    As a software process expert, I can give you the secret three best practices that every programmer must follow:
    1) Find someone to blame for failure. Usually it's the new guy. Keep him stupid and drop hints to the project manager that he might be messing up the code
    2) Try to make your programming complicated. Hey, if anybody can do it they are liable to hire some Indians to do it at three bucks an hour. Try using ancient Egyptian for your comments. Name all your variables something like A1 and A2. Catch and throw away your errors -- you don't make mistakes anyway. Let the calling code bomb, not yours
    3) Get a week ahead on your status reports. What did you accomplish this week? Put that as your goals for next week. Every week you'll hit your targets dead on. The other guys will flail. Try to be sympathetic to them. Offer to help out with their programming.

    This is my blog

  134. Lots of TPS reports by Joe123456 · · Score: 0

    All the of the PHB's just make use do lots of TPS reports.

  135. kids today! by Fractal+Dice · · Score: 1

    Figure out the code in a couple of hours? I'd be happy if I could find the code in a couple of hours.

  136. Peer Review by TeacherOfHeroes · · Score: 1

    If you have the time, have a second programmer take a brief look at the code and evaluate it. If they are able to read the comments/code and give an accurate description of what the code does, then pass it. If not, send it back to the first programmer to be cleaned up.

  137. 'taint no "couple of hours" by amigabill · · Score: 1

    so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code

    Huh. I'v ehad to figure out someone else's code before, while I actually was working in software before my hardware design job. My employer licensed sources from a partner company for merging into my employer's larger system. One component of the messaging system had no documentation and virtually no commenting, and what rare comments were there were wrong. My task was to document the messages, their structures, and what each message type was used for so my coworkers could fill in the two ends of this communications system.

    It was 2-space indented, which I had to change to my favorite 4-space indent, so I could see the flow of the code. 2 days. Understanding the flow, 3 days. Picking out the details of each message type, 4 days. Adding comments as I went along to help remember what I figured out earlier. 3 or 4 more days to type up a document for the thing for other coders to use. There were only 6 or 7 functions, and less than 10 message types. Still took a heck of a lot longer than a couple hours to ficure out what was going on in there.

  138. If it compiles... by MrJack5304 · · Score: 1

    it definitely works!

    But seriously if you want to have readable code you really need to have useful commenting, where you don't comment every line just the ones that are out of the norm or do somethign crazy. I find that using a naming scheme for variables works extremely well. For instance, if you have an object of any sort o_objectName, an integer i_intName, a String s_stringName, etc. It lets the reader know what the variable is for and what type it is when you are looking at it. I hate when people assign dumb names to variables, makes code a pain to read.

  139. What we do by InAbsentia · · Score: 2, Insightful
    Small shop of 12 coders about 98% java code. Total source under version control 270,000 lines of code plus 130,000 lines of unit tests. We use cvs for source/version control.

    The most important thing is AUTOMATE everything that you can.
    We run a cycle where we do an automated checkout every 15 minutes. This is compiled and the checks below are done on all packages that have been updated or which raised errors the last time. Every three hours we do a zero base checkout and run tests across everything including running all unit tests. We also then do a complete construction of installers etc. for the products we ship and run tests on that (rather than in the developer environment). We also checkout across multiple platforms and run the unit tests on these (this is a bit more irregular). The results are collected on a company internal website and errors cause a real-life set of traffic lights to turn red (everyone can see them).

    The things we automate include:
    • style checking (checkstyle) and some other similar packages
    • spelling
    • javadocs on all publicly accessible methods
    • running unit tests
    • we check the unit tests by running a mutation tester which checks how well the unit tests cover the code

    There is more to testing than this but this certainly deals with the low level coding stuff well.
  140. Standards Shandards! by Hawkeye477 · · Score: 1

    So they asked u to create standards? Well basically they put u in one hell of a shitty position since most people are no longer going to like you. From the sounds of it u work for a company where IT is a supporting role, not a Money Making role. If i were u I would create the simplest standards to get the job done. The most important thing to do is be PRODUCTIVE! if you are not productive who cares what standards you have, cause u ain't gonna have a job. So if I were u, make is SIMPLE. ONLY put commects in areas of code that are NOT intuitive. put all code in same place, have a testing environment and production environment. Anything else the tradeoff is time used will not be worth it to the time away from pure development. Any coders worth there salt will perform very well with minimal standards. Besides the previously mentions, on a need only basis for everything else, such as backtesting etc... in non software shop they are of VERY VERY limited value. Productivity is what matters ... and beisdes, no one likes the guy who makes lots of standards and makes there lives miserable.

    Thinking about it again though I should probably reconsider my advice, the more standards you guys put in the more of a chance you wont deliver and the company will get desperate and hire a high priced whore like me to come in and get shit done and pay me lots! :)

    --
    My Web Site - www.ocean-liners.com
  141. partially agree by xswl0931 · · Score: 2, Insightful

    If code is written well, it should have few comments as the logic should be fairly obvious. In the case of if (x == 456), this should really be something like "if (STATUS_BUFFER_FULL == statusCode) ..." now it's obvious what is going on. Descriptive variable names and method names mean less comments are needed.

  142. No cursor? by Anonymous Coward · · Score: 0

    >> refrain from cursors/temp tables

    Try running a data warehouse type application without them, smartass.

  143. It's simple by tuna_boat_tony · · Score: 1

    Put code that goes together, together. If a section is long or coded sloppily, make a comment summarizing what it does. If it's coded too sloppily, delete it. If it makes sense, do nothing except more of the same. There is your guide.

  144. XP Process and Project Tracking by Interested+Spectator · · Score: 1

    My boss encourages us to use extreme programming tactics such as daily status meetings, recording and tracking stories and tasks, estimating hours and code refactoring. In addition, we have a continuous build system in place (Cruise Control) and version control software (Subversion with Tortoise client). Also, we're encouraged to use a Test Driven approach and the unit tests are executed within Cruise Control. We comment our code, but I've noticed that this environment really encourages quality code, not the code commenting. So, my suggestion is to read up on agile development, scrum, and extreme programming before trying to pursue coding standards. I think you'll find those more useful in creating quality, maintainable code. That's my 1 cent.

    --
    jg
  145. My thoughts by ribblem · · Score: 1

    I am a big fan of having a standard coding style. By this I do mean having developers follow a fairly strict set of rules on comment style, where spaces belong, spaces vs tabs, indentation rules, naming conventions, ect. There are many different ways you can do each one of these points, but the important thing isn't which way you choose, but that your code is consistent. That said I would apply these rules only to new projects and leave the old projects as they are. Cleaning up active projects makes diffing for differences in files nearly impossible.

  146. Work type hacking... by Anonymous Coward · · Score: 0

    So long as we don't end up on dailyWTF it's all good.

  147. Who are you trying to kid? by fatjesus · · Score: 1

    "so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code"

    HAHA bra haha
    Good one!
    HA!


    hehe

    Ok seriously - WTF? A couple of hours? What color is the sky in your world? Even the best commented code in the world is going to take a couple of hours to understand. Exactly what kind of trivial software are you thinking of developing?

    1. Re:Who are you trying to kid? by MudDude · · Score: 1

      Sound like a "Hello World" program.

      --
      You don't need to see my .sig. This isn't the .sig you're looking for...
  148. do whatever works... by david_bonn · · Score: 1

    Some things are really in the motherhood and apple-pie categories: revision control, a build system architecture, bug tracking, documentation of the codebase. A lot of other things like coding standards and naming conventions are, to me at least, less valuable. I'll articulate on why that is later on.

    The real important point: All of these things are tools to used to produce something hopefully useful. Having a killer bug-tracking system or a great coding standard won't keep your company in business. It won't even guarantee that you'll produce a great product. Lots of successful companies have been arguably successful without those things. Lots of software we all use and love has rather repulsive code at its heart, and even the cleanest projects have their dank corners. I've worked for lots of companies that aren't around anymore that did have excellent coding standards and even followed them, though.

    Far more important is making sure that the people writing the code and the people who know the requirements are able and willing to talk to each other. Preferably over many beers. This is even more important if they are the same people.

    About coding conventions and comments: we humans tend to see what we expect to see when reading source code. I'm usually a naive, trusting person and if the comments say that the code does X, I assume that it does X. Even if it doesn't, really. And figuring out what it really does when the comments are out of sync of the code (and face it, that always happens -- smart people have been writing buggy code for decades now, and having the code out of sync with the comments is just another bug that there is no way to detect except through unpleasant experience) is often harder than dealing with no comments at all. On the other hand, if I come into a project and am handed 50k lines of C++ from someone just fired for an act of workplace violence and no comments except copyright notices I know I'd better put my thinking cap on and pay attention.

  149. Sound advice by star_aas · · Score: 1

    Follow this document and you'll be irreplacable.

  150. I like the keyboard by Anonymous Coward · · Score: 0

    Most of my coding practice uses the keyboard. I tried just using the mouse for a while, but the keyboard really makes it easier to code.

  151. I have a marvelous set of coding standards... by anandamide · · Score: 1

    ...but the margin of this posting is too small to contain them.

  152. Process first, Coding standards last by ferretous · · Score: 0

    I have worked on a number of big projects in a number of organisations and 'coding standards' are one of those issues that are always contentious and divisive. Even in my current job I have been pestered by individuals who insist that K&R style indenting is 'our policy'. These same individuals seem to spend more time on these relatively trivial matters than actually co-operating effectively and maturely in our collaborative efforts.

    I think team communication and an environment that nurtures and repects all members' opinions and contributions is the most fundamental aspect of successful software development. Of course decisions need to be made and here is where you will need some benevolent despot or despots to act. But these decisions should be made after consulting with the group.

    I would forget about coding standards for now and concentrate on your development process, namely how do we decide, communicate, feedback etc in order to get the job done. When all members of the team feel they can contribute effectively to this process you'll be amazed at how productive they will be and how easily they will accommodate slight differences in coding standards.

    Having said all that, you could of course all agree that code will be commented and use certain methodolgies, components, etc. But these will be easy to do if the group comunicates well.

  153. Some of my rules by gregm · · Score: 2, Insightful

    I'm not really one for coding standards, just make each person maintain a certain level of consistantcy and make damn sure they make good comments. You might want to institute some common variable naming scheme. Here are a few rules I've come up with over the years.

    1) Thou shalt NOT make the user re-enter data
    2) Waste not clicks for they are precious
    3) Thou shall not design a screen that hath no purpose
    4) Move not your bits about the screen like a drunken stripper
    5) Gulp not your data but merely sip... as it makes reguritation less lumpy
    6) That which the user doeth the most, shall not be obscurred by that which he doeth least
    7) Dress not your screens with vain and lustful colors that are without purpose
    8) The user is the one true god and thou shall hold no gods before the user
    9) The user is a friggin idiot
    10) An image that measures 16 pixels across and 16 pixels along it's length is rarely worth one word

    G

    1. Re:Some of my rules by guitaristx · · Score: 1

      8) The user is the one true god and thou shall hold no gods before the user
      9) The user is a friggin idiot

      And people wonder why programmers are such an "eccentric" bunch....

      --
      I pity the foo that isn't metasyntactic
  154. Doxygen VS project lead by McLae · · Score: 1

    We are using Dosygen for documentation on my current project. Doxygen works fine.

    However, the project lead has decreed "No Comments In Source Code". ! So for the last release, we hires a batch of Interns to document the source, ran Doxygen, then threw that code set away. For this release, I am adding comments back to a new source tree. Which will be thrown away.!

    Don't let anyone become as powerfull as this 'leader'. (Even yourself!) Make sure that everyone agrees to the standards, then follows them.

    Even so, this is better than the geek I once worked with who wrote 'self documenting assembler code'. Think about it. :)

    1. Re:Doxygen VS project lead by KozmoStevnNaut · · Score: 1

      No comments in source code?!

      That's just about the most retarded coding policy I have ever heard of. Please, do tell... What could possibly have caused this outburst of pure stupidity from the project lead?

      --
      Eat the rich.
  155. -Wall -Werror by davewalthall · · Score: 1

    Every file should compile cleanly with a specified set of warnings on. With gcc, I use -Wall -Werror (with some other flags like -Wshadow that aren't turned on by -Wall).

  156. I keep my own log book for programming by Cappadonna · · Score: 2, Insightful
    I'm a freelance developer for a day trading firm and a PACS/RIS** administrator for municipal hospital, so most of my projects involve really massive planning for large amounts of data. Whenever I start a new project, I right every little component in a big lab notebook. I even right out major snippets of code, line by line. This helps me in several ways.

    One, when I start plunking away at the keyboard, most of my ideas have been muddled through and I'm not wasting time fumbling through books and websites to find answers. I can also note what ideas did and did not work. Also, since I am typically juggling mutliple projects, it helps me keep track of what I've done and what I have to do.

    Second, I've learned to keep it for review. Basically, I learned at my last job that documentation can save your butt, especially when working with nurse manager who still can't find her archives folder in Outlook or trying to explain how archaic software works to management when nobody has even looked at the source code in 7 years. Its a picture into my brain and its a log of where things have progressed for a give project.

    Third, my notebook has served me are my only way to figure out what the heck I'm working on. Essentially, I've always been given a massive system to rework/hack/redesign that nobody else bothered to figure out. My notebook is my only guide to solving problems, since its my only reliable reference.

    Fourth, a journal can double as a weekly to do list. Alot of times, I have so much crap going on running my system that I forget what the hell I was working on. So, I often write down 10 projects or assignments I need to do within two weeks and cross them off as I go along.

    And finally, it keeps me from having to write the same things twice. Often, I can use code snippets, data structures and old work flow schemas in other projects. that's really helpful when you're up until 12-1 in the morning hammer away at some God awful perl script and you need to get everything finished by the weekend.

    ** PACS and RIS stand for Picture ArChiving System and Radiological Information System, respectively. They are two ancillary systems that hospitals now use to save X-ray, CT, MRI and other images of the body.
  157. Not enough by embedded_C · · Score: 1
    Coding standards are certainly necessary, but they are really just the tip of the iceberg when you are talking about implementing (from scratch it sounds like) software processes. Just know ahead of time that you are going to piss some people off and it will probably be an uphill battle.

    With that said, I would just pick a standard for each language that you use at your place of business. How are you going to enforce the standard? I assume that there will be peer reviews, right? Ok, good.

    Oh, by pick a standard I mean a conventional programming style is all. I believe that Steve McConnell has some good ideas on this in Code Complete.

  158. right on sibiling! by plopez · · Score: 1

    (brother or sister)!

    to which I would only add one caveat: don NOT be overly clever. Write code for maintainabilty NOT for a clever solution. Maintaining code can cost much more than writing it. stupid and clear is better than clever than obscure.

    --
    putting the 'B' in LGBTQ+
  159. Meaningless Standards by BigTimOBrien · · Score: 2, Informative

    Most standards are relatively meaningless. Indentation, Spaces not Tabs, "All class names must be descriptive", "Comments are required" - really this is all hand waving. Let individual groups figure out what's best for them. And stop thinking like a boss, or you'll find yourself with no one to manage pretty quick.

    --
    ------ Tim O'Brien
  160. Good way to get rid of your best staff... by RKBA · · Score: 2, Interesting

    I wouldn't work for any company that tried to tell me what "coding style" to use. I'm a retired programmer with 35+ years of experience BTW.

    1. Re:Good way to get rid of your best staff... by Kjella · · Score: 1

      I wouldn't work for any company that tried to tell me what "coding style" to use.

      I honestly couldn't care less what style I write. I can grok my own code no matter what. I do have some preferences about what style I want to read, but do to that you need *drumroll* a company policy. If you seriously turned down a job over having to write in any particular format, I probably wouldn't want to be your employer anyway. It might take me a little while to get used to, but any developer that couldn't conform to a coding standard just isn't flexible.

      --
      Live today, because you never know what tomorrow brings
    2. Re:Good way to get rid of your best staff... by Anonymous Coward · · Score: 0

      Well if you are retired then there is no reason for you to comply. For us in the rat race we have at least show some team spirit.

      /Is not 1965 you know

    3. Re:Good way to get rid of your best staff... by @madeus · · Score: 1

      I wouldn't work for any company that tried to tell me what "coding style" to use.

      Yeah! Bollocks to co-operation! What would anyone else know about how to code properly anyway?

      If they aren't man enough to deal with what ever random crack fuelled code you dream up, they are wimps right?

      I'm a retired programmer with 35+ years of experience BTW.

      My word, 35 years and you've never worked on a well run large collaborative project, or been able to adapt your own style?

      You know, I really wouldn't brag about that.

    4. Re:Good way to get rid of your best staff... by ediron2 · · Score: 1

      I'm sure there's a midground to this position you've taken... right? If nothing else, you could list the things you do that you'd never let some pointy-hair force you to *stop* doing so TFA is answered, right? For example:

      Presumably, you've edited other people's code (or your own after [insert timeframe slightly longer than the recall threshold for what you ate for breakfast]). That's taught you over 35 years the value of readability and you attempt to work those best-practices into your coding... right?

      Presumably, you recognize the value for source control, especially when dealing with 'nimrods' that could unknowingly break your code. And the house rule is 'Commit Often, build often, don't break the build'. Right?

      Presumably, the team tries to make sure that someone writing critical-path code isn't *lost* for enough time to endanger the project (typ. no more than a few days), either by regular peer reviews, pairing, partial-function demos, memos detailing the design-so-far, regular commits or whatever else works. Right?

      Presumably, you are comfortable with various design/code cycles, even if your favorite is [waterfall|objects|XP|whatever]. And whatever the boss recommends, you find a way to honor the letter of their desire while staying as true as possible to the spirit of your preferred methodology? Right?

      Presumably, you keep current in your field. Maybe you read a few books, subscribe to and read a few mags, putter with a new language or OS, learn a new tool every once in a while. When you see something cool, you share the discovery with coworkers. When a coworker does something cool, you're not too proud to say 'howdyoudodat?'... Right?

      Presumably, you (try to) respect your peers. Or at least seek/recognize what strengths they have. Right? Even the village idiot can be useful, after all. Personally, I always try to populate that peer group with people it is easy to respect, so the job isn't so tough.

      And, to steal a line from McCarthy, do you avoid flippin' the bozo bit too quickly. Right?

      When some clueless coworker comes to you and rags about some coding habit of yours that they hate, you eventually calm down enough to figure out a compromise point. Right?

      I joined a team that used hungarian notation in object-oriented code. I adapted, but showed the team articles that showed how this was a risk. Ultimately, I realized the anti-hungarian research didn't fit a unique case we were up against, where 3 data hierarchies overlapped enough that the hungarian info helped avoid hard-to-debug misunderstandings and mistakes. But the other coders got rid of hungarian fever with respect to iThis and bThat and lpctstlHolyCrapIReallySawThisOnce. Likewise, it took me ages to convince a *much-wiser* coder that his code was worse if he used punny/cute variable names (WizardOfOz, SuperFreak, Smoother, MyWayOrD).

      We all have a bit of these habits, but serious primadonnas, persistently-negative people, dinosaurs, lone-wolfs, unacknowledged visionaries, and pyromaniacs can utterly fsck up a project. When I was assigned to lead a dysfunctional team, I initially spent almost half my time trying to undo all sorts of ugly team dynamics. I'm not alone in thinking that it is more productive to shunt anyone (even the most brilliant coder) into non-critical-path (or out the door) than to let a whole team fail because of 'em. FWIW, second place goes to recognizing and rewarding people that are very valuable, without resorting to lame tricks or metrics.

      Back to TFA, coding conventions can be as simple as a 1-pp doc we called our 'zen of coding', that mentioned habits and team-agreed conventions we'd keep in mind as a group. Or they can be as anal as a friend's workflow policy for altering code for some piece of weaponry (cruise missiles?), where a few dozen lines of code per year per programmer is a tolerable average. His life is 5 parts design, 5 parts design review, 1 tiny part code, 10 parts test, 5 parts peer review, followed by another

    5. Re:Good way to get rid of your best staff... by MikeBabcock · · Score: 1

      If you're my best programmer, but you can't be a team player, you're no use to me in the team.

      You'll retire, your code will be unmaintainable, and I'll be unhappy.

      I've got a lot of code to maintain that was written by a partner at our company who is no longer here, and his coding style was completely different from everyone else.

      Sure, he wrote fast working code, but its been a couple years now and we still find things we don't understand in what he did.

      --
      - Michael T. Babcock (Yes, I blog)
    6. Re:Good way to get rid of your best staff... by RKBA · · Score: 1

      Gads, you all sound like the same sort of management jerks that would expect their staff to submit to the degradation of drug testing. Do you?

    7. Re:Good way to get rid of your best staff... by RKBA · · Score: 1
      ... never worked on a well run large collaborative project,...

      I don't know about the "well run" part ;-), but is there a mandatory coding style for OSS, such as Linux for example? I don't object to guidelines in general, but I do object to mandatory so called "guidelines."

    8. Re:Good way to get rid of your best staff... by ediron2 · · Score: 1

      Yeah, I always loved those places. I mean it is a stretch to expect this out of people that operate crushers, cranes or other heavy/dangerous equipment, but what the hell sort of damage can I possibly wreak by being buzzed while coding.

      Heck, I can remember some remarkably productive marathon code-weekends spent with a keg of homebrew gradually pouring past my palate, back in college. I've never gone back to verify the code quality, but at the time I determined that a very very mild buzz did wonders for my concentration...

  161. Write read-only comments by Symbiot · · Score: 1

    Avoid writing any comments that have to be changed when the code changes. Act as if the people who will maintain the code will never update the comments. It's not that they never will, if they're any good at all they always will, but in a lot of environments it doesn't. Comments that have to be changed with the code make the code harder to maintain because of the volume of change that has to be made. They make changes more error prone for the same reason -- the bigger the change the bigger the chance that something will go wrong. Furthermore your compiler will never complain when the comments aren't updated and faulty comments will never cause a test to fail.

    Source code can be very expressive and that expressive power ought to be leveraged to its maximum extent before being augmented by comments. At that point it should be augmented by comments, but those comments should be all about things that can't be expressed in the code like exactly where I can go to read about the algorithm you are using (title, author, revision, page number, URL -- be specific), implicit preconditions, class comments describing their single responsibility, non-obvious side-effects, the reason for some complicated piece of code (only when the code itself really can't be made simple -- like for a profiler driven optimization for instance), your email address. Anything that I as a maintainer could possibly need to know that I can't find out by studying the code should be in a comment somewhere. And nothing else should be. The information that can only go into a commment is too valuable to be obfuscated by other gratuitous comments.

  162. Domain Driven Design by Symbiot · · Score: 3, Informative

    If you want code that can be readily understood you need something other than coding conventions. Coding conventions only make the code all look the same. You can get almost all of the benefit (without most of the arguments) by saying only that each file must be written with the same coding convention throughout. The code will get prettier and prettier with tighter conventions and developers will waste less time reformatting each others code. But it won't do a thing to make your project more understandable.

    For that you need an understandable design and the best advice I've ever seen for that is in Eric Evens' "Domain Driven Design" http://domaindrivendesign.org/. The advice there will work for both Agile and non-Agile projects and its core themes are pretty much unavoidable truths about how to write code for a project that is also written about the project: use language that comes from the projects domain, insulate code from each domain or sub-domain from the rest of the world, keep each method at the same level of abstraction (that's big) and make implicit concepts explicit, to name a few. The key is for your developers to consider themselves to be authors and to strive to keep each little piece of code they write on-topic. Not only will it be easier for new developers to come up to speed but the code will work a heck of a lot better too.

  163. environment by SebNukem · · Score: 1

    People here seem to focus on coding rules but in my experience developers don't follow coding rules. The better the developer, the less likely he/she will follow coding rules. IMO what's more important than coding rules is the environment. I would first standardize compilers, tools and OS between all developers.

  164. Re:Comments lie by mabinogi · · Score: 2, Insightful

    That depends on what you expect it to tell you.

    Comments can lie, and code never lies about what it does, but code doesn't tell you anything at all about what the author intended it to do. The comments are more likely to give you a hint, and at the very least if the comments and the code agree, you can probably be sure it's right. When the comments and the code disagree then you know that at least one of them is wrong.

    --
    Advanced users are users too!
  165. Our process by I+Like+Pudding · · Score: 2, Funny

    If it compiles, ship it. If it doesn't compile, ship it. If the users complain, ignore them (they are always complaining). If the users complain moreso than normal, work all day and night and fight with QA and the admins and the VPs to get a patch in.

    Repeat until app becomes unmaintainable. Repeat furthur. Repeat.

    I will be giving seminars on how to implement Sisyphusian Unified Process throughout the year down at the bar. If I happen to be unconcious, please leave me be - that's my "comp time".

  166. Use automatic code formatters by mophab · · Score: 2, Insightful

    Use indent for C and C++
    And Jalopy for Java.
    Formatters are available for most languages.
    Decide on what all of the options are for each formatter and make
    a script available that runs the formatter with the appropriate options.

    Require that automated formatters be run before code is checked in.

    It is easier to read consistant formatting than your favorite formatting.

  167. Comment Usually Fail by Bellum+Aeternus · · Score: 1
    Commented code is great on day one - but after even a few days of update / compile / test / tweak the comment become out of sync with the actual code. The best practice is easy to read code that use human readable variable/method/class/object names.

    Also, I find that hungarian notiation, while sucking to write, is very easy to read.

    --
    - I voted for Nintendo and against Bush
  168. Three Things a Liar Make... by Lord+of+the+Fries · · Score: 1

    Statistics, Politics, and Code Comments

    --
    One man's pink plane is another man's blue plane.
  169. Four Ideas by dj+e-rock · · Score: 1

    1) don't code before you have to
    2) draw pictures
    3) consider extreme cases
    4) only use the data you have

    Of course, there are plenty of other practices, but those are some good ones to start with, especially if you have relatively new folks.

  170. Software engineering standards by kumashish · · Score: 1

    How about striving for a CMM Level for the IP department of your company. That will actually put you on course for a streamlined process.

  171. Coding standards won't help by blair1q · · Score: 1

    Coding standards won't help.

    DESIGN standards are what you need.

    Just hand out a blessed indent(1) configuration and get on with making sure people design and implement understandable software instead of spazzing about indents and brackets.

  172. Good coding practices by superspaz · · Score: 1

    Besides commenting code, running a code review (comments included) on every change to the code is key to maintaining quality and keeps people more up to date on changes. Implicit in this is using a decent versioning system and having a set of standard practices.

    If code has a consistant style and format, it is far easier to read. Also, forcing a team of coders to regularly "eat their own dog food" cuts down on hack and cruft and encourages good code housekeeping.

  173. Eliminate duplication by russh347 · · Score: 1

    Don't allow pillage and paste coding. Duplicated code should be refactored.

  174. there's a lot more to projects than coding by Cally · · Score: 1
    Off topic, cos you specifically said you're only looking at coding standards at present, but of course you know/realise that there's a lot more to a project development methodology than coding standards. It's a tough line to walk though, my one bit of advice would be 'allow for people to be fallible human beings" - make your processes be robust in the event of other stages failing,or duplicating activities, going off on their own direction for a while, getting blocked for ages etc.

    bon chance

    --
    "None are more hopelessly enslaved than those who falsely believe they are free." -- Goethe
  175. Coding standards by Todd+Knarr · · Score: 4, Funny

    As someone with 20+ years of professional programming under my belt, a lot of it doing maintenance and enhancement of existing code, I'll say this: most of what's considered "coding standards" doesn't much matter. Indentation, brace positioning, type prefixes on variables, underlines vs. StudlyCaps, capitalization in general, most competent programmers can pick up on any variation quickly. The few things that count are more general:

    1. Comment logic and motivation, not the code itself. I can figure out what the code's doing. What I need coming into it's what it's supposed to be doing, why the code does things the way it does, what the data structures are supposed to represent and how they're supposed to be used. On routines, tell me what the routine's supposed to accomplish, what arguments it takes in and what results it spits out (including error conditions).
    2. Make variable names descriptive. Abbreviate where it makes sense, but make the name give me an idea of what it's for. It's less important that I know it's a string than that I know it's the last name of the customer whose order you're processing. And if all it's for is the index in a loop and it's got no meaning outside of the loop, then yes i and j are perfectly legitimate names that any programmer will (or should, at least) recognize.
    3. Programmers should try to use consistent indentation, brace alignment and other formatting things when writing new code, and should try to match the existing formatting when modifying code. Emacs and other modern editors can do automatic indentation and pretty-printing for you, make use of those features and make it easy for programmers to set their editors up to match commonly-used styles. And make them clean up garbage, things like trailing whitespace and irregular alignment are disproportionate pains. I don't care much what the tab interval is, but I hate it when the interval changes every few lines.
    4. Use whitespace for readability. Code like if(strlen(obj.getname())" is legal, but it's a lot harder to read than "if ( strlen( obj.getname() ) ". It also makes it easier to distinguish functions ("f(x)") from control structures ("if ( x )"). Similarly, putting the opening brace of a loop or conditional on the end of the line may be compact, but it makes it hard to distinguish the start of a multi-line body from a single-line body followed by some lines with the wrong indentation.
    5. A few small formatting things are overall useful. Symbolic constants should be immediately recognizable as such and all-caps is a commonly-recognized way of doing that, for example. And the indentation level of the code should match the logical level, that is the "then" and "else" bodies of an if statement should be indented further than the "if" and "else" keywords (which should both be indented at the same level).
  176. [Resolved: By Design] Re:Good way to get rid of... by Captain+Entendre · · Score: 1
    So what happens on a team with a couple dozen people like you? Does everybody maintain rigorous ownership of "their code" so it stays in "their style?" Or do you let responsibilities overlap and just let the coding style vary at random?

    We all have better things to do than make sure we use "var=value" here and "var = value" there. That's just overhead. The nature of the standard doesn't really matter - even hungarian is perfectly readable once you get used to it. But committing to a project-wide standard gives everybody a lot less bother in the end. Except for people like you I guess.

    I've never met someone like you in the 15 years I've been in this business. Maybe that's because I wouldn't work for a company that indulged egos like yours.

  177. I'll second that by Anonymous Coward · · Score: 0

    I think that you should ask yourself if you only want to enforce coding standards so that you could feel more "in control" of things.

    Especially if you are yourself a non-coder, this might make the coders feel like you want to boss them around instead of listening to them. It might very well be that they themselves have excellent suggestions on how to improve the things overall. They might also wish that you could forward these to upper management.

  178. introduce yourself by Anonymous Coward · · Score: 0

    to books like Bob Martin's Agile programming. It presents few hints from real-life experiences, test-driven programming, refactoring code etc. It also introduces rules of thumb to avoid pitfalls from code to uml-design by experiences from real-life projects.

  179. Dont re-invent the wheel by Neeth · · Score: 0

    Use what you and others have made before; code as if you'll be using it again later.

    --
    Yes, I am the one with the legendary sig.
  180. Re:Comments lie by lordrhett · · Score: 1

    If the comments disagree with the code, they are both wrong.

  181. As much a social/managerial issue as a tech one by crucini · · Score: 2, Insightful
    First of all, how many developers do you have? Few enough to fit in a conference room? How many languages? Do all the developers know all the languages, or are they fragmented into language communities?

    The first step is to assess the current situation - what coding practices are currently in use? What do the developers want? Can you roughly group the existing codebase into various standards, plus a pile of incoherent crap? Is it worth while rewriting the crap portion to the new standards?

    Second, decide what level of standardization you want to achieve. The more detailed your standards, the more difficult and risky. You will probably make some wrong decisions, and they will irritate developers now or in the future. However, if all your developers code in the same language, and several of you are experts, you may be able to write detailed standards and get it right.

    Third, identify relevant references. If you're working with Perl, Damian Conway's Perl Best Practices is a good choice. In C++, Meyers' Effective C++ series is good.

    In general, micro-standards will not be successful. Instead of trying to make everyone use the same indentation or something, you'll get the most bang for the buck by focusing on high level issues. For example:
    1. Require at least one Wiki page for each piece of software; in addition to any docs on how to use the software, this is a page on how the software works internally.
    2. Keep code units to a reasonable size, with a clear interface. Reduces chaos, and lets you rewrite one unit from scratch if it's written horribly.
    3. Require a peer code review of each code unit. Persuade the reviewers to read the code before the meeting so you get more than off-the-cuff comments. Experienced programmers may disagree about indentation, but they generally agree about things that really shouldn't be in your code. Comments from these reviews may crystallize into a de facto standard.

    Good luck.
    1. Re:As much a social/managerial issue as a tech one by zettabyte · · Score: 1

      Thought I'd throw in my buck-o-five on code reviews.

      In my experience, the most successful code reviews I've been involved in have worked as follows:

      The reviewee creates a 'task branch' in source control where they do all the work for this 'unit', say a use case or a portion of a use case. They check their changes into this task branch.

      When they are done with their unit of work, the reviewer(s) is notified (email works fine) that a task branch is ready for review.

      The reviewer(s) pull down the task branch to be reviewed, and proceed to add '// REVIEW' comments to the code, where necessary.

      e.g., // REVIEW [dvh] Try using recursion here instead of nested fors...

      The reviewed code is checked back into the branch. The original author goes about addressing the issues uncovered by the reviewer(s). Once finished, the branch is merged with the head.

      Depending on the reviewee and your level of paranoia, you can repeat this process before merging to the head, if you don't trust the reviewee to do the work properly. But if you don't trust them, why were they hired in the first place?

      I'm not the originator of this idea, but I think it works pretty darn well.

  182. I can understand anything by oo_waratah · · Score: 1

    DOes that mean that I have to accept the crap that some people put forward as code.

    Standards should at least set a minimum. meaningful comments, code that is structured, etc.

    MOst good programmers think this is common sense, well it is.

  183. C++ coding style by HighPerformanceCoder · · Score: 2, Interesting

    Mostly these threads focus on comments and naming conventions. One of the most important coding styles I've adhered to for the last decade is to always encapsulate new and delete within a class. This ensures every new has a corresponding delete called when the class's destructor is called. Use C++ automatic variable declarations to control object lifetimes.
    The only time I've had a memory leak in the last 10 years was when I had to break this coding standard (eg for library compatibility).

    The second most important coding style is to use pointers only when necessary - some graph algorithms need them, and so do some "legacy" C libraries. Otherwise, use references - there in the language for that purpose.

    The 3rd most important coding style is use standard library container syntax whereever it makes sense. Even if you write your own container libraries - follow standard library conventions. Makes it much easier for other coders to follow.

    After this follow a bunch of useful stuff - eg ensure that meaningful default, copy constructors and assignments are available for your class, use the const keyword wherever it makes sense

    On the subject of naming conventions - naming conventions can lie! Tools like doxygen will quickly tell you what a particular indentifier refers to in a particular context. If not, then grep is pretty handy at working it out. However, often one wants to use the same name for type names and instance names - a convention like first letter upper case for typenames, or appended _t can help the addled brain.

    Throw open a question now - any good tips for organising namespace names, and macro names to avoid the inevitable clashes?

  184. Code cleanly and remove comment by oo_waratah · · Score: 4, Insightful

    replace a stupid name with a sensible name:

          messages_processed++;

    This actually makes sense without the comment.

    1. Re:Code cleanly and remove comment by rkww · · Score: 3, Insightful
      replace a stupid name with a sensible name:
      messages_processed++;
      That's still got potential for confusion - it could be a 'we've finished processing the messages' flag, which obviously should be a boolean, but somebody else wrote the code, so we can't be sure.

      totalMessages++;
      would be better, but it's still not perfect. Sometimes the hardest part of programming is creating meaningful variable names.
    2. Re:Code cleanly and remove comment by amightywind · · Score: 0, Troll
      totalMessages++;

      would be better, but it's still not perfect. Sometimes the hardest part of programming is creating meaningful variable names.

      Arguing about proper names for counters is good example of getting bogged down unnecessarily in trivialities. Personally I find your use of camel case offensive. Also your use of the post increment operator is in bad form. ++message_count is much better. You must be a Java programmer.

      --
      an ill wind that blows no good
    3. Re:Code cleanly and remove comment by An+Onerous+Coward · · Score: 1

      Proper variable names aren't "unnecessary trivialities". My opinion is, if you can't come up with a meaningful and intuitive name for a variable or a function, it's usually because you don't have a clear grasp of what it is you're trying to get the code to accomplish.

      Now, camel case versus underscores... that's trivial. So long as your code is consistent about it (lately I've been using underscores for variables and camel notation for function and class names) do it whichever way you like.

      --

      You want the truthiness? You can't handle the truthiness!

    4. Re:Code cleanly and remove comment by Tattva · · Score: 1

      Or refactor to a method: ...
      MessageReceived() ...
      }

      void MessageRecieved()
      {
          m_totalMessages += 1;
      }

      --
      personal attacks hurt, especially when deserved
    5. Re:Code cleanly and remove comment by Tattva · · Score: 1

      Hmmm, why not refactor to a class?

      class MessageListener
      {
      private:
          int m_totalMessages;
      public:
          void ReceiveMessage()
          {
                m_totalMessages += 1;
          }
      };

      --
      personal attacks hurt, especially when deserved
    6. Re:Code cleanly and remove comment by Anonymous Coward · · Score: 3, Funny

      Or you could turn it into a Web Service.

    7. Re:Code cleanly and remove comment by maxwell+demon · · Score: 1

      If messages_processed is a relatively good name, totalMessages is a misleading name: The variable doesn't count all messages, but only those which were processed. totalMessagesProcessed (or total_messages_processed) would be a better name. So would be messages_processed_counter, numofMessagesProcessed or cnt_msg_processed.

      --
      The Tao of math: The numbers you can count are not the real numbers.
  185. emacs (vi) by tal_mud · · Score: 1

    The most important standard to enforce strictly is that everyone should use emacs (vi) and absolutely shun using vi (emacs).

  186. Be picky about what you cover by try_anything · · Score: 2, Interesting

    There are three categories of standards:

    1) First, there are arbitrary choices where uniformity across the company is more important than having a perfect fit for each project.

    A perfect example is the choice of information management tools and formats. Unlike an indentation style, a source control or bug database learning curve can be a significant barrier to a developer helping out another team for a few days. It's also important to ease access for non-development personnel. Pick some tools and make everyone use them.

    "Every project shall use Subversion as its source control system, BugZilla as its bug tracking system, and DocBook for user documentation."

    Depending on the size of your company, the choice of a unit test framework or a build tool might be standardized. Keep in mind the benefit of diversity in these matters, though.

    2) Second, there are matters of practice that can be fairly unambiguously stated and checked.

    A few examples:

    "Every project shall version its acceptance tests."
    "Every project shall archive acceptance tests and test results for every software release."
    "Every project shall publish a current schedule, updated daily, and a summary of outstanding defects, updated at least weekly, to the IT intranet."
    "Every project shall maintain a system of peer review, so that all code must pass by a second pair of eyes within a week of being committed."
    "Every project shall automatically generate API documentation."

    3) Third, there are matters that may be important but shouldn't be included in your standards.

    There are two good reasons for being so picky. First, you want your standards to be as short as possible so people actually read them. Second, you don't want to publish standards that you can't or shouldn't enforce.

    An example of a good coding rule that doesn't fall into the first two categories is "Document intent, not mechanics." Everyone should do it, but checking and enforcement should be done among project teammates, not by a higher level of management.

    Another example is "Test everything that can break." The extent of test coverage can only be determined by people actually working on the project, so you can't enforce this rule. It's a great rule, but it doesn't belong in your standards.

    Since so much attention has been paid in other posts to matters of code formatting, I might as well add my two cents. For languages where there is One True Way, such as Java and Python, there's no good reason to deviate from the One True Way. Is it really your job to point out and enforce the obvious? I don't think so. Let the project managers handle it.

    For other languages, such as C++, there are a variety of accepted styles. Uniformity is good, and every project should certainly pick a style and use it consistently. Whether to pick a uniform style for the company is a judgment call. Professional C++ programmers are used to dealing with variety and shouldn't have problems switching when they jump from project to project. For your company the right rule for dealing with C++ projects may be this:

    "Every project that uses C++ shall adopt and publish a uniform brace and indentation style."

    Or it may be this:

    "All C++ code shall be formatted as in The C++ Programming Language, Special Edition."

    A final note: Be firm about setting standards, but talk to people first and don't issue any orders that you don't have the muscle to enforce. Find out what people's prejudices are and eagerly defer to them when it doesn't make much difference. Migrating CVS users to Subversion should be no big deal, but if a bunch of stubborn CVS users refuse to migrate, and you fail to make them, all the rest of your standards will go out the window as well. If your authority is shaky, the best way to shore it up is to avoid controversy and issue a bunch of commands that nobody minds obeying ;-)

  187. Re:Comments lie by Yeep · · Score: 1

    Actually, code can also lie with all he optimization the compilers do nowaydays.
    So: comments lie, code sometimes lie, disassembly never lies.

  188. Industrial Strength C++ by Echemus · · Score: 1

    In my previous position we drafted a coding standard based on the recomdendations on this book, then we had a peer review with several of the senior developers changing the rules and recomendations. (I personally disagree with some of the unqualified statements made in the book - then again, for every rule there is always going to be an exception)

    It really annoys me where I work now, where developers have a bit of a freedom on naming conventions on variables - you want to access a member of the structure, you know it is called "Memory ID" - you have no idea whether it is actually spelt m_memoryId, m_MemoryID, memoryID, MemoryID, all of which are used in the (large) code base.

    The thing is though, there is no way of correcting these problems - it is not really possible to go back and re-write code based on the new coding standards, only new things that are created can really be expected to adhear to the coding standard.

    If you are dealing with a large legacy code base (as I am now) there is not much hope for change, sadly. The developers will resist changing from their own style of coding as that is what they are most comfortable with.

  189. regarding best practices by utnapistim · · Score: 1

    We had to maintain a big repository of C and C++ code that was cross-platform; that meant that you opened the same file with visual studio and it looked ok, changed a like and when you opened it under solaris the indentation got all wrong because VS inserted tabs instead of spaces.

    One of our rules was to set all editors to put 4 spaces for tab length and never use tabs.

    Make sure naming conventions are allways followed. The best way to do this is to have an approver/reviewer of all changes (we had senior developers do that).

    If using hungarian notation use the Apps Hungarian notation instead of the Systems notation. The reason for this is that while systems documents code functionality Apps documents code purpose. And make sure to have your coding conventions well documented and used consistently.

    Make sure to fix changes where code is wrong and where feasible, don't use work-arounds. When using workarounds the project becomes un-maintainable and developers get to hate it. Also, never leave in code blocks that never get executed; We have an old project around here that is full of code like:
    if(0)
    do_something
    else
    do_something

    It's a nightmare to maintain: you have to go through lots of useless garbage because some nameless programmer in the past was affraid of deleting the wrong code.

    Make a practice of enforcing the rules: i've seen an office where the people breaking the build had to buy the team some snacks the next day :).

    Forbid spagetti code constructs (like goto) and enforce consistency of look and feel (for example we had all if statements being followed by braces even when there was a single statement under it, and all 'case's in a switch had to have a break statement).

    Make sure every change is well documented and as speciffically as possible; create a standard for documenting changes in your version control system that should describe the purpose of the change and the contents of the change; For example:

    Purpose: fix defect ID12345

    Description: Added new function int Foo(int); centralized ID length to local constant ID_LENGTH;

    Make sure every change is clean: If you diff two revisions of the same file with any file diffs utility you should be able to see only the semantically different code; Like this it's easy to follow when the code causing you problems was added and for what purpose. This is a dream come true when maintaining code: then you can see what defect/enhancement it was introduced for and you can follow that by ID to some external documentation.

    Enforce refactoring: If a change requires the same two lines of code used elsewhere add a new function for them.

    --
    Tie two birds together: although they have four wings, they cannot fly. (The blind man)
  190. Re:Comments lie by bullgod · · Score: 3, Insightful
    But code can only tell you the how it can never tell you the why. That's usually more important
    I once came across a ~1400 line function of complex maths transformations with one comment

    i++ /* increment i */

    What's i? and more importantly why increment it?

  191. use meaningful variable name by oliderid · · Score: 1


    A lot of time you try to figure out what the variable is supposed to deal with:

    For example;
    int d=0;

    means nothing but:

    int gross_sales_cents=0;

    can help you to understand its purpose and avoid any useless comment.

    Use heavily javadoc and the like.

    Object should have common method's name too.
    For example, when you have to stop a runnable object, I've seen to many stupid stuff like object.stop_whatever() instead of a simple object.stop(). So you don't have to think about the correct method you have to use.

    Olivier

  192. Keep standards at a minimum by jandersen · · Score: 1

    1. Realize from the beginning that standards have to change regularly in order to fit the needs.

    2. Allow people to decide for themselves what is the best way to code. Define a small set of minimum requirements, but keep it simple and easily achievable. Comments are good - but it is better to take the time to write proper code:

        a. Proper code is well indented.

        b. Proper code is simple - this means small functions, no macros and short symbol names.

        c. Proper code is well abstracted: this is often the most difficult part of coding. Abstraction means that the code solves a whole class of problems rather than just one. Well abstracted means that it is not taken too far; there has to be a balance.

        d. Proper code is easy to maintain.

    3. Provide the proper tools - that is: tools, not toys. Some people will want an IDE like Visual C++, others prefer vi and make. Make sure the entire production system and the standards allow for this. For version control, use something that has both a CLI and a GUI etc etc.

  193. Nearly as useless by samael · · Score: 1

    Can I asked why you called your counter "counter"?

    If your code read

    processedMessageCounter++;

    in the first place, then the code itself would tell you what it was doing. That way there's no way you can update the code and forget to update the comments, because the code itself _is_ the comments...

  194. Use named constants, not bare constants by Jeremy+Singer · · Score: 1

    Use named constants so we can understand what you are doing without a comment.
    If you have a lot of constants that are related, encapsulate them statically in a class (if you are using an object oriented language) or in an include file.
    For every method, function, or procedure make a comment header describing what it does and what the parameters and return values should be.
    Keep line length shorter than 80 characters so human beings can read it without scrolling left and right.
    Use white space within the line to improve readability.
    Match braces vertically like this when indenting:
    {
          {
          }
    }

    so that you can match braces easily with a straight edge (even though your editor can help, you might need to do this on a printout.)
    Keep code blocks less than 1 page in size.

  195. The REALLY critical parts by Eivind+Eklund · · Score: 1
    1. Revision control, including full description of each commit, and including all relevant files (yes, config files too.) Have people review their own diffs before they commit them. I use CVS (though Subversion is probably better, and darcs/arch/git/etc even better than that.)
    2. Bug tracker of some kind. The goal is to keep this comletely clean. RT3 works.
    3. A reviewing code nazi, nagging about code style for each thing that's committed to the version control repository until the style is in sync.
    4. A standardized install that installs everything: No manual tweaking, no manual installs.

    While I love unit tests etc, I think the above are the most critical parts. I also like setting up a Wiki and logging what people actually do when they do repeated tasks. These are second to the above, though.

    Eivind.

    --
    Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
    1. Re:The REALLY critical parts by gedhrel · · Score: 1

      Agreed; fetch/build/deploy as one-click or one-command operations are (usually, certainly here) a fundamental requirement before worrying about unit testing: because if the programmer can't do the former, then they're unlikely to be able to simply and trivially run their unit tests, either.

  196. Comments standards by Anonymous Coward · · Score: 0
  197. THE BEST PROCESS!!!!! by Anonymous Coward · · Score: 0

    Just pay hommage (And large amounts of dough) to Watts Humphreys and SEI and use PSP/TSP.
    Then watch how fast your projects go nowhere! :)

  198. Do not waste time worrying about coding standards by gedhrel · · Score: 1

    That rathole is a luxury you cannot afford yet. "Coding standards" are something that it's hard to enforce without a relatively uniform environment in the first place, and lots of things will get in the way of programmers adhering to these.

    So, your principle goals should be to create uniformity in the development and deployment environments. That means build engineering and software layout, automation, etc. It doesn't necessarily mean mandating a particular IDE or toolset (although that can help) - it _does_ mean getting your infrastructure in place so that a programmer can shift to a project, get hold of the code, build and deploy to a test environment (their workstation or a testing box), look at the check-in history, look at the bug and feature lists, and so on. And they should be able to produce software that's laid out in a way that "just another project" can be deployed much like any other, wherever possible.

    If you manage that, then worry about the coding standards!

    As to this: a decent set of stock tools will help getting a programmer up to speed far better than coding practices which might not be adhered to. So, make it easy to test and check in code that works. Make it easy to run tests. Find a decent code comprehension tool and give your developers training with it. Find the most popular IDE and automate project layout and deployment in that IDE. Ensure that programmers can ask "what broke?", "what changed?" and fire up a debugger against different versions with minimal hassle. Keep your sysadmins happy, and ensure that these processes are scriptable.

    Above all, involve the developers. Consult! Find out what tools they use, what they're lacking. Organise a regular informal technical get-together where people can show off tools; it's the best way of developing a consistent practice, and "consistency" is a key factor in local "best practice". Find your champions. Finally, don't be afraid to invest in developer training with the new tools.

    Always measure the areas that your are about to address by some simple yardsticks: estimate the effort, the cost, the benefit, the likely takeup, the risks. Is it worth it?

  199. Systems Hungarian by VGPowerlord · · Score: 1
    Avoid Systems Hungarian Notation at all cost.

    Surprisingly, Wikipedia talks about the difference between Systems Hungarian and Apps Hungarian... each one being named after the division of Microsoft that primarily used it.

    The difference between them boiled down to a misunderstanding by the Systems team as to what the author of Hungarian Notation actually meant.

    An issue that sometimes gets skipped is brace style. Some people prefer the "one true brace" method, where things look like this (pretend the code is indented properly):

    if (this < that)
    {
    some code;
    }
    else
    {
    some other code;
    }
    and some people prefer opening braces on the same line, like this:
    if (this < that) {
    some code;
    } else {
    some other code;
    }
    Having one style for braces makes it easier to follow.
    --
    GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
  200. Don't change anything by juergen · · Score: 1

    So your company is developing software for 35 years now. They must be doing it right.

    Dont't ruin it just to save a couple of hours here and there, and to appease some bean counters with fancy reports about hours saved, and projects bungled in the process. Find out how they have worked in the past, and maybe try to improve slightly once you absolutely understand it, but do not just put down standards. It will only hurt.

    Don't change a working system.

  201. Re:Do not waste time worrying about coding standar by gedhrel · · Score: 1

    ps. Yes, we do this here: this isn't theoretical. Yes, decent build engineering takes time and talent. Programmer management takes other, political skills. It's hard work but absolutely worth it for our environment.

  202. Diagrams and Models by TarikJax · · Score: 0

    Has anyone mentioned modelling yet? If a system has been planned and designed with UML or a similar modelling tool before coding it makes it much easier for someone to jump in and start work on a particular module. Reading code is painful. The more you can explain how your code works with simple diagrams and pseudoc-code the easier it will be for people to relate the actual code to the purpose it is intended for.

  203. The simple things. by Delta · · Score: 1

    It's not all about getting the developers to use the same code formatting and indenting. Often it's in the simple things you can think up to solve spesific problems.

    Good things to consider could be small, easy and quick things, like creating a small text document detailing the structure of the source directories.

    And if you're not already doing it, by all means use a source revision control system. Not only do you get the revision controls, the advantage of more easily being able to have multiple developers working on the same source set, but you get the advantage of making it easier to keep an eye on what's going on with a project.

    Both of these things will lead to quicker returns, for a lot less work, than changing the developers coding habits.

    --
    Terje Elde
  204. Re:[Resolved: By Design] Re:Good way to get rid of by RKBA · · Score: 1

    Wimp.

  205. Small functions and few local variables by anandsr · · Score: 1

    I just love Linus's Style guide where he says that the functions should be small with large tabs (8 char),
    and the function should have less than 7 variables.

    I think this is the holy grail. All these three are so intermingled that if you follow all these you will
    realize how much it improves your code.

    If you use large tabs you cannot do too many nestings forcing you to break the function. If you have too
    many variables your function must be very complex or else you must use a structure. This also foces you
    to break up a function. This forces you to define new functions.

    If you have few local variables then you don't need descriptive names for local variables.

    I have found this set of advice to be the most important coding style requirement.

  206. Blog about it! by thepeterbe · · Score: 1

    We don't have any standards at my company, but we're small. We've tried all sorts of documentation systems such as wikis, READMEs, CVS comments, bug tracker and nothing has worked as well as blogging about it. It's not really a standard (answer to your question) but if you skip the strict rules of standards and just ask production people to blog about it, then you'll easily build up a wealth of information that is sort- and searchable to help anybody get involved in a project. For bug tracking we use issuetrackerproduct which is great too for making sure the communication between various parts (client and production team) happens in a consistent standardised manner.

  207. The beauty of slashdot :) by KZigurs · · Score: 2, Insightful

    Aaah, what a beauty. The real questions that should concern this are more in lines of the following:
    - What is a development envorement?
    - What is QA?
    - How can I test code before putting it on production?
    - How can I plan for and track team progress in development?
    - What kind of documentation will I need?
    - What is a process?
    - How do you declare/manage process?
    - Who is responsible for builds, who writes specs?
    - Do we have separate QA team?
    - Is there any testcases?
    (silly, I know, but shows the scope of his position a bit)

    YET we have 300 comments + discussion of using or not using hungarian notation in naming variables.

    Perrfect! :)

  208. Coding standards by Handyman · · Score: 2, Informative

    Here's what I like:

    1. As for code comments, rely on "Use The Source, Luke" as much as possible. Force people to write readable code, so that this actually works. Logical variable names, no unnamed magic numbers, no cryptic constructs. No loop bodies consisting of only a semicolon, e.g. "for(...;...;...);". Comment only on the things that aren't obvious. Any extraneous comments are bound to be outdated by the code, and will confuse more than help.

    2. Write down the design in comments in the source files, as a readable piece of prose containing all of the design considerations and decisions. Design of an algorithm goes in the function body, design of a class goes above the class definition. Programmers are aware that designs are often outdated, so when they read them this is not a problem. Having the design in the code has the advantage that you can actually *find* the design for the code you're looking at. There have been too many times where I've been looking for a design document that was "somewhere on the network". Or that I've been looking at a design document on the network that had been superseded three years ago. Having your design under source control fixes that.

    3. Build at least every day, or even better: continuously.

    4. Automated testing. Run automated tests on every build, if possible.

    5. Code reviews. Sit together once a week with one other team member who then reviews all your code for the last week (all of it, based on reports from source control). That shouldn't cost more than an hour or something, it's a good way of keeping the knowledge going around, it works as a very good "desensitization therapy" for those programmers who can't handle criticism, it increases communication within the team because people get to understand each other's work better. The only downside is that there is usually a lot of opposition against this -- I know a *lot* of programmers who don't like to have their code criticized. And there's a very clear risk that people will get into endless discussions about very small details of style ("should there be a space between the if and the parenthesis?") or other inconsequential things. To prevent these issues hogging the review, there should be a formal "escalation procedure", where the issue is passed on to an arbiter (team lead) with arguments from both parties. If a disucssion on an issue seems to go in this direction, either party *or* somebody else in the room whom the discussion irritates the hell out of should be able to cut off the discussion and "escalate" it. :) The team lead can then decide on a policy, e.g. "there will be no discussion on this point, everybody can do it how he/she pleases", "everybody will do it *this* way", something like that.

    Note that I'm currently working in an environment where we have (1) to (4) implemented. I'd like to have (5), because there is too many crap code being committed, and there's no check on that. It's been all too often that we've had to replace the *entire* work of a team member after he/she left, because the team member had been able to commit crap code without check during all the time (s)he was on the team.

  209. The best coding practice, stop coding! by cabazorro · · Score: 1

    I would expect developers to spend less than 20% of the time coding because the should be busy doing:
    Requirement Analysis.
    Design.
    Requriment reviews.
    Design reviews.
    Test Plans.
    Testing.
    Requirment-Design-Code-Bug tracking.

    Thus, when the time come to code, if you do all of the above right, the code part is
    not some obscure obfuscation that later on has to be reverse engineered..right?

    --
    - these are not the droids you are looking for -
    1. Re:The best coding practice, stop coding! by Wiseazz · · Score: 1

      Agreed - provided that the PHBs give you enough time for analysis, design, etc. Sadly, that's not always the case (dare I say, "rarely?")

      I'm actually on a project now where the client has agreed for two months of analysis and design. That's certaintly not the norm. Not that we don't try, but in the end you have to bow down to your customer's wishes (either external or internal corporate "customers")

      What you describe is awesome and goes a long way to ensure a project's success, but is often not a reflection of reality for most developers.

      --
      My sig sucks.
  210. Practicing, but no standards by Cyphertube · · Score: 1

    Sometimes I begin to think all we do is practice writing code. We seem to not follow standards and we tend to repeat a lot of the same functionality over and over again with different code.

    Of course, we don't practice writing documentation ever, so that might be the problem.

    Except for me.... the non-programmer who's supposed to somehow reverse-engineer documentation out of this code. Yeah.

    --
    Linux - because it doesn't leave that Steve Ballmer aftertaste.
  211. Keep it simple, make them use it. by smilindog2000 · · Score: 1

    The most important thing is to get everyone coding the same way. If you've had no structure in the past, this is extremely hard to do. No one will want to listen to you, and each programmer will feel their creative freedom has been compromised. If you can get people writing code in almost identical styles, then you'll find cooperation between them will improve greatly, easily justifying the effort. In my experience, most often these efforts fail, and you'll be the guy they blame, while also saying how dumb the whole idea was to start with.

    So, the easy thing that most people do is practically worthless: force everyone to use a complicated header over each piece of code that describes the author, purpose, I/Os, etc. This will make your bosses happy without seriously changing anybodies coding style. It's the wimp approach and does nothing to improve productivity.

    Or, you could take the hard road: force everyone to use a common coding style. For example, if you're a C++ shop, pick a set of templates (like STL, or others) and force everyone to use them. Pick a code format and make everyone use it. Do you use case or _'s to separate words in identifiers? Pick one and enforce it. It's so much easier working with code that your fingers know how to type.

    My advice is to keep the 'official' coding style simple. Many of your company's programmers will hurt their brains trying to understand aspect oriented coding. You'll be lucky if they can use abstract base classes properly. Remember that the less than average programmer will likely be in charge of your code some day. Target the coding style to help him succeed. The geniuses in your group could succeed in FORTRAN, so don't worry about them.

    As for details... there are so many coding styles, and each takes a book just to describe it. We document our data structures with entity relationship diagrams and have separate internal and external header files for modules. We all use the same collection classes. We use access functions to access fields of objects, rather than accessing them directly. We use an old CASE tool that automates memory management and generates virtual recursive desctructors for us. Every funtion has a comment, and we keep functions small. We improve quality with data structure self-tests, and an automated run of many data sets through our system each night. We use SVN. We make everyone code in EXACTLY the same way. We use capitals in identifiers, keep braces on the same line as the 'if', indent by 4 spaces, and have 50 other rules for how code should look. Sometimes we can't remember who wrote what code, and there's no way to know!

    --
    Beer is proof that God loves us, and wants us to be happy.
  212. Typo? by Anonymous Coward · · Score: 0

    Part of the problem is because we came from different backgrounds (Some delhi people...

    Was that a typo (Delphi) ?

    Or a Freudian slip? (I believe it's called New Delhi now, btw)

  213. My way... by Kjella · · Score: 1

    I'm notoriously bad at writing very long variable names and such while debugging. counter++?

    for ( ii = 0; ii < MAX; ++ii )
    {
        (code here)
    }

    and debug it through until it work and *then* I do a search & replace on the function for ii with a long variable name, e.g. "messagesProcessed". Otherwise I end up being majorly pissed at the places where I wrote "messagseProcessed" instead. That way it seems very reasonable to the next guy, wihtout going overboard on typing.

    for ( messagesProcessed = 0; messagesProcessed < MAX; ++messagesProcessed )
    {
        (code here)
    }

    --
    Live today, because you never know what tomorrow brings
    1. Re:My way... by UnknownSoldier · · Score: 1
      Even better, IMHO...
      for (iMessage = 0; iMessage < nMessage; iMessage++ ) { ... }
      or even
      iMessage = nMessage;
      while (iMessage-- > 0) { ... }
    2. Re:My way... by fdicostanzo · · Score: 1

      Its not a complete cure for errors but find an editor with completion (emacs...) and just tab complete long variables. I rarely have to enter a variable more than once or twice.

      --
      Synergies are basically awesome, and they're even better when you leverage them. -PA
  214. The Practice of Programming by orbitor · · Score: 2, Informative

    I make sure that every new technical hire to our company reads this book by Kerninghan and Pike. Then, I give them a copy of our coding standards which really just outline the syntatic sugar. If the person was bright enough to get hired, they are more than capable of understanding and applying the concepts presented to them through these two sources.

  215. Let each team decide by VaderPi · · Score: 1

    I suggest a recommended standard from the top, but it is important to give each team the flexibility to reject parts of the standard or the include things that are not part of the standard.

  216. Has Someone forgot the GNU Programming Guidelines? by url80 · · Score: 1, Informative
    From the GNU homepae: (www.gnu.org/prep/standards/standards.html)

    The GNU Coding Standards were written by Richard Stallman and other GNU Project volunteers. Their purpose is to make the GNU system clean, consistent, and easy to install. This document can also be read as a guide to writing portable, robust and reliable programs. It focuses on programs written in C, but many of the rules and principles are useful even if you write in another programming language. The rules often state reasons for writing in a certain way. Best, url80

  217. !(How to write unmaintainable code) by fbonnet · · Score: 2, Informative

    Read this thoroughly, and try to do the opposite.

  218. Wait wait..... by lucifuge31337 · · Score: 1

    ...I know I've heard this one before. I think it starts with "You find three letters from the previous manager. The first one says 'open me now'....."

    --
    Do not fold, spindle or mutilate.
  219. Cleaner hungarian based by Anonymous Coward · · Score: 0

    if (iCurKey == iLastEntry) pRec->SetKeyTag(szUsername);

    Notice how my deviation of hungarian notation never uses more than 2 characters, and I treat the record like a class (Use strncpy if you prefer). Hungarian notation has made our company code easier to manage for me because I don't have to scroll up to determine what types the variables are. However, H.N. IS NO SUBSTITUTE FOR CODE COMMENTS. H.N. isn't supposed to tell you how the gears turn; it's supposed to tell you whether you're using phillips head screws or flat head screws.

    I also don't normally read code out loud when I'm doing maintenance; I think it would upset my co-workers :)

  220. Our coding standards.... by CrazyTalk · · Score: 1

    Our companies coding standards can be described in one word - outsourcing.

  221. Limit the number of programming languages by Anonymous Coward · · Score: 0

    I think it's a good idea to limit the number of coding languages. If everyone knows Perl, and one new programmer wants to use Ruby for a few scripts, don't let them. Who is going to maintain the Ruby script?

    Of course, if you decide that from now on, Ruby will be your main scripting language, then it would be fine to start with a few random scripts here and there. Or if you decide to try Ruby on one isolated project and see how it goes, that's OK too.

    The decisions about which languages to use should be made on what's good for the business, not what's good for the programmer's resume.

  222. Re:Comments lie by Lehk228 · · Score: 2, Funny

    disassembly can lie if the operating environment or hardware is bugged (either error or with malicious code)

    the only truely trustworthy code is code hand compiled to run on a tube CPU which you have personally blown the glass and formed every tube.

    --
    Snowden and Manning are heroes.
  223. Do you think coding standards will help? by SLOGEN · · Score: 2, Interesting

    Most people who advance coding standards talk about how braces should be put and whether there should be used braces in one-line if's, maybe they even mention the horrible and feared Hungarian Notation. I have yet to find out how any of this *actually* helps understanding code.

    Readable code is a prerequisite for understandable code, education is a prerequisite for understanding.

    Coding-standards is trying to apply a method of syntax to an education-problem, it's not gonna work. Don't think that coding-standards will give you readability, much less understanding.

    My advice is to get a few people with experience, solid, broad knowledge of the language and a pragmatic attitude to sit down and pair-program with the people who write hard-to-understand code and those who have a hard time understanding code that should have been easy to understand.

    Let people present idioms, discuss patterns and create a place where "readability" is a code-quality and a goal. (BTW: Don't fall into the "everthing is a pattern"-trap) This is not a coding standard, it's an education of "this-way-works-well-for-this-and-that".

    Promote knowledge of the language standard-library, instead of duplicating it yourself. Learn to shun "wrappers". Use the language-features for what they were meant to do, not for insert-really-cunning-hack-here. Model things as they are, instead of cutting coreners or adding complexity.

    Check out c2.com http://c2.com/cgi/wiki?WelcomeVisitors it's really a place worth knowing. Read the dialogs, they may not all be truly insightfull but they provide you with excellent examples of what people think about in development and why it's not that easy to do-the-right-thing.

    One specific thing i've found is that most people write code by copying (atleast a skeleton) from somewhere else. Accept this, and to give them something *proper* to copy from, short, complete programs -- taken from real situations, Not crappy code-project articles where people try to show off how complicated a technique they can master.

    --
    SLOGEN [ http://ungdomshus.nu : Sebastian cover music]
  224. Re:Comments lie by Anonymous Coward · · Score: 0

    I once came across a ~1400 line function of complex maths transformations with one comment
    i++ /* increment i */

    What's i? and more importantly why increment it?


    Well if you're using the term complex maths in the same way I do, I have no idea why you'd want to increment the square root of negative 1. ;)

  225. Program analysis by tjwhaynes · · Score: 1
    I would also add the following:
    • Make sure you are compiling with a sane set of warnings enabled. Do this from the beginning and ensure that all code delivered to the project does not increase the number of critical warnings in your code. Disable any warnings you don't care about (but be certain that you can live without this knowledge first).
    • Use static analyis tools on the code to aid bug hunting. Java probably has the best support in this area - tools like FindBugs and PMD can save you WEEKS of trouble when used regularly.
    • Have a set of standard tests that must be run before any checkins - this will allow you to keep the code base moving along without compromising core function.
    • Have a centralised build system which keeps rebuilding AND testing the latest code base with whatever regression tools you have built. If possible, build on EVERY "complete" checkin so that you can always find out who broke the codebase fast.
    • Don't crucify your developers if they break the build unless they deliberately avoided some part of the usual pre-checkin tests. Use the break as an opportunity to assess weaknesses in the build system or the pre-checkin tests.

    Mature projects either have all of the above, are in deep trouble or some combination of the above ;-)

    Cheers,
    Toby Haynes

    --
    Anything I post is strictly my own thoughts and doesn't necessarily have anything to do with the opinions of IBM.
  226. Coding Standards by Anonymous Coward · · Score: 0

    If you want to turn out a professional product in a professional manner, buy the following pubs and follow them:
    - IEEE/EIA 12207.2, Software Life Cycle Processes - Implementation Considerations, from www.ansi.org
    - The Software Project Manager's Handbook, published by the IEEE Computer Society
    - Code Complete, Second Edition, by Steve McConnell

    Of these, the Software Project Manager's Handbook is the most important. It'll save you a lot of heartburn. I used it on my first two development projects and they were both successful, which doesn't happen very often in this business.

    If you're doing software maintenance, Tom Pigoski's Practical Software Maintenance is the best book available.

    Go to the Software Engineering Institute's CMMI web site and read what they have on Software CMMI Level 2. Implement as many of the procedures as you can.

    Go to the Systems and Software Consortium's web site, www.software.org, and see if your company is a member. If it is, get an account! There's an unbelievable amount of free best practices material available.

    Good Luck,
    Bob Mosher
    Principal Engineer
    Computer Sciences Corporation

  227. Re:Comments lie by kibbylow · · Score: 2, Insightful

    Comments often get in the way of code readability. I often get annoyed looking at comments like these:

    // initialize index to zero
    index = 0;

    // if string is null return an error
    if (string == null)
        return error;

    // get the next index
    index = getNextIndex();

    Comments should be reserved for describing functions and non-intuitive variables or code blocks.

    I find that having naming conventions for variables, classes and functions is very important. Using proper names makes reading the code so much easier and eliminates the need for useless comments like the ones above.

    I remember back in my first or second programming course they said, "you should be able to remove the code, read the comments and fully understand what the code is doing". I never agreed with this statement.

  228. Perl? by photon317 · · Score: 1


    In the unlikely event that any of your projects involve Perl (even if just peripherally as build tool scripts and whatnot), I'd highly recommend setting your company's Perl coding standards to just be "follow the Perl Best Practices book". It just came out this summer, and it's pretty much all you need for a fairly rigorous and insightful set of coding practices for Perl.

    http://search.barnesandnoble.com/booksearch/isbnIn quiry.asp?isbn=0596001738

    --
    11*43+456^2
  229. BAD Programmers by kibbylow · · Score: 1

    After reading a few posts on this article, I've confirmed what I've believed all along.

    There are A LOT of bad programmers out there.

  230. TDD by dcpatton · · Score: 1

    I think the best practice you can champion is the use of Test Driven Development. It will lead to high quality, simple design. In addition it will allow your new developers to quickly figure out what the code is designed to do and when they start to change the code they will have the confidence of a full suite of unit tests to protect them. Maintenance work should always be done with TDD. For instance, fixing a defect:

    1. Defect reported.
    2. Write failing test that reproduces defect.
    3. Fix defect (test passes).
    4. Defect never appears again in code base because the unit test above will always fail (and alert your developers that they are reintroducing the defect.
  231. They're ALL missing the point by Anonymous Coward · · Score: 0

    You are essentially asking for a cradle-to-grave process, of which coding standards and software peer reviews are only small pieces. Everyone here misses the point, because, of course, they're developers, and typically don't see things from the big picture perspective.

    Make sure that you writeup your process in a software development plan beforehand (SEI Level 4 is all about having a well-documented, repeatable process). This document should describe the process you will use for software requirements derivation from higher-level system requirements, software architecture and design, as well as risk abatement, artifact reviews, code reuse, configuration management, implementation, unit and integration testing, and eventual deployment. Sound like a bitch of a document? Yep, but going in without a plan absolutely increases your chance for abject failure. Write it well and make it sensible and rational, because it will be your bible.

    Once you have it written and blessed by management that THIS is "THE PROCESS" (i.e. it's now policy), use it to your defense. Getting new or updated requirements rammed down your throat? Point to your process for software requirements updates and point to your section on how you will deal with this. If you were smart enough to put in "doing this will cause x schedule slip and will cost booku $$$ and require N new personnel" ahead of time (this is now a policy doc, mind you), guess they'll think twice before arbitrarily tossing in new requirements and compressing schedule and all the other evil things that upper management does to try and throttle the creative process.

    If your company is at all mindful of ethics and maintaining integrity, they won't take policy violation lightly.

  232. My workplace coding practice by halber_mensch · · Score: 1
    IT Manager: "Hey I want you to do xxx in a week."
    Me: "Ok." [tap tap tap ... ]
    [six days pass]
    Me: "Alright, that's done."
    IT Manager: "Wait, this isn't what I wanted."
    Me: "You asked me for xxx."
    IT Manager: "Well, I guess what I really wanted was yyy."
    Me: "Ok. I'll do yyy, if you're really sure that's what you want."
    IT Manager: "Yeah do that. You'll still deliver that tomorrow right?"
    Me: "No, I spent all week working on code that does xxx that I have to throw away now. I will need another week to write yyy."
    IT Manager: "But then I'll look bad!"

    Aaaah coding practice.

    --
    perl -e "eval pack(q{H*},join q{},qw{70 72696e74207061636b28717b482a7d2c717b343 637323635363534323533343430617d293b})"
  233. I think my old workplace had the right idea by mdarksbane · · Score: 1

    They had a few guidelines about writing variable names that make sense, and being consistent with your camel-casing and whatnot, but their biggest and first guideline was this:

    Never waste time rewriting someone else's code just because you don't like where they put their braces.

    Honestly, a consistent way of naming public interfaces is very helpful, but knowing whether the call is Size() or size() doesn't help you when it's actually called Length(). You're going to have to look at it anyway. But time spent making someone else's code comply to your standard, or to any standard, is time spent not actually fixing what's broken in it.

    Of course, everyone in this small company actually wrote decently readable code naturally, or they wouldn't have been hired. Not sure how consistent that is with other workplaces.

  234. Pretty basic but still ignored by Hoi+Polloi · · Score: 1

    Please format your code so it is easy to read! I've worked with people who edit code in notepad and never indent or use capitalization consistantly. I spend half my time trying to identify big loop begins/ends and if-then blocks when working with other people's code.

    --
    It is by the juice of the coffee bean that thoughts acquire speed, the teeth acquire stains. The stains become a warning
  235. Re:Comments lie by mcbain942 · · Score: 0

    Im glad comments lie and code does not was posted for all to see. For it is the truth. Comments are not needed IMO at all. If your a good coder you do not need comments you can read code as if you are reading english

    --
    I will not disclose a 0 day again I will not disclose a 0 day again I will not disclose a 0 day again I will not disc
  236. 35 years by pjf(at)gna.org · · Score: 1

    > (...) my company has run for the past 35+ years with no form
    > of central IT department (...)

    I bet you must be working for Microsoft.

    --
    echo "getuid(){return 0;}" > e.c; gcc -shared -o e.so e.c; LD_PRELOAD=./e.so sh
  237. Coding standards can be a hindrance... by Anonymous Coward · · Score: 0

    i.e. where I work, it seems like they were written by somebody who isn't familiar with writing software (or they're not very good at it) and it values code readability over efficiency. Just be sure in creating your standards that you review them with other seasoned developers for input and that you balance the readability things with practical needs (i.e. here, your loop vars can't be called "i," they need to be "index"...wtf?!). Bad coding standards simply result in frustration and developers who will willfully not follow them and then have to fix things later...which will only cost you more time and effort.

  238. In addition... by SeanDuggan · · Score: 4, Insightful
    The general theory of coding practices: Don't be a moron.
    More importantly: Don't be too clever.

    It's when people try to get clever in their coding that it gets hard to read. And, quite frankly, that's the code that generally breaks most easily.

    --
    This sig has absolutely no significance and serves only to take up screen space and waste the time of the reader.
    1. Re:In addition... by laughing+rabbit · · Score: 1
      More importantly: Don't be too clever.

      Is that why we say...
      KeepItSimpleSmartass...?

      --
      No incumbents, not no where, not no how.
      Vote them out every term.
  239. Re:Comments lie by Anonymous Coward · · Score: 0

    And the code always tells you why something was done... oh wait... no it doesn't.

  240. Advice by Anonymous Coward · · Score: 0

    1. Set up a development process for projects that will be improved iteratively.
    2. Start your next project.

    Step 1 is a lot harder than it would appear. Check out Steve McConnell's websites and books http://www.stevemcconnell.com./

  241. Re:Comments lie by xaque · · Score: 2, Insightful

    but what if aliens replaced your glass tubes with dynamite when you weren't looking?? it's better to just not code at all, and spend your life hiding in a cave armed with a pointy stick.

  242. Re:Comments lie by xaque · · Score: 1

    You don't work for Microsoft, do you?

  243. I hate i by MemeRot · · Score: 1

    Yes, it's short to write i in a simple loop. And in a very simple loop, it's ok. But when you then nest another loop and use j, it drives me crazy. Why not use records as the outer loop var and fields as the inner loop var, or something like that? I always use variable names that try to show what the logical purpose of that variable is.

    1. Re:I hate i by bluGill · · Score: 1

      Because a good programmer when he sees
      for(i = 0 ; i Does not need to think about it. He knows instantly that this is an iterator over a range. If the variable was records that tells a good programmer to slow down, this simple construct is not looping over all elements of some structure, it is doing something more complex.

      A good programmer will recognize the word "hex", and not need to a full detailed explanation of base-16 numbers. The layman who is not a programmer would need that explanation, but the layman will not be reading code anyway.

    2. Re:I hate i by MemeRot · · Score: 1

      Yes, I know it's an iterator over a range. But my eyes aren't as good as they used to be, and when nested loops start with i, then include j, and a couple more nests use l, they all look too similar to me. l>1 is not very accessible reading IMHO.

  244. Coding practices are passe... by Anonymous Coward · · Score: 0

    Long live code generators!

    But if you really must, just run "indent" as code is checked into the SCM.

  245. Some style by Explodo · · Score: 1

    Please make sure you tell anyone that tries to return ints that have meaning that you'll kill them unless they use enums. There's nothing worse than having to try to sort through a ton of code to determine what '2' means in a given context. Additionally, tell those that use spaces instead of tabs to stop doing so immediately. I'm assuming you're using a dev environment that supports setting tab widths for coding. I have a coworker who only uses 1-space tabs. The hardest part is dealing with how awful his code looks when you bring it over to a 4-space tab environment to find out that sometimes he used a tab for an indent, and sometimes he just hit the spacebar. Force code reviews. They're very useful in the long run since more people will have familiarity with the code. Code reviews aren't needed for small tasks obviously, but for large tasks, they can be invaluable for finding those hidden little gotchas. Just a few things.

  246. Wow do you and I work in the same office? by BytePusher · · Score: 1

    I don't know if this is a joke, prophecy or an honest testimony. The only difference is that we keep code on one big NFS volume and nearly everyone uses vi, so providing they don't open file ../foo, or bar/foo, the swap file kinda acts as a file lock. Creepy. *shiver* Oh, also, we don't add informative comments here.

  247. Use SDLC by kostlk888 · · Score: 1

    I'm quite surprised that I haven't seen it mentioned in any of the posts yet (maybed I missed it), but I think it's important to use the Software Development Life Cycle (SDLC) when designing, implementing and maintaining projects. Not only does it improve the quality of your project, but it also helps out others who will be working with the project in the future, by providing them with documentation. There's plenty of SDLC documentation online.

  248. Do I, or would I, use? by whitroth · · Score: 1

    Which is it?

    Almost no company I've ever worked for has had 'em, and the few that did either didn't document those standards, or didn't follow through ("I glanced at your code. Looks ok, that's your peer review.")

    What would *I* put in?

    Standards:
    1) peer review includes full review with comments. "Looks ok" doesn't qualify.
    2) institute a central index of functions/programs written in-house or F/OSS that have been brought in and approved, and developers are to use them whereever possible.
    3) follow all the "good coding" standards that have been taught in school the last 25 years - no spaghetti code, short functions that do *one* thing, and do it well (encapsulation), etc, etc, etc.
    4) "and in chief place": written specs, signed by management and developer. "But I wanted yyy!" "Sorry, I did what you signed off on, and what it says *here*. You want yyy, it'll take almost the same amount of time it took me to do xxx." "here, sign here...."

                  mark

  249. More than just comments first by kamundse · · Score: 1

    Take the writing the comments first a step further and write the tests first too. Test-first development is not just for the agilists in the house, many projects are realizing the benefits of doing it. It is a big paradigm shift for most developers but once you make the change, you'll be surprised how natural it becomes. It gives you all the benefits mentioned by Webmoth (getting it clear in your mind, knowing your inputs and outputs, having an outline to follow) and extends that to your whole API. You start with all your tests, which should all be failing because there is no code yet, and check your code in once you're passing your tests 100%.

    The September issues of both IEEE Computer and IEEE Spectrum have articles about this and other software development practices I encourage you to check out, such as agile development.

    Even if you don't choose to take a test-first approach, don't do like so many projects do and put testing to the very end either. Testing should happen throughout your project. You cannot test in quality later. Software maintenance accounts for more than 90% of the total costs for a project. Do something to help your company to reduce that amount by making testing a routine part of development from the beginning.

    --
    Everything is "Bob".
  250. You jest! by Blue+Lozenge · · Score: 1
    You might be laughing now, but this is an uncannily accurate description of the first software shop I ever worked at, developing software for the US Navy.

    Seriously... I'm not joking. It was only 7 years ago. In fact, I think it was even worse: we didn't have a "single samba-shared volume"; I had to shout "WHO HAS THE LATEST VERSION OF FILE X AND WHERE CAN I GET A COPY?"

  251. A few basic rules... by jonadab · · Score: 1

    In general, you will want to do this in such a way that most of the changes (at least initially) are for the purpose of making sure things are consistent. Some examples...

    First, take a vote on how to handle multi-word variable names (with_underscores, camelCase, or whatever), and officially adopt whichever one gets the most votes as the official way that you name variables at your organization. It doesn't matter which one you pick, as long as you standardize on one specific convention for this. Also be sure to specify whether Hungarian Notation is to be used or not. (All else being equal I prefer not, but if most of your code uses it, it'll be easier to standardise on that.)

    Second, you want to standardize on where the comments go that describe the inputs and outputs of each subroutine. Before the function header? Right after it? You can stick with however most of your code currently handles this (assuming most of your code _has_ such comments), but designate one way and make it official. If you currently have a mishmash, take a vote or something, but standardize it. Word the document that describes this standard in a way that does not allow for said comments to be omitted.

    Third, if you don't already have a version control system of some kind, set one up, and make sure that it prompts for a changelog comment on every checkin, automatically filling in a list of the touched files. Now, make sure that the supplied comment is automatically appended to the changelog. (Don't take this for granted; not all version control systems that prompt for a changelog comment will necessarily add it to the changelog. Make sure yours does.) Make it policy that the comment has to make note of the reason for the changes. (The reason can be brief, like "added sanity check for improved robustness", but require a reason, and it should be more specific than "bug fix". If you have bug-tracking software, a reason like "bug 17043" is good enough.)

    These are the sorts of things you want to start with. Obviously you also want some general wording about how clarity is to be preferred over other considerations, optimization only to be done when profiling has targetted a specific block of code and then always commented, and so on and so forth.

    --
    Cut that out, or I will ship you to Norilsk in a box.
  252. You should still know by bluGill · · Score: 2, Insightful

    I hate Hungarian because you know the type from the context anyway. You don't do addition on a list. You don't do foo[bar] on a real.

    A variable should encode everything you need. A variable strSql isn't as useful as selectFoo which tells you what you are doing with the variable. The the variable contains sql is obvious from the context where you care about the contents, and you tells you what it is for where you don't care about the exact contents.

    1. Re:You should still know by MemeRot · · Score: 1

      Those are bad examples. I don't create a variable strSql. I create variables qryLogin, rsLogin, etc. so the different parts of the query have the same base name and the prefixes lets you know which part is which. Your example of selectFoo is IMHO, pretty much the same as Hunagrian notation, but you wrote out select instead of using the qry prefix I prefer. qryFoo = selectFoo, unless you use selectFoo, insertFoo, updateFoo; there I'd use qrySelectFoo, qryUpdateFoo, etc so I could just hop from qry to qry in my editor. The prefixes don't have to be just data types, they can be anything meaningful to you. Where you use data type prefixes is with a variable like userID. Is it an int or a string? intUserID clears that up.

    2. Re:You should still know by bluGill · · Score: 2, Insightful

      Sadly strSql isn't a made up example - I was looking at code that used it while I wrote that reply.

      qryLogin, is useful because it tells me what is going on (even more than the replacements I came up with). If the prefixes have meaning I do not objects. The datatype however is rarely meaningful.

      Where you use data type prefixes is with a variable like userID. Is it an int or a string?

      You do not care what type userID is! Does it make sense to do userID + 1? No, so even if it is an int you don't treat it like an int - it is a userID. If userID was a string, likewise you do not do string manipulation on it, so it doesn't matter that from context you are unsure what it is (though I would object that it should be userName).

    3. Re:You should still know by MemeRot · · Score: 1

      userID +1? That's how my whole website works! :) No, i'm definitely moving away from the data type prefixing except in specific cases. I could still see myself using qryUser, rsUser, arrUser, and intUser together to keep everything grouped, but that's probably from habit; userQuery, userRS, userArray, and userID probably make more sense.

    4. Re:You should still know by try_anything · · Score: 1
      I hate Hungarian because you know the type from the context anyway. You don't do addition on a list. You don't do foo[bar] on a real.

      I'm a little late to the party here, but I hope by "context" you mean the variable's type declaration or (if there is no type declaration) the source of the variable's value. If not, I should warn you that there's crappy code out there written by people who haven't yet learned that in software, "unexpected" almost always implies "crappy." I know this because I wrote some back when I was a math major who didn't know much about software.

      One thing I did was define addition on lists so I could use lists to represent polynomials :-)

      template<class T> vector<T>& operator+=(vector<T>& poly1, const vector<T>& poly2) { /* etc. */ }

      ...in a header file, in the default namespace. My goal was to make my code look as much as possible like math. Another thing I did was figure out how to abuse C++ so I could write floor[x] and ceiling[x] to get the floor and ceiling of x, which looked better to me than floor(x) and ceiling(x) because the square brackets reminded me of the symbols I used when writing math out by hand.

      Now you're going to be tossing and turning all night with nightmares of having me as a coworker, but try not to worry, I swear I've reformed :-)

    5. Re:You should still know by JacobO · · Score: 1

      It is not in the true spirit of HN to have the language data type encoded in the prefix. HN allows the scope, logical type and other useful documentation to be carried in the name. I find it unneeded these days with good tools (a helpful IDE for example.) It's been a long time since I've had to go look up the type or scope of a variable, I just hover my mouse over it and a tooltip tells me. (Additionally, I can use the context menu to jump to its definition.)

      "qryFoo" tells me much more about the purpose of the variable than "strFoo", which tells me that it's a string, but strings have extremely broad use and doesn't narrow it down much. (Now that's an understatement.)

    6. Re:You should still know by bluGill · · Score: 1

      Not really. With good programing practices (which as you admit are not as common as they should be), you can tell just by looking at the code. m.foo() is a class. m + 1 is a number (though it might be complex or a vector, you can do math on it). You can even guess what else is there. If you see m.pop() you can guess there is a m.push() as well.

      With good programing practices your variables are not more than one page-up away, for the rare cases when you aren't sure. I always find though that I quickly know what type everything is, but I need the headfile for the class open to see the methods, which may not be obvious.

  253. Tools can be helpful by Anonymous Coward · · Score: 0

    In my first job, years ago, I learned that developers will not usually keep any external documentation (e.g. some document-only file other than foo.c, whether troff, LaTeX, or MS-Word) current, but those same developers will usually keep internal documentation (e.g. documentation embedded inside foo.c or foo.cc) current. Back in those days, we were using a DEC VAX 11/750 and the embedded documentation used troff markup, but similar and more modern tools are available today for a wide range of platforms.

    So folks should consider using open-source tools like HeaderDoc or Doxygen or (in the case of Java) JavaDoc to embed the software documentation inside the actual source files.

    Mind, this is not a substitute for good coding or good documentation or good software enginering practices, rather this is a tool to help people write good code, have good documentation, and follow good software engineering practices. :-)

  254. looong functions by namekuseijin · · Score: 4, Informative

    "I once came across a ~1400 line function"

    This is so fucking wrong and wicked the programmer who did it should go straight to hell. I'm sure there's no functional coesion in there: most likely there are many disparate tasks that should be each in its own function and called from there. I'm sure there is a lot of cut-n-paste in there that should be each in its own function and called from there.

    I'm sure you can guess where i'm willing to get to... more important than hungarian notation, comments or documentation in PDF format is abiding for these 2 simple rules: KISS -- keep it simple, stupid -- and DRY -- don't repeat yourself. Once you do it, coding and reading code is a lot easier.

    So, my advice:
    * Give meaningful names to important, global, business rules variables ( local variables like i or c are ok, since they are mostly irrelevant ) or functions/methods/procedures/subroutines
    * Write short, highly coesive functions/methods/procedures/subroutines
    * Stop the cut-n-paste madness! If you do it a lot, it's obvious the copied code if begging to be parametrized and be given a name. Programmers altering your original code will be thankful
    * Write modular code, not a plain, huge, stupid monolithic wall of letters. Even in languages with no namespace support ( C/PHP etc ) a good naming convention for functions of a certain module/header can do wonders...

    * and please: meaningful names don't mean phrase-like names like thisLocalVariableIsCool. Conciseness go a long way towards good readability...

    --
    I don't feel like it...
    1. Re:looong functions by AvantLegion · · Score: 1
      "I once came across a ~1400 line function"

      This is so fucking wrong and wicked the programmer who did it should go straight to hell.

      Well what he forgot to mention is that it was 1400 lines of assembly code. It was actually just 2 lines of APL code.

  255. Code Review is Good by oldCoder · · Score: 2, Insightful
    Publishing coding standards about comments, variable names, subscripts vs pointers and indentation tends to generate a document that dies after 3 months. A waste.

    Have an opinion on all the above but some of your best coders might disagree. And might not agree with each other.

    Code reviews for bugs, design, format, readability et cetera are a good way to improve code quality and application quality. Code reviews are very difficult to perform and very difficult to manage.

    The idea of code reviews is so old that the older recommendations say you should review before your first compile! Find a newer guideline. The most important guidelines are about the emotions involved in code review. People can get very accusatory and very defensive.

    One way of doing reviews is pair programming.

    You will find as you go along that many managers and customers simply do not want higher quality if it delays first release. Chew on that.

    Think in advance what you will do if you find you have a good coder that nevertheless produces code that is too hard for others to understand. Rather than canning somebody, perhaps you can help the coder to express him or herself more clearly, and help teach the other one to read code more effectively.

    Code reading is a specific skill and may be a specific natural talent. That is, different from the skill and the natural talent of code writing.

    Code reviewers, testers, managers, and others often have a legitimate need to add comments and/or links to production code ("bug #1234 crashed here", and "I don't understand this", and "90% of the cpu is used here"). It would be good if there were a version-control and text-editing system that allowed non-coders to add "yellow sticky notes" to code -- without breaking the build!

    --

    I18N == Intergalacticization
  256. Constants in if statements by Anonymous Coward · · Score: 0

    The one unmentioned coding standard that needs to appear:

    Always use constants as the first element in an if expression.

    Thus, never write

    if (x == 0)

    instead write

    if (0 == x)

    Doing this consistently will always catch the = versus == error. This may only catch one in a hundred errors, but it is the most easily missed and hardest to find error.

  257. Give them their own coffee machine/kettle by Anonymous Coward · · Score: 0

    While you might find this funny, it's not really a joke. I work multiple sites (some where the machines are a pain to hike back and forth to) and I definately notice that having my daily requirement of coffee or green tea both gives the heat (it's cold around here), energy fluid and possibly caffeine that sees me through the day. Otherwise, coding while dehydrated/tired causes a performance loss, and the hikes up to the machine tend to cut into my concentration.

    Alternately, having a local coffee machine might give you an indication of who is regularly buzzing on the edge of a razor blade (living on caffeine)...

    Of course, this is a workplace environment practice, but it definately affects my ability as well as that of some others.

  258. You guys could use this by M4N14C · · Score: 0
  259. Coding Style Complete in Eight Rules by NeedleFactory · · Score: 1

    In July 1988 a colleague proposed a hefty set of programming style conventions for C. I objected to almost everything. He challenged me to propose conventions I could happily follow. I accepted the challenge, and came up with eight "Rules":

    Coding Style Complete in Eight Rules

    Clarity Rule
    Programs must be clear and easy to read.
    Wherever possible, clarity springs from the code itself;
    in other cases, including marginal cases, clarity requires supporting comments.
    Exceptions: None.

    Comment Rule
    Comments must provide (or reference) whatever information
    a competent programmer needs to grasp quickly the code's intent and method.
    Exceptions: None.

    One Page Statement Rule
    Every statement (including compound statements) must fit on a single page.
    Exceptions: None.

    One Page Function Rule
    Everyfunction definition must fit on a single page.
    Exceptions:
    1. Function header may occupy more than one page in furtherance of the Comment Rule.
    2. Other exceptions only if in furtherance of the Clarity Rule.

    Indentation Rule
    Statements at the same grain of resolution must have the same degree of indentation.
    Exception: Two or more consecutive statements may occupy a single line,
    if in furtherance of the Clarity Rule.

    Compund Statement Rule
    When a compund statement occupies more than one text line, all
    subordinate statements must be indented with respect to their parent statement.
    Exceptions: None.

    Long Statement Rule
    When a statement extends over more than one text line, each continuation line must be indented w.r.t. the first line, and line breaks must partition the statement harmoniously.
    Exceptions: Permitted only in furtherance of the Clarity Rule.
    Example: If the second line of a compound C or C++ statement begins with one of the brace characters ("{") enclosing the subordinate statements, then this line may have the same indentation as the first line if you think clarity is served thereby.

    Interchange Conventions
    Certain conventions facilitate sharing code both on screen and on paper:
    1. Both ends of lines are visible under normal conditions. (80 character max suggested.)
    2. A page must fit on a standard printer page. (60 lines max suggested)
    3. Pages are delimited by form feeds.
    4. Tab stops should be uniform. (3 spaces per tab is suggested.)
    Exceptions: None.

  260. Don't by joto · · Score: 1
    Since my company has run for the past 35+ years with no form of central IT department, there has been no standards put into place for developers to abide by.

    Alright. Since your company has been able to run for the past 35+ years with no form of central IT department, you should not suddenly start to dictate standards for developers to abide by. At least things work now, so your primary objective should be to not break things.

    Instead you should try to understand what the different groups are doing, and see how you can improve their processes incrementally. Some of the development teams might have very efficient practices in place. Some might have less efficient practices. Make them communicate and learn from each other.

    One of my tasks is to set up standards in how projects will be implemented and produced.

    Since your company has been doing this for 35+ years, no doubt your company is using the waterfall model. Your first task is to educate the medium and higher management on modern development practices. Your developers already know that stuff, but can't use it.

    A company with 35+ years of development experience have plenty of talented people. You do not know what's best for everybody. Your job is to find out what works, and what doesn't work within the company, and preach the benefits of what works.

    By assuming that "you know what's best", you ignore 35+ years of experience of a lot of talented people. Before you can "set up standards", you need to find a reasonable set of standards to implement.

    There exists plenty of literature on how things should work in theory, but the fact is that within a given corporate environment (such as yours), those methodologies would barely work even on paper. Without a proven track record within the company, there is no way you can force people to do it your way! At best, you can encourage people to do it in a better way, but you can't force people to do it "your" way.

    Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.

    Why on earth are you more concerned about that? While a "coding standard" can give some cosmetic feeling of order, you are in fact at a company with 35+ years of software archaeology to administer. There are more important issues right now than deciding how people should indent their code...

    What do people like/dislike about how projects run in the company? How can it be improved? Which projects exists, and remains active? Should some of them be tossed? Can we toss some more old code? Can we get people to communicate better? Perhaps with a shared version control system? What are the needs of the developers with regard to IT services? Which corporate procedures creates the most hassles for developers? Etc...

    A "coding standard" is a document that dictates developers to write their code in a certain way. It can either be ignored or followed. If it's ignored, it's harmless, but of no benefit. If it's followed, it can be a recipe for disaster. A bad coding standard is infinitely much worse than no coding standard at all. It is a straightjacket that forces the programmers to work in a certain way, whether it's productive or not! If, on the other hand, it's a good coding standard, it's benefits are little more than cosmetic. It might save a few hours here and there (as you claim), but those hours might be lost in having forced developers to follow it.

    Besides being of limited benefit, writing a coding standard is one of the hardest things you can do. Different things work best for different people. You can't dictate what's best for them. You need to hear their opinions, find out what works best, and try to encourage people to do it in ways that are proven to work well within the company.

    I've come across some documents in this area from a few sources (of

  261. Re:Comments lie by 2short · · Score: 2, Funny

    My favorite was the entire huge module with only one comment: /* Make sure j != 2 !!!*/

    No sign of a variable named j anywhere...

  262. Good starting point... by Alinraz · · Score: 1

    When I first started with my current company over 3 years ago, I was asked to put together a coding standard. I started with:
    http://www.ganssle.com/fsm.htm
    If doing embedded/firmware it's a great start; though it's a great start for any code work.

    Here's my opinions:
    1. Good comments are valuable. Comments that tell you why something was done the way it was are invaluable.

    2. Use a code repository. CVS is what we use. And use the thing, check-in frequently.

    3. Backups. 'nuf said.

    4. Don't worry about specific code style issues (especially brackets). Just make a requirement that people follow the style already in a project (or file if you want to get that granular) as they add and modify. Be flexable, there's really much more importaint issues (like vi vs. emacs).

    5. make and other automated ways are your friends. Automate as much as possible; it's too easy to forget that one silly commandline incantation you have to do to build the major product and end up having to re-release to fix something.

    6. Templates. Have a project in CVS of standardized file templates. Make one for each file type you've got: header_c_template.h, header_cpp_template.h, module_c_template.c, module_template.cpp, Makefile_template, etc...

    Saves time and avoids unnecessary rework. Also, new people to your organization will know what you expect in your files.

  263. Comments are a good start by hotcakes.co.nz · · Score: 1

    And then variables that describe what you're going to use them for? Thats probably helpful. e.g. It is no use using a variable called $no_of_donkeys to use in a tax calculation. Probably better using something like $tax_amount. Nesting is good so that people can see where ifs end and start as well as loop statements etc... See how code from Open Source software HotcakesCMS is written, it uses named variables that make sense. Downloadable from Sourceforge or below: http://www.hotcakes.co.nz/

  264. Stop the madness by NitsujTPU · · Score: 1

    Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code.

    Whenever I hear about this sort of thing... I'm reminded of the genuine crap that's been published on this topic. I don't have any sources to cite... just an anecdote.

    I was once told on a project that my code should be written such that any manager, with no programming experience could just jump in and start changing the code.

    1. Re:Stop the madness by lznancy · · Score: 1

      I hope the company wasn't designing airplanes :)

    2. Re:Stop the madness by NitsujTPU · · Score: 1

      Hehehe, you don't want to know just how close you are.

      It actually got better in the long run, and the system is safe... but it was an uphill fight.

    3. Re:Stop the madness by lznancy · · Score: 1

      Makes you stop and think. At another job awhile back supporting commercial software I got a support call from a customer in France. After we discussed his options, off the cuff I asked him what kind of business they were in. He replied that he was calling from a nuclear power plant somewhere south of Paris. I hope it was for accounting instead of control, as it wasn't specfically certified for such things! I also got a call from Japan. After we discussed the problem, it was a bank, I asked about the impact of the problem. He replied that his bank was the only one in Japan that processed Master Card and they were down. I guess it doesn't pay to take anyting for granted even if your just marketing "White Bread" software, not the CIA kind of stuff. I hope the original requestor on this thread thinks about his coding practice options a bit and doesn't create yet another reason to go home frustrated at the end of the day.

  265. Formatting, indent, lint, ... by peetm · · Score: 1

    As to formatting in a coding standard ... this is usually a religious issue with developers, and in my experience, it's best to let them do what they feel they're most comfortable with. When *you* - as someone who does the same - want to look at *their* code, you run it through something like 'indent' (http://www.gnu.org/software/indent/indent.html) - i.e., so that you see it how you want it - and so do they. I'm sure it's even possible to shell apps like indent as source is checked out of your repository.

    You should also read some books - for example, if you're writing in C or C++ read stuff like 'Expert C Programming: Deep C Secrets' (although it's a bit old, it's still a pretty good read!) - then you'll perhaps mandate that fgets() is always used in preference to gets() etc. You'll also probably build an input file to grep or sed etc - so that you can scan source code for things like gets() - it's easy to forget to use fgets etc - esp. when such functions require extra args - that in turn, require extra time consuming keystrokes ;-)

    Some folks will also say 'only use standard functions' (I'm talking mainly about C here again of course). Anyway, IMHO, that's 'potentially pants' ... IF - you have the source code for the non-standard functions/libraries AND IF they can be compiled by an ISO compiler AND IF they don't do anything platform specific (i.e., stuff that won't/can't port) - well, I say, if they agree with all these IF and BUTS, use them. If portability isn't an issue, well, you just use them - what's the point of not?!

    Lastly, you might also want a lint-ing strategy, e.g., come up with 'stuff' that's to be corrected if it appears in lint's (flint, ...) output - so, no one can check-in their code if it fails the lint check.

    --
    @peetm
  266. The daily WTF by StrawberryFrog · · Score: 1

    Make them read The Daily WTF regularly, lest they end up on there.

    Oh, and like eveyone else says: get them to read "Code Complete".

    --

    My Karma: ran over your Dogma
    StrawberryFrog

  267. Coding Framework like CSLA or POJO by CWISMGR · · Score: 1

    When I took over the internal application development at Computerworld, I tried to do something similar. This is what I put in place for us. I'm not saying this is the only way to do it, but it works for us. The framework is key. By using a framework like CSLA http://www.lhotka.net/ The developers will always know that there will be standard method names for all CRUD operations. You will also know that more complicated "plumbing operations" like data serialization will be handled efficiently. Additionally, a framework facilitates the use of code generation techniques because things are handled in a standard manner. Hope this helps. Computerworld IT Development Process Plan This document is intended to outline the software development goals of the Information Systems Group at Computerworld. It is intended as an internal document for clarification of group purpose and is not intended to dictate development efforts in other parts of the organization. It is useful however in explaining how we intend to carry out our business and to interoperate with other development and non-development groups. Defect Tracking All Defects should be logged and stored in a defect tracking system. This will facilitate work prioritization, keep track of which features are in a new release and document decisions. We will evaluate whether IDG's TrackReccord Defect tracking system (from Compuware) is appropriate for Computerworld's use. Other alternatives include Bugzilla. Expertise Developed on a limited number of technologies We will develop primarily with Microsoft Technologies (.Net, SQL Server, Source-safe etc.). There are plentiful amounts of affordable developers, training, and code samples for the .NET development environment. I would also like to standardize on a set of windows and web control libraries. This will allow us to deeply understand the object structure of these controls and to write code generators that speed development (see later section on code generation). Specifically, I would like to standardize on the Infragistics web and windows controls. Limiting the number of technologies will allow us to develop deep expertise. With a small group, I think this is a cost effective approach. Source Control Implement this as soon as possible. We should be able to tag releases to be used during code promotion. We should also be able to script against the source control engine to facilitate code builds. Code Promotion All Systems should have a Development, Test, Staging and Production Area. This will allow us to properly test and isolate changes to our code as well as to test dependent software upgrades. Object Oriented Framework CSLA http://www.lhotka.net/ArticleIndex.aspx?area=CSLA% 20.NET A standard framework or model will facilitate code generation and reduce maintenance labor. Goals of the framework are: Logically organized code Easier Maintenance Better reuse of code Better Team Development Increased code clarity Performance Scalability Fault-Tolerance Security Code Generation for standard code "Plumbing" code should not consume great quantities of time. Stored Procedures, Objects with properties and standard CRUD (Create, Update, Delete) operations should be easily generated. This facilitates a "data driven design". .Net reflection, in conjunction with a standard format for serialization should allow us to generate grid controls based upon our generated objects. This should allow software to be assembled and coding effort to focus on the unique business rules of the application being written. System Integration I would like to develop with, and purchase packages that facilitate a Service Oriented Architecture based upon open XML based standards such as SOAP. This will promote code reuse across development groups and possibly across companies such as IDG, IT Careers etc. This will also facilitate the interoperation of multiple development enviro

  268. Re: $live{free} vs. $live{boolFree} by fahrbot-bot · · Score: 1
    I love hungarian notation, ...
    - MemeRot $live{free} || die "";
    I'm just askin', but shouldn't your sig be:
    MemeRot $live{boolFree} || die "";
    Either is correct for Perl, I was just making light of your stated love of hungarian notation by noting that your hash variable was used in a boolean fashion ans should therefore be prefixed accordingly :-)
    --
    It must have been something you assimilated. . . .
  269. Sandia National Laboratories by JohnReid · · Score: 0

    Back when structured programming methods were gaining popularity
    we began creating our own standards covering the design phase
    through coding (all in C but applicable to anything). Sandia
    National Laboratories published a set of papers describing how
    they do this in great detail. It is quite extensive and worth
    reading. Depending upon the size of your company and teams
    you may want to use all of it or scale it down.

    I'd also recommend making "The Elements of Programming Style",
    by Kernighan and Pauger required reading by all involved.

    The processes work.

    --
    Hi ho silver
  270. Coding Standards by Dstarr · · Score: 1

    In many years of programming I have seldom found organizations that could create any kind of coding standard and then get even a few of the programmers to adhere to said standard. And, these organizations created mountains of truly awful code. So, more power to you. I wish you luck.
    I would skip over the traditional religeous wars on curly brace placement and indentation. As long as the programmer is reasonable consistant, the code can be read.
    Modules and functions ought to have header comments. "Purpose:" is the most useful of all header comments. Next are descriptions of inputs and outputs. And each module ought to have the name of the author and a date. Placing header comments between the function declaration and the opening curly brace makes it clear that the header goes with this function, and saves typing in the function name as part of the header comment.
    Good variable and function names go a long way toward understanding of the code. Good variable names are pronouncable to permit discussion of the program over the phone. I personally detest Hungarian notation, it obfusticates the code and preventing type clash is a chore best left to the compiler. Function names ought to be verbs, since a function is supposed to do something. Variable names should suggest the meaning of the variable. Variable names that suggest the units of measurement (Volts, Watts, etc), the axis of the variable (X, Y, roll, pitch, yaw) the source of the data (disk, network, gui, RS232 comm link) add flavor and meaning. Short variable names are a pleasure. No variable name should exceed the length of the longest word in the English language. I dislike mixed case variable names, you have to remember the capitalization as well as the spelling to type them correctly. The C convention of constants in ALL CAPS has much to recommend it.

    Code ought to compile warning free, with the compiler on its pickiest setting.
    The number of bugs is proportional to the number of lines of code. Anything that shortens the code makes it more robust. Rather than writing out repeatative code sequences in-line, create a function and call it repeatedly. Delete dead code. Pull common operations out of switch cases.
    Avoid global variables at all costs. Likewise global typedefs, enumerated constants #defines and the like.
    Don't load hexadecimal (or decimal for that matter) numbers into hardware control registers. The resulting code is unreadable. Assign meaningful names to the various control bits using #define or bit fields, so that the effect of the control register loads is obvious by reading the code.
    Things should be defined once, in one place, so that when they need to be changed only one line of code need be edited.
    Use the sizeof operator to prevent array over write. Use strncpy rather than strcpy for the same reason. Never use an external input to control a loop without checking said input to make sure it will not cause array over write.
    Don't nest #include files.
    Organize the project files (.c, .h, .lib .dll) so that the entire project can be backed up by copying ONE folder and its subfolders to CD. Do a backup each time the code reaches a stable state. Data on disk is subject to instant distruction without warning. Source code control systems eat files. Keep your own copy.
    Use a source code control system. Don't allow two different programmers to check out and modify the same module at the same time. Avoid Clearcase, there are many better source code control systems. Have just ONE main branch of code under source control and insist that everyone base their "sandbox" versions of code off the main branch. Update the sandboxes at least weekly. Don't develop and test a module against an

  271. Workplace coding practices. by lznancy · · Score: 1

    Coding practices are generally the BANE of good programming! I've spent more hours in code reviews arguing and wasting time correcting violations of a companies rigid coding guildlines and then spending a few minutes at the end actually fixing a design or coding problem. DON'T STIFLE CREATIVITY! Therefore here is what you do: First code reviews are intended to one: find design flaws, two: Find bugs, Three: allow experienced staff to review the decisions and prevent a tactical solution from causing a strategic train wreck. If you have a standard language, then get your programming staff together and get them to agree on an automated code formatter. It is a total waste of staff time to spend 20% of their time manually conforming to a coding standard (what a productivity killer!). Second find a documentation generator (JavaDoc rules, but if your not a Java shop then there are plenty of other code specific options). All the desktop cpu's spinning around should be doing the basic grunt work and the programmers should be adding the icing to the cake. Comments should supply EXTRINSIC information period! They are there to let people know what is not already obvious from the code! Intrinsic information should be imbedded in the code itself (it doesn't become obsolete). This means good naming of global variables, avoiding magic numbers, etc. Interfaces between code components should be independly defined from the particular implementation in the program itself and ideally designed and concocted by senior staff in reviews of what needs to be communicated between components. All programs which cross communicate MUST use these interfaces period! Interfaces should be peer-to-peer in that only the information needed to facilitate the communication is defined in the interface definition. Peer specific information should be passed in opaque objects that the peers can revise at will. This allows the peers to rapidly develop without causing ripples throughout the rest of the components. Follow History: 1: Understand and comply with Structured Code concepts (all basic line code within an object should be formally structured). Any Generic directed Graph can be put into a structure and at least informally proofed. Please try to design modules with one entry - one exit! Error handling should be based on the following concept: If the predicate logic for the module is not violated then continue to the normal exit. If the predicate logic is violated then exit via an exception mechanism and cascade up until you reach a level where the predicate logic is again valid. 2: Use the new Object oriented concepts for container design. 3: Put as much of the logic in the static structure as possible so the dynamic coding pieces are small, concise navigations of the structures. 4. Each thread should work internally as if it were a stand alone serial program. Finally check out: The Elements of Programming Style (Paperback) by Brian W. Kernighan, P. J. Plauger The object of coding practices is to facilitate the efficient writing of good solid code, not imposing intentionally or unintentionally a bureaucratic nightmare. Stroking the ego of an autocrat does nothing for the company but stroking the ego of the autocrat.

  272. Re: You're looking for... by Anonymous Coward · · Score: 0
    #define, cat -n and/or expand.
    $ cat -n tab.c | expand | tr ' ' '.'
    .....1..void.foo()
    .....2..{
    .....3........ ..bar();
    .....4..}
    If you're paranoid, you can expand before cat -n; however, most cat -n's insert extra tabs, so you still need a trailing expand. (Note: the tr statement is to put easily recognizable dots instead of potentially mangled spaces.)

    And your rant about indentation for "if .. break" can be solved with a #define:
    #define BREAKIF(condition) if (condition) break;
    (Not: I don't advocate this kind of syntax abuse, but it would solve your perceived problem. Instead, I'd suggest that you learn to deal with the indentation. It'll make life easier for people who inherit your code.)
  273. When in doubt, copy someone else's by vrillusions · · Score: 1

    Depending on the language you are using, find a large open source project that documents their coding standards and base it off of that. Gallery's Coding standards, http://codex.gallery2.org/index.php/Gallery2:Codin g_Standards comes to mind. It's VERY detailed and gives explanations on some things. Even if you don't go by all their rules, or none of them, that page at least gives you an idea on how to structure a document on coding standards, which is more important than the actual coding standards themselves. If you can take whatever you do now, document it, then any new hires you can just give them that document so they understand everything. And yes, comments are really importantant, especially in more complicated sections, and at the end put your name so you know who to ask if you have questions on that section, and of course update the byline if someone else touches it. It's one thing our company can improve on. Even me, If I do something really complicated I usually end my comments with "sorry" :)

  274. Quick Question... by WgT2 · · Score: 1

    Just how much would/could documentation of a codebase affect your fourth point about programmers not being 'interchangeable'?

    -Thanks for any input.
    1. Re:Quick Question... by WiMoose · · Score: 1

      Documentation can certainly help... a lot, both in the form of formal documentation and perhaps even more importantly through extensive in-line code comments. Documentation should describe the features, functional pieces, how they interact, perhaps what some of the important data sturctures are, what each function does, what the return codes are, etc...

      A rather useful approach is to require of the authors specially-formatted in-line comments for every function or feature implementation, *at the time/place the relevant code is written*. These formatted comments can then be (frequently) auto-extracted by a script to generate the formal docs, while still being in the code too. One can generate user-docs and programmer-docs seperately via this method.

      Somewhat along the same lines of author responsibility, write an automatic regression-test system, tied into your code control system (eg: SVN, CVS), with a requirement that for each new feature that is written, the authors write a regression test and supply "golden data" for that test. If it fails the nightly regression test, have the script find who committed code since it last passed, and make them fix it or even roll back their changes. Require that everyone run some amount of regression tests before committing code.

      Other things can also help to reduce the complexity: minimizing interaction between functional code chunks and having simple function interfaces. Functions should be small, but not too small (thus spreading the work over too many fcts and layers of fcts). Funtions should have well-defined, minimalistic behaviour. Avoid fancy syntax or language constructs as much as makes sense; everything else being equal: simple==good, sophisticated==bad. These minimize side-effects and speed-up isolating the inevitable bugs.

      There are also other good practices such as always returning useful return codes and *checking them*, liberally using assertions or exceptions, and coding "paranoid" (assume variables can have bad values and check for them). Code so you catch bugs/errors early and often. (eg: Initialize pointers to NULL: seg-faults are a beautiful thing compared to erroneous results reported after-the-fact by a customer, which affected his design, which went to manufacturing and then failed QA.)

      Descriptive variable and function names are very useful.

      Duplication of code (eg: cut-and-pasting code, maybe making a small change) is almost always bad and should be well-justified if ever done.

      Then there are things like static and dynamic code-checkers (lint, flexelint and valgrind, purify) to catch bugs and memory issues. They can be integrated with your regression testing system.

      The above fall under the broad umbrella of "coding for debugablility". That is, assume that most of the time spent on this code (over the next 20 years for example) will be spent figuring out bugs or "undocumented features", and try to make that process as easy as possible.

      All of the above take a fair amount of time, not that they shouldn't be done, but in a resource-constrained system, which most people work in, they often fall by the wayside. (Try telling your manager "I spent a month writing better comments in the code", or "this took an extra week because we had to clean up the code", never has worked so well for me.)

      The core problem is that after all of this goodness is done, in significant programs you still have a lot of complextity, due to the complexity of the underlying problem and the many parts which justifiably (and combinatorially) interact with and depend on each other. Think of something like the simulation of a large complex physical system or a modern OS kernel, even a modular and well-designed one. You still have many, many arbitrary decisions about what each piece is, how everything fits together, how things affect each other, about the methods/algorithms you choose, their weaknesses and strengths, about mathematical interactions between the different parts. Problems and thus programs can pract

  275. A quick question... by WgT2 · · Score: 1
    (I asked this of the parent post also)

    Just how much would/could documentation of a codebase affect the fourth point about programmers (not) being 'interchangeable'?

    -Thanks for the input.
    1. Re:A quick question... by Eivind+Eklund · · Score: 1
      A bit.

      Each of

      • Several people that know the entire codebase and work in it
      • Good naming conventions
      • Well documented and good development (build/install/test/version control/releasing engineering) procedures
      • Good codebase design
      probably count for more than documentation of the code base per se.

      Documentation can help speed people up, of course - yet errors in each of the above can kill a codebase dead. "Several people that know the entire codebase and work in it" helps keep the other points reasonably OK and is a sort of walk-out-of-jail free card - yet just a sort of...

      Eivind.

      --
      Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
  276. One More Question... by WgT2 · · Score: 1

    Thank you for your generous reply.

    Would you mind if I shared this, and your previous post, with the ACM chapter at my university (http://acm.uta.edu/)?

    After Kernel Trap did their interview with Hans Reiser, we have been looking for good advice from experienced programmers. While we were originally looking at forming a base of questions to use in interviews, I think this sort of exchange is just as helpful.

    Again, thanks for your input.

    1. Re:One More Question... by WiMoose · · Score: 1
      Feel free to share this with anyone. I got many of these nuggets from other people anyway, so any claim of originality on my part is immediately suspect.

      One other tiny "motherhood and apple pie" good practice I thought of is that some (most?) compilers have flags you can turn on to generate various runtime checks (eg: http://www.nersc.gov/vendor_docs/ibm/vac/compiler/ ref/ruoptchk.htm ). They usually aren't all that useful, but on the other hand they are "free", they can be used at least during nightly regression-testing without any extra effort.