The Jade 2025 release focuses on modernising the developer experience and helping you build faster, smarter, and more scalable applications.
I think the majority of the time that we create objects we also want to initialize them, so currently this is a two step process - create object, call initializer. If an object can be initialized in more than one way, we have to create intializers with different names (because of the lack of overloading).
It would be nice if we had parameterised constructors so that creating objects was a one step process and it would be nice if we had overloading so it was clear which methods were inializers and we didn't need to come up with unique names for them.
Previously discussed at https://forums.jadeworld.com/viewtopic.php?f=7&t=2045&hilit=constructors and elsewhere
|
HistoricalComments
Ben Butterfield 29/09/2017 3:17:41 AM Parameterised constructors would be number one on my request list. It is a clear and dependable way to express the dependencies in a class. I.e. The compiler would not allow the creation of an instance of a class without supplying the dependencies in the constructor. As the original post states there is currently a reliance on initialize methods, there is also another step that is needed to check the client has called this method, with parameterised constructors the compiler enforces this. These should accept the same parameters as "normal" Jade Methods. They should support parameters of type JadeInterface to allow varying the behaviour of the class depending on what is passed to it - polymorphism by composition. There is also the case that they would be the easiest and clearest way to create immutable objects. |