#120 Definite Assignment

brian Tue 28 Nov 2006

Both Java and .NET have the notion of definite assignment - a local variable must be assigned before being used. The Java Spec has a really long chapter on how compilers must check for it which strikes me as incredibly complicated. In Fan virtually all local variables are assigned at initialization time to take advantage of type inference - I rarely find myself declaring variables the old fashioned way. So I don't want to complicate the compiler with true definite assignment. Instead, what Fan will do is is automatically set a local variable to null if it doesn't have have an initialization expression. This is consistent with how fields are initialized too, so it seems to promote overall consistency and simplicity at the expense of not catching true definite assignment logic errors (but those should be rare if using type inference coding conventions).

Login or Signup to reply.