godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Enhance experience for unmodified constructor inheritance #1145

Closed Erawpalassalg closed 4 months ago

Erawpalassalg commented 4 years ago

Describe the project you are working on:

On Godot 3.2.2

Let's say we have a simple project structure with 3 scripts.

Describe the problem or limitation you are having in your project:

First thing first. If I wanted my example to work properly I'd have to do something like _init(param).(param) in my Child.gd. As a side-note, if I wanted to modify my child's constructor, the current state of the editor wouldn't be an issue (except for the compile-time/runtime weirdness, but that's not a big problem)

Now, let's say I didn't declare my Child's constructor.

This is pretty confusing. But it gets worse.

Let's say, now, that instead of having 3 files, I have only one file declaring 2 inner classes (still called Base and Child). Still not declaring the Child's constructor.

None of these error messages are useful in this case. Worse, they muddy the waters about something which is already not that obvious (why do I have to redefine my constructor if I expect my child to be built the same way than its parent? plus this thing has a unique and weird syntax, which is understandable, but already confusing as a beginner).

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

This could be enhanced by either:

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Unfortunately I have no clue about how to implement this in the Godot's codebase (for now)

If this enhancement will not be used often, can it be worked around with a few lines of script?:

I think it would be used often 😛

Is there a reason why this should be core and not an add-on in the asset library?:

Well, yeah, taht's because it's pretty core stuff

danielzting commented 4 years ago

I second inheriting constructors by default. I have a base class called ComparisonSort with a constructor that takes an array. It feels really awful to have to copy and paste

func _init(array).(array):
    pass

into each of my seven and growing child classes (BubbleSort, InsertionSort, SelectionSort, etc...), maybe because it adds very un-GDScript-like boilerplate, or it feels like dead code but really isn't.

dalexeev commented 4 months ago

This is resolved in 4.x, so we can close this?

Calinou commented 4 months ago

Closing per @dalexeev's comment.