- Following on from a discussion here:
Suggestions on documentation improvements - Page 26 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=1434&p=262959#p262959
- While it's possible that some things re. if-statements/comparisons could be changed re. objects, it's not something that particularly concerns me, and I can work with the current system. I make these points only because prompted.
- When you compare two items of different types, either you get an error, or you determine *some* measure of comparison, a metric.
- E.g. what sensible comparison rules could you come up with for comparing strings and objects. Perhaps you could compare them as strings or compare the addresses.
- Some ideas re. if-statements with objects and comparing objects:
- At the moment we consider 3 things: addresses, which are obtainable via &obj anyway, 'IsObject', whether something is an object or not, and strings, at present the string representation of an object is always a blank string.
- The string representation for an object could be based on a ToString method, if present, otherwise it could be blank, working just like the AHK v2 String function.
- To compare if two variables point to the same object is pretty rare, and not very useful, so obj1 == obj2 could be redeployed, and besides, you could do it like this with &obj1 == &obj2, i.e. you can use the & operator.
- 'if var' as equivalent to IsObject is not particularly useful (since we already have IsObject). 'if var' is most useful to check if something is 'null'/'empty'. So 'if obj' could check whether the object contains keys or not. E.g. a function that returns an array of matches, did it contains any results: 'if oArray := ObjGetMatches()'.
- (var1 == var2) is most useful for comparing if the contents (not addresses) of 2 things match. As mentioned, (&var1 == &var2) can compare addresses.
- You could have it so that obj1 == obj2 compares the objects as strings, (i.e. obj.ToString would create a string listing its keys/methods) and this would give true if the contents (keys/values) of the objects were identical.
- There are pros and cons to every system. I'm not necessarily advocating anything yet.
ideas for if-statements
ideas for if-statements
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: ideas for if-statements
Personally, I don't mind that ahk avoids comparing them internally.
If I wanted to compare I'd choose how to compare usually by a certain key.
I wouldn't mind being able to check if an object is empty, but through a method similar to "array.length()". Maybe .keyCount() or something like that.
Sorry that one exists already, --> .Count() I must have missed it when it was released.
If I wanted to compare I'd choose how to compare usually by a certain key.
Sorry that one exists already, --> .Count() I must have missed it when it was released.