Fable
Fable copied to clipboard
Question: Implicit vs compiler generated constructors
I'm a bit confused about the naming of some functions, i.e transformClassWithImplicitConstructor vs transformClassWithCompilerGeneratedConstructor. It seems to me that transformClassWithImplicitConstructor has a very explicit cons argument since the type that is being translated contains one (or more) constructors.
While transformClassWithCompilerGeneratedConstructor do not have any explicit constructor and will generate one for you. Thus the constructor is implicit here.
Shouldn't the names instead then be transformClassWithExplicitConstructor and transformClassWithCompilerGeneratedConstructor, or have I misunderstood something?
- Explicit: fully revealed or expressed without vagueness
- Implicit: capable of being understood from something else though unexpressed
You're right @dbrattli. I think the name comes because for some reason I think of F# primary constructors as being implicit in the type declaration (vs C# constructors that are declared separately). But it's true it can be confusing. I'm OK with the proposed change 👍
I've wondered about that constructor naming too in the past, so it's a good idea to change it to make sense.
I take it the change is just from transformClassWithImplicitConstructor to transformClassWithExplicitConstructor,
we should update all languages to be uniform.
Ok, thanks. I've fixed this for Python.
@dbrattli Actually I take that all back, hopefully I'm not entirely wrong again ;)
It's better to stick to the F# terminology, and there (like in other languages) the primary type constructor can be called implicit probably when you don't technically declare it as a constructor (using the constructor syntax), but it is a constructor nonetheless.
If you look at its method definition, it will have .IsImplicitConstructor = true.
So calling it implicit in that context makes sense.
Sorry for going 180 on this, naming things is hard, so it's better to stick to existing nomenclature.
Ok, @ncave that's fine. I can rename back. I just need to think "primary" every time I read "implicit" 😄
@dbrattli Yes, primary is another name for it, actually F# documentation doesn't really mention implicit, only primary, so that must be a .NET thing. We can switch to transformClassWithPrimaryConstructor then, if you prefer, I agree it's much clearer.
@ncave I'll give a +1 for that suggestion. Then it's self explanatory.
@alfonsogarciacaro @dbrattli Fixed in #3061, feel free to merge if you approve.