What style to choose?

Discussion in 'C Programming' started by maths_fan, Oct 19, 2003.

  1. maths_fan

    maths_fan Guest

    What style do you prefer? Where to place brackets? How to name
    variables, functions, constants, etc. How do you format your source
    code? Do you write comments?
     
    maths_fan, Oct 19, 2003
    #1
    1. Advertising

  2. maths_fan

    Mike Wahler Guest

    "maths_fan" <> wrote in message
    news:...
    > What style do you prefer?


    Clear and readable.

    > Where to place brackets?


    Such that they contribute to the above.

    >How to name
    > variables, functions, constants, etc.


    Such that they express their purpose.

    > How do you format your source
    > code?


    Such that it's clear and readable.

    > Do you write comments?


    Yes, when they aid readability, otherwise not.

    -Mike
     
    Mike Wahler, Oct 19, 2003
    #2
    1. Advertising

  3. (maths_fan) wrote:

    >What style do you prefer?

    Baroque.

    >Where to place brackets?

    On the wall.

    >How to name
    >variables, functions, constants, etc.

    Pick random scrabble pieces out of a bag.

    >How do you format your source
    >code?

    With an editor.

    >Do you write comments?

    No. The purpose of writing comments is to confuse the reader.
    They're only useful in military strength code.

    --
    Irrwahn
    ()
     
    Irrwahn Grausewitz, Oct 19, 2003
    #3
  4. maths_fan

    Malcolm Guest

    "maths_fan" <> wrote in message
    > What style do you prefer?
    > Where to place brackets?

    I always place brackets one above the other, and always have a bracket as
    the only entry on its line.
    > How to name variables, functions, constants, etc.

    Generally I think one should use mathematical conventions - eg i for a loop
    counter, x for a general real and y for a dependent one, N for a count etc.
    An angle would be theta.
    You do have problems with namespace collisions in C.
    > How do you format your source code?

    Without tabs, 2 spaces of indents.
    >Do you write comments?

    A function needs a comment to expalin what it does, what parameters it
    takes, and what it returns. Usually heavy commenting of the function body
    should be unnecessary because the function should be simple enough for
    another programmer to see what is going on.
     
    Malcolm, Oct 19, 2003
    #4
  5. Irrwahn Grausewitz wrote:

    > (maths_fan) wrote:
    >
    >>Do you write comments?

    > No. The purpose of writing comments is to confuse the reader.


    That is merely an unfortunate side-effect of badly-written or
    poorly-maintained comments.

    > They're only useful in military strength code.


    All code should be "military" strength.

    I know you're just winding the guy up, but it's fairly obvious that /he/
    doesn't know that - hence this clarification.

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
     
    Richard Heathfield, Oct 19, 2003
    #5
  6. On 19 Oct 2003 06:43:51 -0700, (maths_fan) wrote:

    >What style do you prefer?


    The one true style, obviously. :)

    >Where to place brackets?


    Cuddled except for function definitions, where they go one line under.

    >How to name variables


    By function.

    >functions


    By variable.

    >constants


    Constantly.

    >How do you format your source code?


    As I go... (seriously: adjusting formatting after the fact tends to confuse
    version control systems).

    >Do you write comments?


    /* FIXME: broken */

    (Yes, direct quote I'm afraid :)

    Serious answer: simple, undertandable, consistent.

    -- Mat.
     
    Mathew Hendry, Oct 19, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. warstar
    Replies:
    12
    Views:
    692
  2. Karl Shifflett

    Web Setup Choose Web To Install In

    Karl Shifflett, Jan 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    336
    Karl Shifflett
    Jan 13, 2004
  3. Matthew Belk
    Replies:
    1
    Views:
    353
    Chris Jackson
    Feb 23, 2004
  4. Vaughn

    Why choose SQL Server or Access?

    Vaughn, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    397
    Curt_C [MVP]
    Apr 19, 2004
  5. Ken Varn
    Replies:
    0
    Views:
    472
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page