This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
If this question can be reworded to fit the rules in the help center, please edit the question.

19

After reading thru this list suddenly I feel like I've had a very lucky career to avoid any of this forced standard crap!
–
matt bOct 20 '08 at 17:15

5

And I'm embarrassed to admit that very early in my career, I imposed one of the answers on a team. I'm so sorry, guys.
–
JasonFruitMar 1 '10 at 16:09

112 Answers
112

What is the supposed point of this rule? Personally I'd fail a code review for code that could be made easier to read by putting in another return.
–
Mark BakerOct 20 '08 at 15:31

22

On the other hand, eliminating an option at the beginning like "if(param == null) return null" can clean up your code quite a bit, to prohibit this instead of encourage it is somewhat criminal.
–
Bill KOct 20 '08 at 16:17

Up until recently, multiple returns were banned. Then the fact this was a leftover from C, rendered obsolete by C++ RAII and functions with size less than 15 lines, was revealed. Since then, like Braveheart: "FREEDOM !!!!" ... :-p ...
–
paercebalOct 20 '08 at 21:13

In a similar vein, I hate when ID columns in databases are prefixed with the table name, like in the product table there'd be a productid column. Redundancy that sometimes makes scripting without an ORM more of a headache than it needs to be
–
Andrew IngramOct 20 '08 at 17:27

30

I actually prefer the ID column to be prefixed with the table name. Makes writing queries a bit easier. And for foreign keys you can have the foreign key field the same as the key field.
–
CraigOct 20 '08 at 23:24

38

On a similar note, I hate it when table names must be singular. My instinct is to name a table that holds, say, customers, "Customers", not "Customer". Sounds minor, till you realize all the trouble you would save if only you could name your table "Transactions" instead of "[Transaction]".
–
AtarioNov 17 '08 at 19:49

... because not everyone "gets it". If you told me, "Don't use it because we've had to rewrite them when the structures get too complicated" (nested ternary operators, anyone?), then I'd understand. But when you tell me that some developers don't understand them... um... Sure.

I used to fall into this camp ... But grew out of it, and have learned to love the conditional operator (when it's appropriate).
–
John RudyOct 20 '08 at 13:14

22

If anything, the rule should be "always use the ternary operator", an operator of pure beauty :)
–
Bobby JackOct 20 '08 at 16:13

16

I love it, but the reason I get most often for not using is is the same as your experience "people wont understand it". My argument is that they shouldn't be working if they can't understand the concept...
–
AidosOct 21 '08 at 3:28

7

How else would you conditionally initialize a constant variable without writing a whole new function (which won't do much good for readability). The use of const for local "variables" does much more good for understanding and following the code than a ban of the ternary operator.
–
Andreas MagnussonNov 5 '08 at 13:06

To NEVER remove any code when making changes. We were told to comment all changes. Bear in mind we use source control. This policy didn't last long because developers were in an uproar about it and how it would make the code unreadable.

I really hate that... there's a few people who do that here (it's not a standard or anything though)
–
chills42Oct 20 '08 at 16:03

7

