F# vs C# vs Nemerle [closed]
F# vs C# vs Nemerle [closed]
我在我的TODO列表中有一个新项目,无法选择F#或Nemerle。
我目前正在学习F#,并且有一些Nemerle项目。
我喜欢F#的方式,我喜欢默认缩进(我也希望nemerle2有默认缩进),我喜欢F#的许多特性和魔力,但是它没有宏。
F#的目标是VS2010,也许(也许)更大的开发团队,它看起来像Haskell(可以用它创建轻量级的Linux程序,很有趣)。
Nemerle的目标是宏,我认为我更喜欢Nemerle的一些语法。
而且大多数人只喜欢C#...
- 所以这门语言必须具有前景
- 语法必须是逻辑的、易于理解的、整洁和强大(代码更少)
- 它必须易于与.NET一起使用
- 所以我已经限制了我的选择。
- 我可以同时使用它们,但是怎么选择呢,对我来说并不容易。
举个例子,我更喜欢(Nemerle):
match(STT)
| 1 with st= "Summ"
| 2 with st= "AVG" =>
$"$st : $(summbycol(counter,STT))"
而不是(F#):
let (|Let|) v e = (v, e)
match stt with
| Let "Summ" (st, 1)
| Let "AVG" (st, 2) -> srintf "%s ..." st
F#:
["A"; "B"] |> List.iter (fun s -> printfn "%d" s.Length)
Nemerle:
["A", "B"].Iter(x => printf("%d", x.Length))
F#(希望没有弄错):
let type X =
let mytable a = ""
let mytable b = ""
new(A, B) = {
a <- A
b <- B }
member X.A
with get = a
member X.B
with get = a
Nemerle:
[Record] class X public A : string { get; } public B : string { get; }
C#:
class X { private readonly string _a; public string A { get { return _a; } } private readonly string _b; public string B { get { return _b; } } public X(string a, string b) { _a = a; _b = b; } }
而且这是我已经无法转换成F#的Nemerle代码(所以我只是学习它)...
abstract class ABase abstract public A : string { get; } interface IB B : string { get; } [Record] class My : ABase, IB public override A : string { get; } public virtual B : string { get; }
与C#相比:
abstract class ABase { abstract public string A { get; } } interface IB { string B { get; } } class My : ABase, IB { private readonly string _a; public override A : string { get { return _a; } } private readonly string _b; public virtual B : string { get { return _b; } } public My(string a, string b) { _a = a; _b = b; } }
显然,Nemerle代码更易于维护和阅读。
@Brian 所以这就是为什么我在问,如果在F#和C#上能否实现这样的简化,也请告诉我是否我做错了,因为我对其他清晰地实现相同功能的方法不太确定。