76

Have you ever had to work to coding standards that:

  • Greatly decreased your productivity?
  • Were originally included for good reasons but were kept long after the original concern became irrelevant?
  • Were in a list so long that it was impossible to remember them all?
  • Made you think the author was just trying to leave their mark rather than encouraging good coding practice?
  • You had no idea why they were included?

If so, what is your least favorite rule and why?


Some examples here

finnw
  • 1,467
  • 2
  • 17
  • 21
  • 4
    I've asked a similar question (but not exactly the same) on SO before by the way: http://stackoverflow.com/questions/218123/what-was-the-strangest-coding-standard-rule-that-you-were-forced-to-follow – Brian R. Bondy Sep 08 '10 at 16:30
  • @Brian, thanks, I had seen your question but forgotten about it. – finnw Sep 08 '10 at 16:54
  • 4
    The real problem with coding standards is the time and effort wasted arguing over whether they are correct or not. Nothing beats a good curly-brace war for creating internecine strife... – MZB Oct 14 '10 at 16:07

56 Answers56

128

Had a professor once who demanded we have at least one comment for each line of code.

//Set x to 3
var x = 3;

//if x is greater than 2
if(x>2){

    //Print x
    Print(x);
}

It was pretty ridiculous.

Fishtoaster
  • 25,909
  • 15
  • 111
  • 154
  • 10
    Isn't this just so the professor knows that you know exactly what is going on? – John MacIntyre Sep 08 '10 at 18:13
  • 80
    I think it's clear what's going on, and it ain't education. – Dan Ray Sep 08 '10 at 19:09
  • 18
    The example you have above is clear, but what if a student copies some function call from another app or a book or what ever, and doesn't really understand it? How will the prof know? This stupid rule doesn't allow any grey area (which in his defense, has probably been abused before). That's how I interpret this. ... mind you if I saw this in a non-academic environment it might scare me a bit. ;-) – John MacIntyre Sep 08 '10 at 19:55
  • @John MacIntyre: That's what tests are for. The student who copies all his homework from others without understanding it is going to be screwed when he has to write code on the spot. – Tim Goodman Sep 08 '10 at 20:08
  • 4
    Yeah, except you can always write comments that just repeat the code and don't show any understanding. Does he make you right "// Ending Brace" before the ending brace? – alternative Sep 08 '10 at 21:07
  • I think this may be justified for the first week or so of the very first intro to programming course someone may do. After that, yes, it is bonkers. – Tom Morris Sep 08 '10 at 23:28
  • 1
    @mathepic: Probably only if you put the ending brace on its own line. – Tim Goodman Sep 09 '10 at 01:32
  • Yes, strangely, on school years it was always preached by professors that we should comment our code.. no one talked much about good naming conventions, etc. – Shady M. Najib Sep 09 '10 at 15:53
  • 1
    I hate this type of commenting. It's like reading French and commenting "//yes" for each Oui. Either you can read programming or you can't, such comments aren't helping. – Hans Sep 10 '10 at 02:21
  • Maybe it was a way to catch plagiarism? – JeffO Sep 14 '10 at 19:42
  • That may be bad teaching to require that without explaining good commenting, but I've had several cases where logic-heavy code I wrote justified comments on nearly every line (esp. Javascript). Not so much "Set x to 3" as "3 is the ID for html element nodes" or instead of "if x is greater than 2", "if we have more than 2 elements we want to hide the rest" – Nicole Sep 16 '10 at 21:36
  • 3
    @John MacIntyre: Scare you a "bit"? It scares me at least a whole byte. – MIA Sep 24 '10 at 01:09
  • 6
    What if you've accidentally got a useful comment in your code? Do you need to put `// comment` on the line before that? – configurator Sep 29 '10 at 03:49
  • 2
    To one-up you a bit, I had a Java class where the 'professor' required not only a comment for every line of code, but that the comments start in column 7 (the 'professor' was a retired COBOL programmer) – Cercerilla Nov 15 '10 at 14:54
  • 2
    Just give him a one-liner: `var x=3;if(x>2)Print(x);`. Bonus points for obfuscation and golfing. – Mateen Ulhaq May 20 '11 at 03:57
  • @JohnMacIntyre Even copied from a book with the student not understanding it, they'll still be able to put literally-translated comments on each line, as shown in the answer. This provides no "protection" from that situation. – Izkata Jul 18 '12 at 18:07
  • //point out the mind-numbingly obviously to a prof that's afraid I might do something s/he doesn't understand – Erik Reppen Jun 22 '13 at 21:16
  • If it was an intro "first time" programming class, I'd consider making students do 1:1 commenting just to force them to explain what they are doing and why. I'd also make them deliver all their code printed in Comic Sans, though. I think it's very "wax on, wax off" - now do it again, but use only wingdings. – BrianH Dec 05 '13 at 17:38
102

Our company (C#) coding standard called for extensive use of #REGIONs (for those who don't know, it marks blocks of source code that will be collapsted to a single line in Visual Studio). As a consequence, you always opened what seemed to be a nicely structured class, only to find piles and piles of garbage swept under deeply nested rugs of #REGION constructs. You'd even have regions around single lines, e.g. having to fold out a fold out a LOG region to find one single declaration of the Logger. Of course, plenty of methods added after some region was made, were placed in the "wrong" region scope as well. The horror. The horror.

Regions are one of the worst features ever added to Visual Studio; it encourages structuring the surface rather than the actual OO structure.

Nowadays, I kill #REGIONs on sight.

Cumbayah
  • 161
  • 1
  • 1
  • 5
  • 11
    I tried to up vote this a dozen times... – TGnat Sep 09 '10 at 17:54
  • 22
    If you think you need #REGION, I think you need to refactor. – Jay Bazuzi Sep 09 '10 at 19:56
  • 1
    I slightly disagree with you, Jay Bazuzi. Whilst they can definitely be used to mask poor coding "standards", they can actually be useful to developers who have to come back and diagnose an issue in complicated processes - IF USED RIGHT! – Sk93 Sep 10 '10 at 08:15
  • 23
    I generally organize code by regions into constructors, properties, events, methods, and members. It makes managing and navigating the source a cinch (especially in some static utility classes that can grow pretty large). I wouldn't use them any more than that though. – Evan Plaice Sep 11 '10 at 08:23
  • 26
    We have a simple coding standard: **never** nest regions. Just use them to group related methods (initialisation, serialisation, properties, etc) – Jason Williams Sep 11 '10 at 21:53
  • 3
    Agreed, and Visual Studio is a decent IDE with enough code navigation options not to need them. They're one more thing that needs maintaining, and over time usually end up out of sync with the code they're supposed to be wrapping. – richeym Sep 13 '10 at 23:12
  • 5
    Grouping functions, initialization and properties make pretty good use of regions though. Anything else is incredible confusing – Jonn Sep 14 '10 at 04:27
  • I never understood the #region hate. Ctrl+M,L and they're all expanded. – Richard Morgan Sep 23 '10 at 17:16
  • 6
    The only good purpose of #regions is to hide code that **doesn't need to be edited**. That could be generated code, or code with a difficult-to-get-right algorithm that you'd rather people not touch, or maybe ugly debugging-code blocks. But not code that people will be working on. For those stuck in a #region shop, I have a macro that collapses to definitions but expands regions. See here: http://stackoverflow.com/questions/523220/awesome-visual-studio-macros/1545900#1545900 – Kyralessa Sep 29 '10 at 01:28
  • @Kyralessa I disagree. Regions shouldn't be used to hide code. They can be used to group similar parts of the class (using whatever definition of similar you want for that class), but they have to be used smartly. – configurator Sep 29 '10 at 03:55
  • Re-read; using regions just to hide code isn't what I said. – Kyralessa Sep 29 '10 at 13:33
  • 1
    regions when used correctly and in moderation are helpful at hiding code you don't need to see, such as a list of properties in a model class when you're creating methods. – Jason Oct 05 '10 at 19:00
  • I like the approach taken by Eclipse. No manual regions, but it does auto-hide the `import` statement block. Everything else is up to you, but is based on the semantic content of the source code. –  Oct 24 '10 at 11:13
  • At one of my former companies, the guy who did this a lot and advocated it as a refactoring solution now runs the entire department (30+ people). Go figure. – Jas May 20 '11 at 08:20
  • I find regions useful when working with legacy/spaghetti/monolithic code where I need to group things together so I know what is doing what. It helps with the refactoring or maintenance of that code. – theJerm Oct 16 '12 at 15:51
97

This may ruffle a few feathers, but standards that mandate templated block comments at the top of each method always bug the crap out of me.

1) They are always out of date since they are too far from the code that does the actual work to notice when you are updating things. Bad comments are worse than no comments.

2) They often just repeat information that is already contained the source control tool, just less accurate. For example: Last Modified by, list of modification date/reasons.

