值得花精力去学D吗?

发布于 2024-09-16 22:16:44 字数 1432 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

野侃 2024-09-23 22:16:44

在我看来,与更“传统”的静态类型语言相比,D 具有以下优势:

  1. 疯狂强大的编译时元编程工具。例如,查看 D2 标准库中的 std.algorithmstd.rangestd.parallelism 模块可能很快就会被包含在内,如果/当它被包含时,它将是另一个很好的例子。这些功能足够强大,以至于该语言有时感觉几乎是鸭子类型,但具有静态类型语言的性能。另请参阅有关 D 元编程的 SO 问题: D 模板的示例可用于

  2. 默认的 D2 并发模型基于消息传递。如果您不以明显的、可 grepable 的方式破坏类型系统,则 D2 中的线程之间不可能存在隐式数据共享。当然,如果您确实想要不受检查的数据共享,您可以通过强制转换来打破这一点。例如,当前正在审核的 std.parallelism 模块就是通过这样做来获得全力以赴的多核并行性。

  3. D 倾向于使简单的事情比 C++ 或 Java 简单得多。 (我对 C# 不太确定。)简单来说,我的意思是基本文件 I/O 或策略模式之类的事情不需要几乎那么多的样板文件。事实上,我觉得 D 的主要设计目标之一是从地球表面消除样板代码,因为在语言和标准库的设计中都非常强调避免对它的需要。

相对于动态语言,D 具有:

  1. 具有本机编译语言的性能,同时放弃的便利性比您预期的要少得多,主要是因为出色的元编程工具及其在设计中的使用标准库。

  2. 静态检查。您的程序有一天不会因为错误输入变量名或尝试将字符串分配给整数而崩溃。

  3. 从事低级工作的能力。例如,除了几小段内联汇编器之外,D 的垃圾收集器完全用 D 编写。

As I see it, D has the following advantages over more "traditional" statically typed languages:

  1. Insanely powerful compile time metaprogramming facilities. For example, check out std.algorithm or std.range in the D2 standard library. A std.parallelism module is likely to be included soon, and if/when it is, it will be another good example. These facilities are powerful enough that the language sometimes feels almost duck-typed, but with the performance of a statically typed language. Also see the SO question about D metaprogramming: Examples of what D’s templates can be used for

  2. The default D2 concurrency model is based on message passing. If you don't subvert the type system in obvious, greppable ways, there can be no implicit sharing of data between threads in D2. Of course, if you really want unchecked data sharing, you can break this with a cast. For example, the std.parallelism module that's currently in review does this to get pedal-to-the-metal multicore parallelism.

  3. D tends to make simple things a lot simpler than C++ or Java. (I'm not as sure about C#.) By simple things, I mean things like basic file I/O or the strategy pattern don't require nearly as much boilerplate. In fact, I feel like one of D's primary design goals was to banish boilerplate code from the face of the Earth, as avoiding the need for it is heavily emphasized in the design of both the language and the standard library.

Relative to dynamic languages, D has:

  1. The performance of a natively compiled language while giving up much less convenience than you would expect, mostly because of the awesome metaprogramming facilities and their use in the design of the standard library.

  2. Static checking. Your program won't one day crash because you mistyped a variable name or tried to assign a string to an integer.

  3. The ability to do low-level work. For example, except for a few small pieces of inline assembler, D's garbage collector is written entirely in D.

顾冷 2024-09-23 22:16:44

我本人正在学习 D,来自 C/C++ 背景。 D 因其优雅而吸引我,其设计经过深思熟虑。在经历了密集、深邃和黑暗的 C++ 角落之后,感觉就像天堂一样。

对我来说,D 的一大缺点是缺乏库。即使是标准库,我也觉得做得不是很好。语言很棒,但库(还)不是。不过你可以使用 C 库,这是一个很大的赞。

虽然 D 看起来有很多专业知识和很多语言方面的知识,但它还没有 C++ 的一半。所以我认为它的学习速度要快得多(肯定是因为 90% 来自 C++ 或相关语言)。所以学习语言应该需要几周/几个月的时间。

由于还没有很好的 GUI 工具,您可能想用其他东西来开发编辑器。另外两个项目非常适合 D。

I myself am in the process of learning D, coming from a C / C++ background. D attracted to me because of its elegance, it's well thought through design. That feels like heaven after intensive, deep and dark C++ corners.

For me, the one big disadvantage of D is the lack of libraries. Even the standard library I don't find very well done. The language is great, but the libraries not (yet). You can use C libs though, which is a big thumbs up.

Although D seems to have many know-hows and many language aspects, it's not half of what C++ has. So I'd argue it's remarkably quicker to learn (definitely because 90% comes from C++ or related languages). So learning the language should be a matter of weeks / months.

Since there aren't great tools for GUIs yet, you might want to develop the editor in something else. The other two projects are perfectly suited for D.

另类 2024-09-23 22:16:44

如果您想要 C++ 的“强大功能”而无需繁琐的语法,或者想要 C 的“强大功能”且具有有用的功能(例如适当的字符串和类),我认为这是值得的。如果您喜欢依赖庞大的 API(C#/Java),那么 D 可能不会让您感兴趣。 还要确保使用 D 1.0,因为库(wxD 和其他 GUI 库)和编译器(GCD、LDC、除 DMD 之外的任何东西)支持对于 D 2.0 来说是令人震惊的,尽管该版本的语言有了明显的改进.

If you want the "power" of C++ without the cumbersome syntax, or the "power" of C with useful features such as proper strings and classes, I'd say it's worth it. If you like having a giant API to lean on (C#/Java), D probably wouldn't strike your fancy. Also make sure to use D 1.0, since library (wxD & other GUI libs) and compiler (GCD, LDC, anything not DMD) support is appalling for D 2.0, even though that version of the language is a clear improvement.

路还长,别太狂 2024-09-23 22:16:44

我只想说,昨天我成为了 D 爱好者,当我了解到它比 C++ 好得多时,出于纯粹的热爱,我连续两天学习了 D。哦,它并不完美,但是与 C++ 相比呢?没有比赛。 Java 也是如此。截至 3 天前,C# 是我选择的语言,但今天我认为它的排名已经下降了。

尚未将 D 用于任何严肃的工作,我可能会弄错。但是 D 对 C++ 常见的每一个主要批评都有一个答案,从编译时间到差的类型安全性,到维护头文件的麻烦,到编译速度慢。 D 不仅仅是一种进化式的改进,它还拥有世界上任何一种流行语言中都没有的创新:

  • 据说它拥有世界上最快的编译器之一
  • 。您可以使用 try/catch/finally 和 RAII,但是 scope(exit ) 使异常安全代码更易于阅读和编写
  • 您可以定义编译器可以内联的闭包(C++11 编译器是否这样做?我不确定,我'由于需要支持 Windows CE,我陷入了 Visual C++ 2008)
  • 垃圾收集是标准但可选,因此您可以通过避免 GC 分配来编写具有低延迟保证的程序(但如何管理内存) ?我怀疑人们可以使用 alias this 来使智能指针成为一种C++?)
  • 切片,一种比 C++ 迭代器更安全、也更方便的集合访问机制,无需像 lower_bound(blobCollection.begin(), blobCollection.end(), blob) 那样重复自己 code>
  • 泛型比 C++ 更灵活,并且不会产生错误消息页面
  • 编译时元编程大大优于 C++(显然 C# 也是如此)
  • ="noreferrer">编译时反射(我希望,但无法确认)如果有人想要一种设计良好的、多范式的并发方法, 共享内存和消息传递架构的有趣功能
  • 内置对单元测试的支持
  • 数组表达式,例如 a[] = (b[] + c[]) / 2 (MATLAB 更简洁地做到这一点,但在一般情况下- 专用语言中这种功能很少见)
  • 高级浮点功能(例如 nextUp()/nextDown()/ulp()、十六进制浮点数、硬件异常控制)

对于编译器或搜索引擎库,D 显然会表现出色。而且由于 D 与 C++ 非常相似,因此您不必花费大量时间来学习它,所以为什么不呢?另外,从 C++ 移植小型程序和库应该不难。我的印象是 GUI 绑定也得到了改进,所以也许 D 现在可以很好地用作文本编辑器。

不可否认,我对一切都不满意。它们仍然迎合 C 人群,因此您仍然必须用 breaks 填充 switch 语句,static 关键字被过度使用,令人困惑,lambda需要大括号和“return”语句(与 C# 更快的 x -> x+1 语法相反),所有函数和 try/catch 都需要大括号,调用时隐式传递引用网站...但是 D 提供的东西太好了,不容错过。

当然,虽然 D 语言显然很棒,并且标准库显然已经成熟,但周围的工具可能不太好:IDE、对智能手机平台的支持等。我尝试过的唯一 IDE ,Visual D(Visual Studio 的 IDE 插件)工作得很好,包括调试,它似乎和 Visual C++ 调试器一样工作,并且可以单步进入标准库(有趣!)。然而,代码完成还不能很好地工作。

与 C# 相比,D 在大多数方面都更好,但在动态链接和反射方面似乎较弱。例如,您的文本编辑器可以轻松地在 .NET 下拥有插件系统,但我不太确定 D。.NET 还提供运行时代码生成,而 D 则不提供。不过,有一个研究编译器可以将 D 编译为 .NET 代码。鉴于 C++/CLI 已经编译为 .NET (C++/CLI),也许有一天,人们将能够同样好地使用 D 来处理托管代码和本机代码(当然,在托管领域中性能会受到一点影响。)

与 C/C++ 的互操作性和.NET 都相当不错。 D 应该通过 extern (C++) 和 C++ 名称修饰(但是哪个编译器的名称修饰?)与 C++ 函数和单继承类进行互操作,同时您可以轻松创建可从 .NET 和其他语言调用的 COM 接口。

I would just like to say I became a D enthusiast yesterday, when I learned how much better it is than C++, and I have been studying D for two days straight out of sheer love. Oh, it's not perfect, but compared to C++? No contest. Ditto for Java. C# was my language of choice as of 3 days ago, but today I think it has moved down a rank.

Not having used D for any serious work yet, I could be mistaken. But D has an answer to every major criticism commonly raised against C++, from compilation time, to poor type safety, to the headache of maintaining header files, to slow compilation. D isn't just an evolutionary improvement, it has innovations found in none of the world's popular languages:

  • It is said to have one of the world's fastest compilers
  • You can use try/catch/finally and RAII, but scope(exit) makes exception-safe code easier to read and write
  • You can define closures that the compiler can inline (do any C++11 compilers do that? I'm not sure, I'm stuck on Visual C++ 2008 due to a need to support Windows CE)
  • Garbage Collection is standard but optional, so you can write programs with low-latency guarantees by avoiding GC allocations (but how to manage memory instead? I suspect one could use alias this to make smart pointers a la C++?)
  • Slices, a collection access mechanism that is far safer than C++ iterators and also far more convenient, no need to repeat yourself as in lower_bound(blobCollection.begin(), blobCollection.end(), blob)
  • Generics are more flexible than in C++ and don't produce pages of error messages
  • Compile-time metaprogramming that vastly outclasses C++ (and obviously C# too)
  • Compile-time reflection which (I hope, but can't confirm) one could use to build a run-time reflection system if one wanted
  • A well-designed, multi-paradigm approach to concurrency with interesting features for both shared-memory and message-passing architectures
  • Built-in support for unit tests
  • Array-wise expressions, e.g. a[] = (b[] + c[]) / 2 (MATLAB does this more tersely, but among general-purpose languages this kind of feature is rare)
  • Superior floating-point features (e.g. nextUp()/nextDown()/ulp(), hex floats, control of hardware exceptions)

For a compiler or search engine library, D would obviously excel. And since D is so similar to C++, you wouldn't have to spend a lot of time learning it, so why not? Plus, it shouldn't be that hard to port small programs and libraries from C++. I have the impression GUI bindings have been improving too, so maybe D would work well for a text editor these days.

Admittedly, I'm not happy with everything. They are still catering to the C crowd, so you still have to fill your switch statements with breaks, the static keyword is confusingly overused, lambdas require braces and a "return" statement (as opposed to C#'s quicker x -> x+1 syntax), all functions and try/catches requires braces, pass-by-reference is implicit at the call site... but what D offers is too good to pass up.

But of course, while the D language is clearly terrific, and the standard library has apparently matured, the surrounding tools might not be so good: IDEs, support for smartphone platforms, etc. The only IDE I tried, Visual D (IDE plugin for Visual Studio) works pretty well, including debugging which seems to work as well as the Visual C++ debugger, and which can step into the standard library (fun!). However, Code Completion doesn't work very well yet.

Compared to C#, D is better in most areas but seems weak when it comes to dynamic linking and reflection. For example, your text editor could easily have a plug-in system under .NET, but I'm not so sure about D. .NET also offers runtime code generation while D does not. However, a research compiler exists to compile D to .NET code. Given that C++/CLI already compiles to .NET (C++/CLI), perhaps someday one will be able use D equally well for managed and native code (with a small performance hit in managed land, of course.)

Interoperability with C/C++ and .NET are pretty decent. D is supposed to interoperate with C++ functions and singly-inherited classes via extern (C++) and C++ name mangling (but which compiler's name mangling?), while you can easily create COM interfaces callable from .NET and other languages.

那片花海 2024-09-23 22:16:44

我会给+1表示效率,0(没有赞成或反对)表示模块化,0表示团队合作,以及一个巨大的-1表示错误修复。

-1 是因为 D 的使用还不够充分,无法使库功能完整且没有错误。在这种情况下,您总是会通过修复第 3 方代码来浪费时间。对于不存在好的 D 调试器来说也是一个巨大的 -1。

通常 - 作为一名 Eiffel 程序员 - 我会给 D +1 的合同设计,但这并没有在标准库中经常使用,而且 95% 的附加库绝对没有使用。所以你不会从中获得很多好处。

I would give +1 for efficiency, 0 (no pro or con) for modularity, 0 for team work and a huge -1 for bug fixing.

The -1 comes from the fact that D is not really used enough to make the libraries feature complete and bug free. In this cases you will always loose time by fixing 3rd party code. Also a huge -1 for the non existance of a good D debugger.

Normally - as an Eiffel programmer - i would give D a +1 for having design by contract but this is not used constantly across the standard library and absolutely not used by 95% of the additional libraries. So you will not gain a lot of benefits from it.

無處可尋 2024-09-23 22:16:44

我认为 D 绝对最适合编译器,不太适合其他两个任务。

I think D is definately best suited for the compiler, and less suited for the two other tasks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文