Your Coding Style?

This is a discussion on Your Coding Style? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; What kind of coding style do you like to use in the following situations? 1.) Code: A.) void Function(){ //myCode ...

  1. #1
    People Love Me
    Join Date
    Jan 2003
    Posts
    412

    Your Coding Style?

    What kind of coding style do you like to use in the following situations?

    1.)
    Code:
    A.)
    void Function(){
       //myCode
    }
    //-----------------------------
    B.)
    void Function()
    {
       //myCode
    }
    2.)
    Code:
    A.)
    int *myPointer
    //-----------------------------
    B.)
    int* myPointer
    //-----------------------------
    C.)
    int * myPointer
    3.)
    Code:
    A.)
    if (condition == false)
    //-----------------------------
    B.)
    if (!condition)
    4.)
    Code:
    A.)
    const char msg[] = "Welcome to Utah.";
    //-----------------------------
    B.)
    const char *msg = "Welcome to Utah.";
    5.)
    Code:
    A.)
    void Function(int& x){
         x = 25;
    }
    
    int main(void){
        int x=0;
        Function(x);
        return 0;
    }
    
    //-----------------------------
    
    B.)
    void Function(int *x){
         x = 25;
    }
    
    int main(void){
        int x=0;
        Function(&x);
        return 0;
    }
    My answers would be:

    1 - A
    2 - A
    3 - A
    4 - B
    5 - A

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    1) A
    2) A
    3) B
    4) B
    5) B (A is C++ only)

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    1) B
    2) A
    3) B
    4) B
    5) A & B
    Woop?

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    B
    A
    B
    A
    5b wouldn't have the same effect as 5a by the way.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    B
    A
    B
    B
    Depends

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Stop trying to be like me thantos.
    Woop?

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    1) B
    2) A
    3) B
    4) B
    5) A (with obligitory B answer as well)
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    *this
    Join Date
    Mar 2005
    Posts
    498
    1) B
    2) B
    3) B
    4) A
    5) A

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    A
    A
    B
    B
    Depends...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    A
    A
    B
    B
    Arn't they essentialy the same?

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    B
    A
    B
    B
    B...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Code:
    void Function()
    {
       //myCode
    }
    Code:
    int* pPointer;
    Code:
    if( ! bCondition )
    Code:
    LPCTSTR lpszMessage = _T("Welcome to Utah.");
    Code:
    void Function( int& nX )
    {
         nX = 25;
    }
    
    int main()
    {
        int nX = 0;
    
        Function( nX );
    
        return 0;
    }
    Edit: daveP special: ... and yes, a horse is a miscapitalized HANDLE to an Orse. It should read hOrse.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    1. B (I like symmetry)
    2. B (the * is a part of the type name)
    3. B
    4. none (STL strings)
    5. A (use references instead of pointers where possible) (also my code usually compiles, unlike 5B )
    Last edited by Sang-drax; 05-31-2005 at 04:02 AM.

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    1. B
    2. B
    3. B
    4. Depends.
    5. A
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    > 2. B (the * is a part of the type name)
    int* p,i;
    What type is i?
    If you're thinking i is a pointer, think again.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 4 1234 LastLast
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, 09:39 AM
  2. Coding style?
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 10-22-2003, 11:26 AM
  3. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  4. comment on my coding style and if i use functions well
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 03-09-2002, 06:24 AM
  5. coding style
    By ActionMan in forum Linux Programming
    Replies: 1
    Last Post: 10-03-2001, 07:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21