Thread: Your Coding Style?

  1. #31
    FOX
    Join Date
    May 2005
    Posts
    188
    I meant impossible to not do it without imposing a newline somewhere. My main gripe with it is that I have to use extra spaces along with tabs to indent the code.
    Code:
    static char *long_function_name(const char *dest, const char *src,
                                    const char *options, size_t n)
    This example may not have been the best one since it incidently works out ok with 8 space tabs as well.

  2. #32
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    I prefer to write my functions to save space in their declarations:

    Code:
    #define st static
    #define ch char
    #define fu st ch*
    #define na function_name
    #define co const
    #define cc co ch*
    #define si size_t
    
    fu na(cc dest,cc src,cc options,si n){ /* Code */ }
    Look! My function only takes one line of code now! You can move the #define's to a header and think of all the space you'll save!

  3. #33
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I meant impossible to not do it without imposing a newline somewhere.
    Well, the very definition of a line break makes it impossible to avoid using a newline. It seems to me that your problem is lining things up nicely, to which my response is "tough!". As I said, as long as it works, it doesn't have to be pretty. And any competent programmer will be able to read a reasonable format.
    My best code is written with the delete key.

  4. #34
    ---
    Join Date
    May 2004
    Posts
    1,379
    Thantos's example looks nice but I don't like the fact that a prototype takes up so many lines so if I have to I use Prelude's example.

  5. #35
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    For what it is worth.

    1. b
    2 a
    3. a
    4. a
    5. A- scoobasean is right here B would not work needs:
    Code:
    B.)
    void Function(int *x){
         x = 25;
    }
    
    int main(void){
        int x=0;
        Function(&x);
        return 0;
    }
    Should be *x = 25;
    Mr. C: Author and Instructor

  6. #36
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    just a thought...

    Code:
    static char *long_function_name
                 (const char* dest, const char* src, const char* options, size_t n)
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  7. #37
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    A
    B
    B
    B
    A
    Hmm

  8. #38
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    For long functions: with prototypes I do:
    Code:
    type name(  type arg,
                   type arg,
                   type arg);
    I make them line up, which I won't try in the variable-width field here. If they don't line up, I advance the first argument to the next tab stop.
    For function defintions, I do
    Code:
    type name(type arg, type arg,
      type arg, type arg)
    {
    }
    My rationale is that it's more important for a prototype to be quickly readable. With the implementation, I'd rather save the space.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #39
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    if it doesnt fit on one line raise your resolution :-p
    Hmm

  10. #40
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by B0bDole
    if it doesnt fit on one line raise your resolution :-p
    Or get a bigger screen.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  11. #41
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    80 chars are still 80 chars, and that's what I limit my lines to.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #42
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Code:
    //const char* msg[] = "Welcome to Utah.", "Welcome to Arizona";
    //const char *msg = "Welcome to Utah.";
    const char* msg[3] = {"Welcome one", "Welcome two", "welcome three" };
    /*
    int functionVerOne { 
    // my code;
    }*/
    int functionVerTwo {
    // my code
    /*
    // my buggy code
    */
    /*
    // my second solution for buggy code
    */
    // my code that usually works as wanted 
    }
    I switch off between languages frequently, so I'm always grasping for syntax in variable declarations. I also have a bad habbit of commenting unworking code bits because I'm affraid the next attempt will be worse and I wont remember the first - better working code to return to. I'm too indecisive.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  13. #43
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    1. B)
    2. A)
    3. A)
    4. A)
    5. A)
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  14. #44
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Code:
    void Function()
    {
       //myCode
    }
    I couldn't live without lined-up braces.
    Code:
    int *myPointer;
    For the obvious reason, to minimize the confusion over what's a pointer and what's not.
    Code:
    if (!condition)
    Some say the other way is clearer, but I don't buy that. If you're a programmer, then you know what it means. Code like
    Code:
    if(bCondition==true)
    is ridiculous and redundant.
    Code:
    const char *msg = "Welcome to Pennsylvania.";
    Really, though, I'd rather be using a std::string, but I rarely have a choice at work.
    Code:
    void Function(int& x)
    {
         x = 25;
    }
    
    int main(void){
        int x=0;
        Function(x);
        return 0;
    }
    I'm a big fan of pass by reference.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  15. #45
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I should also mention that I have slightly different coding styles in C++, Java, PHP and JavaScript.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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. 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, 07:24 AM
  5. coding style
    By ActionMan in forum Linux Programming
    Replies: 1
    Last Post: 10-03-2001, 07:36 AM