On Thu, Oct 23, 2014 at 9:20 AM, Marcel Taeumel <[hidden email]> wrote:
Would be nice if there is no warning at all if you write this kind of code.
you mean you don't want to be warned of use of uninitialized variables or something else? If the former I disagree I find the warning very useful, and hence put up with the annoyance when I'm depending on the variable having been initialized to nil.
In this code example, the programmer was aware if the nil-case, which is the same as uninitialized. I find it sometimes strange to have to write "x := nil." in an algorithm just to get rid of this message.
In other cases, this warning is fine. :) Maybe there are some patterns that indicate that "not initialized" is totally fine. Maybe it is just the case when #ifNil: is explicitely found in the code.
On Thu, Oct 23, 2014 at 11:03 AM, Marcel Taeumel <[hidden email]> wrote:
Some addon: I personally think that all variables are initialized with "nil".
Yes they are, and its one of the nice guarantees that Smalltalk makes that all variables are initialized either to nil or, in non-object data to 0 or Character value: 0. But the compiler can't in general tell whether a reference to a variable before it is assigned to is a mistake or not. For example in this:
| t |
self doSomethingWith: t
the compiler can't know whether t is being used correctly or not ever. It is pointless for the compiler to try and analyse any relevant implementations of doSomethingWith: looking for e.g. ifNil: guards since doSomethingWith: can be redefined. Marcel, do you have some concrete criteria for squashing the warning in certain cases? If you have a good set of criteria we can implement them, otherwise I think we have to accept the inaccuracy of the warning.
In this case, the initialization is kind of deferred in the very same method. Maybe I wrote bad Smalltalk code, but I had this several times. Finding some object in a complex structure or so... So this could be detected, right? :)
[It is not that I am really that annoyed by these compiler warnings because I made them non-modal in my tools.]