Saturday 15 September 2012

null - Should References in Object-Oriented Programming Languages be Non-Nullable by Default? -


Null signals are described as "". Some languages ​​have reference types that can not be assigned to zero values.

I wonder if there is a reference to creating a new object-oriented language that should prevent the default behavior from freeing empty space. Its special edition can be used to override this behavior. For example:

  MyClass notNullable = new MyClass (); Notline = null; // Error! // a la c #, where "t?" Means "null & lt; T & gt;" my class? Drains = new MyClass (); Drain = null; // permission  

So my question is, is there any reason to do this in a new programming language?

Edit:

I wanted to add that it was indicated that in unstarred types there is a special problem used in ARAS. I also want to thank all for all my useful insights. It is very helpful, sorry that I can choose only one answer.

The main barrier I have non-default falsifiable reference type is that some part of the programming community is set -Set-usage pattern:

  x = new foo () x.Prop & lt; - Some InitValue x.DoSomething ()  

For overloaded constructors:

  x = new fu (some inlay values) x.DoSomething () < / Code> 

and this API designer leaves the bind in relation to the initial value of the example frequency, which may otherwise be blank.

Of course, just like the 'tap', the set-set-using pattern makes a lot of meaningless, prevents the object status and useful inventions, so get rid of this is actually a curse rather than a a boon. However this API affects some of the design methods in such a way that many people are unfamiliar, so it is not lightweight.

But overall, yes, if there is a great catastrophe that destroys all existing languages ​​and compilers, only can expect that when we rebuild we will not repeat this particular mistake . Emptiness is an exception, not a rule!


No comments:

Post a Comment