Objects - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=57591
- Thanks again. The material is very complex, and so the responses have been a bit slow. It might help if someone could summarise what new functionality is available, and if any old functionality is affected (breaking old scripts).
- Here are my concerns re. the functionality of objects, taking into account what I've understood from reading through the md files and looking at the code.
OBJECT MODES
- one object type for everything has proved a good, simple and clear paradigm, normally when I create an array, I think, I'd like the standard AutoHotkey array but with these deviations (even if you had multiple object types e.g. Map, granular mode control might still be useful)
- so, for any AHK object, there'd be an on/off/count etc mode for each of the following:
- (additionally you could have functions that can override defaults)
- integer keys: e.g. key name 1 (string) is converted to 1 (integer) (perhaps this could be bypassed via ObjRawGet/ObjRawSet, e.g. so that hex numbers as strings are returned in the correct order)
- takes precedence: keys/properties take precedence (or perhaps, in one mode, adding a key replaces a property, and vice versa) [EDIT: perhaps not needed]
- takes precedence: keys/methods take precedence (no longer an issue in Object.ahk: you can create a key with the same name as a method)
- [KEY] set default value: blank string/0/new empty object (default value for a non-existent key) (e.g. for immediate concatenate/increment/push and for code simplification/greater readability)
- object type: case-sensitive/case-insensitive key names
- object type: e.g. fixed-length array, e.g. integer keys only, e.g. prevent certain key names from being added (experts can use these settings to achieve more efficient performance, equivalent to separate object types in other programming languages)
- object type: (in general: 1 object with modes/restrictions, versus different object 'types')
- enumerator: specify a common built-in enumerator type that will be used by a for loop [see 'FUNCTIONALITY (ENUMERATORS)' below]
- perhaps a Mode method for objects (to handle such options) (or something else)
FUNCTIONALITY (SIMPLICITY)
- [KEY] I would suggest .key and [key] be equivalent, for simplicity and to avoid bugs (and to use methods for any special functionality)
- _NewEnum and Next, seem like simple intuitive names, that perhaps wouldn't benefit from being changed (new related methods could still be added)
- [KEY] I would consider having everything available as methods and no built-in properties (or any built-in properties also available as methods) [Length/Count properties could be built-in, but if a key existed with the same name, it would override them, whereas Length()/Count() methods would always work]
- ... perhaps obj.base := {} and obj["base"] := {} should not set the base object (perhaps a base() method could allow direct assignment)
FUNCTIONALITY (ENUMERATORS)
- functionality to support common enumerators would be well worth considering:
- loop as variadic functions (linear array) (keys 1 to .Length(), including undefined keys)
- loop integer/string keys only
- loop alphabetical/key creation order
- loop reverse order (and the ability to loop and delete) (get the last key name)
- (perhaps loops should only retrieve keys by default, or keys and properties)
- (functions to list all properties/list all methods)
FUNCTIONALITY (GENERAL)
- multiple assign: a shorthand or function that can accept [...] or {...} for adding keys to an existing array (e.g. create a blank array, set the modes, add keys)
- (ObjToString, or another function, to list keys/values)
- (methods for strings/integers/floats, not just objects)
[EDIT: the only functionality I especially want in this regard, can be implemented by the user like so:]
if var in/contains comma-separated list/array - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=43593&p=247622#p247622
"".base.base := {split:"StrSplit"}
- [KEY] (classes: it might be useful to have the ability to do something whenever non-existent *and existing* keys are read from/written to, although this can be done with existing functionality, by placing data inside the class object) [note: __Get/__Set, in AHK v1, only handle *non-existent* keys]
LISTS
- I find with anything it helps to have a list (more or less complete):
Code: Select all
methods:
__forin()
__getprop()
__initclass()
__setprop()
Clear()
DefineMethod()
DefineProperty()
DeleteMethod()
DeleteProperty()
Has() [cf. HasKey]
HasMethod()
HasOwnProperty()
HasProperty()
New() [cf. .__New/new]
Properties()
ToString()
also:
Count property [cf. Count method]
Item[] [not 'Item()']
ObjFromPtr function
prototype property