|
-
Oct 12th, 2003, 11:16 PM
#1
Thread Starter
Hyperactive Member
coding convention
what is the best coding convention that can be followed with vb?
-
Oct 13th, 2003, 02:06 AM
#2
So Unbanned
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.
-
Oct 13th, 2003, 05:41 AM
#3
Hyperactive Member
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)
-
Oct 13th, 2003, 05:43 AM
#4
Fanatic Member
-
Oct 13th, 2003, 05:45 AM
#5
-= B u g S l a y e r =-
-
Oct 13th, 2003, 05:59 AM
#6
Frenzied Member
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?
-
Oct 13th, 2003, 06:05 AM
#7
Hyperactive Member
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.
-
Oct 13th, 2003, 06:12 AM
#8
-= B u g S l a y e r =-
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.
-
Oct 13th, 2003, 06:36 AM
#9
Frenzied Member
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.
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.
It would also need have an option to use the coding conv. that
suits you best, like peet said.
-
Oct 13th, 2003, 06:46 AM
#10
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.
Are you taking the piss?
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
-
Oct 13th, 2003, 06:47 AM
#11
Hyperactive Member
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.
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).
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.
-
Oct 13th, 2003, 06:59 AM
#12
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
-
Oct 13th, 2003, 07:06 AM
#13
Hyperactive Member
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
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".
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.
-
Oct 13th, 2003, 07:07 AM
#14
Each to their own I suppose
-
Oct 13th, 2003, 07:11 AM
#15
Hyperactive Member
Originally posted by Wokawidget
Each to their own I suppose
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.
I wonder what the longest prefix would be? A far pointer to a constant wide-string?
lpcwstrName
HAHAHA... now that would piss me off.
-
Oct 13th, 2003, 07:13 AM
#16
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
-
Oct 13th, 2003, 07:38 AM
#17
-
Oct 13th, 2003, 08:00 AM
#18
Addicted Member
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.
-
Oct 13th, 2003, 08:11 AM
#19
-
Oct 13th, 2003, 08:19 AM
#20
Frenzied Member
ravi is going to be well surprised we he logs back in and
sees so many replies to such a short question!
-
Oct 13th, 2003, 03:07 PM
#21
-= B u g S l a y e r =-
Originally posted by mendhak
Don't you mean Reddick?
Reddick ?
-
Oct 13th, 2003, 10:47 PM
#22
Fanatic Member
Originally posted by peet
Reddick ?
VBA conventions based on Hungarian (and other common conventions). Mostly based on Access I think. I found this article on Google:
http://216.239.39.104/search?q=cache...hl=en&ie=UTF-8
-
Oct 13th, 2003, 11:01 PM
#23
Not a bad reference 
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.
-
Oct 13th, 2003, 11:08 PM
#24
Fanatic Member
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!)
I just looked at the end of the file. Says he worked at MS for four years.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|