avatar
M*9
1
家里就我一个人看见过,长得跟平常人一样。当时大院里,基本家家都有。
avatar
k*r
2
下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏
args.foreach{ arg => greeting += (arg + " ") }
args.foreach( arg => greeting += (arg + " ") )
args.foreach( arg => { greeting += (arg + " ") } )
avatar
k*r
3
and these both compile fine:
def main(args:Array[String]) {
println("hello")
}
def main(args:Array[String]) = {
println("hello")
}
avatar
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")
: }

avatar
k*r
5
嗯。偶觉得这么灵活,主要主要为了省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")
: }

avatar
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 + " ") } )

avatar
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.

avatar
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.

avatar
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.
avatar
c*t
10
习惯了就好

【在 k***r 的大作中提到】
: 嗯。偶觉得这么灵活,主要主要为了省typing,搞得这么难学,
: 得不偿失呀。

avatar
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.
avatar
k*r
12
我发现就language本身,scale要学的东西远比java多多了,
而且很多是这种很tricky的,很大程度上重复的东西。
Python有个原则,就是希望只有一种(reasonable的)方法做一件
事情,显然scala作者不以为然。

【在 c**t 的大作中提到】
: 习惯了就好
avatar
k*r
13
顺便问一下,你平时用scala工作吗?感觉如何

【在 c**t 的大作中提到】
: 习惯了就好
avatar
s*n
14
java里面很多地方也可以随便加 ( ) 和 { }啊。

【在 k***r 的大作中提到】
: 下面三段code竟然等效。为啥搞得这么灵活而不可捉摸捏
: args.foreach{ arg => greeting += (arg + " ") }
: args.foreach( arg => greeting += (arg + " ") )
: args.foreach( arg => { greeting += (arg + " ") } )

avatar
k*r
15
但是没有两个可以互换的时候吧

【在 s******n 的大作中提到】
: java里面很多地方也可以随便加 ( ) 和 { }啊。
avatar
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 + " ") } )

avatar
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

avatar
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

avatar
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.

avatar
k*r
20
The "ceremony" part is not just for show, though. It has
a lot to do with maintainability.

【在 l***i 的大作中提到】
: 补充一下,“让代码看起来更简洁”甚至还有一个很酷的指标:
: Ceremony vs. Essence
: 大概意思是在一段代码中,有多少是业务逻辑相关代码,多少是为了让代码符合语法规
: 范才写出得代码。
: 好的编程语言写出的代码"essence"部分更多一些,比如Ruby。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。