JohnFx
  • 19,052
  • 8
  • 65
  • 112
  • 12
    I find (at least now, earlier at school that seemed strange) that Commenting altogether is a bad practice – Shady M. Najib Sep 09 '10 at 15:52
  • 14
    Not only that but I've found that the overhead associated with creating a new class file when you have to put a load of boilerplate at the top actually dissuades devs from creating new classes and encourages enormous unwieldy classes and hence bad design. – Gaz Sep 09 '10 at 16:50
  • 13
    Disagree! We don't add useless ore reduntand information, but an actual textual explanation of what the function does (in the .h file) and it is so useful! Of course we are committed to maintain it in sync with the code. – Wizard Sep 09 '10 at 18:09
  • 2
    The exception to this one are Javadoc/XMLDoc/Doxygen style comments. – Billy ONeal Sep 09 '10 at 20:07
  • 5
    @Shady M Najib bad always or bad when allowed to go uncontrolled/unmaintained? Generally, good code will make its purpose obvious enough to avoid the need for comments- but that isn't always the case and I feel that in these scenarios commenting is crucial. I can't think of one bad reason to include XMLDoc comments. – Nathan Taylor Sep 09 '10 at 23:27
  • @Nathan Taylor Enforcing comments to stay in sync always proves to be such a failure.. I claim (actually not me, much well known ppl like Uncle Bob for eg) that using Longer & more descriptive classes/methods/variables names or let me say generally applying SOLID principals in your code is much better than writing comments that lose their meaning in no time – Shady M. Najib Sep 10 '10 at 01:01
  • 7
    A block explaining what it does is good. A block simply re-iterating the types and names of the arguments and return value is bad. When I had to work with a standard mandating the latter, I wrote an emacs script to auto-generate the majority of it. – AShelly Sep 10 '10 at 16:53
  • 1
    On classes that are have public or internal access they're necessary for documentation (with only information pertaining to the contents, no last modified junk of course). For private classes/methods a one line short description should suffice. – Evan Plaice Sep 11 '10 at 08:18
  • Use a tool like AtomineerUtils (http://www.atomineerutils.com) to fill in/update the comments for you. Then it takes almost no time to do and it's easy to keep comments in sync with the code. Yes, all the information that it puts in the comment is derived from the code so you could 'work it out for yourself', but it forms a *quick-read summary* (e.g. it automatically lists all exceptions thrown within the method). You can then add the vital documentation notes to help others who have to use or modify the method in future without wasting time on the 'boilerplate'. – Jason Williams Sep 11 '10 at 21:44
  • @Jason - I think you are missing the point. It wasn't just that I hated writing those comments. I hated how they cluttered up the code. – JohnFx Sep 12 '10 at 00:22
  • 2
    @JohnFx: I agree that forcing programmers to add useless comments is a waste of time. To my mind, "not liking the clutter" usually indicates (a) you don't feel the comments add value, and (b) you're not used to having them there... so they feel like they're getting in the way. The way to turn this around is to make the comments *useful and informative*. – Jason Williams Sep 13 '10 at 21:05
  • 2
    I'm all TOO used to having them there. I don't find they are valuable. A single line that summarizes what the method DOES is fine. I'm mostly talking about the whole "Created On, Created By, Last Modified, inputs, Outputs" type comment blocks. – JohnFx Sep 14 '10 at 13:52
  • They can be useful if, for instance, you're using the /// tags in a language that uses it for the purposes of intellisense. – Steven Evers Sep 23 '10 at 16:29
  • @shady, there is nowhere else to put the "why?"s –  Sep 26 '10 at 22:02
  • @Thorbjørn Ravn Andersen - If it needs "why?"s then the code probably could use some refactoring. Hence the reason some think excessive comments is a code smell. – JohnFx Sep 27 '10 at 01:04
  • 1
    @Thorbjørn Ravn Andersen I find the claims (by ppl like Uncle Bob for eg) that meaningful (yet longer) variable/methods names, and using shorter methods bodies (taking Single responsibility principle to the extreme) will make you achieve more readable code & would make you relay less on comments.. The code would really be speaking out its intent – Shady M. Najib Sep 29 '10 at 09:01
  • I was going to post a question about (Do you think of Comments as a Code SMell or a must-do?) but I found this: http://programmers.stackexchange.com/questions/1/comments-are-a-code-smell we might join this discussion better to talk about it – Shady M. Najib Sep 29 '10 at 09:06
  • @JohnFx, perhaps a better word is "because". Explaining why a certain algorithm was chosen *because* you happen to know that there is another requirement over there too. –  Oct 04 '10 at 06:39
  • 1
    @Shady, long variable names do not necessarily express the underlying decisions. For instance, why choose a TreeMap instead of a HashMap? _Because_ the output happen to be sorted which is needed later. –  Oct 04 '10 at 06:41
  • @Thorbjørn Ravn Andersen: I'm not really sure if such "architectural" decisions should be even expressed in code (either comments or variables names).. – Shady M. Najib Oct 04 '10 at 07:05
  • @Shady, this is a much lower level than arcitechture. For any non-trivial decision not to use the defacto-standard (like an ArrayList or a HashMap) you should tell the future readers _why_ you didn't. –  Oct 06 '10 at 11:20
  • 2
    Like code complete says. The code should contain the "how it does it". The comment should contain the "what it does". – Carra Oct 27 '10 at 15:53
  • I think what you're describing is poor documentation, not a bad standard. – Rei Miyasaka Aug 21 '11 at 23:27
  • We use this style in our COBOL code on z/OS. No subversion (or better) tools there. – Wayne Werner May 17 '12 at 11:32
  • the documentation is never wrong, the code is. – DPM Jun 23 '13 at 03:25
80

In one job we were forced to use some weird form of Hungarian notation in the database.

I can't remember the details, but from memory, each field name had to contain:

  • No vowels
  • All uppercase letters
  • A reference to the table
  • A data type indicator
  • A data length
  • A nullable indicator

For example, the column holding a person's first name might be called: PRSNFRSTNMVC30X (Person table, First Name column, Varchar 30 characters, Not Null)

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Damovisa
  • 1,975
  • 3
  • 20
  • 23
47

Insisting that all braces be followed by comment for what the brace ends:

e.g:

for (int i = 0; i < 10; i++)
{
    if (foo > bar)
    {
        printf("Foo greater than bar");
    } // End If (foo > bar)

    while (baz)
    {
       farb();
    } // End while (baz)
} // End For
Kris Erickson
  • 381
  • 2
  • 4
  • 21
    More seniable: if you need a comment to say what the start of the block was, then the block is too long, or its content is too complex => refactor. – Richard Sep 09 '10 at 19:56
  • 5
    I want to vote down, because long, deeply nested blocks can be hard to sort out, and these comments might help. I want to vote up, because those comments will become wrong (and very confusing) pretty soon, and because long, deeply nested blocks are a sign you need to refactor, not add more comments. – Jay Bazuzi Sep 09 '10 at 20:06
  • 7
    that was a great idea for a world with no powerful IDE. – IAdapter Sep 09 '10 at 22:17
  • 9
    @Jay in any decent IDE you can highlight one brace and it'll highlight the other corresponding brace. I personally loathe when people do this. – Evan Plaice Sep 11 '10 at 08:32
  • @Jay Bacuzi: Tabs/Spaces + decent IDE. Done. – Hello71 Sep 14 '10 at 00:07
  • @0101: Note that, by this criterion, both vi and emacs as shipped are powerful IDEs. – David Thornley Sep 23 '10 at 14:48
  • Inherited such a code base..... Sigh... –  Sep 26 '10 at 22:05
  • 3
    While your example is a bit on the crazy side (as they aren't long enough that it would matter and would slow you down when changing the logic), this isn't always a bad thing. Comments like that are really useful for closing namespaces/endif declarations that span an entire file. – jsternberg Oct 31 '10 at 19:55
  • I sometimes use this: `for (int i = 0; i < 10; i ++) { } // for i`, because `i` identifies the `for` – Ming-Tang Nov 10 '10 at 05:02
  • Well, it makes sense, if your IDE sucks and you have long blocks of code. It happened at one of my jobs and it didn't seem extraordinarily bad there. I would like to add that it only makes sense if you have nested code with lots of lines between, not as a general rule. And yeah, I agree that this is a bit code smelly, but if you have to maintain old code that cannot be completely refactored, it's not that bad. – Anne Schuessler Apr 13 '11 at 16:09
  • 1
    Yes! I have seen this pain. The practitioners of this style say "but it might grow to be a large block some day!" To which I say, "Yes, and when it does, THEN refactor to add your end-of-block comment." In the common case (1-5 line if/for/while blocks) these are wholly unnecessary. Make the common case clear and clean, don't muck it up for the 3% of large blocks out there. – anon Aug 21 '11 at 23:07
37
#define AND  &&
#define OR   ||
#define EQ   ==

'nuff said.

Niall C.
  • 879
  • 2
  • 11
  • 16
36

I was asked by the software leader of a company to do "simple, rendundant code". It was forbidden, for example, to add a new parameter to an existing function. You instead had to duplicate the function, leaving the original untouched in order to avoid regressions. No formal testing of course (waste of time).

We were also forbidden from using merge software; each file could only be modified by one programmer at a time. Revision control software was science fiction, of course.

The happiest day of my life was when he was fired (consider that it is very, very difficult to fire someone in Italy).

John Kugelman
  • 202
  • 2
  • 7
Wizard79
  • 7,327
  • 2
  • 41
  • 76
36

All interaction with the database has to be done through stored procedures. It might make sense if we're living in 1997 and not 2010.

I just realized that this actually covers all the criteria of the original question:

  • Greatly decreased your productivity? CHECK. Please - just use an ORM.
  • Were originally included for good reasons but were kept long after the original concern became irrelevant? CHECK. The manager was a developer for a database server 1000 years ago and put this coding standard in.
  • Were in a list so long that it was impossible to remember them all? CHECK. This included 'as much logic should be stored in the database as possible'.
  • Made you think the author was just trying to leave their mark rather than encouraging good coding practice? CHECK. Keeps coming back to the manager being an ex-database server developer.
  • You had no idea why they were included? CHECK.
Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Jaco Pretorius
  • 4,057
  • 2
  • 27
  • 38
  • Wow that sounds so much like my last project. – Jass Sep 09 '10 at 17:50
  • 2
    We've got some people in this camp in my workplace. It's funny when they try to play the performance card and demonstrate just how out of date their knowledge is – Doctor Jones Sep 09 '10 at 17:55
  • 3
    wait.. in all seriousness, I thought SP's WERE better, performance-wise, than straight SQL calls from, say, C#? – Sk93 Sep 10 '10 at 08:14
  • 2
    Yeah I don't have a problem with SP's - I just have a problem with not using an ORM and forcing ALL db interaction with SP's – Jaco Pretorius Sep 10 '10 at 09:53
  • 3
    Sounds like you know exactly why they were included. :P – Mason Wheeler Sep 10 '10 at 23:38
  • But didn't the DBA write all of those? – JeffO Sep 14 '10 at 19:45
  • 4
    When I grew up I finally understood why everything should go through the DB :) In all seriousness, this simplifies so many things, don't try and re-invent the wheel. – Jé Queue Sep 16 '10 at 17:19
  • 3
    I've heard the lovely reasoning "We can't use an OR/M because all interaction must use SPs". Such a waste of man-power. – configurator Sep 29 '10 at 04:01
  • 1
    @Jaco: and you've missed one issue with Stored Procedures, performance. Better to put the burden on the multiple clients that on the database when possible, cause you only have one database. – Matthieu M. Oct 14 '10 at 17:55
  • Some databases are very easy to program through stored procedures. E.g. DB2/400. –  Nov 01 '10 at 08:13
  • I don't agree with it. There're scenarios where you need stored procedures because it is the only way to have a controlled restricted access to result sets. You don't have a "user may select rows x y but not z from table a"-privilege on most databases. – Falcon May 20 '11 at 11:15
  • I'd much rather use SPs than ORM when the original devs built the whole damn system as a workaround to hibernate config-fail at the foundation. – Erik Reppen Jun 22 '13 at 21:22
  • SPs in conjunction with a half-arsed home-brew ORM is the ultimate hell. Another crazy standard at the place that dumped that on me was "No IDENTITY columns in the database" - so we ended up having to home-brew a mechanism for generating entity IDs. – Julia Hayward Dec 05 '13 at 16:56
36
  • Local variable names are all lowercase with no underscores

Real examples: paymentmethodtotalshtml, contracttypechangecontexts, customsegmentspectexts, potentialmsceventref

The New York Times weighs in:

“Word spaces should not be taken for granted. Ancient Greek, the first alphabet to feature vowels, could be deciphered without word spaces if you sounded it out, and did without them. […] Latin, too, ceased to separate words by the second century. The loss is puzzling, because the eye has to work much harder to read unseparated text. But as the paleographer Paul Saenger has explained, the ancient world did not desire ‘to make reading easier and swifter.’”
Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
John Siracusa
  • 101
  • 1
  • 5
  • 3
    +1. The minor annoyances add up. Also they are hard to argue against because the coding standards editor or PM can say "It's no great burden so it's not worth changing it." – finnw Sep 09 '10 at 18:43
  • 1
    Exactly. (Though in this case, reading umpteen variablenameslike thiscanreally adduptoquitea greatburden.) – John Siracusa Sep 09 '10 at 18:58
  • 57
    Amuse yourself by inventing names than be parsed two ways. pageshits, penisup, etc. – Jay Bazuzi Sep 09 '10 at 19:59
  • 4
    @Jay *sexchange – configurator Sep 29 '10 at 04:04
  • 2
    @configurator: When the Visual Studio debugger team was working on a feature to let you see the currently-in-flight exception in the watch window, they were going to add a pseudo-variable called "$ex". We didn't notice for a long time. Then we renamed to "$exception", but I still read it as having an 's'. – Jay Bazuzi Sep 29 '10 at 06:33
  • 1
    You should have kept it as $ex. Would make programming a bit more fun! – configurator Sep 29 '10 at 06:34
  • Hilarious. Reminds me of a bunch of code we have where the dev reduced potential deal to potDeal. isPotDealDifferent() just writes it's own parameters. – Erik Reppen Jun 22 '13 at 21:25
33

Not being allowed to use the STL or other standard C++ libraries because the CTO believed 'we' could do it better and faster. Even basic constructs like lists and the string class.

David B
  • 21
  • 2
  • 4
  • 5
    The only time I've ever heard of anyone not using the STL because it wasn't fast enough, and being right, was for games. EA made their own implementation of the STL for their games. I highly doubt it matters anymore (modern games are GPU limited) and I doubt they use it. But even still, it was an *implementation* of the STL, not a whole new library. You were still using the STL when using EASTL. – Matt Olenik Sep 13 '10 at 23:18
  • 1
    @Matt: to add to this, EA complaint was centered on memory usage and initialization. Their own implementation consumed less memory, released it sooner, and avoided initializing objects that would be initialized later. – Matthieu M. Oct 14 '10 at 18:00
  • I'd tell him to code it himself. –  Aug 12 '11 at 14:30
31

Hungarian notation

Sample extracted from "Charles Simonyi's explication of the Hungarian notation identifier naming convention" on MSDN.

1  #include “sy.h”
2  extern int *rgwDic;
3  extern int bsyMac;
4  struct SY *PsySz(char sz[])
6      {
7      char *pch;
8      int cch;
9      struct SY *psy, *PsyCreate();
10      int *pbsy;
11      int cwSz;
12      unsigned wHash=0;
13      pch=sz;
14      while (*pch!=0
15        wHash=(wHash11+*pch++;
16      cch=pch-sz;
17      pbsy=&rgbsyHash[(wHash&077777)%cwHash];
18      for (; *pbsy!=0; pbsy = &psy->bsyNext)
19        {
20        char *szSy;
21        szSy= (psy=(struct SY*)&rgwDic[*pbsy])->sz;
22        pch=sz;
23        while (*pch==*szSy++)
24            {
25            if (*pch++==0)
26              return (psy);
27            }
28        }
29      cwSz=0;
30      if (cch>=2)
31        cwSz=(cch-2/sizeof(int)+1;
32      *pbsy=(int *)(psy=PsyCreate(cwSY+cwSz))-rgwDic;
33      Zero((int *)psy,cwSY);
34      bltbyte(sz, psy->sz, cch+1);
35      return(psy);
36      }
sourcenouveau
  • 6,460
  • 4
  • 29
  • 44
JD Frias
  • 401
  • 3
  • 8
  • That looks more like *literal* Hungarian notation. – DisgruntledGoat Sep 09 '10 at 16:31
  • 5
    Ow ow ow ow ow ow! – Doctor Jones Sep 09 '10 at 17:57
  • 22
    The biggest problem with this sample is the meaningless variable names. Strip away the Hungarian prefixes and some of them are 1 or even 0 characters long. – finnw Sep 09 '10 at 18:54
  • I've only ever found hungarian notation useful in GUI programming where labels/buttons/etc, all pertain to the same functionality. Ex, lblName, btnName. – Evan Plaice Sep 11 '10 at 08:25
  • 8
    This is Systems hungarian, which is useful in weakly-typed languages (as it encodes the type information that is critical for working in these languages in the names) - it's useless in strongly typed languages. The better alternative for strongly typed languages is Apps Hungarian, which encodes important information about the *usage* of a variable (member, pointer, volatile, indexer) - something the language itself provides no support for. – Jason Williams Sep 11 '10 at 21:51
  • 5
    Oh please. I've never _ever_ confused a local with a member, and I don't use that silly Hungarian for members/locals/fields/whatever. I think they might be useful for differentiating between different kinds of strings, like 'safe' and 'unsafe', like Joel's example in [Making Wrong Code Look Wrong](http://www.joelonsoftware.com/articles/Wrong.html) – configurator Sep 29 '10 at 03:59
  • 3
    @configurator: Joel's example is horrid, he'd be better off having different types, then the compiler would enforce the use. – Matthieu M. Oct 14 '10 at 17:57
  • Different types of strings? That support all the string operations? How would you do that, exactly? – configurator Oct 14 '10 at 23:38
  • @configurator: Honestly, I'd rather make wrapper classes for Safe and Unsafe, even if I had to make an extra dereferencing call. – Scott Whitlock Oct 31 '10 at 19:18
  • @Scott: So would I, in most cases. But not always. – configurator Nov 01 '10 at 19:19
  • 2
    I thought this code was obfuscated... – jokoon Nov 29 '10 at 13:45
  • What. The. F? My eyes, the goggles do nothing! – Wayne Molina Apr 13 '11 at 18:30
  • The only reason I'd ever consider using hungarian is for UI elements because they rarely change. Other than that...I can't see anymore after reading that. – Casey Jul 08 '11 at 16:48
  • 1
    @configurator I actually did come across an explanation for the value of putting "m_" on member variables recently: http://www.javaspecialists.eu/archive/Issue025.html Of course then they go on to explain why it's not actually necessary but I was glad to see there was an actual good reason. – Tyler Jul 09 '11 at 00:54
28

I once worked on a project in which the project lead mandated that every variable - EVERY variable - be prefixed with "v". So, vCount, vFirstName, vIsWarranty, etc.

Why? "Because we're working in VBScript and everything is a Variant anyway".

WTF.

26

Almost forgot this one:

Quote from a manager:

Do not fix or document any bugs of issues you find in your own code. The customer will pay us to identify and fix them over the next few years.

This wasn't for consumer software, but custom for a single large organization. Needless to say, the customer did pay for years afterwards. May seem trivial, but trying to ignore bugs is harder than finding them.

David B
  • 21
  • 2
  • 4
  • 2
    This is a horrible policy. I hope this manager was canned. – Bernard Mar 16 '11 at 15:37
  • @Bernard-In most organizations creating a long term revenue stream is grounds for rapid promotion. Hopefully, somebody else saw the insanity in this and accidentally ran him/her over in the parking lot. – Jim Rush Jul 08 '11 at 17:54
24

Enforced XML comments on all non-private methods, constants, enums, and properties.

It led to some pretty cluttered code, especially since the end result was people either just hitting /// to create an empty comment stub for everything or installing GhostDoc and having it add auto-generated comments:

/// <summary>
/// Validations the handler.
/// </summary>
/// <param name="propertyName">The property name.</param>
public void ValidationHandler(string propertyName) 
{
   // whatever
}

[Edit] The reason I mention this as a ridiculous standard isn't because I think method comments are stupid but because the quality of these comments wasn't enforced in any way and resulted in just creating lots and lots of clutter in the code files. There are better ways of creating meaningful code docs than blind "must have a comment" build requirement.

Adam Lear
  • 31,939
  • 8
  • 101
  • 125
  • I never understood why /// is used instead of multiline comments for these. – alternative Sep 08 '10 at 21:36
  • 13
    '`Validations the handler`' - uh-oh – Eric Sep 08 '10 at 21:46
  • 8
    +1 Ugh I hate this. I think if your using software to generate comments then you dont need them. – bleevo Sep 08 '10 at 23:40
  • Only public? No minum length or required punctuation at the end? Nothing run on every build to check it? Consider yourself lucky... – Robert Fraser Sep 09 '10 at 03:13
  • 1
    They're enforced in the solution files... nothing builds if there is any non-private method, etc. without a comment. – Adam Lear Sep 09 '10 at 03:20
  • 9
    I don't think this is a bad rule. When reading a method that I have to maintain for the first time it helps a lot if I have specifications for all the arguments. There are usualy subtleties (e.g. what happens if the argument is null, what if it's an empty collection, the name of a nonexistent file etc.) Another good (IMHO) rule is method names should be verbs but in your example it's a noun. – finnw Sep 09 '10 at 09:18
  • 3
    @finnw I think it's a good practice, but a bad standard. If developers are on board and writing meaningful method comments when they're warranted (exception details, etc), that's great. If not, you end up with a big mess. And in the former case, you don't need compilation-level enforcement at all. – Adam Lear Sep 09 '10 at 13:27
  • 2
    This isn't quite O/T but my pet hate is when you get a page full of property comments of the sort "Gets or sets Foo". You don't say! – Gaz Sep 09 '10 at 16:52
  • 7
    Classic case of undocumentation. Comments that don't tell anything apart from the blatantly obvious should be killed on sight. – Cumbayah Sep 09 '10 at 17:05
  • Guilty of this. A previous client DEMANDED the .xml files on a regular basis; since then, it's pretty much crept into other projects as well. – Jeremy Frey Sep 09 '10 at 17:56
  • 1
    I personally like this -- but if and only if the comments are actually meaningful. The docs generated have been quite useful quite often -- they save me from having to reread quite a bit of code. – Billy ONeal Sep 09 '10 at 20:10
  • 1
    It's necessary if you're using auto documentation generation or creating a library that will be used by others. No comments on public/internal members = no useful intellisense info and failed autodoc generation. – Evan Plaice Sep 11 '10 at 08:30
  • A little diligent commenting can go a long way. Why not? Combined with SandCastle, it saves you and a few future developers time to understand what something does. (I prefer doing this after the code's all prim and proper so I won't have to change a lot of things when change creeps in) – Jonn Sep 14 '10 at 04:32
  • I cannot agree with this one more. Our code bloats itself by at least a factor of 3 for stuff like this which in my view obscures code more than making it readable. – David in Dakota Sep 24 '10 at 16:55
  • If you have CollapseToDefinitions mapped to a handy key combo (I use Alt-Left), these aren't as likely to get in your way while you code. – Kyralessa Sep 29 '10 at 01:31
  • You don't have to use ///, you can use /** ... */. Even "obvious" doc comments are very useful if you use intellisense or external docs, where you **can't see the source code**. GhostDoc & AtomineerUtils save a lot of time entering basic info, so it only takes a few seconds to create great docs, including critical info that even "self documenting" code won't tell you. They keep existing docs in sync with code effortlessly. AtomineerUtils extracts much more info from the code (e.g. thrown exceptions) that takes a long time to read for yourself, so it very effectively summarises the code. – Jason Williams Feb 17 '11 at 20:59
  • I put this in the Standards for our company, but for a reason. Not only is it enforced to put a comment, but the contents of the comment are also enforced. The contents must make it clear that the method does one thing, thus following SOLID Principles. If you have to type "and" in the comment, you need to refactor. This also ended up making "brown-field" transition into Unit-Testing very easy for "legacy" software. But not many places have legit reasons and enforcement to pull this off. – Suamere Sep 16 '13 at 17:34
23

Not really a coding standard, but we had a file in source control called 'changelog.txt'

Every time you made a checkin, you had to manually add an entry to this file. This entry was the subversion revision number and your checkin comment.

When the new CTO started and someone told him this, he promptly made an executive decision and said, "We're not going to do this anymore" and deleted the file. This had been going on for years.

Jon Purdy
  • 20,437
  • 7
  • 63
  • 95
Jim A
  • 119
  • 4
  • 6
    And no one was aware of `svn log`? – Htbaa Mar 16 '11 at 14:51
  • 1
    Those who started the policy were long gone and those that followed kept it going. I started within the same week as the new CTO (friend of mine) and we both looked at this and said WTF? – Jim A Mar 30 '11 at 11:06
20

Some of the places I've worked with insisted on commenting out unused or deprecated code instead of deleting it. Instead of trusting the VCS for history, etc. it was painfully maintained in the files through commented out code.

The big problem I found with this is that you often had no idea why the code was commented out. Was it because some dev was actively making changes and wanted to keep it around for reference or was it no longer needed?

Jeremy Wiebe
  • 121
  • 3
  • 3
    I've been deleting a lot of old commented out code recently. – CoderDennis Oct 05 '10 at 20:03
  • 2
    I usually delete commented out code unless it is accompanied by a good explanation for why it's commented out and why it should be kept in place. – Jeremy Wiebe Oct 06 '10 at 00:35
  • I totally agree. Commenting code out as long as you work with it is okay, but everything that goes into a release version/main branch should be void of commented code. Someone told me that they "liked to know how it could be done differently". I just find it irritating for the reasons mentioned: Is that obsolete, a workaround, another way to do it? WTF – Anne Schuessler Apr 13 '11 at 16:12
  • With VS2013 "Peeks" this is all out the window. But we put a comment that says "Changed Equation - Initials" or something, so somebody wondering what the old code was would look in TFS/VCS if they needed to. So it's one line instead of 10 commented-out lines. But VS2013 is awesome, it shows TFS history right there for you. – Suamere Sep 16 '13 at 17:39
17

The worst coding standard I've ever participated in is code bases which had none at all. I'd rather follow a coding standard I completely disagree with than work in code bases where there is none at all. It makes it that much harder to learn new parts of the code base.

JaredPar
  • 997
  • 6
  • 12
16

Forcing inline comments for version control was about the most pointless coding standard I ignored.

//Changed on 2/2/2004 By Ryan Roberts for work item #2323332
Dim Some Horrendous VB
//End Changed

The Oracle DBA that insisted on correct use of whitespace while 'maintaining' a database with a highly contended table that had over 200 fields and 40 triggers comes close.

Ryan Roberts
  • 491
  • 2
  • 7
  • That's pretty heinous – Evan Plaice Sep 11 '10 at 08:31
  • 5
    Mmm. Dim Sum... – configurator Sep 29 '10 at 04:06
  • I did this, before we had source control, of course. Once we had source control, it was such a habit, we practically needed an intervention for the team to stop doing it. Eventually we stopped and deleted all the existing ones when we found them. – Scott Whitlock Oct 31 '10 at 19:24
  • Our senior dev still tries to force us to do this. I ignore the policy whenever I think I can get away with it (and sometimes when I know I can't). – Joshua Smith May 20 '11 at 14:23
  • We have a guy on our team who still does this everywhere (he also includes huge "Change Log" things on our SQL scripts which are also under version control). The argument, as explained to me, is that after a few changes/commits you don't remember the date something was changed, so the change log is good to immediately notice who changed what and why when you open up a file. – Wayne Molina Jun 02 '11 at 15:43
  • VS2013 is coming out (I'm using RC now), and it allows you to Peek at TFS history for lines or methods... it's amazing. Nobody should ever say to comment out code or comment changes ever again. Lol – Suamere Sep 16 '13 at 17:40
14

I did code reviews on a project led by a C++ first timer who decided that all class member functions should be prefixed with the class name and visibility:

class MyClass
{
   public:
      void MyClass_Public_setValue(int value);
}
9

I had a job years ago where all our code had to be left-aligned - no indenting. The guy who came up with that policy disliked having to scroll back and forth horizontally when viewing long lines of code, equating it playing ping-pong with his eyes.

Jeremy
  • 1
  • 2
  • That's a horrible, horrible coding standard to have to follow. And a stupid reason for it, too! – gablin Sep 23 '10 at 21:00
  • 4
    If you need to scroll horizontally (for example more than half a page) there's probably something wrong as well. No indenting isn't good either as it makes code completely unreadable. I try to stick with a 78-col limit, but if required to go over that amount I don't mind, but I do try to avoid it. – Htbaa Mar 16 '11 at 15:11
8

Being required to indent all code by four spaces ;)

RedFilter
  • 119
  • 5
  • 2
    How was this bad? – Jay Bazuzi Sep 09 '10 at 20:06
  • 1
    Because then every line has 4 unneeded spaces at the beginning of it? – nohat Sep 10 '10 at 02:09
  • Oh, I get it now. – alternative Sep 10 '10 at 22:21
  • 21
    Yeah, StackOverflow has really bad coding standard. :-) – P Shved Sep 11 '10 at 07:22
  • Big indents force you to keep the code nesting level low. I have seen indents of 8 and it worked fine. – Toon Krijthe Sep 15 '10 at 08:49
  • It all depends on the language. I've noticed my Java code is far more indented than C# code, because of Java's extra-silly anonymous-interface-instead-of-lambda syntax. And if you're developing in a language like Lisp/Scheme you can expect some major indentations. Also, if you're indenting by too much you'd start avoiding stuff like inner classes, which can make code much simpler sometimes. I like 1 tab for indentation, and my tab size is 4 spaces when using C#. – configurator Sep 29 '10 at 04:16
  • I use a mix of tabs (size 4) and spaces. – Mateen Ulhaq Nov 21 '10 at 23:48
  • I shouldn't have been so opaque — I was referring to the fact that you need to indent code by 4 spaces on StackOverflow for markdown purposes. – RedFilter Nov 22 '10 at 05:26
  • Lol, SO Jokes. Seriously though, I'm thinking of making 4-space indents a standard. I hate when some rogue dev changes their indenting and checks in a project. Then anybody else comes behind and makes a small change to one line and their VS settings partially jack up the entire project. >. – Suamere Sep 16 '13 at 17:42
8

This more an example of how not having coding standards can hurt.

A contractor working at a large bank insisted that following the standards were the best ever. The application was written in dBase/Clipper which he was the sole developer for and of course he came up with the standard.

  • Everything is in upper case. I mean everything, including the rare comments he made.
  • No indentation.
  • Variable naming was something along the lines of APRGNAME. A = scope of variable, eg P for public, PRG = first three characters of the source file that created the variable, NAME = variable name in the remaining 6 characters that dBase/Clipper allowed.
  • The first 4 and last 4 lines of the source code were 80 * long. Why? So he could hear the dot matrix printer starting and finishing the printing of a file. Memory is the entire program was printed via the mainframe weekly, 20,000 pages.
  • I'm sure there were many more that I've managed to dump from my brain.

I was a very new self-taught programmer at that stage but knew enough not to listen to the mad scientist and get the hell out of there before I asked to take over the project.

And yes we told management how bad these practices were but always got the usual "were paying this contractor top dollar he must know what he's talking about".

Tim Murphy
  • 578
  • 3
  • 9
  • 7
    Do not mock older dinosaurs, please. *They* made us possible. – P Shved Sep 11 '10 at 07:24
  • 4
    Sounds like job security. – MIA Sep 24 '10 at 01:22
  • 7
    Having an audio marker so you know when each file is printing is ingenious. I'm going to add `\07` to the start of each file now. – configurator Sep 29 '10 at 04:20
  • 2
    Using a naming scheme like this (Not the upper case) made some sense as dBase's variable "scoping" rules were non-existant. Everything was effectively global. An `i` used to index an array in one procedure could interfere with an `i` in a calling procedure. You need to use `PRIVATE ALL LIKE m*` and `PRIVATE i` to prevent this "shadowing" – Gerry Sep 30 '10 at 01:12
8

One more blast from my past.

Quote from company owner:

There will be no code written using interpretive languages because I lost 25 million on that {expletive} project written in Java.

The Java project was a stock trading system designed to handle a few dozen stocks, that was now being used to process thousands. Instead of addressing the design flaws or poor hardware, the whole company was forced to convert all non C/C++ applications to C/C++, and all new development had to be in C/C++. Interpretive languages meant anything not compiled, and the owner only considered Assembler, C and C++ compiled.

For an 800 person company, in which most of the code was in Java and Perl, this meant the whole company spent most of their time over the next couple of years rewriting perfectly fine code in C/C++.

Funny enough, some twenty years before this fiasco, I was at another company in which the tech lead decided that our sorting logic (it was a Bubble Sort) needed to be recoded in assembler instead of being replaced by Quick Sort because -- Algorithms do not improve performance. The only way to improve performance was to rewrite the same logic in assembler.

In both cases, I left shortly after the dictates came down.

David B
  • 21
  • 2
  • 4
6

Like a lot of programmers (but not enough), I hate code decoration. It infuriates me when I have to use a dollar sign($) prefix for variable names, or underscores for private variables, even with no getters/setters. If you need to decorate you code to understand it, then you need to get the hell out!

Adam Harte
  • 575
  • 4
  • 11
  • Well, as "Will" says, "I prepend with the underscore so that my private variables are grouped in my intellisense. However, I only do this for variables scoped to a type. Variables declared within a method or narrower scope I leave the underscore off. Makes it easy to keep them separate and keep less used variables together." and I have to agree with him. – 7wp Sep 09 '10 at 18:11
  • 1
    I don't think grouping your variables together in your favourite proprietary IDE is a good enough reason to deface all your code. – Adam Harte Sep 09 '10 at 20:44
  • If it's your code, making it usable in your IDE seems completely reasonable. Also, prepending underscores is common in many languages, so whenever people see it, they know what it means. – rjmunro Sep 09 '10 at 22:01
  • 1
    +1 Using a good IDE (one that can use _regex search_) makes more sense to me. Scratch IDE, learn to use a text editor and terminal and you will be a much better programmer. As a side note, I don't particularly like the perl sigils, but at least they have a use, unlike the PHP ones. – alternative Sep 09 '10 at 22:32
  • 6
    Sigh... another one of those "IDE's are for pussies" people. – Nailer Sep 23 '10 at 13:41
6

I worked in a project were the chief architect demand to write (way too) explicit code. One of the worst examples I found in the code (and he happily approved) was the following.

private string DoSomething( bool verbose )
{
    if ( verbose ) { return someString; }
    else if ( !verbose ) { return otherString; }
    else { return string.Empty; }
}

Even ReSharper told you this is wrong!

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
  • 9
    You'd be hard pressed to return something from a function declared as void. – Mircea Chirea Sep 09 '10 at 18:16
  • What is "explicit" about this code? – matt b Sep 09 '10 at 18:49
  • 7
    @MAttB Consider under what conditions the final (`else`) branch would be taken. – Richard Sep 09 '10 at 19:52
  • 6
    else { return string.Empty; } will execute when the above 2 lines have been edited by a maintenance developer 5 years from now. However, returning string.Empty will hide the fact that is used to be an *impossible* condition. It should instead throw InvalidOperationException("This code wasn't intended to support three value logic"); – MatthewMartin Sep 10 '10 at 19:23
  • 1
    This is horrific. What's wrong with `return verbose ? someString : someOtherString;`? – Callum Rogers Sep 24 '10 at 10:45
  • 1
    @callum Ternary operator might be banned :) been there before... – hplbsh Jan 11 '11 at 04:30
6

At my last job, "standards" would be a very strong term for what I was given by the guy who hired me. Programming websites in ColdFusion and SQL, I was given coding requirements like:

  • Don't use includes. I like one big page
  • Always separate words in variable and column names with underscores (except isactive, firstname, etc.)
  • Never use abbreviations -- always write out firstname (he frequently wrote fname and so forth)
  • Don't use confusing names (like amount_charged and charge_amount, which measured differnt but related things)
  • Don't use DIVs, and use minimal CSS -- use nested tables instead (I found some six layers deep, once).
  • Don't cache any queries. Ever.
  • Going to use a variable on more than one page? Application scope.
  • Each page is its own try/catch block. We don't need/want a global error handler.

I started changing these as soon as he quit.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Ben Doom
  • 101
  • 3
  • "Don't use confusing names" seems fair enough to me... – 8128 Oct 02 '10 at 15:15
  • 1
    It's absolutely a fair guideline. My point was that he didn't follow it at all. I guess his idea of "not confusing" and mine were different. – Ben Doom Oct 03 '10 at 15:00
6

I've been working with a web system for a while where all parameters passed had to be named P1, P2, P3 etc. No chance in hell to know what they where for without extensive documentation.

Also - although not strictly a coding standard - in the same system, every single file was to be named xyz0001.ext, xyz0002.ext, xyz0003.ext, etc - where xyz was the code for the application in itself.

6

This was a LONG time ago -- 1976 to be exact. My boss had never heard of Edsger Dijkstra or read an issue of CACM, but he had heard a rumor from somewhere that "GOTO is bad", so we were not allowed to use GOTO in our COBOL programs. This was before COBOL added the "end if", so at the time it had only two-and-a-half of the three classic control structures (sequence, if / then / else, perform (i.e. do while)). He grudgingly allowed GOTO in our Basic programs, and branch instructions in our Assembler language programs.

Sorry that this is a sort of "you had to be there" story. As far as I know, every language invented since 1976 has adequate control structures so that you never need to use GOTO. But the point is, the boss never knew WHY GOTO was considered harmful, or which language was the infantile disorder and which was the fatal disease.

Mark Lutton
  • 193
  • 6
4

In my life as C++ coder, two really nasty "rules" were enforced:

  1. "We can not use the STL, because VC++ 4.1 does not support it (and we can't switch to VC++ 6.0 at this time)."
  2. "Do not use QuickSort, because it can be O(n^2) in bad cases; use this implementation of the HeapSort algorithm I (name of project leader deleted) wrote as a student."
  • 6
    What was wrong with the project lead's HeapSort? – 7wp Sep 09 '10 at 18:02
  • 4
    Actually if code accepted external user input QuickSort may be wrong as it opens to `O(n^2)` DOS attacks (feeding worst-case input). Also why it wasn't possible to switch - it itself was valid excuse of not using STL. – Maciej Piechotka Sep 09 '10 at 22:17
4

I'm forced to have XML documentation for all classes and class members. Including private. I'm encuraged to use default ghostdoc comments.

public class User 
{
    /// <summary>
    /// the _userID
    /// </summary>
    private int _userID;
}
4

Nearly any sort of variable naming convention that reiterates the variable type, mutability, scope / storage class, and/or their reference. Basically, any construct intrinsic to the language. This is no longer necessary in the 21st century with modern IDEs (and in my opinion only originally solved poor code layout / practices to begin with). This includes hungarian notation and its variants:

  • bigBlobStr - A string.
  • bigBlobStrCurLocPtr - A pointer to the "current location" in said string.
  • someIntArray - Array of integers

or things like:

  • e_globalHeading - External variable
  • sg_prefPoolSz - Static global variable

and of course one the farthest reaching eyesore in OOP, m_ for all members. If you can't be sure / keep track of which variables are local, members, globals, static, or final/const, you might be writing unclear, poorly factored, spaghetti code.

This is wholey different than specifying a prefix/suffix convention for things like min, max, avg, size, count, index, et cetera, which is fine.

charstar
  • 101
  • 3
  • 1
    Sometimes there are [good reasons](http://www.joelonsoftware.com/articles/Wrong.html) for including type information in variable names. – finnw Sep 14 '10 at 02:09
  • 3
    Umm... interesting that you quote Spolsky's article on it, as it's more to the point, "The dark side took over Hungarian Notation." It's all about "Apps Hungarian" being twisted into "Systems Hungarian" because people make an incorrect inference about what Simonyi meant when he said "type". It's to see wrongness when you are assigning a "colX" to a "rowY", not so that you can keep track of the fact that something is a long integer as opposed to a short. Also, I specifically call out only variables. I foresee a -1 from swaths embedded devs still using vi and C++ devs as it's "just the way". – charstar Sep 14 '10 at 06:18
4

I worked for a short time in Japan. I was doing complex mathematical coding. The company coding standard was to have absolutely no comments. It was difficult as I would have liked to add some comments to explain the complex calculations and not forget myself after few weeks. Pity the next guy who comes after me to understand what the code was doing.

It was the first time I ever saw that coding comments were prohibited.

softveda
  • 2,679
  • 1
  • 21
  • 21
4

Worst standard I've ever had to face:

StyleCop for C#

Take every pointless standard ever and put it into a tool that runs at compile time instead of in the IDE at design time.

//this is not a legal comment.
//  nor is this

// must be followed by a single space, if you are debugging, use //// to comment code. Properties must also have 'triple slash' comments and they must read "Gets or Sets xxxxx" complete with a period at the end and properly capitalized.

Ugh. Maybe there's a point with widely published APIs but my main beef is they surely could have built it as a plugin a la R#.

MIA
  • 5,264
  • 19
  • 29
  • There's a plugin for ReSharper (Style Cop For ReSharper), which makes styleCop a lot more useable. – Ed James Nov 15 '10 at 17:53
  • My personal standard for period at the end is: if it's not a complete sentence, leave it out. It's fine to have a period here: `// Initialize balloon release context.` , but not here: `// If malloc fails`. – Joey Adams Dec 14 '10 at 04:06
  • StyleCop is great, though, IF you go in and remove those pointless standards that just make unnecessary work. Some things that StyleCop enforces are actually very, very useful. – Andrew Mar 03 '11 at 16:24
  • Using a different syntax to comment out code temporarily for debugging, and to write actual comments, makes sense. – Tyler Jul 09 '11 at 01:04
3

at my previous job, which I gladly quit 3 months ago:

database:

  • Table names had to be uppercase.
  • Table names had to be prefixed TBL_
  • Fields had to be prefixed: DS_ (for varchar, which made no sense) NU_ for numbers CD_ for ("bit fields") DT_ for dates
  • database fields had also to be uppercase [CD_ENABLED]
  • same with sp names [SP_INFINITY_USER_GROUPS_QRY] and database names [INFINITY]
  • did I mention sp names were actually like that? SP_ prefix, then database name SP_INFINITY_ then table name, SP_INFINITY_USER_GROUPS then what the sp was actually expected to do (QRY,UPD,DEL,INS) jesus, don't even get me started on queries that weren't just CRUD queries.
  • all text fields had to be varchar(MAX), unequivocally.
  • numbers were either int or double, even when you could have used other type.
  • "boolean" fields (bit) were int, no reason.
  • stored procedures had to be prefixed sp_productname_

asp.net / c# / javascript

  • EVERY single function had to be wrapped in try{}catch{}, so the applications wouldn't "explode" (at least that was the official reason), even when this produced things not working and not having a clue why.
  • parameters must be prefixed with p, e.g pCount, pPage
  • scope variables had to be prefixed with w (as in "working", what the hell does that even mean?)
  • statics with g, etc.
  • everything post framework 1.1 was offlimits, like you had any real uses for linq and generics anyways. (I made it a point to enforce them to let me use jquery though, I succeded at that, at least).
bevacqua
  • 221
  • 1
  • 8
  • If your DBMS was MS SQL Server then there *is* a reason to avoid `bit` - it cannot be part of an index, whereas a `tinyint` can be part of an index and you can add a `CHECK` constraint to restrict it to the values `0` and `1`. +1 for the try/catch rule. – finnw Nov 19 '10 at 12:25
  • I can guarantee that wasn't the issue at all, in fact all numeric fields were int (even fields supposed to be decimal), which led to obscure errors in the math department. – bevacqua Nov 19 '10 at 13:27
  • What a bunch of clueless idiots! I especially hate the "p" prefix for a parameter (code I am working on is full of that, sometimes with underscores sometimes without, sometimes without a p in general). Do people not understand that all of this pseudo-Hungarian Notation crap can be invalidated if you actually **name things meaningfully**?? – Wayne Molina Jun 02 '11 at 15:54
3

Mandatory inclusion, expansion of $Log$ information when our SCC was antiquated version of PVCS. We had some files where the $Log$ information was much, much longer than the actual code in the file.

Ian C.
  • 488
  • 4
  • 10
  • Can just put the $Log$ line at the end of the file, I've had to do that too, but sometimes I actually figured a few bugs out this way. – Jé Queue Sep 16 '10 at 17:23
  • 1
    If we were allowed to do sanity saving things like that, it wouldn't be in this thread. :) It was mandatory it appeared at the top of the file too. – Ian C. Sep 17 '10 at 16:20
3

The worst was a project (C++) where classes were prefixed with module abbreviations.

For example, if something was in the MessagePassing module, and part of the Response mechanism, it might be called MESPAS_RESSomeobject.

Working on that code made me want to gouge out my eyes.


Not the worst, but my current job requires a c_ prefixes on classes and e_ prefixes for enums. Nothing for structs. but _t postfix on typedefs. It's pretty ugly too.

Oh, and function header comments in BOTH .h and .cpp (declaration and definition) which of course almost never match.

µBio
  • 2,466
  • 4
  • 22
  • 23
  • Use `struct`'s with private members instead of classes then. – Joe D Sep 24 '10 at 19:43
  • Never heard of namespaces? – configurator Sep 29 '10 at 04:13
  • 1
    @Joe D. Yeah, because I, a lowly developer, can change the coding standard for a company that employs 3,000+ other developers. – µBio Sep 30 '10 at 16:37
  • @configurator I wish they had. By the time I started there were > 10 million lines of C++ code on that product – µBio Sep 30 '10 at 16:38
  • @BioBuckyBall: You could if you didn't consider yourself lowly. – configurator Sep 30 '10 at 21:00
  • 2
    @configurator it's not a matter of whether I consider myself lowly or not. I check in code out of coding standard format, it doesn't go to trunk. Period. And so my tasks don't get complete. Who looks bad, the engineers who define the standards for the entire industry, or me, who didn't complete my task? – µBio Oct 01 '10 at 22:18
  • @BioBuckyBall: It may not be easy to change coding standards. But it's hardly ever impossible. The way to do it isn't by trying to check in non-compliant code though! – configurator Oct 02 '10 at 00:11
  • 1
    With repesect to the second part of your answer: The class prefix is the really bad one. I'm indifferent about the _t for typedefs, since the C standard library (and thus much of the C++ standard library) uses that convention, and I can see some value in going with the language's standard convention. I'm not really a fan of the enum prefix, but can see some tiny value in it as a reminder that it is only a thin wrapper over an integer, and may have invalid values. – Kevin Cathcart Apr 23 '12 at 18:37
3

My favorite is the "No magic numbers" rule applied cluelessly. For example, I once saw a comment in a code review stating then the "No magic numbers" rule had been violated by this line of code:

if (fscanf(file, "%s %hd",name, nbrObject ) != 2 )

I guess the reviewer wanted a constant instead of 2, such as #define TWO 2

  • 1
    I'm in favor of magic numbers. You want to know the semantics of the "2" so a constant of TWO defeats the purpose. – Toon Krijthe Sep 15 '10 at 08:48
  • 4
    My C is a little rusty and I don't know what fscanf returns. Therefore this test is incomprehensible to me. Either a constant or a comment would solve this problem. – Foole Sep 20 '10 at 03:26
  • 28
    I think you misunderstood your reviewer. He probably wanted you to to add write it like this: const int itemsToRead = 2; if (fscanf(file, "%s %hd",name, nbrObject ) != itemsToRead ) – Nailer Sep 23 '10 at 13:34
3

All output in a PHP script must be echoed line by line.

<?php
echo "<div id=\"foo\">";
echo "<h1>" . $title . "</h1>";
echo paragraphs($body); // just an example
echo "</div>";
?>

(Disclaimer: I didn't have to follow it, but a team I worked with did.)

sholsinger
  • 131
  • 1
  • 4
3

At a previous job, the C# standard was to have at least two spaces between type name and variable name in declarations, the method name must begin on the next line from the access modifiers and return type, a space must occur before any open-punctuation (parenthesis or bracket), all variable declarations at the beginning of the method, declarations separate from assignment and the indentation was 3 spaces. Example:

private static int
ThisIsTheMethod (int  code, string  message)
{
   int  i;
   int  j;
   int  k;

   for (i = 0; i < message.Length; i++)
   {
      if (message [i] == '!') return -1;
   }

   j = SomeMethod (code);
   k = OtherMethod (j);

   return k;
}

While ugly, it was workable with the exception that Visual Studio really didn't want things that way and it was more an extra step after coding "normally" to reformat it as this.

Jesse C. Slicer
  • 6,002
  • 2
  • 32
  • 44
  • 1
    My head would explode. Seriously, WTF?! – Marcel Lamothe Sep 23 '10 at 15:21
  • 2
    Some of these you can configure in VS options (like the space before the parentheses), but not the double spacing. That doesn't make enough sense to be configurable. – Kirk Broadhurst Sep 24 '10 at 01:32
  • 1
    I've come to the conclusion people using C# need to realize **IT IS NOT VB6**. You can set variables on the same line as declaration. You don't need Hungarian Notation. You don't need this "m_" crap for member-level variables. I swear, most of my frustration with C# comes from people who still think in the old Classic VB mentality. I'm mad, bros. – Wayne Molina Jun 02 '11 at 16:00
  • Preach it, Brother Wayne! – Jesse C. Slicer Jun 02 '11 at 16:37
3

Our method names had to be in the format 'Get/Set/Add/Delete' + name of the target object + names of all the parameters.

GetUserById(userId);
InsertUser(user);
DeleteUser(user);

Fair enough - but the rule very strict. Complex object types were not allowed to be abbreviated, and operations always had to list every request parameter, no matter how ridiculous:

GetCustomerOrderDeliveryDetailsByCustomerIdAndDeliveryDateAndOrderStatus(...

After adding in the full variable names (which weren't allowed to be shortened, either) you can imagine how long some simple method calls were. Word wrappingly long.

Kirk Broadhurst
  • 4,199
  • 18
  • 27
  • I don't really see the problem. When using autocomplete at least. The function names are very descriptive. –  Aug 12 '11 at 14:34
  • The problem is about usability - when you can't see the name of a method and all of its parameters in a single screen width (i.e. you have to horizontally scroll to see the whole call) then it becomes significantly less usable. – Kirk Broadhurst Aug 14 '11 at 00:47
2

Maybe The Huawei Software Company's coding standard. They want you to declare all members public:))

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
LostMohican
  • 715
  • 1
  • 6
  • 10
2

Writing anything in Fortran (WATFOR, FORTRAN 77) where a non-whitespace character in column 1 was a comment, and the compiler didn't warn you if you went beyond column 72, it would just silently ignore it.

At least I only spent seven years doing this.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Mark Thalman
  • 171
  • 3
  • 10
  • Ouch - How much time did you waste? – Basic Oct 04 '10 at 10:32
  • It's a bit fuzzy, being this happened almost 20 years ago. You also need to know that a non-whitespace character in col 6 was a continuation of the previous line. I had an if statement that spanned multiple lines and what was out beyond col 72, when you ignored it, was still syntactically correct, so the compiler wasn't really wrong, but it could have put out a warning. I spent a total of about four hours figuring this out. This was on an HP-1000 mini running RTE. – Mark Thalman Oct 05 '10 at 12:10
  • That's not a coding standard so much as either a language or compiler problem. I assure you that if you'd been using punch cards with an 029 keypunch and a proper control card, you'd never have had that problem. – David Thornley Nov 15 '10 at 22:51
  • I missed punch cards by a half dozen years or so. My first programming class was taught on Commodore Super Pets with a cassette tape for storage. – Mark Thalman Nov 16 '10 at 15:48
  • Isn't being restricted to certain columns a coding standard? – Mark Thalman Nov 16 '10 at 15:48
2

Having what amounted to C header files, in a Java project.

Interfaces exist for some good reasons, but this standard mandated an interface (foo.java) for every single class (fooImpl.java) whether it made any sense or not. Lots of stuff to keep in sync, complete disruption of Eclipse click-into-method, pointless busy-work.

The build system enforced it, but I cannot imagine what the original purpose was. Fortunately we ditched it for new code when we switched to a new version-control and build system, but there's still a lot of it about.

At the same time we also ditched the stupid version-control-info-in-file-comments habit which had been mandatory.

Mateen Ulhaq
  • 968
  • 3
  • 11
  • 21
  • If you are using Eclipse, you also have "Extract interface" and "Pull up" and if there is only one implementation you will only get one result for "Find implementing methods." I agree this would be a pain in some editors, but not in Eclipse. And interfaces must be the #1 "Holy War" issue for Java coders. – finnw Sep 09 '10 at 18:51
  • This only makes sense if your creating a library, honestly, where you want any one class to be easily replacable simply by implementing the correct interface. Secondly, it is the interface that should be named weirdly, like IFoo or FooInterface or something... – alternative Sep 09 '10 at 22:47
  • @mathepic, I disagree because the interfaces tend to be referred to more often than the classes (for example you often see `void someMethod(Set s)` but not `void someMethod(HashSet s)`) and if you use the plain name for the class it can be ambiguous (is `class Set` a tree or a hash table? And what if you already have one in your library and want to add the other?) – finnw Sep 10 '10 at 09:14
  • @finnw But IFoo isn't any more difficult to type than Foo and it emphasizes that this class is an interface and can be completely rewritten. – alternative Sep 10 '10 at 22:20
  • 2
    +1 to rally against the belief that every class someone writes might some day be part of an far-reaching public API of global importance and therefore needs a rigid interface separate to its implementation... as if it's destined for the IETF or something. Most of time I see "Impl", it makes my blood pressure go up because this tells me you didn't write the interface to specify class compliance (good), you did it to because "everything is a framework" (bad+wrong). – charstar Sep 13 '10 at 23:00
  • 1
    "Find Implementing Methods" is all very well, but it's not much help when you see `foo.frobnosticateWith(bar);`, ctrl-click on frobnosticateWith, and find yourself at the interface definition of the method rather than the implementation you wanted to see. It's fine when interfaces are being used for good, and maybe there are (or could be) multiple implementations, but this is not the case here. –  Oct 05 '10 at 16:28
  • I don't know why this old thread just popped up on the prog.se homepage, but I just want to say in Eclipse Indigo, instead of ctrl-click, it's ctrl - small popup window - click, and in the small popup window you can choose "open declaration" or "open implementation" -- if there's only one implementation it just goes right to it. If there's more than one, of course, you have to choose. – Tyler Jul 09 '11 at 01:12
2

I currently work in a company where SQL queries are done through something called "Request Class". How ridiculous:

In "include/request.class.php"

class RequestClass
{
    // ... some code.

    public function getUser($where)
    {
        global $initrequest

        $sql = $initrequest['users']
        $sql.= $where;

        return execute($sql);
    }
}

In initrequest.php:

$initrequest['users'] = 'SELECT * FROM users WHERE ';

And it was called from the application in this way:

$request = new request();
$tmpquery = "username = $username AND password = $password";
$request->getUsers($tmpquery);

And they have a similar template system based in "blocks", but after understanding what I show here, I kept pressing to trash our whole software and rewrite it in Symfony.

  • BTW I forgot to say that this is properly indented because I wrote it that way. Don't expect that in the production code. –  Sep 09 '10 at 17:50
2

Where I'm working now the variable naming process for anything dealing with the database is:

  • $sql for statements
  • $result for query results

Which makes sense, however when I brought up the point that the convention was too generic and that this would end up with variable overlap the response was "use result_alt or sql_alt." My feelings on commenting, if you used proper variable names that signify purpose you wouldn't need comments or as many of them.

chrisw
  • 817
  • 2
  • 7
  • 14
2

The worst coding standard I ever had to follow was "All object variable names must be prefixed with 'obj'". This was on a big Java project, so almost everything was an object. The worst part was, almost everyone adopted a policy of naming variables by simply prepending "obj" to the class name. We wound up with stuff like Person objPerson1 throughout the code. I objected once, and had one of the other developers interject that she liked the convention "because then I don't have to think about my variable names". That place was a real horrorshow...

TMN
  • 11,313
  • 1
  • 21
  • 31
  • Sounds very painful since everything inherits from Object... that's a short lifespan on your 'o' 'b' and 'j' keys :) – anon Aug 21 '11 at 23:19
1

In Visual Basic 6.0, we had to add error handling blocks to every single method. No exceptions. So we did.

Then we had to explain why parts of the application were slow.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
1

Limited space for variable/object names is probably my largest irritation. I've worked in a relatively modern, proprietary language that only allows 10 characters. This is a holdover from its original versions.

The net result is that you end up with funny naming conventions defining what each character of your allowed 10 is to represent. Something like:

  • 1-3: application prefix
  • 4-6: module prefix
  • 7-9: user defined section
  • 10: a number just in case two...or 9 are named the same thing.
Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Brad Gardner
  • 101
  • 2
  • I know this is prevalent in online PLC programming due to limited storage space, but what modern language limits namespace like this? Why 10? – Christopher Jul 08 '11 at 14:58
1

My favorite would have to be the database naming guidelines we currently are trying to abide by. All tables used for many-many relationships should be named using the names of the linked tables and must be suffixed with "Link". And of course, no pluralization of table names.

  • OrderLines? Nope. It should be called OrderProductLink
  • Friends? Nope. It should be PersonPersonLink
CodingInsomnia
  • 439
  • 3
  • 7
1

"Do not use C++ comment style for C code".

While this may still have a small value if there is risk of needing to port your program to an obsolete compiler, it's mostly just a hassle. My biggest objection is that it makes it really hard to use /* to block comment out a large region during development or unit testing. */

AShelly
  • 5,793
  • 31
  • 51
  • +1. One of my projects came 'full circle". The original C compiler allowed only `/*` comments. Then an upgraded version allowed `//` comments. Then `//` comments were deprecated because the compiler vendor wanted to follow the standard more strictly. Then eventually we switched to another C99 compiler. Then we adopted another standard where `/*` comments were deprecated. Each time we had to change *all* comments in the whole project. Fortunately the project was relatively small (~200K LOC) – finnw Sep 10 '10 at 18:44
  • 4
    I use `#if 0` and `#endif` to block out regions, myself. – David Thornley Sep 23 '10 at 15:01
1

No more than one line of code allowed in Main()

A professor at my university who I was fortunate enough not to have insisted that her junior C# students not be allowed to put more than one line of code in their console applications' entry point.

This makes a reasonable amount of sense when developing a professional application, but when the program's only intent is to take few basic inputs and produce a single output (i.e. MultiplyTwoNumbers.exe), such a requirement is more pain than good.

On top of the "one line of code in main" the professor also insisted that every line of code have a descriptive comment and every class member have a verbosely descriptive name. Points lost if the professor didn't feel that these requirements had been met "adequately".

The students forced to stick to these rules were (almost) all newbies to programming and thus I can see the value of enforcing conducts like good-naming and separation of concerns. Despite that, as the .NET Tutor at my university I was constantly helping her students meet these mundane and obnoxious requirements long after they had gotten their code working.

In my opinion, when educating someone who is brand new to a programming language the first concern should be how to create code, not how to create standards-based code.

Nathan Taylor
  • 1,598
  • 17
  • 20
1

(C++)

All return values had to be HRESULTS (the standard ones - not user defined hresults)

This was just a few years ago. The senior people were still so infatuated with COM and they never read or learned of other best practices. It was an amazingly closed environment.

The same place also did not allow using STL.

I left shortly after I found out that tidbit.

Tim
  • 946
  • 7
  • 9
1

My ADA lecturer at uni insisted that every method had a comment outlining preconditions, postconditions and big O. The biggest issue with this was that he never bothered to explain what big O actually meant and never checked if they were correct so I found myself copying and pasting this comment block hundreds of times.

-- Method_Name
-- PRECONDITIONS: none
-- POSTCONDITIONS: none
-- O(n) = n
Christopher
  • 269
  • 1
  • 7
0

At one company we had to write technical documenation that explained how we will write a functionality. It fast got out-dated since you wont think about everything when youre programming in UML.

IAdapter
  • 1,345
  • 1
  • 9
  • 22
0

Being forced to add a file description in each file (it's a C# project).

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="User.cs" company="Company">
//   Copyright (C) 2009 Company. All rights reserved.
// </copyright>
// <summary>
//   The user.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
  • I can sorta see the copyright bit, but I'm pretty sure you can have Visual Studio do it for you. – Matt Olenik Sep 13 '10 at 23:30
  • 1
    Or a macro. Is this that bad? Think about *why* your company needs this - if a Google search for 'Copyright ' turns up something... – JBRWilkinson Oct 15 '10 at 21:41
-5

I find many of the Mono coding guidelines to be pointless or counter-productive. For example:

  • 80 column limit - considering we're all using widescreen monitors these days is just wasting the limited vertical space we don't have, and not making use of the horizontal space we do have.
  • Tabs for spaces - perfect way to make your code look like a mess when opened in different editors which have different tab sizes. (Also, eight space tabs is just wasting the very limited 80-columns you have to work with anyway).
  • Inconsistent brace positioning, for what reason? What's wrong with 1TBS?

There are a number of other guidelines there which are just "good practices", without reasoning.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Mark H
  • 2,470
  • 1
  • 19
  • 12
  • 6
    There is good *readability* reasons for limiting the width of text, but should be a guideline to avoid indefinitely long lines rather than a hard limit. – Richard Sep 09 '10 at 07:09
  • sparkie, turn your two monitors sideways? – Peter Boughton Sep 09 '10 at 17:10
  • If you write a program spanning more than one screen height, you might want multiple windows open. Some kind of fixed width helps there. 80 columns probably should be enough anyway. / You really need to choose either tabs or spaces. Tabs are still handled inconsistently, but it's better than a mix. – Tom Hawtin - tackline Sep 09 '10 at 17:12
  • I can see the 80 column limit especially for many folks who use smaller laptops with lower resolutions. – Jeremy Wiebe Sep 09 '10 at 17:39
  • 4
    I prefer tabs over spaces just so that, if my co-worker likes 2 space indentation and I prefer 4, we can just set our editors to be different. – Ben Doom Sep 09 '10 at 18:22
  • @Jeremy even laptops have wide monitors. 1920x1080 is becoming common on laptops too; 1280 is the bare minimum for any decent laptop. – Mircea Chirea Sep 09 '10 at 18:24
  • I would raise the limit to 120 columns, beyond that it's not doing any good. This also allows you to flip your monitors if you want. – Mircea Chirea Sep 09 '10 at 18:24
  • The problem with tabs vs. spaces is that you can't normally see the difference. I've set my editor to display tabs with a very light grey '»', so it's clear. – rjmunro Sep 09 '10 at 22:06
  • 80x24 is standard terminal size. Many FLOSS coders DO use terminals for coding and it DO cause problems. Such brace positioning is very popular in many languages (for example C and Java). – Maciej Piechotka Sep 09 '10 at 22:27
  • 5
    Am I the only person who likes 80 column limits because that way I can have multiple files open side by side, and so side-by-side diffs can be displayed without line wrapping? – nohat Sep 10 '10 at 02:11
  • 2
    If your using tabs, you don't have to make them 8 spaces. – alternative Sep 10 '10 at 22:27
  • Try printing some source code, in order to take to a coding review, etc. How many columns makes sense, in portrait? – JBRWilkinson Oct 14 '10 at 14:41