Live data from Hacker News

What was the strangest coding standard rule that you were forced to follow?

stackoverflow.com

21–30 of 83 posts

Re: What was the strangest coding standard rule that you were forced to follow?

#21
post #2

The worst thing I've ever seen: http://blog.jgc.org/2007/08/why-you-dont-want-to-code-for.ht...

Most amusing I've seen was Java code that was rather over zealous about DRY and no-string-literals in code (i.e. all strings had to be define as constants).

This resulted in code like:

   url = HTTP + COLON + SLASH + SLASH + WWW + DOMAIN_NAME + DOT + COM;
based on lots of definitions like:

   public final static String COLON = ":";
   public final static String SLASH = "/";
   public final static String DOT = ".";
   public final static String COM = "com";
[Apologies if this contains any Java syntax errors, I pretty much stopped using Java soon after this experience]

Also I've just realised that I'm really glad Java doesn't have a standard pre-processor - truly evil things would then have been possible

Re: What was the strangest coding standard rule that you were forced to follow?

#22

Maybe someone knows of a solution but it would be great if SVN/version control was able to store a standard formatted version of source code and then depending on client/user preferences could reformat the file accordingly on checkout and then also be able to factor in / unformat when doing diffs/checkins. I feel like if it could work like this it would mitigate a lot the inevitable battles that take place over small…

I know a solution: Agree on the broad points of formatting - ie. tabs/spaces, where the braces generally go. Make engaging in formatting battles a firing offense, but listen to anyone who can make substantial arguments in favour of a practise. Automatic reformatting is evil - sometimes codes is more readable if formatted in a particular way. Readability and maintainability always trumps adhering to rules.

I guess what Im saying is if you could have a tool that could compare 2 pieces of source code, be able to merge them, and maintain the formatting of each persons local copy it would be great. Its probably a pipe dream because your version control would have to have an intimate knowledge of the specs of any particular language used in the source code (nevermind the version of the language you are using)

Re: What was the strangest coding standard rule that you were forced to follow?

#23
post #2

The worst thing I've ever seen: http://blog.jgc.org/2007/08/why-you-dont-want-to-code-for.ht...

Most amusing I've seen was Java code that was rather over zealous about DRY and no-string-literals in code (i.e. all strings had to be define as constants). This resulted in code like: url = HTTP + COLON + SLASH + SLASH + WWW + DOMAIN_NAME + DOT + COM; based on lots of definitions like: public final static String COLON = ":"; public final static String SLASH = "/"; public final static String DOT = "."; public final s…

COLON + OPEN_BRACKET

Re: What was the strangest coding standard rule that you were forced to follow?

#24

Maybe someone knows of a solution but it would be great if SVN/version control was able to store a standard formatted version of source code and then depending on client/user preferences could reformat the file accordingly on checkout and then also be able to factor in / unformat when doing diffs/checkins. I feel like if it could work like this it would mitigate a lot the inevitable battles that take place over small…

I know a solution: Agree on the broad points of formatting - ie. tabs/spaces, where the braces generally go. Make engaging in formatting battles a firing offense, but listen to anyone who can make substantial arguments in favour of a practise. Automatic reformatting is evil - sometimes codes is more readable if formatted in a particular way. Readability and maintainability always trumps adhering to rules.

Automatic reformatting is the only solution, because you want to be able to make unreadable code readable without conscious effort. My preferred policy would be something like:

1. There is an agreed autoformatting template, checked into version control.

2. It is always ok to format the lines you are working on however you like, with the understanding that other people may run the autoformatter on the file.

3. It is always ok to run the autoformatter on a file you are working on (autoformatters only really work at file granularity).

4. It is not ok to format code you are not working on.

Re: What was the strangest coding standard rule that you were forced to follow?

#25
post #19

Maybe someone knows of a solution but it would be great if SVN/version control was able to store a standard formatted version of source code and then depending on client/user preferences could reformat the file accordingly on checkout and then also be able to factor in / unformat when doing diffs/checkins. I feel like if it could work like this it would mitigate a lot the inevitable battles that take place over small…

so I would have something on L249 and you would have it on L321? nonsense.

Yeah, you'd likely need some other way to refer so a position in the code than the line number. Maybe an anchor (like html) or a path in the syntax tree.

Re: What was the strangest coding standard rule that you were forced to follow?

#26
Not so much strange, as Twilight Zone-esque insane: All methods and properties must be commented with XML.

Sounds like a good idea, until you see how this turns terse and readable code into a bag of chatty noise. Basically this:

    public enum ConnectionState {
        Disconnected, Connecting, Connected
    }
Was not compliant ("There's no comments! It's not readable!"), while this:

    /// 
    /// The Connection State.
    /// 
    public enum ConnectionState {
        /// 
        /// The Connected State.
        /// 
        Connected,

        /// 
        /// The Disconnected State.
        /// 
        Disconnected,

        /// 
        /// The Connecting State.
        /// 
        Connecting
    }
Was considered Compliant and Good. This example has not been simplified, by the way.

Re: What was the strangest coding standard rule that you were forced to follow?

#27

Earlier quoted context omitted.

It is crazy if you misuse Hungarian Notation like 99% of the people out there For the 1000th time "there is no need to encode the type of a variable into the name" It's not the data type (int, char, etc), it's the nature of the thing being counted! Number of apples, height, distance, etc But of course when saying "type" most people would think it's the data type when it's not

I'm not sure what you're referring to, but in all instances of Hungarian notation I've seen (especially in Windows programs) it was the data type (pointer to char, 8 bit int, 32 bit int etc) encoded and not "the nature of the thing". I agree that adding the "nature of the thing being counted" makes sense, but then you don't have to call it Hungarian notation anymore, "number_of_apples" is just a sensible variable nam…

Joel Spolsky wrote a good summary about the Hungarian notation, and how it got corrupted within Microsoft:

http://www.joelonsoftware.com/articles/Wrong.html

Re: What was the strangest coding standard rule that you were forced to follow?

#28
The strangest coding standards were imposed when I was working at an AS/400 shop a dozen years ago.

No indentation allowed. Even though the modern compilers supported it, it looked ugly to veterans who had worked with fixed-format compilers for 30 years.

No comments in the code allowed. The function had to be entirely clear by looking at the code. Any code that needed comments for clarification was considered too 'clever' and 'obfuscated' for production.

No new language features allowed. IBM maintained languages and tools always acquire large amounts of feature bloat over the decades. Only a small subset of these features was 'white listed' by the CTO.

Re: What was the strangest coding standard rule that you were forced to follow?

#29

I was talking to someone today, and they commented: "Good programmers eventually learn to misspell words like void or int so that they can name their variable names what they want to name them." I of course told him that this was terrible advice, and would mess with the next person who had to maintain the code because you couldn't tell at a glance if a word was a keyword or a keyword mispelled. I asked him what langu…

klass for a variable of type Class is totally normal in Java.

Re: What was the strangest coding standard rule that you were forced to follow?

#30
post #2

The worst thing I've ever seen: http://blog.jgc.org/2007/08/why-you-dont-want-to-code-for.ht...

Most amusing I've seen was Java code that was rather over zealous about DRY and no-string-literals in code (i.e. all strings had to be define as constants). This resulted in code like: url = HTTP + COLON + SLASH + SLASH + WWW + DOMAIN_NAME + DOT + COM; based on lots of definitions like: public final static String COLON = ":"; public final static String SLASH = "/"; public final static String DOT = "."; public final s…

At University we were also forced to do this. This and other stupid rules (like declaring all variables at the beginning of a method) were considered 'good style'.
Post reply on HN