Jump to content

Is that good code?


Recommended Posts

  • Moderators

This seems to come up pretty regularly. Would it be worth a line in the Help file - "Always enclose the expression in () when using NOT - If NOT($iFred < 9)"?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Moderators

I am just glad Richard came up with the question first!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

What, like this?

Func _isOrganic(ByRef $num)
    Local $properties[2]
    $properties[0] = "ganic"
    $properties[1] = "gasmic"
    MsgBox(0, "Numberical Properties", Round($num*0.62) & " is or"& $properties[Random(0,1,1)])
EndFunc
Edited by czardas
Link to comment
Share on other sites

If've got a question whether this ... If Not $iDimension > 0 Then ...is really good code?

Personally, I've always treated NOT as a function in whatever language I've used, so I would instinctively write that as If Not( $iDimension > 0 ) Then... and so would not have written it this way. So, I agree that it is not really good. That's NOT(really) good, rather than NOT(really good), just to be clear.
Link to comment
Share on other sites

Is it faster to pass large arrays by reference rather than by value?

Did you not read the ByRef documentation? (hint: the answers to both questions are the same :mellow:.)

$mArray = [ONE MILLION ITEMS!]

DoSomethingDumb($mArray)
DoSomethingSmart($mArray)

Func DoSomethingDumb($aArray)
ConsoleWrite($aArray[999123])
EndFunc

Func DoSomethingSmart(ByRef $aArray)
ConsoleWrite($aArray[999123])
EndFunc

One copies the entire array to the local $aArray. The other just uses a reference to the existing array. It's much faster and uses less memory.

Edited by JRowe
Link to comment
Share on other sites

Common guys, this shouldn't be a discussion thread for all that stuff. :mellow:

Three topics are handled here:

1) Not... is that good code? Answered : Yes, I think so.

2) _ArrayUnique performance! Answered : Not completely. FMPOV, there should be a rewrite for better performance in case

a ) to strip down huge arrays

b )dealing with already stripped arrays

3) ByRef or ByValue! Answered : Yes, I think so.

Thanks!

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Did you not read the ByRef documentation?

Well, my answer was mostly rhetorical - Richard asked why the OP was passing an array by reference, I would have thought that the default behaviour should be to always pass arrays by reference unless the function always needs to modify a temporary copy of the array.
Link to comment
Share on other sites

One copies the entire array to the local $aArray. The other just uses a reference to the existing array. It's much faster and uses less memory.

Kind of anyway :mellow: You'll find that AutoIt uses copy-on-write optimization for arrays, so that unless the array is modified in the the function, the array never actually gets copied. In that case, the performance difference between ByRef and non-ByRef array parameter passing is absolutely negligible. There probably is still a tiny bit of overhead for not passing ByRef to functions that perform read-only operations on the array, but we're talking microseconds/milliseconds even over many iterations.

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Link to comment
Share on other sites

Man, just when I think I know something about anything. So an array isn't copied, even if it's not passed ByRef, unless it's manipulated inside a function?

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