Yah - The C# and current Cobra behavior is same as Java - call a base initializer explicitly if desired or the compiler will insert a default call for you
I dont have a problem with that
ditto compiler insert/create a default initializer if you dont specify one - Its needed as part of the architecture (initializer chaining so objects get constructed correctly)
- I'd suggest if devs dont realize or forget that they are liable to have other problems as well
While I guess its possible the default rules might cause problems if theres no baseclass no-arg initializer I cant say I've ever seen that happen ( Java ).
I vaguely recall that the Java language description reccommends that all classes have a no-arg constructor even if it does nothing beyond indicating an error - can't remember if the (java)compiler
warns or enforces that or not.
I'd imagine the default insertion behaviours cover this mostly anyway with the possibility that if default no-arg constructor is incorrect for must-init cases in which case you'll probably find out about it pretty quick .
FWIW I think its overly pedantic to
always enforce an explicit first statement call to a base or sibling initializer (I preferred the original Cobra/C#/Java behaviour) - for most simple classes ( those that have/use no-arg ctors) its pointless boilerplate. Let the compiler insert it for you
For the implicit (no initializers specified at all ) case I agree its probably more preferable to shadow the baseclass initializer(s) in their entirety rather than create a default no-arg ctor
re use of pass in initializers; ( partial initializer ??)
I'd agree thats its a pretty pointless case but I seem to have been doing it rather a lot recently for some reason (placeholding stubs?) the warning is just annoying ( perhaps more so since it used to work silently)
With this
- Code: Select all
cue init
pass # do nothing else
What I want is as if I'd done this
- Code: Select all
cue init
base.init
pass # do nothing else
since the pass is indicating that I explicitly have said I dont want anything else whereas
- Code: Select all
cue init
def anotherMethod
Might be construed as that I'd forgotten to insert any initializer code and that a warning may be appropriate...
Re webnovs points I mostly agree (with the concept at least, not the particular issue with type naming
)
- while the compiler can try and enforce its view of desirable behaviours and guide with warnings, at some point it becomes counterproductive and annoying
(unless you work from the assumption that the developer always cant be trusted to know what they doing and must be forced to the 'one true path')
The devlpr makes the choice about what their app is for and what its range/target shall be and what their concept of consistency for it is
- the compiler should allow that freedom and provide the possibility of just doing as its told and getting out of the way
OTOH perhaps its in the warning wording (tone) ?
rather than
warning: Use the builtin type "int32" instead of the struct "Int32
perhaps something a little more obsequious
warning: Perhaps you meant to use the cobra builtin type "int32" instead of the less portable platform struct "Int32 (sir)