Formatting code...
-
Hey guys! I'm still trying to decide the best way to format my VB.Net code. I've looked over this project I've been working on for a couple of months and saw the number of different formatting/variable naming (etc) approaches I'd used, and I've decided that I'd best try to stick to one style. Can anyone recommend and easy-to-follow and neat way of formatting/laying out/variable naming my code? I hope this doesn't sound silly, but at the least, I'd like to have my code look uniform... :~ X| :doh: Awaiting replies eagerly :)
modified on Wednesday, June 23, 2010 12:58 AM
-
Hey guys! I'm still trying to decide the best way to format my VB.Net code. I've looked over this project I've been working on for a couple of months and saw the number of different formatting/variable naming (etc) approaches I'd used, and I've decided that I'd best try to stick to one style. Can anyone recommend and easy-to-follow and neat way of formatting/laying out/variable naming my code? I hope this doesn't sound silly, but at the least, I'd like to have my code look uniform... :~ X| :doh: Awaiting replies eagerly :)
modified on Wednesday, June 23, 2010 12:58 AM
With regards to vaiable naming its really a matter of personal style, and just as long it's easy to follow and consistent then the choice is yours. If you're after ideas then what I do is prefix all my variables with a 3 letter abbreviation. For example, String variables I prefix with 'str', booleans with 'bln', etc. But as for layout and format, if you're using Visual Studion then that should take care of it for you.
-
With regards to vaiable naming its really a matter of personal style, and just as long it's easy to follow and consistent then the choice is yours. If you're after ideas then what I do is prefix all my variables with a 3 letter abbreviation. For example, String variables I prefix with 'str', booleans with 'bln', etc. But as for layout and format, if you're using Visual Studion then that should take care of it for you.
Well, you see, I kept mixing styles where I named every control starting with a 3char prefix, with a style where everything had that prefix (e.g. variable in code too), with other styles for classes. And by layouts, I can't explain exactly what I mean but... Can anyone point me to some examples of beautifully formatted VB.Net code?
-
Well, you see, I kept mixing styles where I named every control starting with a 3char prefix, with a style where everything had that prefix (e.g. variable in code too), with other styles for classes. And by layouts, I can't explain exactly what I mean but... Can anyone point me to some examples of beautifully formatted VB.Net code?
As a hundred people, and you'll get a hundred different answers... There's no RIGHT answer, really... My personal style has spontaneously evolved to something like: Private/method variables: Camel case, no prefix (Since you can mouseover to get the type - If it's confusing, would be using extra comments anyway) Properties/Methods/Classes: Pascal case... Methods are verbs, classes and properties are nouns (Except boolean properties, which are named like IsBold, CanCalculate, etc - Kinda like that convention as used in WPF) Iterator variables: I tend to use short names like "idx", "row", "col", "rec"... But I avoid single-letter names unless it's x/y/z for a coordinate system. If I end up using more than one or two at a time, I tend to give them longer names to keep it readable. As for braces, well, you're using VB, so you don't have to deal with the curly brace debate.
Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)
-
Hey guys! I'm still trying to decide the best way to format my VB.Net code. I've looked over this project I've been working on for a couple of months and saw the number of different formatting/variable naming (etc) approaches I'd used, and I've decided that I'd best try to stick to one style. Can anyone recommend and easy-to-follow and neat way of formatting/laying out/variable naming my code? I hope this doesn't sound silly, but at the least, I'd like to have my code look uniform... :~ X| :doh: Awaiting replies eagerly :)
modified on Wednesday, June 23, 2010 12:58 AM
I would NOT prefix variables with a couple of letters that indicate the type, since that makes type changes hard. You may start with an array of something, later turn it into a list, and afterwards decide to go for a dictionary. You then would have to rename the variables all the time. I do recommend using meaningful names, using full english words (except for very local variables), and using singular and plural as applicable, so I would write:
For Each stu as Student in students
:)Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
-
I would NOT prefix variables with a couple of letters that indicate the type, since that makes type changes hard. You may start with an array of something, later turn it into a list, and afterwards decide to go for a dictionary. You then would have to rename the variables all the time. I do recommend using meaningful names, using full english words (except for very local variables), and using singular and plural as applicable, so I would write:
For Each stu as Student in students
:)Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
Sound advice thanks.
-
As a hundred people, and you'll get a hundred different answers... There's no RIGHT answer, really... My personal style has spontaneously evolved to something like: Private/method variables: Camel case, no prefix (Since you can mouseover to get the type - If it's confusing, would be using extra comments anyway) Properties/Methods/Classes: Pascal case... Methods are verbs, classes and properties are nouns (Except boolean properties, which are named like IsBold, CanCalculate, etc - Kinda like that convention as used in WPF) Iterator variables: I tend to use short names like "idx", "row", "col", "rec"... But I avoid single-letter names unless it's x/y/z for a coordinate system. If I end up using more than one or two at a time, I tend to give them longer names to keep it readable. As for braces, well, you're using VB, so you don't have to deal with the curly brace debate.
Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)
The convention for naming methods etc would give my code more structure. Thanks for your advice. I tend to use x for local vars, a habit which really is nasty...
-
As a hundred people, and you'll get a hundred different answers... There's no RIGHT answer, really... My personal style has spontaneously evolved to something like: Private/method variables: Camel case, no prefix (Since you can mouseover to get the type - If it's confusing, would be using extra comments anyway) Properties/Methods/Classes: Pascal case... Methods are verbs, classes and properties are nouns (Except boolean properties, which are named like IsBold, CanCalculate, etc - Kinda like that convention as used in WPF) Iterator variables: I tend to use short names like "idx", "row", "col", "rec"... But I avoid single-letter names unless it's x/y/z for a coordinate system. If I end up using more than one or two at a time, I tend to give them longer names to keep it readable. As for braces, well, you're using VB, so you don't have to deal with the curly brace debate.
Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)
Hi one thing I've found really useful is to not use words such as Date, Time, etc the VB uses, can muck up your code big time, as I've found out. Apart from that use variables that you will understand when looking at code 6mths down the line. I agree with alot that I use things like strBookings if a string for example. Good luck x :)
Kris MCP