So, I have a large library I'm writing. It's designed to be user friendly for simple projects but allow for finer control as needed. This is accomplished by auto-creating certain handles and then defaulting to them when that variable was not explicitly passed. This works as intended.
To show you what I mean, consider this random example method:
Code: Select all
AddEasyToMulti(easy_handle?,multi_handle?){ ;auto-invoked during EasyInit()
easy_handle ??= this.easyHandleMap[0][-1] ;defaults to the last created easy_handle
multi_handle ??= this.multiHandleMap[0][-1] ;defaults to the last created multi_handle
ret := this._curl_multi_add_handle(multi_handle,easy_handle)
this.easyHandleMap[easy_handle]["associated_multi_handle"] := multi_handle
return ret
}
To put it another way, calling foo.AddEasyToMulti() is designed to be equally as valid as calling foo.AddEasyToMulti(easy_handle,multi_handle). Nearly all of the forward facing class methods (plus several supporting methods) have one or both of those ??= lines. I expect many more future methods to start with those boilerplate lines, as well.
I'm curious if there are any other possible approaches to handling default values in exposed class methods. In particular does a getter work across an entire class? If so, how would I go about implementing it? The variables can be encapsulated/attached to this if needed.
It's also okay if it can't be done. This is more of a thought exercise.