Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A few friends and i are planning to work on a project together and we want a COMPLETELY DIFFERENT coding standard. We do NOT want to use the coding standard the libraries/language uses. Its our project and we want to mess around.

So i came here to ask what you guys think are good standards and arguments for it (or what not to do and arguments against it). The styles i remember most are

  • Upper casing the entire word
  • Camel and Pascal casing
  • Using '_' to separate each word
  • pre or postfixing letters or words (i hate m for member but i think IsCond() is a good func name. SomethingException as a postfix example)
  • Using '_' at the start or end of words
  • Brace placement. On a new or same line?

I know of libs that use Pascal casing on all public and protected members. But would you ever get confused if something is a func, var or even property if the lang supports it? What about if you decide a public member to be private (or vice versa) wouldnt that great a lot of fix up work or inconsistencies? Is prefixing C to every class a good idea? I ask what do you think and why?

share|improve this question

closed as not constructive by gnat, Walter, ChrisF Aug 23 '12 at 13:38

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.

What language(s)? – Jonathan Khoo Feb 22 '11 at 5:36
@Jonathan: Irrelevant ;). It wont be functional tho. We want to start fresh – acidzombie24 Feb 22 '11 at 5:40
Well, at least you guys are focusing on the really important stuff like where to put '{' rather than the pointless details like how, when, or whether to use the more problematic features of the language your project is based in. – Crazy Eddie Feb 22 '11 at 5:47
@Crazy: Its still fun. We'll have lots of opportunities to get bogged down with language or project problems. This is a relatively fun project which we want to experiment with – acidzombie24 Feb 22 '11 at 6:22
-1: Asking "is prefixing C to every class name a good idea" is fine if there is an actual basis to judge "good" by. – NickC Feb 22 '11 at 6:54

First off, I can't tell if you and your programmer friends are just looking to set out, being rebellious, and defy every programming style guide known to mankind. If this is the case, I urge you to rethink what you're doing because you're wasting valuable time in trying to do things incorrectly.

Otherwise, I recommend checking out google-styleguide. Adapt whichever one you prefer and modify it if you feel the need. For this sort of thing, it's highly subjective and you can just about justify anything.

share|improve this answer

What's the rationale behind not using the style your platform is using?

Code style (at least the category of things you listed) is about consistency and discipline, and there's no real right or wrong. The first step would be to adhere to the style of the used platform (if a major one exists) and stick to that. It helps others reading your code, and helps you reading the code of others in the same ecosystem, and it already answers some of your points that can only be decided by personal preference.

Further I prefer as few visible noise as possible, which means no prefies like '_' or 'm', no useless braces or other things. If you get confused between functions and variables then your name choices are bad, and/or your code is badly structured. Break it down to small comprehensible parts, use verbs for methods, nouns for variables.

Ultimately you shouldn't get hung up on such minor issues (which often can be automated with a proper IDE. For example I'm pretty picky about superfluous and inconsistent whitespace, but I don't waste my time with that, I automate it.). There are far more important points that should be covered in a style guide like usage of advanced language features, resource ownership etc.

share|improve this answer
What is useful about having m_ or similar in the members is that it leaves the regular name open as a function name so you don't need a get prefix. So class member variable m_size, function size() const; rather than getSize() const; – CashCow Feb 23 '11 at 12:22
+1 "If you get confused between functions and variables then your name choices are bad" Descriptive identifiers are much better, if done properly you can understand what a function achieves without understanding how it achieves it. They won't event take longer to type if your using a decent IDE. – Joel Aug 23 '12 at 13:37

I'm not a big fan of proscriptive standards; you only really need to have agreement between the people who are actually in the code. You should get together with your friends, decide on a common set of code style conventions (even if other people think they're really bizarre), and stick to them. It sounds like you're fairly new to development, so it might be a good learning experience.

I'm a Java programmer, and while I started with my own idiosyncratic style conventions (some picked up from my professors), I've since adopted the Sun Code Conventions. Also, when I learn a new language, I try to adopt the most common style conventions of its community. I've come to realize that the biggest benefit of style conventions is consistency, which enhances readability, and you gain the most benefit from being consistent with the most people.

share|improve this answer
+1. ie, it doesn't matter which standard you choose - you'll always be wrong when you work on someone else's project. So don't bother, just make sure you're consistent within your own project. That's my 1 and only coding standard rule. – gbjbaanb Jul 28 '11 at 10:16

Prefixing letters

known as the Hungarian notation and it works to some extent but was really badly overdone, so much so that it became hated. Variable names like uiSize... The "m_" to show a class member is still quite popular though. That is showing scope, not type. "pImpl" is a commonly known idiom, based on the fact that the exact name was used for the variable with the "p" prefix meaning "pointer to". It was noticeably not called the "m_pImpl" idiom...

I generally do not like prefixed underscores. We actually switch the postfix underscore to be used for the variable name to the constructor that sets a member name to the same, just as an easy notation to give it a different name. (You can give it the same name but a different one is preferable).

Brace placement

Putting it on a new line makes the code far more easily readable although you can't see quite as much of it on a screen at a time, and if you print it on paper it may use more. Therefore it depends which of these is more important to you. I prefer the readability advantage.

share|improve this answer
+1, funny, i use postfix underscores as well. – acidzombie24 Feb 22 '11 at 8:29
brace placement: if you put the initial brace on the same line, you're really judging scope blocks by their indentation. Its not so bad once you know that... and you keep to the same style throughout. – gbjbaanb Jul 28 '11 at 10:14

Is your way better or are you just being a prima donna)

My first impression from the questions is that you can't play well with others, probably arrogant, and focussed on trivia.

I could be completely wrong of course but as a manager I'd start to wonder ...

As for "your project", who pays your wages...?

share|improve this answer
Its school. With friends, throwaway and possible a week to two – acidzombie24 Feb 22 '11 at 8:27
@acidzombie24: so you're learning to be a prima donna...? – gbn Feb 22 '11 at 8:59
haha +1 for the comment. I'd say i'm learning to have fun while i still can but words are words ;) – acidzombie24 Feb 22 '11 at 19:09

No one standard is inherently more right than the other, it's a matter of taste and convention.

If the language designer(s) like the under_score_style more, they will decree it as the standard convention.

share|improve this answer

If you don't follow a standard, you will make things dificult four yourself as a programmer and for the people who will maintain the code, probably yourself.

Why? Because every example in books, forums, etc. will use the standard, and you will have to constantly translate from the standard the world accept, to your inner-circle-standard.

If you want to be productive follow a accepted standard.

If you want to mess around, then don't follow a standard.

share|improve this answer

Sophisticated IDEs really replace the need for a lot of the Hungarian Notation-esque coding standards. In most IDEs it is easy to identify member variables and local variables, etc. Furthermore, in Java at least (and I believe in Python too), a general standard is widely used across open source libraries (e.g. don't capitalize method names).

I've worked on a project where a really unique coding standard was in place and one of the big issues we had was using 3rd party libraries since they violated the standard. Furthermore, when we extended a 3rd party class we could either continue to violate the standard or create some kind of horribly hybrid monster.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.