Rules like that are why I feel a NEED to print source code I inherit from others in color. At a dime a page, that's not very nice to my company -- but it's the only way I can read it if I have to print it. (We've inherited a lot which followed this rule ... )
–
John RudyOct 20 '08 at 21:38

3

Sounds like a rule developed pre source control. Or due to programmers only checking in once a week.
–
CraigOct 21 '08 at 0:09

Feel for you... we're on SVN for 4+ years, but the senior developer hates it and checks in about once per two months, spending the next three days complanining about broken code :/
–
Viktor SvubJun 28 '10 at 9:02

The VB King was the pure master of MS Excel and VBA, as well as databases (Hence his surname : He played with Excel while the developers worked with compilers, and challenging him on databases could have detrimental effects on your career...).

Of course, his immense skills gave him an unique vision of development problems and project management solutions: While not exactly coding standards in the strictest sense, the VB King regularly had new ideas about "coding standards" and "best practices" he tried (and oftentimes succeeded) to impose on us. For example:

All C/C++ arrays shall start at index 1, instead of 0. Indeed, the use of 0 as first index of an array is obsolete, and has been superseded by Visual Basic 6's insightful array index management.

All functions shall return an error code: There are no exceptions in VB6, so why would we need them at all? (i.e. in C++)

Since "All functions shall return an error code" is not practical for functions returning meaningful types, all functions shall have an error code as first [in/out] parameter.

All our code will check the error codes (this led to the worst case of VBScript if-indentation I ever saw in my career... Of course, as the "else" clauses were never handled, no error was actually found until too late).

Since we're working with C++/COM, starting this very day, we will code all our DOM utility functions in Visual Basic.

ASP 115 errors are evil. For this reason, we will use On Error Resume Next in our VBScript/ASP code to avoid them.

XSL-T is an object oriented language. Use inheritance to resolve your problems (dumb surprise almost broke my jaw open this one day).

Exceptions are not used, and thus should be removed. For this reason, we will uncheck the checkbox asking for destructor call in case of exception unwinding (it took days for an expert to find the cause of all those memory leaks, and he almost went berserk when he found out they had willingly ignored (and hidden) his technical note about checking the option again, sent handfuls of weeks before).

catch all exceptions in the COM interface of our COM modules, and dispose them silently (this way, instead of crashing, a module would only appear to be faster... Shiny!... As we used the über error handling described above, it even took us some time to understand what was really happening... You can't have both speed and correct results, can you?).

Starting today, our code base will split into four branches. We will manage their synchronization and integrate all bug corrections/evolutions by hand.

All but the C/C++ arrays, VB DOM utility functions and XSL-T as OOP language were implemented despite our protests. Of course, over the time, some were discovered, ahem, broken, and abandoned altogether.

Of course, the VB King credibility never suffered for that: Among the higher management, he remained a "top gun" technical expert...

Re: 1-indexing. Sometimes you just have to stand up and say something strong like "that's stupid and wrong". Draw a line in the sand. Forget placating egos and just say it. I can almost guarantee that every other worthwhile programmer will immediately start nodding and joining in.
–
Kirk StrauserOct 21 '08 at 15:45

31

@jrista: If YOU ARE NOT commenting the spelling of my text, please ignore the following ... ... ... ... ... ... ... ... If you are commenting my text, please consider (1) proposing corrections, (2) correcting the spelling yourself, or (3) Consider that not every developer in the world (far from it) are native english speaker, so I guess tolerating incorrect spelling is the minimum you can do, or prove you can do better by sending me the correct translation IN FRENCH... ^_^ ...
–
paercebalJun 10 '09 at 16:27

4

If this guy were my boss, I would have gone straight to every member of higher management with a well-written and documented list of complaints and gotten him fired. -1 for not having the balls to stand up for yourself.
–
muusbollaJul 10 '09 at 21:08

34

@muusbolla: Who told you we did not complain? It escalated until a delegation of two (including me) went straight to the CEO to explain the problem. But I'm sorry to have to tell you there is a difference between a idealistic world, where justice reigns, and the real world, where some bosses believe "the management is never wrong, even when it is", and will crush anyone that will dare to contradict that dogma. The only happy souvenir I have from that time is the day I resigned, almost three years ago, and I am a happier man since that day. Anyway, if true, your downmod reason is lame. Sorry.
–
paercebalJul 15 '09 at 13:37

Back in the 80's/90's, I worked for an aircraft simulator company that used FORTRAN. Our FORTRAN compiler had a limit of 8 characters for variable names. The company's coding standards reserved the first three of them for Hungarian-notation style info. So we had to try and create meaningful variable names with just 5 characters!

Luxury: we had just 6 characters; the package had names starting with g; the internal functions all started gk; there were workstation drivers with codes such as 0p (so gk0p was the start), leaving us two characters for the rest of the Fortran name. gk0paa, gk0pab, ...
–
Jonathan LefflerOct 21 '08 at 3:02

103

"When I was your age, we only had 2 characters! And it was case-insensitive!"
–
pookleblinkyOct 21 '08 at 6:45

53

We used to have to get up at 2 in the morning, 3 hours before going to bed, then write our own compilers and pay the company for the privilege of going to work. We were allowed just the letter A for our variable names. Then our boss would delete our code and dance on our listings singing hallelujah.
–
David ArnoOct 21 '08 at 7:02

I worked at a place that had a merger between 2 companies. The 'dominant' one had a major server written in K&R C (i.e. pre-ANSI). They forced the Java teams (from both offices -- probably 20 devs total) to use this format, which gleefully ignored the 2 pillars of the "brace debate" and goes straight to crazy:

I would think that maintaining a greater visual distinction between C and Java would make the transitions easier. (+1 for "and goes straight to crazy.")
–
Jeffrey L WhitledgeOct 20 '08 at 15:03

4

Looks like Whitesmiths style which was used in the original 'Programming Windows' by Petzold - go figure! ;)
–
Bobby JackOct 20 '08 at 16:12

7

I find this the most intelligent brace style. Unfortunately, most people don't use it. If braces have semantic meaning, they should be treated like it, not stuck at the end of a line and ignored.
–
KyralessaOct 24 '08 at 15:56

7

@Kyralessa. I disagree... I don't know if braces have semantic meaning but they can certainly affect pattern-matching and a sense of space. IMO, this version loses that completely. e.g. I want my bookmark to poke outside the book, not be flush with the pages.
–
Michael EasterOct 24 '08 at 23:57

6

This is actually my preferred style, but everything in the world (Visual Studio especially) defaults to other modes, so I've given up. Why do I like it? The braces are "part of" the contained code -- they force it to "look like" a single statement to the if, which is what it expects.
–
AtarioNov 17 '08 at 19:33

a friend of mine - we'll call him CodeMonkey - got his first job out of college [many years ago] doing in-house development in COBOL. His first program was rejected as 'not complying with our standards' because it used... [shudder!] nested IF statements

the coding standards banned the use of nested IF statements

now, CodeMonkey was not shy and was certain of his abilities, so he persisted in asking everyone up the chain and down the aisle why this rule existed. Most claimed they did not know, some made up stuff about 'readability', and finally one person remembered the original reason: the first version of the COBOL compiler they used had a bug and didn't handle nested IF statements correctly.

This compiler bug, of course, had been fixed for at least a decade, but no one had challenged the standards. [baaa!]

CodeMonkey was successful in getting the standards changed - eventually!

Once worked on a project where underscores were banned. And I mean totally banned. So in a c# winforms app, whenever we added a new event handler (e.g. for a button) we'd have to rename the default method name from buttonName_Click() to something else, just to satisfy the ego of the guy that wrote the coding standards. To this day I don't know what he had against the humble underscore

Has the unfortunate side-effect of preventing the use of FILE and LINE for debugging. And #if __cplusplus extern "C" in header files. And the integral types in stdint.h. And size_t.
–
Steve JessopOct 22 '08 at 2:06

I seriously discourage underscores (although not in the OP case listed above. It's an extra two keystrokes (shift + _) that I prefer not to have put upon me when pascal or camel case will do just fine.
–
TGnatJun 29 '09 at 19:37

You know, I think I'm with you on that. The hungarian warts aren't nearly so objectionable when tacked onto the end like that.
–
T.E.D.Apr 27 '09 at 19:21

6

When I worked in MS VC++ support, we had several customers submit repro code written like this. It took a while for us to realize it was actually in C++ (they didn't include the #defines).
–
JBRWilkinsonFeb 18 '10 at 14:19

Well, at that point you might as well give up, right?
–
Kirk StrauserOct 20 '08 at 13:56

90

Some one got bitten by not understanding the difference between postfix and prefix, claimed compiler bug, then inflicted it on other people, me thinks.
–
BernardOct 22 '08 at 13:26

5

Actually, they were right, in some circumstances. Banning seems a bit over the top though. Take for example, the line : a[i] = i++; i may get incremented before it is used to index a, or after. The language does not define this.
–
T.E.D.Oct 23 '08 at 18:31

9

He's right--the order of operations is not guaranteed when you use the same variable elsewhere in the statement. Just ban potentially ambiguous code, not all uses of it, though!
–
Loren PechtelNov 16 '08 at 6:05

2

Might as well ban = as it can be used to cause undefined behaviour.
–
configuratorSep 15 '10 at 13:10

Thats why tab identation is so great. Everyone can change the size in his editor ;)
–
xardiasOct 21 '08 at 14:24

41

Yeah, tab indentation is great... until you actually open someone else's file, and find things misaligned because spaces got mixed in where they shouldn't have, or didn't get mixed in where they should have. Then you auto-reformat, and version control diffs get ugly. Ugh.
–
Alan HenselOct 23 '08 at 3:02

41

that's why you're supposed to use only tabs to indent, and only spaces to align, and never the twain shall meet. and if you're going to make a change to the whitespace in a file, then that needs to be the only change you make for that particular check-in.
–
joh6nnMar 6 '09 at 21:50

The very strangest one I had, and one which took me quite some time to overthrow, was when the owner of our company demanded that our new product be IE only. If it could work on FireFox, that was OK, but it had to be IE only.

This might not sound too strange, except for one little flaw. All of the software was for a bespoke server software package, running on Linux, and all client boxes that our customer was buying were Linux. Short of trying to figure out how to get Wine (in those days, very unreliable) up and running on all of these boxes and seeing if we could get IE running and training their admins how to debug Wine problems, it simply wasn't possible to meet the owner's request. The problem was that he was doing the Web design and simply didn't know how to make Web sites compliant with FireFox.

It probably won't shock you to know that that our company went bankrupt.

Using generic numbered identifier names

At my current work we have two rules which are really mean:

Rule 1: Every time we create a new field in a database table we have to add additional reserve fields for future use. These reserve fields are numbered (because no one knows which data they will hold some day) The next time we need a new field we first look for an unused reserve field.

So we end up with with customer.reserve_field_14 containing the e-mail address of the customer.

At one day our boss thought about introducing reserve tables, but fortunatly we could convince him not to do it.

Rule 2: One of our products is written in VB6 and VB6 has a limit of the total count of different identifier names and since the code is very large, we constantly run into this limit. As a "solution" all local variable names are numbered:

Lvarlong1

Lvarlong2

Lvarstr1

...

Although that effectively circumvents the identifier limit, these two rules combined lead to beautiful code like this:

...
If Lvarbool1 Then
Lvarbool2 = True
End If
If Lvarbool2 Or Lvarstr1 <> Lvarstr5 Then
db.Execute("DELETE FROM customer WHERE " _
& "reserve_field_12 = '" & Lvarstr1 & "'")
End If
...

You can imagine how hard it is to fix old or someone else's code...

Latest update: Now we are also using "reserve procedures" for private members:

Private Sub LSub1(Lvarlong1 As Long, Lvarstr1 As String)
If Lvarlong1 >= 0 Then
Lvarbool1 = LFunc1(Lvarstr1)
Else
Lvarbool1 = LFunc6()
End If
If Lvarbool1 Then
LSub4 Lvarstr1
End If
End Sub

EDIT: It seems that this code pattern is becoming more and more popular. See this The Daily WTF post to learn more: Astigmatism :)

No kidding. I bet it took forever to go through and remove all those SQL injections. ;-)
–
Kirk StrauserOct 21 '08 at 16:03

