what is the best coding convention that can be followed with vb?
Printable View
what is the best coding convention that can be followed with vb?
There's a program called VB Law that'll scan your source code and report fallacies with varying degrees.
It even functions as a plug-in, and the demo version scans five modules at a time. Although one at a time should be sufficient.
What kind of things does it report back? Unreferenced variables/functions? Badly named variables? Innefficient code (ie calling the same thing twice with no difference or something)
Also were can we download VB Law??:confused:
Its quite comprehensive, especially if you are just a casual programmer
I was hoping for something to merely check that Strings have str at the start etc
and maybe give the option to automatically change all occurances of them
anyone fancy writing this and putting it in the Codebank? :bigyello:
That would piss me off to be honest. I never use those three character prefixes for variable names anymore, I avoid them at all costs. To me, reading code shouldn't be full of "str" or "lpstr" or "int" or "lng" or "lbl" or "txt"... sure, it allows you to immediately realise what it is, but if it wasn't obvious enough already by the name then you aren't naming your variables correctly in my opinion. Mind you, my variables are usually all 1 letter and different cases (when in C++), but I don't like other people reading my code.
and unless you are alot of programmers working together it seems like a lot of money for little...
use a coding conv. that suits you. :)
The trouble comes when you develop something for a company and leave (or leave the project)Quote:
Originally posted by Dreamlax
Mind you, my variables are usually all 1 letter and different cases (when in C++), but I don't like other people reading my code.
It becomes a nightmare for the subsequent people to work out what is going on.
I'd essentially like a find and replace program/addin to modify the
crap projects I've been given to make them easier to read.
It would also need have an option to use the coding conv. that
suits you best, like peet said.
Are you taking the piss?Quote:
Originally posted by Dreamlax
That would piss me off to be honest. I never use those three character prefixes for variable names anymore, I avoid them at all costs. To me, reading code shouldn't be full of "str" or "lpstr" or "int" or "lng" or "lbl" or "txt"... sure, it allows you to immediately realise what it is, but if it wasn't obvious enough already by the name then you aren't naming your variables correctly in my opinion. Mind you, my variables are usually all 1 letter and different cases (when in C++), but I don't like other people reading my code.
I would not hire any developer who didn't use naming conventions, use GOTOs or the END command.
It's a pain in the neck trying to read other peoples code that haven't used naming conventions. It's just silly :(
Woka
If I am programming something that needs to be left to someone else later then I use a convention... kinda... but for me, X (capital) is always a counter, Y (capital) is always a second counter, Z (capital) is always a third counter, and the lowercase versions are always how much they are incremented by (if not 1).Quote:
Originally posted by agmorgan
The trouble comes when you develop something for a company and leave (or leave the project)
It becomes a nightmare for the subsequent people to work out what is going on.
I'd essentially like a find and replace program/addin to modify the
crap projects I've been given to make them easier to read.
X += x;
Y += y;
Z += z;
You see that a lot in my projects. But since I'm the only one that ever reads them, I figure I might as well write it in a way that only I can understand, but if anyone else needs to read it then I try and use whatever convention they use.
That still makes no sense.
What if you come back to do some work on your project in a few montsh time. You will have forgotten what X, Y, and Z are...are they Longs, or Integers? I don't know, niether will you, unless you search your code for their declaration.
Also using them like counter is all good and well, but as another developer I would want to see lngUserIndex instead fotr X, and lngProjectIndex instead of Y etc.
Way easier, and good programming. It's harder to use X, Y and Z than it is to using naming.
Woka
I know exactly what they are. In VC++ an "int" is the same as a "long" (you use "short" for a 16-bit integer), so I only ever declare them as "long".Quote:
Originally posted by Wokawidget
That still makes no sense.
What if you come back to do some work on your project in a few montsh time. You will have forgotten what X, Y, and Z are...are they Longs, or Integers? I don't know, niether will you, unless you search your code for their declaration.
Also using them like counter is all good and well, but as another developer I would want to see lngUserIndex instead fotr X, and lngProjectIndex instead of Y etc.
Way easier, and good programming. It's harder to use X, Y and Z than it is to using naming.
Woka
Trust me, I can look at code I've written 3 years ago and still understand it, I use my own convention that hasn't particularly changed, and if it has, not very much.
Each to their own I suppose :rolleyes:
I guess hehe, but you are right, it is better practice to write with naming conventions, I just like to type up code quicker, and having to type lpstr before every string slows me down.Quote:
Originally posted by Wokawidget
Each to their own I suppose :rolleyes:
I wonder what the longest prefix would be? A far pointer to a constant wide-string?
lpcwstrName
HAHAHA... now that would piss me off.
I use:
- str (locally declared in a sub)
- mstr (decalared at the top of a module)
- pstr (passed to a function/sub)
- gstr (declared golabally in a module)
obviously str can be replaced by lng, int, bln etc.
Woka
I think the posts above shows that you should use what you find best :)
if you need a starting point, the Hungarian Notation Naming Conventions for VB is IMO a good starting point :)
http://msdn.microsoft.com/library/de...annotation.asp
http://support.microsoft.com/default...NoWebContent=1
http://www.apostate.com/programming/hugarian.html
For Me -- I dislike TLA's
The convention here is that the code should read like a book ie.
Total = VAT * Units
for a grid
Invoices_Grid.Textmatrix(Invoice_Row,Field_Number)
each to their own though
Simon
ps.
Heard of a project where each Vble was a Letter and then a number and the number could be looked up in a book to see its significance.
Don't you mean Reddick?Quote:
Originally posted by peet
I think the posts above shows that you should use what you find best :)
if you need a starting point, the Hungarian Notation Naming Conventions for VB is IMO a good starting point :)
http://msdn.microsoft.com/library/de...annotation.asp
http://support.microsoft.com/default...NoWebContent=1
http://www.apostate.com/programming/hugarian.html
ravi is going to be well surprised we he logs back in and
sees so many replies to such a short question! :bigyello:
Reddick ?Quote:
Originally posted by mendhak
Don't you mean Reddick?
VBA conventions based on Hungarian (and other common conventions). Mostly based on Access I think. I found this article on Google:Quote:
Originally posted by peet
Reddick ?
http://216.239.39.104/search?q=cache...hl=en&ie=UTF-8
Not a bad reference :)Quote:
It seems alot more robust than the examples/suggestions @ MSDN!
(BTW whoever works for MSDN should be older than 3 years of age - that way we might get some consistancy!)
Bruce.
I just looked at the end of the file. Says he worked at MS for four years. :DQuote:
Originally posted by Bruce Fox
It seems alot more robust than the examples/suggestions @ MSDN!
(BTW whoever works for MSDN should be older than 3 years of age - that way we might get some consistancy!)