Fable icon indicating copy to clipboard operation
Fable copied to clipboard

Question: Implicit vs compiler generated constructors

Open dbrattli opened this issue 3 years ago • 8 comments

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

dbrattli avatar Aug 08 '22 08:08 dbrattli

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 👍

alfonsogarciacaro avatar Aug 08 '22 10:08 alfonsogarciacaro

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.

ncave avatar Aug 08 '22 11:08 ncave

Ok, thanks. I've fixed this for Python.

dbrattli avatar Aug 08 '22 12:08 dbrattli

@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.

ncave avatar Aug 08 '22 15:08 ncave

Ok, @ncave that's fine. I can rename back. I just need to think "primary" every time I read "implicit" 😄

dbrattli avatar Aug 08 '22 15:08 dbrattli

@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 avatar Aug 08 '22 16:08 ncave

@ncave I'll give a +1 for that suggestion. Then it's self explanatory.

dbrattli avatar Aug 08 '22 16:08 dbrattli

@alfonsogarciacaro @dbrattli Fixed in #3061, feel free to merge if you approve.

ncave avatar Aug 08 '22 16:08 ncave