Is Hungarian in VBA OK?

I do not use Hungarian (str, int) prefixes in .Net, but still find it useful in VBA, where it is more difficult to see types.

This is bad? Unnecessary? Maybe I missed something.

I would really appreciate any feedback. For some time I thought.

Thanks to everyone.

+6
vba hungarian-notation
source share
4 answers

I always use one and two letter prefixes in VBA. I am sure that I am the only one who admits this, but I decided that someone should be the opposite.

Of the 18 million lines of VBA code that I wrote, I worked about 1000. If no one sees my code, then I am free to use the convention that I like. If someone else will work on your code, you must agree on an agreement.

I like that it allows me to keep my variable names shorter. I could use FileNumber and FileName, or I could use lFile and sFile. I do not find it more or less readable than the other. It also helps me use reserved words as variables. If I want to use Replace as a variable name, I cannot. But I can use sReplace or lReplace.

+4
source share

I would say that such a Hungarian notation is the root of all evils in almost every language. Some say this is handy for extremely dynamic languages. But no, I think that the type reduction prefix on the variable name is redundant in 99% of all cases and just leads to ugly code.

see. Why shouldn’t I use Hungarian notation?

+6
source share

I would suggest going for something higher level than just types so you can understand what the goal is. So, instead of calling something a str ing, call it name or addr ess, and instead of int call it count or coord inate or ...

(I prefer to use suffixes for prefixes, but this is a matter of style and taste.)

+5
source share

If the style in your company is configured to use Hungarian notation, then there is no problem with its use - politics is politics. There are many tools that help you enforce coding naming conventions (e.g. Stylecop for C # ) so you can move on if you are allowed to.

In principle, standards are a good idea, but the fact that these standards depend on the company for which you work. If you have certain authority, you can try to impose the standards that MS currently advertises, but if you have a lot of legacy code that will include a lot of expensive refactoring with little material benefit.

I would recommend that you move away from the Hungarian notation for new projects (perhaps using a code analysis tool), but be pragmatic about legacy code.

0
source share

All Articles