Initialization and undef

I like C# initialization because it is safe, and I like C++ initialization because not a single CPU cycle is wasted. Skila borrows the best from those two worlds — all variables have to be initialized. Explicitly by you — after a while implicit initialization becomes a habit, and even if not it is too easy to forget about it. However if for some reasons you cannot or don’t want to initialize variable, “assign” undef then:

var a = 5; // OK
var b : Int; // error
var c : Int = undef; // OK
var d = undef; // error

Do you know why the last one is erroneous? Compiler has to know something about a type, so you can have uninitialized (explicitly) variable, but it still has to have a type.

Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: