Coming from a predominantly (but not exclusively) Delphi/Pascal background for the last two decades, I took to the Kotlin syntax like a duck to water, and I’m loving’ it ! I’ve also dabbled in C, C++, VB, C# and Java, etc. during that time. With the exception of Delphi Pascal’s ubiquitous and clunky “begin…end” blocks instead of curly braces (a long-standing bugbear of mine), the Delphi/Pascal syntax is very concise, elegant and expressive, just like Kotlin’s, as are Borland’s (–>CodeProject, -->Embarcadero’s) object oriented extensions to ANSI Pascal. So, a) I’m not surprised to see Pascal-like syntax in Kotlin, and b) keywords like “is, as, in, var”, and variable and function types specified after a colon (:), etc.etc.etc. are very Delphi-ish/Pascal-ish/familiar to me.
The only glaring inconsistency (in my very humble opinion) in the Kotlin syntax is the “when…” case/switch construct. Syntactically it just looks all wrong using → for each case. When compared to other languages’ use of ->, nothing is being mapped, per se, and it’s not defining a lambda expression.
Having borrowed so much from Pascal, it would be much neater to use the good old colon again,
e.g.
when (i) {
1: println(“something”)
2: println(“something else”)
else println(“oops !”)
}
or even…
else: println(“oops !”)
This is, to all intents and purposes, identical to C, Delphi Pascal and Java and there’s nothing glaringly wrong with them that needed improving, with the exception of C’s constant repetition of the “case” keyword. And certainly "else → println(“wtf ?”) doesn’t at all seem in keeping with Kotlin’s philosophy of not being unneccessarily verbose. In the “else” clause, → seems completely redundant to me, syntactically- and token-wise.
Kotlin could even have the World’s first “when…then” construct:
when (i) {
1 then println(“maybe”)
2 then println(“just my two-penneth”)
else println("maybe a bit COBOL-y though ? ")
}
Or have the colon syntax (when… 1: etc) and “when…then” as optional interchangable alternatives of each other. But definately not → !
Is it too late to change the “when” syntax ?..please ???
Just needed to get that off my chest.
Please don’t all jump down my throat at once
Baz.