23.4.07

Booleans - Disturbingly Little

Nice



My apologies to all of you programmers out there who have been developing in real languages all along.

Today I posted to flexcoders that I was a little disturbed by the fact that Booleans initialize to false. Prior to AS3 you could compare a Boolean to undefined. The Flex compiler seems to complain if you even think about Booleans as undefined or null:

"1184: Incompatible default value of type Null where Boolean is expected..."
when creating this function: public function f(b:Boolean = null)

"1012: Variables of type Boolean cannot be undefined... (e.g. )"
when making this comparison: b==undefined

Nice that it acts more like a real programming language, not nice that I have to mend my AS2 ways of using the absence of assignment as some third value for a boolean. In hind-sight, this isnt good programming practice anyway because it requires interpretation to understand the third meaning. Interpretation is always a maintenance nightmare.

End of the day flexcoders answered with something I needed to hear: "use an enum". Don't think the thought wasnt met with some resistance.

"Enum? Shoo-oo-oot those aint in achunscript"

Now earlier today I had concrete ideas about what an Enum is, but I have no real experience creating one. This always drives me nuts because our minds are designed to constantly spin problems with our spare processor cycles (kind of like SETI@home) Unfortunately this intra terrestrial activity tends to reduce the amount of good sleep I get... and it keeps me up at night.

I dove in and came up with an enum example that you can extend to create your own enums. This is pretty straight forward.

I personally think you grasp something 70% by using it 20% by creating it and maybe if you're lucky, 10% wondering about it. In any case, it will be really nice to spend time using enums instead of over-rethinking this really simple concept.

No comments: