Jump to content

Enumerated vs Explicit


Recommended Posts

; Enumerated
    Global Enum Step *2 _
        $VerCenter = 0, _;  0x00
        $HozCenter = 0, _;  0x00    
        $HozLeft = 1, _;    0x01
        $HozRight, _;       0x02
        $VerTop, _;         0x04
        $VerBottom;         0x08
; -OR-
; Explicit
    Global $VerCenter = 0;  0x00
    Global $HozCenter = 0;  0x00
    Global $HozLeft    = 1; 0x01
    Global $HozRight = 2;   0x02
    Global $VerTop    = 4;  0x04
    Global $VerBottom = 8;  0x08
Enumerated

The enumerated method can be confusing if allowed to remain as a single line of code but it is a single function.

Explict

The explicit method is simpler and easier to read and understand. This method makes 6 individual declaration calls.

Conclusion: It Depends

If twenty or more declarations are needed then, in my opinion, the Enumeration method would be more efficient but I have not performed any tests to validate this hypothesis and would like more eyes to look at this and maybe even a developer to confirm one way or the other.

Fixed the Horizontal variable names:

  • Changed $HozTop To $HozLeft
  • Changed $HozBottom To $HozRight
Edited by Zinthose

--- TTFN

Link to comment
Share on other sites

.. Bump

No need to bump after less than 2 hours... The general forum rule is to wait at least 24 hours for a response before bumping. As for your question, I would imagine the enumeration will be a few ns faster, but it's probably more personal preference than anything.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

No need to bump after less than 2 hours... The general forum rule is to wait at least 24 hours for a response before bumping. As for your question, I would imagine the enumeration will be a few ns faster, but it's probably more personal preference than anything.

Fair enough, sorry for the early bump.;)

It also occurred to me that explicit declaration can be shortened to one line.

; Explicit
    Global $VerCenter = 0, _; 0x00
        $HozCenter = 0, _;    0x00
        $HozTop    = 1, _;    0x01
        $HozBottom = 2, _;    0x02
        $VerTop    = 4, _;    0x04
        $VerBottom = 8;       0x08
Using this seams to favor the Explicit method since Enum has to calculate the next possible value and explicit declarations don't need that overhead. Edited by Zinthose

--- TTFN

Link to comment
Share on other sites

; Enumerated
    Global Enum Step *2 _
        $VerCenter = 0, _;  0x00
        $HozCenter = 0, _;  0x00    
        $HozLeft = 1, _;    0x01
        $HozRight, _;       0x02
        $VerTop, _;         0x04
        $VerBottom;         0x08
; -OR-
; Explicit
    Global $VerCenter = 0;  0x00
    Global $HozCenter = 0;  0x00
    Global $HozLeft    = 1; 0x01
    Global $HozRight = 2;   0x02
    Global $VerTop    = 4;  0x04
    Global $VerBottom = 8;  0x08
Enumerated

The enumerated method can be confusing if allowed to remain as a single line of code but it is a single function.

Explict

The explicit method is simpler and easier to read and understand. This method makes 6 individual declaration calls.

Conclusion: It Depends

If twenty or more declarations are needed then, in my opinion, the Enumeration method would be more efficient but I have not performed any tests to validate this hypothesis and would like more eyes to look at this and maybe even a developer to confirm one way or the other.

Personally I would only use Enum when I want a set of constants, to make my code easier to read, that have different values but I'm not interested in what the values are

For example:

Global Enum TBR_DOCKED, TBR_FLOATING,TBR_FIXEDVERT,TBR_FIXEDHORZ

If I need them to have specific values I would always explicitly declare each one.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Using this seams to favor the Explicit method since Enum has to calculate the next possible value and explicit declarations don't need that overhead.

Yeah, thinking this through again, the enum overhead is probably going to be slower than explicit declaration. I've only ever used explicit declaration, as it is the simplest method and you can declare multiple variables on one line just fine.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
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

  • Recently Browsing   0 members

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