View Poll Results: What coding styles? [tick as many as you like]

Voters
46. You may not vote on this poll
  • K&R (bracket on same line as if but not for functions)

    10 21.74%
  • GNU (crazy indentation style)

    1 2.17%
  • Allman (brackets on their own lines)

    33 71.74%
  • Whitesmiths (completely retarded do not tick)

    1 2.17%
  • Hungarian Notation

    0 0%
  • Non-Hungarian notation (stupid microsoft).

    1 2.17%

Thread: Coding style?

  1. #31
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Originally posted by Brian
    I also think hungarian notation is retarded. You should know what all your variables are anyway, and you should only have a few of them per function.
    Maybe I'm biased because its part of my company's coding standards, but I really like using Hungarian.

    When you have millions of lines of code, most of it from other people, knowing the variable type just by looking at it really helps. Even a well named variable, like userSelectedDisplayType, could be many different things - a string, int, long, enum, class, etc. I agree that Microsoft takes this to an extreme, but the idea is still a good one.

    Also, I follow the startWithLowerCase andEachAdditionalWord getsCapitalized style, but it just feels wrong that one word doesn't get the capital letter. I'd much rather have iStartWithLowerCase, bAndEachAdditionalWord, or sGetsCapitalized.

    Maybe its not necessary in smaller or more beautifully written code libraries, but for me hungarian is definitely preferred.

  2. #32
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Originally posted by UnregdRegd
    Behold: the one true coding style!
    You should burn for your horrible style.
    Do not make direct eye contact with me.

  3. #33
    Registered User KurtSurge's Avatar
    Join Date
    Aug 2003
    Posts
    25
    I think the Allman style looks messy because it spreads things out too much.

    I use Hungarian notation all the time, but only on certain variables. I never use it on the standard variables like integer, string, etc. But any uncommon variable, i'll put a prefix on.
    It's too bad that stupidity isn't painful
    --Anton Szandor LaVey

  4. #34
    root
    Join Date
    Sep 2003
    Posts
    232
    >Behold: the one true coding style!
    You are my god! If I used C++ more often I'd adopt your style, but I don't, so I won't...sorry.

    In all honesty, I prefer K&R bracing for everything in my own projects, but if I ever need to match a project style policy I'll do so. I have no problem reading or writing any of the other bracing styles.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  5. #35
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Originally posted by jlou


    Also, I follow the startWithLowerCase andEachAdditionalWord getsCapitalized style, but it just feels wrong that one word doesn't get the capital letter. I'd much rather have iStartWithLowerCase, bAndEachAdditionalWord, or sGetsCapitalized.

    I prefer my variables to fit on one line.

  6. #36
    Registered User
    Join Date
    Oct 2001
    Posts
    62
    I prefer the K&R style, but using indent 2, not 4 or even 8. *brrr*

    I try to keep everything as simple as possible. Most coding styles want to make things clear but instead, they make everything more complex.
    Bad examples (in my opinion) are:

    - useless initialization (static int i = 0)
    - reinvention of the stdlib (MyMemCpy)
    - most typedefs (typedef unsigned int uint)
    - useless #defines (#define LOCAL(x) static x)
    - functions defined but never used
    - inline assembler for non time-consuming functions
    - data structures (queues, stacks) implemented via pointers where a simple array would do
    - deeply nested functions (call stack > 20)

    and, especially: Extreme OOP! I believe that everything is a bunch of computer memory, and not that "everything is an object". ;-) There is a Win32-version of the (excellent!) game "Abuse" out there. Take a look at it and you know what I mean...

  7. #37
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    - useless initialization (static int i = 0)
    How is initalization a bad thing?

  8. #38
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    I dislike Hungarian notation. In principle, it's a great idea, but in general (there will of course be exceptions), the scope of any variable should be small enough, that it is not difficult to determine from its context what it is and what it does.

    I always put braces on their own lines.
    My capitalization scheme depends on the language. In C++, I keep everything lowercase and separate words with underscores. In Java, classes start with a capital, variables and functions with a lowercase letter. Each new word gets a capital letter.

    Most styles I can live with. There are a few things that really get on my nerves, though:
    - Excesive useless macros
    - The useless typedefs (though I find them useful in templatized classes)
    - "Static classes" with all private constructors, assignment operators, etc. They should be namespaces.
    - Lack of coherent OOD design (i.e. don't do too much or too little).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  9. #39
    Registered User
    Join Date
    Oct 2001
    Posts
    62
    Originally posted by Thantos
    How is initalization a bad thing?
    Initialization is not a bad thing, but _useless_ initialization is. Just because it is nothing good for. Some people often assign variables an initial value that they never use. Like this:
    Code:
    int a = 0;
    int b = 0;
    float c = .0;
    char *d = NULL;
    Hey, I want my code to have meaning! ;-)

    (BTW: The compiler already sets static variables to 0.)

  10. #40
    ___
    Join Date
    Jun 2003
    Posts
    806
    It depends on the type of program I guess. A larger OOP program in C++ would be more of an organized with what most books teach. Smaller ones I tend to cheat a bunch and put 2 to 3 things a line.
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  11. #41
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    (BTW: The compiler already sets static variables to 0.)
    I've always been taught to never ever relay (spelling?) on the compiler to initalize anything.

  12. #42
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    if you ever intend on entering a second thread static and global should be avoided where possible so most of your variables will NOT be initialized by the compiler.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  13. #43
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    I think Hungarian notation is a disease you catch when you read MSDN. When I first started out I thought null-terminated strings were prefixed "sz", then MS use that and also "lp" for them, which could be a pointer to anything.

    Do you think all MS programmers are as well clued-up on notation as they think they are?

    Also, Visual C++ likes to force me into Whitesmiths whenever I do "switch(...)" and start a new line. Weird.
    Last edited by SMurf; 10-22-2003 at 10:48 AM.

  14. #44
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Whitesmiths can be set up in the tools/options area. "indent opening brace" and "indent closing brace" Are you sure you aren't set up that way? (My company does that == annoying)
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it bad style of coding ??
    By noobcpp in forum C++ Programming
    Replies: 15
    Last Post: 11-06-2008, 10:39 AM
  2. Your Coding Style?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 45
    Last Post: 06-02-2005, 08:19 AM
  3. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  4. Coding style
    By Clyde in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 04-09-2002, 04:22 PM
  5. coding style
    By ActionMan in forum Linux Programming
    Replies: 1
    Last Post: 10-03-2001, 07:36 AM