5

omg, who the hell would come up with rules like this??? most importantly: how the hell does your team manage to code??
–
hasenDec 2 '08 at 8:14

2

I think he meant that you would select all fields by default so you got all the 'reserve' fields as well, without needing to specify them all.
–
Mr. ShickadanceJun 4 '09 at 23:49

2

maibe you could use code preprosessing, where you would write your code using meaningfull variables names and then replace it with the "correct ones" before compiling somegtinh like '%s/email/reserve_field_12/g' ;)
–
João PortelaSep 29 '09 at 15:02

I will concede with respect to controls. Then Hungarian notation can be helpful. In general though, I think Hungarian notation is obsolete, and generally misused. It has drifted from it's original intention.
–
vfilbyNov 6 '08 at 15:34

I've had a lot of stupid rules, but not a lot that I considered downright strange.

The sillyiest was on a NASA job I worked back in the early 90's. This was a huge job, with well over 100 developers on it. The experienced developers who wrote the coding standards decided that every source file should begin with a four letter acronym, and the first letter had to stand for the group that was responsible for the file. This was probably a great idea for the old FORTRAN 77 projects they were used to.

However, this was an Ada project, with a nice hierarchal library structure, so it made no sense at all. Every directory was full of files starting with the same letter, followed by 3 more nonsense leters, an underscore, and then part of the file name that mattered. All the Ada packages had to start with this same five-character wart. Ada "use" clauses were not allowed either (arguably a good thing under normal circumstances), so that meant any reference to any identifier that wasn't local to that source file also had to include this useless wart. There probably should have been an insurrection over this, but the entire project was staffed by junior programmers and fresh from college new hires (myself being the latter).

