tl;dr: consider wish list ideas for AHK and objects from a newbie perspective (cf. only the expert perspective)
- I've seen small number of users on this forum get quite involved with custom AHK classes, it's the one area of AutoHotkey I've not been too enthused by, whereas usually I like to get involved in the detail.
- Occasionally I see people engage in the joy of the detail, that I often do for other areas of AutoHotkey. A good example of this is this thread:
Code Puzzle Thread - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 17&t=25683
- Because object classes are one of the least newbie-friendly things in AutoHotkey, while the move towards AHK v2 has shone a spotlight on virtually every area of AutoHotkey from both beginner and advanced perspectives. I don't feel that objects/object classes are getting the same attention. Only technical details appear to be really being reflected upon. E.g. here thoughts re. objects are more top-down than bottom-up.
v2-thoughts
https://autohotkey.com/v2/v2-thoughts.htm
- The one exception has been to treat key names that look numeric as numeric, which I believe is the right assumption to make. Although this would mark a major loss of generality, if there isn't some workaround to still create key names that look numeric, stored as strings. I'm somewhat concerned by the lack of discussion re. this point. Are there potential problems if this functionality were unavailable, e.g. perhaps relating to cloning COM objects, or with arrays in AHK v1 that wouldn't work in AHK v2.
- Another simple change is to clear objects when a for loop completes.
- People have mentioned: checking if an array contains an item, getting an item count in an associative array, listing/editing the items within an object via a GUI. Considering simple but common functions for manipulating the items in array, list manipulation, the numbers could increase quite rapidly, to a dozen without much effort. E.g. functions to sort linear arrays or remove duplicate items.
- By not bridging the simple and the complex, I believe that the use of objects within the AutoHotkey Community, could grow far slower than it otherwise would. I will make some points that lie in the middle ground. These are not wish list requests as such, just areas for consideration. If the ideas don't sound too exciting to any object experts, then it's even more important to consider them closely.
- StrSplit to an associative array. Then you can use HasKey to check that an array contains an item.
- Converting two objects to a binary/text representation, to query if they are identical.
- For loop in the reverse direction.
- Multiple enumerators for the same object: e.g. list the alphabet: forwards, backwards, vowels first, consonants first.
- Arrays that are sorted case sensitive/by date created, by default, and/or using these as additional enumerators (i.e. sorted only when needed).
- Allowing an associative array to use literally any string without interfering with methods. Otherwise using a prefix character, that no method begins with, is a good solution, but this looks odd.
obj.HasKey() fails for all keys if a key called HasKey exists - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 15#p148015
- Getting the parent of an item, parent information stored with the key, perhaps a custom class.
- A class to allow a 'for a to b step c' loop.
- Getting the original case of a key in an associative array, without doing a for loop.
- Optimisation for handling associative arrays that have no data, where only the key names matter, i.e. the equivalent of comma-separated lists.
- Making it clear when to use, and when not to use, ObjAddRef/ObjRelease.
- Behind-the-scenes information, e.g. if obj.a versus if obj.HasKey("a"), which is more costly, and by how much?
- A Length() method for a RegExMatch object, so they can be treated more like arrays in certain contexts. [EDIT:] Perhaps normal arrays should have Len() available, as well as Length().
- Why are RegExMatch objects read-only? There are circumstances where it would be convenient to edit the array, and thus a cloning method would be useful.
- Get/Set have access to a key's ancestry, but not Call, limiting what Call can do.
- ... Is it possible to have a class definition where you create an object, but the object doesn't just have keys, it has separate objects that 'belong' to it, but that aren't subkeys of it. A workaround might be a class that gives each object it creates, a unique ID number, and one static object inside the class definition, stores a separate array for each object.
- ... What if you want to, in effect, use Get/Set (used only for keys that don't exist) even when the key already exists, a workaround would be to put objects somewhere else, mentioned above. One reason for interest would be that Get/Set retrieve more information than Call, mentioned above.
- Does it matter if I leave a hundred 10-key arrays in my script, without clearing them.
- What are the most likely/worst problems that can happen when you don't release objects.
- What are window groups behind-the-scenes, something object-like?
- Is it possible to create a class that excludes certain keys from being enumerated by the for loop.
- Are variadic functions with all ByRef parameters possible.
- An efficient way to check that no keys in a linear array contain a certain string. An efficient way to find multiple unused characters, for use as delimiters/separators. This kind of problem would lead me to consider an object where you could retrieve a pointer for the start/end of the address in memory (with padding bytes either allowed or disallowed), you could then perform a binary search for unused characters.
- Can for loops be based on an infinite list of items.
- [EDIT:] I know there was some surprising behaviour relating to the use of () and [], I think it was this. These are equivalent apparently. It isn't a problem as such, but perhaps a script to identify such lines so that the user can make usage consistent would be useful. Also, it did cause me quite a bit of confusion until I realised what was going on.
Objects
https://autohotkey.com/docs/Objects.htm
obj.item(x) := y
obj.item[x] := y
v2-thoughts
https://autohotkey.com/v2/v2-thoughts.htm
- [EDIT:] A collection of simple examples for __Get/__Set/__Call, __New, _NewEnum, Next, base, __Delete, __Class, __Init.•x.y(...) := z is equivalent to x.y[...] := z for all objects
...
•COM objects allow x.y(...) and x.y[...] to invoke a method or a property with parameters
- An official list of methods somewhere in the documentation. E.g. an attempt:
obj.HasKey() fails for all keys if a key called HasKey exists - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 55#p147755
- [EDIT:] Note: A key concern is that by anticipating demands, AutoHotkey would be easier to add to in future, and less likely to require script-breaking changes.
- Thanks for reading.
[EDIT:] Further points:
- To have a key with a value and subkeys at the same time.
- Objects with previous/next methods.
- (I will investigate creating some classes that can make possible some of these ideas.)