Jump to content

Best practice suggestions


Recommended Posts

As they're opinion-based to some degree; how are AutoIt's best practices decided and do suggestions get considered?

Some suggestions :

  • Minimize logic in global scope,
  • separate data & settings from logic,
  • use of vertical space,
  • project organization (folder structure, resource- and include file management).

Example (loop variable-naming, minimizing logic in global scope and separation of settings from logic) :

#include <Array.au3>

Global Enum  $RANDOM_RETURNFLOAT, _
             $RANDOM_RETURNINTEGER
Global Enum  $EXITCODE_NONE

Global Const $g_sChar0   = '-'
Global Const $g_sChar1   = '+'
Global Const $g_iAmountX = 10
Global Const $g_iAmountY = $g_iAmountX

Main()

Func Main()
    Local $aArray[$g_iAmountY][$g_iAmountX]

    For $i1 = 0 To $g_iAmountY - 1

        For $i2 = 0 To $g_iAmountX - 1

            $aArray[$i1][$i2] = Random(0, 1, $RANDOM_RETURNINTEGER) ? $g_sChar1 : $g_sChar0

        Next

    Next

    _ArrayDisplay($aArray)
    Exit $EXITCODE_NONE
EndFunc

Example (project organization) :

+ project_folder
  + bak         [backup files]
  + bin         [distributed binaries and dependencies]
  + inc         [non-standard include files]
  + res         [resource files (icons, file+install files, etc.)]
  + usr         [configuration files, databases, etc.]
  - script.au3
  - script.exe

Example (use of vertical space) :

Func _DigitalRoot($iNum)
    Local $sNum = ''
    Local $aNum

    While $iNum > 9

        $sNum = String($iNum)
        $aNum = StringSplit($sNum, '')
        $iNum = 0

        For $i1 = 1 To $aNum[0]

            $iNum += Int($aNum[$i1])

        Next

    WEnd

    Return $iNum
EndFunc
Link to comment
Share on other sites

  • 1 month later...

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