Jump to content

Hungarian Notation


 Share

Recommended Posts

¡Hi! Well, this is just a little question. ¿Do you think Hungarian Notation is a good idea? I mean, I'm a really indecisive programmer, and sometimes this makes me hard to choose stuff like a name for a function, even the most easy thing. So, personal opinion, and pros vs cons of Hungarian Notation, what do you think?

¿And what about this "http://www.autoitscript.com/wiki/Best_coding_practices#Scopes_of_Variables"?

Codes codes codes.

Link to comment
Share on other sites

There are two different variants on Hungarian notation. Google it.

As long as you can safely determine what the variable should be used for from the name, it's fine.

For example if I had a variable called countFoo, I can be pretty sure it's an integer, referring to how a many foos have been counted.

Sometimes the type isn't all that relevant, for example with control ids, using $iOk wouldn't make sense. Some people use $cOk, but the best option would be $btnOk, as you know from the latter a lot more about what the variable means.

In a language like autoit, where we use variants, naming variables properly can make code a lot easier to maintain, by yourself and others.

If you see code like $iBar = "hello" alarm bells are ringing and it doesn't look right. Same with passing arguments to functions.

That's why it's a good habit to get into.

Link to comment
Share on other sites

There's lots of info you can include in a name if it is fit for the purpose. I am currently working on a project where notating container size helps to differentiate many similar variants. I have $sHex12 (range 000-FFF) and $sHex24 (range 000000-FFFFFF). I have function names like:

  _Hex24ToHex12 $sHex24)

  _Hex12ToBin12($sHex12)

  _Bin24ToHex12($sBin24 )
  _IdentifyHex12($sHex12)

I couldn't cope with the variety of variants I created if I didn't do something like this.

Link to comment
Share on other sites

Sometimes the type isn't all that relevant, for example with control ids, using $iOk wouldn't make sense. Some people use $cOk, but the best option would be $btnOk, as you know from the latter a lot more about what the variable means.

 

I actually use the GuiButton UDF, so $hOk, but this still have no sense. And I like what I've read...the kind, not the type. I googled and found a lot of information, and I think is really more useful $lstFolders than $iFolders for a list (just an example). So basically, I've been working on what is on the Wiki (Best coding practices), and now I think I'm wrong and I must be a little more "flexible".

Codes codes codes.

Link to comment
Share on other sites

I actually use the GuiButton UDF, so $hOk, but this still have no sense. And I like what I've read...the kind, not the type. I googled and found a lot of information, and I think is really more useful $lstFolders than $iFolders for a list (just an example). So basically, I've been working on what is on the Wiki (Best coding practices), and now I think I'm wrong and I must be a little more "flexible".

Like I said, in some cases there are more logical prefixes.

The best practices are correct in most cases though, for instance I would ALWAYS use $a, $p, $t, $tag, $o prefixes for those data types. $s and $f I use most of the time too. $f for flag is quite useful as you know it's either boolean, or you can use BitOR and BitAND on it to get flags.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...