user4157124

Best practice suggestions

2 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



On 10/6/2017 at 1:18 PM, user4157124 said:

enables SciTE selection-highlighting (requires minimum of 3 characters).

This is true. Thanks for the tip :) 

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

  • Similar Content

    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • wakillon
      By wakillon
      For more details go to the Topic
    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake
    • TrashBoat
      By TrashBoat
      I've messed around in scite theme settings and it left this blue bar , how can i get rid of it?
      Image (imgur)