A typical assignment statement (already verbose in Ada) would end up looking something like this:

Fortunately they were at least enlightened enough to allow us more than 80 columns! Still, the facility wart was hated enough that it became boilerplate code at the top of everyone's source files to use Ada "renames" to get rid of the wart. There'd be one rename for each imported ("withed") package. Like this:

package Package_Name renames NABC_Package_Name;
package Some_Other_Package_Name renames CXYZ_Some_Other_Package_Name;
--// Repeated in this vein for an average of 10 lines or so

What the more creative among us took to doing was trying to use the wart to make an acutally sensible (or silly) package name. (I know what you are thinking, but explitives were not allowed and shame on you! That's disgusting). For example, I was in the Common code group, and I needed to make a package to interface with the Workstation group. After a brainstorming session with the Workstation guy, we decided to name our packages so that someone needing both would have to write:

With all that and NASA still couldn't figure out whether to calculate in kilometers or miles...
–
NotMeOct 21 '08 at 14:00

16

Damn, and I really thought you were going to go all out and use a CUN*_ and W*NK_ package naming convention. Sorry, I have slow-burning, explosive, textual tourettes. But yours were much, much, funnier!
–
defmetaNov 24 '08 at 0:47

When I started working at one place, and started entering my code into the source control, my boss suddenly came up to me, and asked me to stop committing so much. He told me it is discouraged to do more than 1 commit per-day for a developer because it litters the source control. I simply gaped at him...

Later I understood that the reason he even came up to me about it is because the SVN server would send him (and 10 more high executives) a mail for each commit someone makes. And by littering the source control I guessed he ment his mailbox.

Get the best of both worlds - Commit to your local branch whenever you dont want to lose something. Rebase and squash those commits when you're ready to put them into master. (forgive the git terminology - I'm sure its possible in mercurial and a bunch of other systems too)
–
Michael AndersonOct 13 '10 at 5:18

