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?"

28 of 682 comments (clear)

  1. 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?
  2. 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 blank89 · · Score: 2, Funny

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

  3. 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.

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

    Outsource them all.

  5. 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!
  6. 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--
  7. Dilbert by RedNovember · · Score: 2, Funny

    heh

    --
    "MY APOCALYPTIC TENOR HAS NOT BEEN DISPELLED!" - T-Rex, qwantz.com
  8. 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

  9. Re:What a question! by chromatic · · Score: 3, Funny

    Perhaps someone broke in and fixed the code.

  10. Even better: CPAMAP by gerf · · Score: 2, Funny

    (copy paste as much as possible)

  11. 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.

  12. 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()?
  13. 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...

  14. 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?

  15. Re:Comments by Hognoxious · · Score: 3, Funny

    Er, like WHOOOSH or something.

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  16. 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.
  17. Re:Comments by el+cisne · · Score: 1, Funny

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

  18. 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)))

  19. 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".

  20. 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).
  21. 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.
  22. Re:#defun is sooo 70s... by goonerw · · Score: 4, Funny

    And Hungarian notation is soo 90's ;-)

    --
    LOAD ".SIG"
    PRESS PLAY ON TAPE
  23. 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.
  24. 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

  25. Re:Code cleanly and remove comment by Anonymous Coward · · Score: 3, Funny

    Or you could turn it into a Web Service.

  26. 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

  27. 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...