@dwu8555 Python 是这样一行而已 ```py scores = [97, 92, 81, 60] scoreQuery = [s for s in scores if s > 80] print(scoreQuery) ```
mcfog
13 天前
你只是看的少了 ....觉得有些新鲜感 ....文面上简洁,基本意味着语法或机制的复杂 ....而语法简洁,基本意味着文面上有冗余 ....美和美之间是有冲突和矛盾的 ....所以大家说谁美谁不美,可能实际上实在争论 xp
dragondove
13 天前
@dwu8555 你这个例子不太能表现出 LINQ 的优势,对应的 scala 代码如下 ```scala val scores = Array(97, 82, 60, 99) val r = for score <- scores if score > 80 yield score
println(r.mkString(" "))
``` python 也可以做到更简洁 ```python scores: list[int] = [97, 92, 81, 60] r = [score for score in scores if score > 80] print(" ".join([str(x) for x in r])) ```
dragondove
13 天前
@scp3125 Result 对比 Checked Exception 并没有显著的优势,你的例子换成 java 写可能还更简洁 ```java public static String readFile(String path) throws FileNotFoundException, IOException { File file = new File(path); try (var fis = new FileInputStream(file)) { return new String(fis.readAllBytes()); } } ``` 异常靠 throws 传播,和你的问号作用基本是一样的,函数的返回类型还更简单,模式匹配靠 catch 匹配,能达到相同的效果,代码还更简洁。
dragondove
13 天前
@Dropless 创建对象的话,kotlin 和 scala 都可以直接 `val person = Person()` 也足够简洁(数字符的话和 Person person = new() 是一样多的),不过 scala 中内置的想法会不太一样,scala 是 universal apply (实际上调用的是 Person 伴生对象的 apply 方法)更加通用一些,也可以自行改造成工厂方法(用起来和构造器一样,实际是工厂,更加统一)
noahlias
13 天前
Haskell 绝妙的美
powerSet = filterM (const [True, False])
Flourite
13 天前
美是一种很主观的事情,自己尝试看喜欢什么。it 行业这种言论多的是宗教,以后 ai 直接把他们都灭了