k***r 发帖数: 4260 | 1 下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏
args.foreach{ arg => greeting += (arg + " ") }
args.foreach( arg => greeting += (arg + " ") )
args.foreach( arg => { greeting += (arg + " ") } ) |
k***r 发帖数: 4260 | 2 and these both compile fine:
def main(args:Array[String]) {
println("hello")
}
def main(args:Array[String]) = {
println("hello")
} |
N*D 发帖数: 3641 | 3 这个也可以
def main(args:Array[String]) = println("hello")
and these both compile fine:
def main(args:Array[String]) {
println("hello")
}
def main(args:Array[String]) = {
println("hello")
}
【在 k***r 的大作中提到】 : and these both compile fine: : def main(args:Array[String]) { : println("hello") : } : def main(args:Array[String]) = { : println("hello") : }
|
k***r 发帖数: 4260 | 4 嗯。偶觉得这么灵活,主要主要为了省typing,搞得这么难学,
得不偿失呀。
【在 N*D 的大作中提到】 : 这个也可以 : def main(args:Array[String]) = println("hello") : : and these both compile fine: : def main(args:Array[String]) { : println("hello") : } : def main(args:Array[String]) = { : println("hello") : }
|
F****n 发帖数: 3271 | 5 en, obviously the designer of Scala is a C++ programmer who does not
understand why Java cleans up OOP syntax.
【在 k***r 的大作中提到】 : 下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏 : args.foreach{ arg => greeting += (arg + " ") } : args.foreach( arg => greeting += (arg + " ") ) : args.foreach( arg => { greeting += (arg + " ") } )
|
k***r 发帖数: 4260 | 6 Hah. He's actually the author of javac from version 1.1 to 1.4,
and one of the authors of Java generics. Not many people know
Java better than him :-) So I think there must be a reason
hidden somewhere for the scala design but I haven't known it
enough to find out.
【在 F****n 的大作中提到】 : en, obviously the designer of Scala is a C++ programmer who does not : understand why Java cleans up OOP syntax.
|
F****n 发帖数: 3271 | 7 If he is the author of javac, then he is a C++ programmer. He may know Java's syntax and JVM mechanism well, but not necessary the language design. Other people designed Java and he is just an implementer. Just like a garage mechanist who knows Mercedez well do not necessarily know how to design a Mercedez and why it is designed that way.
【在 k***r 的大作中提到】 : Hah. He's actually the author of javac from version 1.1 to 1.4, : and one of the authors of Java generics. Not many people know : Java better than him :-) So I think there must be a reason : hidden somewhere for the scala design but I haven't known it : enough to find out.
|
F****n 发帖数: 3271 | 8 You can even go ahead to argue that the mess he / others put in Java
Generics and Scala is a good example of what will happen when a garage man
think he can design a car better than Mercedez. That's a little mean but I
believe a lot of people would agree:)
Java's syntax and JVM mechanism well, but not necessary the language design.
Other people designed Java and he is just an implementer. Just like a
garage mechanist who knows Mercedez well do not necessarily know how to
design a Mercedez and w
【在 F****n 的大作中提到】 : If he is the author of javac, then he is a C++ programmer. He may know Java's syntax and JVM mechanism well, but not necessary the language design. Other people designed Java and he is just an implementer. Just like a garage mechanist who knows Mercedez well do not necessarily know how to design a Mercedez and why it is designed that way.
|
c**t 发帖数: 2744 | 9 习惯了就好
【在 k***r 的大作中提到】 : 嗯。偶觉得这么灵活,主要主要为了省typing,搞得这么难学, : 得不偿失呀。
|
k***r 发帖数: 4260 | 10 how so? what does javac have to do with c++. It's written in java.
【在 F****n 的大作中提到】 : If he is the author of javac, then he is a C++ programmer. He may know Java's syntax and JVM mechanism well, but not necessary the language design. Other people designed Java and he is just an implementer. Just like a garage mechanist who knows Mercedez well do not necessarily know how to design a Mercedez and why it is designed that way.
|
|
|
k***r 发帖数: 4260 | 11 我发现就language本身,scale要学的东西远比java多多了,
而且很多是这种很tricky的,很大程度上重复的东西。
Python有个原则,就是希望只有一种(reasonable的)方法做一件
事情,显然scala作者不以为然。
【在 c**t 的大作中提到】 : 习惯了就好
|
k***r 发帖数: 4260 | 12 顺便问一下,你平时用scala工作吗?感觉如何
【在 c**t 的大作中提到】 : 习惯了就好
|
s******n 发帖数: 876 | 13 java里面很多地方也可以随便加 ( ) 和 { }啊。
【在 k***r 的大作中提到】 : 下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏 : args.foreach{ arg => greeting += (arg + " ") } : args.foreach( arg => greeting += (arg + " ") ) : args.foreach( arg => { greeting += (arg + " ") } )
|
k***r 发帖数: 4260 | 14 但是没有两个可以互换的时候吧
【在 s******n 的大作中提到】 : java里面很多地方也可以随便加 ( ) 和 { }啊。
|
l***i 发帖数: 289 | 15
这个特性是为了方便定义control structure吧:
比如你可以定义一个函数
def loop(range: Range)(op: Int=> Unit) {
range foreach (op)
}
调用的时候第二个参数可以用{}括起来,这样就和自带的control structure看来一样
了:
loop(1 to 5) {
println
} // 1 2 3 4 5
这样可以让这个语言更有扩展性。
让你省两行代码,让代码看起来更简洁。
Scala里面不少语言特性都是从其他语言里面借来的最佳实践, 如果能认真搞清楚其中
原因,收获会比较大一些。
【在 k***r 的大作中提到】 : 下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏 : args.foreach{ arg => greeting += (arg + " ") } : args.foreach( arg => greeting += (arg + " ") ) : args.foreach( arg => { greeting += (arg + " ") } )
|
k***r 发帖数: 4260 | 16 That's true. If you think or look really hard, you will
typically think of of find a reason why it's like that.
But w/o doing that, lots of the reasons aren't obvious.
And the cost of losing the clarify can be high - they leave
people wondering for a while, and give up confused.
【在 l***i 的大作中提到】 : : 这个特性是为了方便定义control structure吧: : 比如你可以定义一个函数 : def loop(range: Range)(op: Int=> Unit) { : range foreach (op) : } : 调用的时候第二个参数可以用{}括起来,这样就和自带的control structure看来一样 : 了: : loop(1 to 5) { : println
|
l***i 发帖数: 289 | 17 补充一下,“让代码看起来更简洁”甚至还有一个很酷的指标:
Ceremony vs. Essence
大概意思是在一段代码中,有多少是业务逻辑相关代码,多少是为了让代码符合语法规
范才写出得代码。
好的编程语言写出的代码"essence"部分更多一些,比如Ruby。
【在 l***i 的大作中提到】 : : 这个特性是为了方便定义control structure吧: : 比如你可以定义一个函数 : def loop(range: Range)(op: Int=> Unit) { : range foreach (op) : } : 调用的时候第二个参数可以用{}括起来,这样就和自带的control structure看来一样 : 了: : loop(1 to 5) { : println
|
l***i 发帖数: 289 | 18 完全同意你的观点。
【在 k***r 的大作中提到】 : That's true. If you think or look really hard, you will : typically think of of find a reason why it's like that. : But w/o doing that, lots of the reasons aren't obvious. : And the cost of losing the clarify can be high - they leave : people wondering for a while, and give up confused.
|
k***r 发帖数: 4260 | 19 The "ceremony" part is not just for show, though. It has
a lot to do with maintainability.
【在 l***i 的大作中提到】 : 补充一下,“让代码看起来更简洁”甚至还有一个很酷的指标: : Ceremony vs. Essence : 大概意思是在一段代码中,有多少是业务逻辑相关代码,多少是为了让代码符合语法规 : 范才写出得代码。 : 好的编程语言写出的代码"essence"部分更多一些,比如Ruby。
|