I don't know why, this given... when sounds so 'English' without really being that

The construct <given ... when> sounds better in English than <switch ... case ...> because: a) Switch is more commonly used in English as a noun, eg., Use the switch to turn on the light. But because English can use nouns for verbs and adjectives as well, eg., 'Switch on the light' or 'he is a switched-on type of guy', it seems ok to use it in for control purposes. Except ... the verb is really 'switch on' not 'switch'. Also we have 'switch over', 'switch from', 'switch between' etc. where as 'switch' as a verb as in 'she just switched boyfriends' means exchanging one for another, not choosing between alternative cases. So really 'switch' as a verb is really more like 'toggle'. So when an English person (or at least one that cares about the use of language) sees 'switch' in a programming language, there is the feeling that something is missing, or not quite right. And there is absolutely no linguistic link between 'switch' and 'case'. If I am uncomfortable with 'switch', 'case' really sucks. In fact, whenever I work in language other than perl, and 'switch' is the preferred construct, I always have to check the syntax to work out what goes where.

b) 'Given' is more commonly used in English as a verb form. 'He was given an award'. Also, it is in the correct form for use at the beginning of a sentence, eg., 'Given three choices, he chose the most profitable'. So we have something that looks and feels like it is a part of normal English speech. The 'when' part is also a natural tag in English indicating one of several alternatives. 'Given' can be used as noun (the power of English! as a language) as in 'we have a number of givens, but the issue is still unresolved'. This is much rarer than the use of 'given' in verb uses.

c) You might ask, why bother? Just choose words, and since switch is the most common one, just use it. Well, computers dont care whether you use words or symbols, so long as semantics can be uniquely extracted from syntax, that is, the computer knows uniquely what you are trying to say to it. But the reality is that humans dont work that way. From the time of FORTRAN and COBOL, the aim has been to choose words over symbols so that they have semantic meaning for the programmer. It makes it easier for programmers to write descriptions of algorithms and operations, and to understand the logic of the descriptions they are writing. This reduces development and debugging time. Perl has been so successful, and my programming language of choice, because where words have been chosen, they have very similar semantics to normal English. That helps me in my programming.

My own guess is that once Perl6 starts being used (When oh when oh when!!!!), other languages or dialects will switch 'switch' for 'given', or at the least, the 'given ... when' will be an alias for 'switch ... case'.

Reply via email to