k*r
2 楼
下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏
args.foreach{ arg => greeting += (arg + " ") }
args.foreach( arg => greeting += (arg + " ") )
args.foreach( arg => { greeting += (arg + " ") } )
args.foreach{ arg => greeting += (arg + " ") }
args.foreach( arg => greeting += (arg + " ") )
args.foreach( arg => { greeting += (arg + " ") } )
k*r
3 楼
and these both compile fine:
def main(args:Array[String]) {
println("hello")
}
def main(args:Array[String]) = {
println("hello")
}
def main(args:Array[String]) {
println("hello")
}
def main(args:Array[String]) = {
println("hello")
}
N*D
4 楼
这个也可以
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")
: }
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")
: }
F*n
6 楼
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 + " ") } )
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
7 楼
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.
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
8 楼
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.
【在 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
9 楼
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.
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.
k*r
11 楼
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.
【在 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.
l*i
16 楼
这个特性是为了方便定义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
17 楼
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
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
18 楼
补充一下,“让代码看起来更简洁”甚至还有一个很酷的指标:
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
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
19 楼
完全同意你的观点。
【在 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 的大作中提到】
: 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.
相关阅读
Lots of Java Positions at Red Hat谁有这本书 "Absolute Java" second editionObject比较Swing 高手们。有没有autocomplete 的dropdown list?网上的J2EE的tutorial大多都太差了' 的问题no official release java 6 for mac yet?what's inside an java object?谁给科普一下什么是javascript?Ask a questionjavascript or jstl?Any body uses wicket framework for web development?关于数组的内存Garbage collection 问题.Net developer doing JavaAn interesting comment regarding Wicket.how to print text in color?JDK US DST Timezone Update Tool请问有没有可能列出所有正在运行的java程序?how to improve performance for web service