iseahound wrote: ↑
07 May 2020, 19:11
There is no reason to make use of this complex boilerplate just to have class1.class2()
1. The purpose of the "boilerplate" was to show how to recreate a function, not to make anything under the sun callable, and certainly not specifically to make classes callable.
2. The "complex" boilerplate code is only necessary in v1, where these changes cannot be made. Just use the Call method in v2.
3. There is no reason (provided in your post) to conflate function calling with instantiation.
Why 2 classes?
Again, this is only for v1.
1. Code reuse. Do you want to redefine all of the "complex" boilerplate code in every callable class?
2. In v1, meta-functions must be defined in a base object, so if you want __Call to be invoked for the class, it must not be in the class itself.
Function Objects should be first-class.
That means nothing to me, without reasons or an explanation. I see not why they should be first-class, nor how making all (or just nested) classes behave as function objects is in line with that.
Newbies start out using classes as more of a tool to organize their functions. By letting them replace their functions with function objects, they can more easily understand classes.
I don't buy it.
Anyone can understand the concept of a container as an organizational tool. Put the function into a class, it becomes a method, not the class itself.