Jump to content
Sign in to follow this  
SirJohann

Hungarian Notation

Recommended Posts

SirJohann

¡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.

Share this post


Link to post
Share on other sites
Mat

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.

Share this post


Link to post
Share on other sites
czardas

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.

Share this post


Link to post
Share on other sites
SirJohann

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.

Share this post


Link to post
Share on other sites
Mat

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.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • nooneclose
      By nooneclose
      I need to perform a subtotal in excel and I would like to automate this process using Autoit if possible like always any and all help will be greatly appreciated. 
      I can not find a good example but the two from Microsoft. Here is one of the two from msdn.microsoft.com/en-us/vba/excel-vba/articles/range-subtotal-method-excel
      I do not really understand how to translate this into AutoIt, but I gave it a try and here is what I have.
      $OpenRange      = "A1:E200" $xlSum          = -4157 $Added_Array[2] = [2, 3] $OpenRange.Subtotal("B1", $xlSum, $Added_Array, True, False, True) I just need to perform a subtotal on a range based on a header called department, and then perform a sum on the results.
    • nooneclose
      By nooneclose
      How to use _Excel_RangeSort to sort my excel file by three different headers Column A1, B1, and C1 have headers on which I want to sort by. The headers on which I want to sort are department, employee type, and name.
      I still really new to AutoIt so I do not actually know how to properly start this line or lines of code, to be honest. The example code is the best I can do.
      _Excel_RangeSort($OpenWorkbook, Default, "A1:C1", "1:1", $xlDescending, Default, $xlYes, Default, $xlSortRows) I just need to sort by those three headers in that order of department, employee type, and name, plus in descending order.
       
      any and all help would be greatly appreciated.  Thank you!
    • Eminence
      By Eminence
      Hello,
      Using SQLite, I was trying to select a specific column with having duplicate entries removed by using the DISTINCT function. 
      Local $sQuery = "SELECT DISTINCT supervisor, COUNT(DISTINCT employee_name) FROM data_db What the above snippet does is just list only one supervisor but with the total count of unique employee names in the whole database when it should be listing out all supervisor entries from the database and list the total count of employees per each supervisors. If I remove the COUNT function, it does list out all unique entries of supervisor names from the list. Attached is a screenshot of an example database as well. 
      Any help will be much appreciated. Thank you!

    • PramodR
      By PramodR
       
      I see couple of ways to import module ,  one with specifying absolute path of the file to get imported, by this logic i believe to import a specific module will be like #include <c:\modulepath\duplicatemodule.au3>
      but i see some registry changes also made in this link , can someone explain why that registry change is really required.
       
×