Moderators Melba23 Posted March 8, 2010 Moderators Share Posted March 8, 2010 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Valik Posted March 8, 2010 Share Posted March 8, 2010 No, I would argue that you should always write the expression correctly to begin with. If Not ($iFred < 9) is really If $iFred >= 9 which is about 703 times clearer to the reader. Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 8, 2010 Share Posted March 8, 2010 (edited) I'd like to see the equation you used to come up with 703 times the clarity. For educational purposes. Edited March 8, 2010 by Richard Robertson Link to comment Share on other sites More sharing options...
Valik Posted March 8, 2010 Share Posted March 8, 2010 Organic random number generator. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 8, 2010 Moderators Share Posted March 8, 2010 I am just glad Richard came up with the question first! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 8, 2010 Share Posted March 8, 2010 You do like those random numbers, don't you. Link to comment Share on other sites More sharing options...
Valik Posted March 8, 2010 Share Posted March 8, 2010 Maybe. Link to comment Share on other sites More sharing options...
czardas Posted March 9, 2010 Share Posted March 9, 2010 (edited) 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 March 9, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 9, 2010 Share Posted March 9, 2010 Why are you passing $num byref? Link to comment Share on other sites More sharing options...
czardas Posted March 9, 2010 Share Posted March 9, 2010 (edited) Why are you passing $num byref?I wish I had an answer to that question. (random syntax) Edited March 9, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 11, 2010 Share Posted March 11, 2010 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 More sharing options...
PhilHibbs Posted March 11, 2010 Share Posted March 11, 2010 Why are you passing $num byref?Is it faster to pass large arrays by reference rather than by value? Link to comment Share on other sites More sharing options...
JRowe Posted March 11, 2010 Share Posted March 11, 2010 (edited) 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 .) $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 March 11, 2010 by JRowe [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 11, 2010 Author Share Posted March 11, 2010 (edited) Common guys, this shouldn't be a discussion thread for all that stuff. 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 March 11, 2010 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 More sharing options...
PhilHibbs Posted March 11, 2010 Share Posted March 11, 2010 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 More sharing options...
Richard Robertson Posted March 11, 2010 Share Posted March 11, 2010 Is it faster to pass large arrays by reference rather than by value?Yes, except that $num was not an array. :| Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 12, 2010 Share Posted March 12, 2010 Yes, except that $num was not an array. :|Er... good point, looks like I mis-read the code quite badly. Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 12, 2010 Share Posted March 12, 2010 Er... good point, looks like I mis-read the code quite badly.You can't see it, but I'm seriousfacing at you. Link to comment Share on other sites More sharing options...
-Ultima- Posted March 14, 2010 Share Posted March 14, 2010 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 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 More sharing options...
JRowe Posted March 14, 2010 Share Posted March 14, 2010 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? [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now