Maintainability could be improved if the table and column names are not unique, but the SP names are. This could make code references easier to find. If there are any other, better maintainability advantages, I am not aware of them. Security is the main reason to use SPs.
–
Jeffrey L WhitledgeOct 20 '08 at 15:17

"Security is the main reason to use SPs" No. Nothing about SP's in SQL Server are more secure. They are only secure when called as a paremeterized queries, which can be done just as well with dynamic SQL.
–
FloryOct 20 '08 at 17:31

4

Nah: sprocs are useful. While it can be a pain at times, you end up writing a better, more reusable database interface. Your dba's can also have an easier time analyzing performance problems and can update a production system without an app code change. I don't advocate biz logic in sprocs though.
–
Robert PaulsonNov 24 '08 at 0:37

It depends on how finely grained your tests are too I guess. I'd consider function(x).should == 2 to be a single test, whereas others would bundle 10 of those together and call it a single test.
–
Orion EdwardsJun 22 '10 at 3:06

Well sure, 'cause comments are just clutter, after all... and think how many cycles the pre-processor saves at compile time! (The app is even funnier than the rule. Good one.)
–
ojracOct 21 '08 at 3:10

In 1987 or so, I took a job with a company that hired me because I was one of a small handful of people who knew how to use Revelation. Revelation, if you've never heard of it, was essentially a PC-based implementation of the Pick operating system - which, if you've never heard of it, got its name from its inventor, the fabulously-named Dick Pick. Much can be said about the Pick OS, most of it good. A number of supermini vendors (Prime and MIPS, at least) used Pick, or their own custom implementations of it.

