Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

null-less language

Name: Anonymous 2013-10-14 13:50

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?

Name: Anonymous 2013-10-14 14:55

JavaScript has already been invented.

Name: Anonymous 2013-10-14 15:05

>>2
Open your JS console and write "x.y();"

It will give you a reference error.

Name: Anonymous 2013-10-14 15:48

default values for uninitialized variables make insidious bugs from typos

i think you are looking for option types though

Name: Anonymous 2013-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: Anonymous 2013-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

Name: Anonymous 2013-10-14 16:20

>>6
that's a good question.

Do any object oriented languages with option types exist?

Name: Anonymous 2013-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)

Name: Anonymous 2013-10-14 16:48

>>3
But typeof x will not.

Name: Anonymous 2013-10-14 17:49

I made a little test in JavaScript:

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: Anonymous 2013-11-23 15:06

>─────▄████▀█▄
   >───▄█████████████████▄
   >─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
   >▄███████▄.▲.▲▲▲▲▲▲▲▲
   >███████████████████▀▀
   YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!

Don't change these.
Name: Email:
Entire Thread Thread List