9 ms·
What was the strangest coding standard rule that you were forced to follow?
- jgrahamc 14y agoThe worst thing I've ever seen: http://blog.jgc.org/2007/08/why-you-dont-want-to-code-for.html http://blog.jgc.org/2007/08/why-you-dont-want-to-code-for.ht...
- arethuza 14y agoMost 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 <shudder>
- minikomi 14y agoCOLON + OPEN_BRACKET
- helpermethod 14y agoAt 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'.
- InclinedPlane 14y agoHah. It's funny how nobody thought to create a simple static utility function which converted a domain-name to a fully-qualified .com URL.
- dejv 14y agoOne company where I worked decade ago have tables numbered, like tbl01_users or tbl14_places. Still have no idea why they establish it this way.
- jacquesm 14y agoLikely because it tied into a data dictionary from a documentation system. The tbl01 makes it unique (so you can have a users and someone else can have theirs too), the data dictionary then tells you what fields exist in that particular table and how those fields relate to other tables.
- SenorWilson 14y agoI'm not sure what's up with all the hate for reverse hungarian notation, but I personally think it is helpful when writing C/C++.
- wladimir 14y agoI think it is crazy. Especially today, when IDEs can show you the declaration of a variable or method while hovering over it, there is no need to encode the type of a variable into the name. Variable names need to be sensible to humans, the compiler doesn't do checking on them anyway: it's all too common for the type prefixes to become misleading when a program has been refactored and they don't match up anymore.
- raverbashing 14y agoIt 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
- wladimir 14y agoI'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 name...
- djpowell 14y agoJoel Spolsky wrote a good summary about the Hungarian notation, and how it got corrupted within Microsoft: http://www.joelonsoftware.com/articles/Wrong.html http://www.joelonsoftware.com/articles/Wrong.html
- unimpressive 14y agoI 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 language he was using. FORTRAN. Where did he work. The United States Air Force. For how long? Six years. When? Before 2000. Since he had more experience, he claimed I was de facto wrong. I fought him on it some more. He told me it was personal preference. I told him you'd have to make me do it. It was at that moment I figured that someone, somewhere, had probably had to do this as part of a coding guideline.
- josh_fyi 14y agoklass for a variable of type Class is totally normal in Java.
- ygra 14y agoIsn't it usually clazz? But such things are quite annoying for automatic code generators, though, as they have to make sure that they won't ever emit an identifier that clashes with a keyword. The ability to just prepend @ in C# is quite helpful in that regard.
- mpyne 14y agoSame for GTK+ C code (where it is used as a gesture toward C++ compatibility, at least for the headers).
- dschiptsov 14y agoThat is why only products made by engineers for themselves should be re-used (nginx, redis, etc.) and those been "managed" by idiots should be avoided.) Over-management is much more common and much worse problem than over-engineering.)
- Jare 14y agoIn my first job as part-time programmer at a bank back in 89, we were developing a large system in C, pretty advanced stuff compared to the usual 'buy from IBM' approach at the time. The 'systems analyst' broke down the design into modules and functions for the entire system, and everything was named something like 'ABM10EI00405'. Yeah, those were the actual names we had to use for .c files and functions.
- duiker101 14y agoI really feel bad for some people in this thread :( this is really painful to read...
- Zenst 14y agoThe strangest one was when I was a COBOL programmer in the mid 80's and was forced to learn and used the GOTO verb. Having learned COBOL JSP style I was unaware that goto even existed in COBOL until then. There again same place made me retest a program I'd tested and was fully working as a full-stop was missing of a comment line. Crazy days.
- moocow01 14y agoMaybe 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 things like formatting/etc. There are obviously things like variable names that it wouldnt be able to solve but at least nobody would be complaining about where Joe put his curly bracket. I guess you can do something similar with an SVN hook but its hard to get a seamless process.
- mseebach 14y agoI 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.
- moocow01 14y agoI 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)
- mseebach 14y agoYes, for merging, that would be incredibly helpful. But what I'm saying is that the formatting of a file may contain contextual clues that will help someone reading the code to understand what it does. Formatting isn't just chrome around the code. Example: In Java, when writing a custom predicate to filter by foos that are bars, I prefer filter(myList, new Predicate<Foo>() { @Override public boolean apply(Foo foo) { return foo.isBar(); } }); to filter(myList, new Predicate<Foo>() { @Override public boolean apply(Foo foo) { return foo.isBar(); } }); (filter is statically imported from Collections2 in Guava) especially when there are multiple of them and they line up neatly underneath each other. Any meaningful autoformatter would change the latter to the former, and in the process loose readability. EDIT: Another example would be when using the builder pattern - getting those methods to line up to be neatly readable often takes some none-standard indentation.
- mrb 14y agoNone were strange. I agreed with all the coding standards I have been forced to follow. The key to not be annoyed by them is to not work at places enforcing stupid standards :)
- panacea 14y ago(
- unimpressive 14y agoIs there something clever I'm missing here?
- deleted 14y ago[deleted]
- DrJ 14y ago)
- ebzlo 14y agoI've been asked that I avoid using classes, because my boss didn't understand OOP (LAMP stack).
- regularfry 14y agoOn a vaguely related note, there was a project kicking around a month or so ago to store editor-neutral code formatting specs in the project root. Can anyone remember what it was? My google-fu is failing.
- biot 14y ago> To NEVER remove any code when making changes. We were told > to comment all changes. I'm afraid given this rule, I would abuse it horribly. My backspace key would no longer function and every typo I make would introduce a new set of /* */ comments. Every refactoring would have the old type, variable, line, function, or entire class commented out with the fixed code alongside it. Bonus points for interleaving the old code and replacement code.
- Shivetya 14y agoI understand the rule, we have this rule in place with a caveat. The rule protects us from a few common events, first being that where some developers just love to tinker with code outside the scope of their project. The second is simply a bad design where the results affected other code in unexpected ways. There have been a few times were code was reverted and having the code merely commented out saved time, time spent cut/pasting from archive. Even with a good CMS keeping commented out code can serve another purpose, knowing what was when and why. That way we can avoid the "well back in year X we had a rule" because we have the code readily accessible. For large blocks (subroutines/procedures/etc) it is not uncommon to move the whole to the end of the source.
- glennsayers 14y ago"saved time, time spent cut/pasting from archive" Surely source control would be a nicer way than copy/pasting old code back in?
- bruceboughton 14y ago>> Even with a good CMS keeping commented out code can serve another purpose [..] This, here, is your problem.
- wladimir 14y agoI've seen this mostly as workaround for broken source control systems, along with a change log at the top of each file. For example with ClearCase it can be a hell to find out preceding revisions of a file (the tools are slow and very user unfriendly), actions that are trivial with more modern systems. I tend to agree more with coding guidelines that go exactly the other way: Do not leave around any commented out or dead code. It breaks the flow of reading the code and can cause confusion as to what is actually happening. If you need to refer to an old state of the code, just provide a commit id in your comment.
- Deestan 14y agoNot 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: /// <summary> /// The Connection State. /// </summary> public enum ConnectionState { /// <summary> /// The Connected State. /// </summary> Connected, /// <summary> /// The Disconnected State. /// </summary> Disconnected, /// <summary> /// The Connecting State. /// </summary> Connecting } Was considered Compliant and Good. This example has not been simplified, by the way.
- afandian 14y agoI too was forced to do that. I too found it ridiculous. But not for long. There was a utility for generating the documentation strings (it got them right most of the time) and there's a lot to be said for consistency, even if it produces the occasional pointless-looking artefact. The reason this requirement is in the C# style guidelines is because it gives a consistent way of commenting and, of course, allows extraction of documentation and intellisense. I am no drone by any means, but this isn't so insane if you give it some thought.
- bruceboughton 14y agoIf you're using auto-doc-generation, there is no information in the generated documentation that isn't in the API.
- afandian 14y agoNot sure what you mean by "the API". You mean C# interfaces? And what about Intellisense?
- bruceboughton 14y ago
- pooop 14y agoThe 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.
- prof_hobart 14y ago> No comments in the code allowed. That's not necessarily bad advice - at least as a starting point. If you use descriptive variable/function names, then a huge amount of your commenting usually needs go away. The big advantage is that people are rarely very good at updating comments - at which point they become at best useless and often downright misleading, Whereas most coders will hopefully at least consider renaming a function or a variable when it's no longer accurate.
- kibwen 14y agoNormally I'd tend to agree with you, but if the gp was using an AS/400, I bet their software was written in RPG. Now, let's play a game. :) I'm going to Gist the example RPG program from Wikipedia, but with all the comments stripped out. Take a guess as to what it does: https://gist.github.com/4204324 https://gist.github.com/4204324 (Note that the spacing shown here is absolutely essential. Keep this in mind if you ever feel like complaining about whitespace in Python.) Answer: http://en.wikipedia.org/wiki/IBM_RPG#Example_code http://en.wikipedia.org/wiki/IBM_RPG#Example_code My company's entire internal business infrastructure is written in, perhaps, millions of lines of this (commented, thankfully). "Right," you may say, "but this is surely easy enough to read for someone who's used RPG for a while." Now consider that (afaik) RPG hasn't been taught in schools since the 70s, and that this entire format is alien to folks reared on Java. Even a poor comment in this environment is like suddenly stumbling across a line of semi-cogent English scribbled in the margins of the Necronomicon. Which is to say, it might just hold the insanity at bay for a while longer. :) Footnote: the Wikipedia article mentions a "FREE" mode that makes writing RPG much more similar to modern languages (what an old hand here might call "freeform" languages, a.k.a. languages that aren't column-based). But I get the feeling that the gp's company would regard such notions as heresy.
- josh_fyi 14y agoFor those who have not yet stumbled on it, thedailywtf.com is a treasure-store of such golden nuggets.
- narag 14y agoMany answers show a common trend: absurd prefixing rules. They're not only useless, but also counterproductive, because they prevent the incremental searches that are present in so many parts of the development tools. If you prefix every table name with "tbl", you can't search for them in the DB manager console, the IDE table listing, a directory list of the creation scripts, etc. I suffered an extreme version of this: there was some prefix that was also the directory name. So the files were called "prefix/prefixBlah". Also the prefix was used as class name and the fields were also prefixed with it. The result was that a reference could become "prefix/prefixBlah/prefixBlah.prefixDoh", an awful noise to signal rate. I complained without success. That way was "a lot more orderly and tidy" <sigh>.
- Patient0 14y agoIn my first job out from school I worked with a bunch of ex COBOL programmers who were re-writing the system in this new-fangled language called "C". One convention was that all "procedures" should be prefixed with a name indicating where they were in the call graph of the program. So the main method was always: int main() { a_initialize(); b_process(); c_shutdown(); } The first function called by a_initialize had to be called "aa_", then "ab_" and so on: void a_initialize() { aa_connect_database(); ab_read_accounts(); ac_read_ledger(); ... } and so on. Of course, sometimes you had to write a function that had to be called from more than one place (strange I know!!) For this, the naming convention "pzzDDDD" was used where D was a digit from 0-9. "p" for procedure and "zz" because these functions didn't belong to any one place in the hierarchy. We had a print out of the "pzz"s because just the number was hard to remember. But I can still remember a few of them: * pzz0030 was for looking up account information from the database (but also for maintaining this information). * pzz0031 for contracts * pzz0241 I think was for looking up fees and commissions. Most of the "functions" had lots of parameters so that they could do different things (modify, update, delete accounts etc.). This soon became unwieldy so eventually you had: * pzz0241_a_setupcharges() * pzz0241_c_cleanup() or something. I forget the details for this last bit. This was in 1997. Neat huh? ;-)
- edw519 14y agoNo numerics permitted in function names. Theory: It's prettier. Reality: Just try to understand the hierarchical relationship between 247 functions in a 10,000 line Material Requirements Planning module of an ERP system when every function name must be all alpha.
- arethuza 14y agoWouldn't that rule just end up with people writing: FloopTwentySeven rather than Floop27 :-)
- d4nt 14y agoI've come to believe that coding standards always end up being either too simplistic to deal with every scenario or longer and just an inferior in-house implementation of Steve McConnell's "Code Complete". Either way you're wasting your time. Style guides are ok though, so long as they're short and not enforced too bluntly.
- contingencies 14y agoThe company must scale! Sysadmin and webdev must be split! Therefore all (junior, barely unix-aware) web developers must provide automated Freebsd-specific install, test, start and stop scripts in a custom and ill-considered package format with no inter-component runtime or instllation-time dependency support. For every project. Therefore the perlmonger in charge and sysadmin extraordinaire can automate their dabblings. Needless to say, getting barely PHP capable people who'd heard of unix to automate dependency installation and maintenance on such a platform didn't work out well. Did I mention this was 2010?
- wlue 14y agoI worked at a start-up whose engineering lead brought familiar coding style to a project that was inherited. We were imposed a combination of C89-esque and Microsoft kernel coding style on an Objective-C source code. Things like defining all variables at the beginning of the function definition in alphabetical order in CamelCase, having instance variables prefixed with the class abbreviation, and other inane rules. It went something like this: - (void) doSomethingOnObjectAndNumber: (NSObject *) MyObject : (NSInteger) MyNumber /*++ Some unstandard doc format. --*/ { ... return; } Before I started, I was told that the project migrated from git to svn to "make branching easier". I do not work there any more.
- ludovicurbain 14y agoFor once, Java was the correct answer.
- RyanMcGreal 14y agoIn one project, I had to use camelCase and cargo-cult-Hungarian prefixes in table objects: tblTableName, sVarcharColumn, iIntegerColumn, vViewName and so on. I actaully surprised myself with just how deeply and viscerally I hated this convention. I could no longer easily convert column names into human-readable headings on reports; and the prefixes were just redundant, completely missing the point [1] of Hungarian Notation. [1] http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%29.aspx http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%2...
- segmond 14y agoput everything in a class!