Coteline是一个全新的基于JVM的编程语言。Coteline是Ceylon的超集,并保持对Ceylon的向后兼容。
比Ceylon改进的地方包括:
"publicasaservice",becausesharedisnotagoodkeyword.
implements,becauseitisfancierthansatisfiesandit closesthegapforexistingJ2EE1.3developers.
Callanobjectasingleton.
Useconstinlieuofvalue.
WritedefasaHipster-compliantvariantoffunction.
InkUnitinsteadofvoidinyourfine-craftedCoteline definitions.
contractandtraitcarrymoremeaningthan interface(andwhocaresabouttheactualformalsemanticsofthese?).
Wethinkprayisabetterreplacementforassert,because thisiswhatyouactuallydowhenyouwriteassertions.
dynamicblocksarebetternamedasunsafeblocks,becausethey escapethewonderlandofstatictypechecks.
Parametrictypeswithin/outforcontravarianceandcovariancearehard tomanipulate.ThisisalsowaytooreminiscentoftheC#world.Coteline providessalvationwithcovarandcontravar.
Lastbutnotleast,youcanalsowriteforeachloopsinCoteline.
示例代码:
"The classic Hello World program"public Unit hello(String name = "World") { const str = "Hello, `` name ``!"; def work() => print(str); work(); pray(1 == 1); plop.plop(); foreach (i in {1, 2, 3}) { print(i); }}singleton plop { public Unit plop() { print("Oh Plop!"); }}"Run the module `better.ceylon.is.coteline`."public Unit run(){ if (nonempty args=process.arguments) { foreach (arg in args) { hello(arg); } } else { hello(); }}
评论