[raising this to laszlo-dev, because I think there's an important 
meta-point/coding-style idea here.]

On 2010-09-23, at 14:32, Max Carlson wrote:

>> 
>> 6) LzMouseKernel#28, LzSprite#212 I'm concerned using . instead of [' could 
>> lead to warnings in debug mode.
> 
> I disagree.  Either way is valid.  Also, I don't think we do that kind of 
> testing in the generated LFC, for performance reasons...  And we only really 
> warn for null properties for swf8 user code, right?

It is true that x.foo and x['foo'] are semantically equivalent in Ecmascript.  
In most compilers, they compile to the exact same code.  And it is never an 
error to reference a non-existent property of an object.

But, both Adobe and we found that it was useful for the compiler/runtime to 
warn you when you referenced a non-existent property, because from experience 
_most_ of the time, it turned out you had made a type-oh.  This is why we added 
just such a warning to swf8, and why DHTML wanted that warning but we could not 
find an efficient way to implement it so it is a little harder to debug, and 
why we were pleasantly surprised to find the Flex compiler generated these 
warnings at compile time.

Coincidentally, both Adobe and we used the idiom x['foo'] to say "I am making a 
dynamic access of a property that _may_ exist at runtime, so please don't warn 
me that it might not".

Because of that, I like to say x['foo'] when I am testing for the presence of a 
property.

That's all I'm saying.  Yeah, it's 3 extra keystrokes, but it helps to 
self-document your code.

Reply via email to