After looking around in the documentation and experimenting a bit with constructors it seems that constructors cannot do properly what they should do. By definition a constructor is used to create a new instance of a class but there are two major drawbacks which don’t make sense:
- Constructors cannot initialise non public variables since they have to be declared as module function instead of being static functions of a class
class1 := class():
# Note that variables with no access specifiers are public by default
Property1 : int
MakeClass1<constructor>(Arg1:int) := class1:
Property1 := Arg
- Constructors cannot exists in abstract classes as they have to immediately return a type which is not possible for an abstract class
class1 := class<abstract>():
Property1 : int
# This constructor will throw a compilation error
MakeClass1<constructor>(Arg1:int) := class1 :
Property1 := Arg
These are very BIG drawback for something so basic in a programming language, especially as they prevent the very few cases where you want to use a constructor over a plain function for security and inheritance reasons.
Do we know if Epic has any intention of improving this anytime soon?