Jump to content

Recommended Posts

Posted (edited)

I meant...

Local $iSomeVar = 1
Local Const $bVarFlag = $iSomeVar == 1 ; True
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

But I don't know if this could be classed as "good coding practice" though you at least know the datatype.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

When a I see flag (in programming) I think of a number (not a general one but for a function parameter) and not of a boolean, so it's a bit weird.

Edited by FireFox
Posted
  On 6/8/2013 at 2:21 PM, FireFox said:

When I see flag I think of a number (not a general one but for a function parameter) and not of a boolean, so it's a bit weird.

 

When I see a flag I think of a red piece of cloth you wave in front of a bull.

Posted (edited)

  On 6/8/2013 at 3:16 PM, czardas said:

When I see a flag I think of a red piece of cloth you wave in front of a bull.

Of course :D

Edit: I edited the previous post to be more precise.

Edited by FireFox
Posted (edited)
  On 6/8/2013 at 3:29 PM, FireFox said:

Edit: I edited the previous post to be more precise.

 

I meant in programming: RedFlag = False ; ==> Do not charge.

I use mental imagery a lot - but perhaps that's just me. :D

Edited by czardas
  • 2 weeks later...
Posted

Even old dogs can be taught new tricks.

Why 'magic numbers' are bad: http://blogs.msdn.com/b/alfredth/archive/2012/02/14/magic-numbers-are-bad.aspx?Redirected=true

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I hardly ever hear anyone pointing out the advantages of using magic numbers and the disadvantages of not using them. I find it hard to take one-sided arguments seriously, even when they have some merit.

Posted

There are a lot of topics on the good and bad points.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 6/23/2013 at 1:21 PM, AZJIO said:

For beginners who don't know English a name of a constant the same magic text as well as number.

Everything is a magic then.
Posted

Now I'm lost?!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

This guide by Google explains their preferred choice of style techniques in C++.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

The alternative to using Global variables is opting for an API-like system.

Example()

Func Example()
    Local $hSomeFunc = SomeFunc_Start(@ScriptFullPath)
    SomeFunc_DoSomething($hSomeFunc)
    SomeFunc_Shutdown($hSomeFunc)

    Sleep(500)

    Local $hSomeFuncElse = SomeFunc_Start(@AutoItExe)
    SomeFunc_DoSomething($hSomeFuncElse)
    SomeFunc_Shutdown($hSomeFuncElse)
EndFunc   ;==>Example

Func SomeFunc_DoSomething(ByRef $aAPI)
    Local Enum $eAPI_FilePath, $eAPI_StartTime, $eAPI_Max
    #forceref $eAPI_Max
    ConsoleWrite('File: ' & $aAPI[$eAPI_FilePath] & ', was started at ' & $aAPI[$eAPI_StartTime] & @CRLF)
EndFunc   ;==>SomeFunc_DoSomething

Func SomeFunc_Start($sFilePath)
    Local Enum $eAPI_FilePath, $eAPI_StartTime, $eAPI_Max
    Local $aAPI[$eAPI_Max]
    $aAPI[$eAPI_FilePath] = $sFilePath
    $aAPI[$eAPI_StartTime] = @HOUR & @MIN & @MSEC

    Return $aAPI
EndFunc   ;==>SomeFunc_Start

Func SomeFunc_Shutdown(ByRef $aAPI)
    Local Enum $eAPI_FilePath, $eAPI_StartTime, $eAPI_Max
    #forceref $eAPI_FilePath, $eAPI_StartTime
    For $i = 0 To $eAPI_Max - 1
        $aAPI[$i] = 0
    Next
    Return True
EndFunc   ;==>SomeFunc_Shutdown

I have purposely not included any comments as this isn't for the novice user, I'm also trying to inspire you to read more into what I am doing.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Here are a few real working examples that have adopted the API-like approach.

>_AppMon - By guinness

>_AppMonEx - By guinness

>_BinaryBin - By guinness

>VirusTotal - By Danyfirex

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

guinness, what do you mean API-like?  That looks like an object-oriented approach to me. Some programs use unique identifiers (Windows uses handles or COM pointers) as an abstraction for an object, some use data structures that are passed around via reference, and others use arrays, etc.  I'd consider all to be object-oriented, since the functions work on/with a specific object.

I've actually used this concept in AutoIt a few times, although it can get troublesome the more data you need to keep track of - in fact the most troublesome had to be the ProcessCounters object for my Performance Counters UDF's.  The object, in this case, was a 2D array full of information about the counter - handle, instance, process name and ID, # of counters, etc.  It was a pain in the ass, but really a necessary evil though, since process counters have a way of 'drifting'.  So, on each call to update the counters, the functions would first verify that the information was still valid (and update if necessary), before returning information back.  The arrays were always corrected internally in this way.

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted

It was >a term Valik used one time.

Honestly I've never had the confidence to delve outside of AutoIt/NSIS/VBScript, but what I've heard about OO, you're probably right.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...