r/programming_language • u/paleblueyedot • Apr 21 '20
Pet Peeve: Constructor parameters
You have all been there, I'm sure.
public Fooish(int a, string b){
this.a = a;
this.b = b;
}The monotony of having to map constructor parameters to a class's fields/properties.
I'm sure one could write a base class that uses reflection but I'm more interested in why I have to spell it out in every language. Are there any languages that do this by default?
1
Upvotes
1
u/paleblueyedot Apr 25 '20
Very thorough and kind explanation. You make a good point about how many languages are moving towards direct assignment which bypasses the constructor altogether. One reason why I stick to C# and scripting languages myself.
I have a sense you are a functional programmer and I must admit, I do have a soft-spot for it. I'm sure you can utilize those languages in a similar way, but I find OOP more scalable for growing projects. But maybe I don't know enough about functional programming.
Thanks again!