chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.77k stars 417 forks source link

Should non-nilable declarations default initialize? #13075

Open bradcray opened 5 years ago

bradcray commented 5 years ago

As a Chapel language designer, I'm wondering whether in the emerging nilable vs. non-nilable class type world, the following declarations should "work" (where the current expected behavior is an error):

var myOC: owned C;  // today: error because myOC can't store `nil` and isn't initialized
var mySC: shared C;  // ditto

For example, you could imagine that the default values of such declarations would be new owned C() and new shared C() respectively (requiring C to provide a 0-argument initializer in order to work).

Arguments in favor: +: turns an error into working, and arguably non-surprising code +: unifies a bit more with record declarations for variables that can't store nil anyway

Arguments against: -: makes var myOC: owned C; diverge from var myOC: owned C?;

bradcray commented 5 years ago

I'm filing this less because I'm an advocate for it and more because I think it's an interesting question that I could imagine others asking over time, so wanted a place to park current thinking on it. Michael brought up the disadvantage above that owned C and owned C? declarations are now more different than one another than ideal which I buy. And in any case, I think it's smart for us to start with this as an error condition because we can always make it not be an error later without breaking code if someone successfully argues that we did the wrong thing.