Do you use Code Formatters or Format your code, or code with the flow?

Discussion in 'Chit Chat' started by Cableguy, May 7, 2015.


Do you properly format your code?

  1. YES, I do it myself by hand ( I know the rules )

    11 vote(s)
  2. YES, I use an external code format utility

    0 vote(s)
  3. NO, I go with the flow

    0 vote(s)
  4. Never did payed attention to that

    1 vote(s)
  1. Cableguy

    Cableguy Expert Licensed User

    Hi Guys

    This has always bugged me...
    I see some example codes that are neatly formatted, then someone (usually me) comes along and post unformatted code.
    My questions are:
    1 * Is there a place where we (I) can find the Formatting rules for our IDE?
    2 * Do you use external code formatters or try to format it?
    3 * This is not that important?
  2. sorex

    sorex Expert Licensed User

    Hey Cg,

    I selected "yes, by hand" above.

    I tend to use tabs for if/then or (nested) loops, but lately I changed it to a single space to keep it more tight together
    and prevent issues due to other tab size settings.
    Just a matter to keep my eye on the right part in nested mess.

    I don't know/knew that there are any rules about this.

    VS auto formats but that is sometimes working on my nerves when it removes my extra spaces used to align code with previous lines.
    So I prefer manual.
  3. klaus

    klaus Expert Licensed User

    I answered yes too.
    I don't know of any formatting rules defined for the IDE.
    I have always used 2 characters for the Tab size, I find 4 characters too big.
    I add also some empty lines to show groups of statements in a routine.
    I am often amazed when I see unformated code and don't understand how these guys can read it.
    Formatting is easy and doesn't really take time, you just need to apply it, then you get used to it, and at the end it's an automatic habit.

    There does exist a code formatter program HERE.
    I have used just two or three times for testing, but I have no need for it.

    Extract from page 4.2.8 Indentation in the Beginner's Guide.
    Wich code is the easiest to read ?




    Attached Files:

    Last edited: May 7, 2015
  4. Cableguy

    Cableguy Expert Licensed User

    I dont mean indentation only... Taking Klaus example code...

    Btn.text = "O K"

    In the first line we have a leading and a trailing space before and after the equal sign, in the second we have none of them...
    Another example are arithmetic expressions..

    Value = ( 3 * n ) / 5

    Which one is 'proper formatted'?
  5. klaus

    klaus Expert Licensed User

    I used this Lbl.Text="" at the beginning with B4PPC, I was somewhat lazy.
    Then I switched to Lbl.Text = ""

    For arythmetic I use:
    Value = (3 * n) / 5

    Then you have also the object and variable naming.
    Label1, Label2
    or lblTitle, lblSubTitle


    At the end, I think that it's the feeling of the programmer.
  6. canalrun

    canalrun Well-Known Member Licensed User

    I think code formatting is extremely important. I have used formatters, but I am always careful to write neat code - not that everybody agrees with my concept of "neat".
    • I believe white space is a powerful tool for implicit commenting. Blank lines between small blocks or functional units of code (maybe a few lines of code or so) can isolate logical units and add to readability and proof of correctness. I definitely prefer spaces between operators and values.
    • I also use two spaces instead of tabs. In ancient times code was written with a text editor and text editors defaulted to different numbers of spaces per tab or even variable numbers of spaces per tab. If you opened source code in a different editor chances are the tabs were formatted incorrectly.
    • Paying attention to indentation levels can help when the compiler reports, "missing end".
    • There are style guides – I've seen them for Java, C, and C++. I don't always agree with them, especially for their placement of braces "{}". I just follow something along the lines of what they suggest.
    RandomCoder and Cableguy like this.
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I agree with all the comments made above and I'm also one of those that likes to pre-fix the type. Having worked for several years on a large VBA Asset Care & Maintenance system that used the default names assigned by the IDE eg "Command1", I took the time to research naming conventions and now I always prefer to use names such as " btnStart" which is instantly recognisable as a "Start Button" whereas "lblStart" would be the "Start Label". In my humble opinion it makes the code instantly more readable without needing to determine what type of object/variable is being referenced, at the cost of slightly longer variable and object names.
  8. schemer

    schemer Active Member Licensed User

    I agree to proper code formatting although I probably don't/didn't do it correct all the time. :) But I sure liked to use Hungarian Notation( or a form of it ) in my VB6 stuff for sure and still use it today. Especially use the prefixes for clarity.