Results 1 to 24 of 24

Thread: coding convention

  1. #1

    Thread Starter
    Hyperactive Member ravi15481's Avatar
    Join Date
    Aug 2002
    Location
    INDIA
    Posts
    421

    coding convention

    what is the best coding convention that can be followed with vb?
    A good friend...

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    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.

  3. #3
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    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)

  4. #4
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Also were can we download VB Law??
    ** HOLLY **

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  6. #6
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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?

  7. #7
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    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.

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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.
    -= a peet post =-

  9. #9
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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.

  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  11. #11
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    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.

  12. #12
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  13. #13
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    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.

  14. #14

  15. #15
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    WGTN, New Zealand
    Posts
    338
    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.

  16. #16
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  17. #17
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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
    -= a peet post =-

  18. #18
    Addicted Member
    Join Date
    Jun 2002
    Posts
    211
    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.

  19. #19
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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
    Don't you mean Reddick?

  20. #20
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    ravi is going to be well surprised we he logs back in and
    sees so many replies to such a short question!

  21. #21
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by mendhak
    Don't you mean Reddick?
    Reddick ?
    -= a peet post =-

  22. #22
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    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

  23. #23
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    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.

  24. #24
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    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
  •  



Click Here to Expand Forum to Full Width