Assume an object oriented language where every object has a property "isDefault." In instances where an uninitialized variable is referenced or used, it simply returns an object with a default value (empty string, 0 for number types) where isDefault is true.
When coding, checks for null are no longer needed unless you specifically need to check for null, as comparisons won't cause null reference exceptions, and calling functions from objects will simply return that function's return value type's default value. So if "object" is undefined, "object.isSomething()" will return will return a boolean object with "isDefault" set to true.
What are the immediate problems with this idea, from a programming standpoint or language standpoint?
default values for uninitialized variables make insidious bugs from typos
i think you are looking for option types though
Name:
Anonymous2013-10-14 16:01
>>4
This is definitely true. In that case I might say the language should still have variable declarations, but not necessarily assignments. "int x;" would be fine, and x's value would be 0, and x.isDefault would be true, but "y = 10;" would not unless y were already declared. That eliminates tthis problem, at least.
Name:
Anonymous2013-10-14 16:12
int x;
fn foo() {
return x + 5;
}
int y = foo(); // y.isDefault? i.e. do "failures" propagate?
again, languages with option types have already solved everything you want to do
Do any object oriented languages with option types exist?
Name:
Anonymous2013-10-14 16:29
c# has a reasonable mechanism for it (you should look at msdn.microsoft.com/en-us/library/1t3y8s4s%28v=vs.90%29.aspx) but they aren't particularly difficult to implement (presuming you understand the semantics of what you want)
function nfe(f) { if(typeof f == "function") { return f.apply(this, Array.prototype.slice.call(arguments, 1)); } else { return {nullable: true}; }
Now, if I have an array like so
var a = [x, y, z, {}];
Where x, y and z both have a function "do()" then
"for(var i = 0; i < 4; i++) { a[i].do(); }"
Will fail, as {} does not have do(). However
"for(var i = 0; i < 4; i++) { nfe(a[i].do); }"
will succeed. However, if the fourth element were null, undefined, or the array simply had a length of 3, even my function wrapper would fail.
In this language all functions would be handled like this nfe function does, but with support for undefined/null, which would just be replaced with an empty object or an object with just "nullable: true" or something.
Name:
Anonymous2013-11-23 15:06
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!