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

Do you properly format your code?

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

    Votes: 11 91.7%
  • YES, I use an external code format utility

    Votes: 0 0.0%
  • NO, I go with the flow

    Votes: 0 0.0%
  • Never did payed attention to that

    Votes: 1 8.3%

  • Total voters
    12

Cableguy

Expert
Licensed User
Longtime 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?
 

sorex

Expert
Licensed User
Longtime 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.
 

klaus

Expert
Licensed User
Longtime 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 ?

upload_2015-5-7_15-49-17.png


upload_2015-5-7_15-49-35.png


upload_2015-5-7_15-50-11.png
 

Attachments

  • upload_2015-5-7_15-49-47.png
    upload_2015-5-7_15-49-47.png
    4.1 KB · Views: 164
Last edited:

Cableguy

Expert
Licensed User
Longtime User
I dont mean indentation only... Taking Klaus example code...

Btn.text = "O K"
Lbl.text=""

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
Value=(3*n)/5

Which one is 'proper formatted'?
 

klaus

Expert
Licensed User
Longtime 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

etc.

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

canalrun

Well-Known Member
Licensed User
Longtime 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.
Barry.
 

RandomCoder

Well-Known Member
Licensed User
Longtime 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.
 

schemer

Active Member
Licensed User
Longtime 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.

https://support.microsoft.com/en-us/kb/173738
 
Top