terriko: (Default)
terriko ([personal profile] terriko) wrote2010-10-19 02:30 pm
Entry tags:

Well, I guess you can tell how often I use case statements lately...

I got this error message, "crosses initialization of $variable" yesterday and was utterly mystified. Turns out that I hadn't put brackets around the details of my case statement and it was complaining because it wanted a smaller scope for those variables.

I'm amused that I've gone over 15 years as a programmer and the error message still meant nothing to me at first glance (although the error itself makes perfect sense). I guess this is what happens when I rarely use case statements (and, I must admit, I haven't done much c/c++ lately either). Or maybe the error message has changed? After years of teaching undergraduates, I sort of felt like I'd probably seen most of the errors a compiler had to offer, so I was as pleased by the novelty of having no clue what the message meant as much as I was annoyed at myself for not knowing. ;)

Blame C++

(Anonymous) 2010-10-19 07:38 pm (UTC)(link)
Every other language I know other than C++ doesn't have that problem, either because you can't express it, or they have some well-defined way to solve the problem (like emitting initialization code in all possible code paths, or forcing the cases of a switch statement to be lexical blocks, or not having some or all of: jumps, uninitialized variables, initialized variables, or error messages).

I've sometimes hit a g++ error message and said "that *has* to be new"--only to do some Googling and CVS/SVN/git blaming and discover that the error message was added to GCC more than 10 years ago. Soon the error messages will be older than your students. ;)
heliumbreath: (Default)

[personal profile] heliumbreath 2010-10-20 11:25 am (UTC)(link)
It's likely that a different compiler would phrase things differently. All the world isn't quite gcc.
unregisteredpseudonymspls: (Default)

[personal profile] unregisteredpseudonymspls 2010-10-21 02:44 pm (UTC)(link)
I've started programming in Scala because some machine learning tools require it, and case statements are pretty fundamental to the point of the language in the "match...case" construct and have scope implications.