This company was a Prime shop, and for their in-house systems they used Information. (No, that was really its name: it was Prime's implementation of Pick.) They had a contract with the state to build a PC-based system, and had put about a year into their Revelation project before the guy doing all the work, who was also their MIS director, decided he couldn't do both jobs anymore and hired me.

At any rate, he'd established a number of coding standards for their Prime-based software, many of which derived from two basic conditions: 1) the use of 80-column dumb terminals, and 2) the fact that since Prime didn't have a visual editor, he'd written his own. Because of the magic portability of Pick code, he'd brought his editor down into Revelation, and had built the entire project on the PC using it.

Revelation, of course, being PC-based, had a perfectly good full-screen editor, and didn't object when you went past column 80. However, for the first several months I was there, he insisted that I use his editor and his standards.

So, the first standard was that every line of code had to be commented. Every line. No exceptions. His rationale for that was that even if your comment said exactly what you had just written in the code, having to comment it meant you at least thought about the line twice. Also, as he cheerfully pointed out, he'd added a command to the editor that formatted each line of code so that you could put an end-of-line comment.

Oh, yes. When you commented every line of code, it was with end-of-line comments. In short, the first 64 characters of each line were for code, then there was a semicolon, and then you had 15 characters to describe what your 64 characters did. In short, we were using an assembly language convention to format our Pick/Basic code. This led to things that looked like this:

EVENT.LIST[DATE.INDEX][-1] = _ ;ADD THE MOST RECENT EVENT
EVENTS[LEN(EVENTS)] ;TO THE END OF EVENT LIST

(Actually, after 20 years I have finally forgotten R/Basic's line-continuation syntax, so it may have looked different. But you get the idea.)

Additionally, whenever you had to insert multiline comments, the rule was that you use a flower box:

************************************************************************
** IN CASE YOU NEVER HEARD OF ONE, OR COULDN'T GUESS FROM ITS NAME, **
** THIS IS A FLOWER BOX. **
************************************************************************

Yes, those closing asterisks on each line were required. After all, if you used his editor, it was just a simple editor command to insert a flower box.

Getting him to relent and let me use Revelation's built-in editor was quite a battle. At first he was insistent, simply because those were the rules. When I objected that a) I already knew the Revelation editor b) it was substantially more functional than his editor, c) other Revelation developers would have the same perspective, he retorted that if I didn't train on his editor I wouldn't ever be able to work on the Prime codebase, which, as we both knew, was not going to happen as long as hell remained unfrozen over. Finally he gave in.

But the coding standards were the last to go. The flower-box comments in particular were a stupid waste of time, and he fought me tooth and nail on them, saying that if I'd just use the right editor maintaining them would be perfectly easy. (The whole thing got pretty passive-aggressive.) Finally I quietly gave in, and from then on all of the code I brought to code reviews had his precious flower-box comments.

One day, several months into the job, when I'd pretty much proven myself more than competent (especially in comparison with the remarkable parade of other coders that passed through that office while I worked there), he was looking over my shoulder as I worked, and he noticed I wasn't using flower-box comments. Oh, I said, I wrote a source-code formatter that converts my comments into your style when I print them out. It's easier than maintaining them in the editor. He opened his mouth, thought for a moment, closed it, went away, and we never talked about coding standards again. Both of our jobs got easier after that.

At my first job, all C programs, no matter how simple or complex, had only four functions. You had the main, which called the other three functions in turn. I can't remember their names, but they were something along the lines of begin(), middle(), and end(). begin() opened files and database connections, end() closed them, and middle() did everything else. Needless to say, middle() was a very long function.

And just to make things even better, all variables had to be global.

One of my proudest memories of that job is having been part of the general revolt that led to the destruction of those standards.