D 语言是否有多个标准库以及 GC 问题?

发布于 2024-09-08 20:19:29 字数 169 浏览 5 评论 0原文

我想知道 D 有多成熟和稳定,以及它是否可以很好地替代 C/C++。

我知道目前有两个标准库(Phobos 和 Tango)。难道还是没有统一的标准库吗?

另外,我不久前听说这些语言在 GCed/非 GCed 代码的边界上存在问题。我在D网站上找不到任何相关参考资料,那么这个问题仍然存在吗?

I'm wondering how mature and stable D is, and if it might be a good replacement for C/C++.

I know that there are currently two standard libraries (Phobos and Tango). Is it still the case that there is no unified standard library?

Additionally I heard some time ago that the languages has problems on the boundaries of GCed/non-GCed code. I couldn't find any reference about that on the D website, so is this problem still true?

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

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

发布评论

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

评论(6

错々过的事 2024-09-15 20:19:29

D 版本 1 成熟稳定,肯定有人在实际工作中使用它。 Phobos 是 D 曾经拥有或可能拥有的唯一标准库,但 D1 的 Phobos 缺乏足够的功能,因此创建了各种第三方库来填补空白。 Tango 是其中最大的,也是使用最频繁的第三方库(因此它经常被称为第二个标准库,尽管它不是,Walter Bright 很快就会指出它不是)。然而,D1 中的 Tango 和 Phobos 混合得不太好(IIRC 因为 Tango 取代了一些标准的东西,比如垃圾收集器),所以在 D1 中编程的人很有可能会在没有 Phobos 的情况下使用 Tango。此外,除了 Digital Mars 的主编译器之外,D1 还受到多个编译器的支持 - 包括 LDC 和 gdc。

D 版本 2 刚刚达到成熟和稳定。他们已经停止对语言进行重大更改,因此您通常不必像过去那样担心编译器更新会破坏您的一切,而他们仍在确定语言。事实上,它现在已经足够成熟,Andrei Alexandrescu 发布了The D 编程语言作为该语言的权威资源,除非文本中出现错误,该资源应该保持有效(并且它是我见过的最好的编程语言书籍之一)也读过)。然而,仍然有大量的错误修复正在进行,因此很可能会遇到一个错误,这会给您的特定应用程序带来相当多的烦恼。它绝对足够成熟和稳定,可以用来进行实际工作,但请注意,它很可能会遇到错误。

Tango 尚未移植到 D2,因此在 D2 中编程时它并不是一个真正的选择。然而,火卫一现在进展得很好。它得到了很多很棒的补充(它现在实际上有了容器! - Phobos 中缺乏容器是在 D1 中使用 Tango 而不是 Phobos 的一个重要原因),并且里面有一些非常强大的东西 - std.algorithm 是特别好。 D 处理 lambda 函数、嵌套函数和函数指针的方式使得将函数传递给算法比在当前的 C++ 标准中容易得多。此外,它已在 D2 中修复,以便 Tango 复制的垃圾收集器和其他一些核心内容现在与 Phobos 分开。因此,一旦 Tango 被移植到 D2,您将能够混合 Phobos 和 Tango 代码 - 尽管正如之前的答案中所指出的,Phobos 和 Tango 使用相当不同的设计理念(Tango 非常像 Java,而 Phobos大量使用模板和使用鸭子类型而不是接口的元编程),所以我不知道从这个角度来看它们的混合效果如何。

目前,我相信 dmd 是唯一一个在 D2 规范方面是最新的编译器,但我相信 gdc 和 LDC D 编译器正在开展工作(尽管这项工作有多活跃,我不知道)。此外,Walter Bright 目前正在开发 dmd 的 64 位端口,因此我们将很快获得本机 64 位编译。

总的来说,我想说 D2 已经可以使用了,但您确实需要意识到,在错误修复等方面仍有大量工作要做。因此,D2 绝对适合业余爱好使用,也可能适合在工作中认真使用,但如果您确实需要稳定性(例如,如果您是波音公司,错误就意味着死亡),那么 D1 可能仍然是一个更好的选择。当然,关于 D2 需要记住的重要一点是它具有许多 D1 所没有的功能,因此除非您确实需要坚如磐石的稳定性,否则 D2 可能是最佳选择。幸运的是,它不断成熟和稳定,所以毫无疑问使用 D2 会更好的时间肯定已经临近。

无论如何,在一般情况下,D1 和 D2 都是 C 和 C++ 的良好替代品。它们可以做 C 和 C++ 所做的事情,并且(特别是在 D2 的情况下)可能可以做得更好。 D 可能落后的主要地方在于它的优化程度。有大量代码在 D 中的速度与在 C 或 C++ 中一样快,但 D 上仍有大量工作正在完成,因此有足够的空间进一步优化它,并且它有时会落后于 C 和 C++ 的效率。因此,一般来说,D 是高效的,但如果您确实需要尽可能高的效率,那么它可能还不足以满足您的需求(尽管它已经达到了目标)。此外,还有大量成熟的 C 和 C++ 库,而 D 没有任何接近相同级别的代码可供使用。任何 C 代码都可以与 D 一起使用,因为可以从 D 调用 C 函数,并且某些 C++ 代码也可以(尽管将 C++ 代码与 D 混合时有很多限制),因此不一定有太多限制。这是一个障碍,但需要注意。它缺少的主要地方是 GUI 库。有一些用于 D1,并且正在为 D2 的 GUI 库做一些工作,但我不认为它们中的任何一个在这一点上特别成熟。

因此,与所有事情一样,您应该使用哪种语言取决于您正在做什么。 D 会做大部分事情,而且会把它们做好。但它并不能解决所有问题,而且它仍在成熟中。就我个人而言,在这一点上,我使用 D,除非我需要为特定项目使用其他东西,这种情况并不常见,除非该项目已经用其他东西编写,而且现在移植它没有意义。所以,我强烈建议使用 D,但你必须研究它并使用它,看看它此时是否真的能达到你想要的效果。

Version 1 of D is mature and stable, and there are definitely folks who use it for real work. Phobos is the only standard library that D has ever had or likely ever will have, but D1's Phobos is lacking enough that various third-party libraries were created to fill in the gaps. Tango is the largest of these and is the most heavily used third-party library (hence why it frequently gets called a second standard library even though it isn't, and Walter Bright will be quick to point out that it isn't). However, Tango and Phobos in D1 do not mix very well (IIRC because Tango replaces some standard stuff like the garbage collector), so there's a good chance that someone programming in D1 will use Tango without Phobos. Also, D1 is supported by multiple compilers in addition to the primary compiler from Digital Mars - including LDC and gdc.

Version 2 of D is just now reaching maturity and stability. They've stopped making major changes to the language, so you don't generally have to worry about everything breaking on you with a compiler update as was the case in the past while they were still nailing the language down. In fact, it's now mature enough that Andrei Alexandrescu released The D Programming Language as a definitive resource on the language which should stay valid barring errors in the text (and it's one of the best programming language books that I've read too). However, there is still plenty of bug-fixing going on, so it's quite possible to run into a bug which causes you a fair bit of irritation for your particular application. It's definitely mature enough and stable enough to do real work with it, but be aware that it's quite possible to run into bugs.

Tango has not yet been ported to D2, so it's not really an option when programming in D2. However, Phobos is coming along quite nicely now. It's getting a lot of great additions to it (it actually has containers now! - the lack of containers in Phobos being a big reason to use Tango in D1 rather than Phobos), and has some really powerful stuff in it - std.algorithm is particularly nice. The way D handles lambda functions, nested functions, and function pointers makes passing functions to algorithms light-years easier than it is in the current standard of C++. Also, it has been fixed in D2 so that the garbage collector and some other core stuff that Tango was duplicating is now separate from Phobos. So, once Tango has been ported to D2, you'll be able to mix Phobos and Tango code - though as has been pointed out in a previous answer, Phobos and Tango use rather different design philosophies (Tango being very Java-like and Phobos heavily using templates and meta-programming with duck-typing rather than interfaces), so I don't know how well they'll mix from that standpoint.

Currently, I believe that dmd is the only compiler which is up-to-date with regards to the spec for D2, but I believe that there is work being done on the gdc and LDC D compilers (though how active that work is, I don't know). Also, Walter Bright is currently working on the 64-bit port of dmd, so we'll be getting native 64-bit compilation one of these days relatively soon.

Overall, I'd say that D2 is ready for use, but you do need to be aware that there's still plenty of work being done to it with regards to bug fixes and the like. So, D2 is definitely ready for hobby use and potentially for serious use at work, but if you really need stability (like if you're Boeing and a mistake means death), then D1 would likely still be a better choice. Of course, the big thing to remember about D2 is that it has lots of features that D1 doesn't have, so unless you really need rock-solid stability, then D2 is likely the way to go. Fortunately, it continues to mature and stabilize, so the time is definitely approaching when there will be no question that using D2 would be better.

Regardless, both D1 and D2 are good replacements for C and C++ in the general case. They can do what C and C++ do, and (especially in the case of D2) can probably do it better. The main place that D might fall behind is in how well it's optimized. There's plenty of code that will be just as fast in D as in C or C++, but there's still plenty of work being done on D, so there's plenty of room to optimize it further, and it will sometimes lag behind C and C++ for efficiency. So, generally, D is efficient, but if you really need as much efficiency as you can get, it might not yet be good enough for what you need (though it's getting there). Also, there are plenty of mature C and C++ libraries out there while D doesn't have anywhere near the same level of code floating out there to work with. Any C code could be used with D since C functions can be called from D, and some of the C++ code could be (though there are quite a few restrictions when mixing C++ code with D), so that wouldn't necessarily be much of an impediment, but it is something to be aware of. The main place where it's lacking would be GUI libraries. There are some for D1, and there is work being done on GUI libraries for D2, but I don't believe that any of them are particularly mature at this point.

So, as with everything, which language you should use depends on what you're doing. D will do most things and do them well. But it doesn't do everything, and it's still maturing. Personally, at this point, I use D unless I need to use something else for a particular project, which isn't often unless the project was already written in something else, and it doesn't make sense to port it right now. So, I'd highly suggest using D, but you'll have to look into it and use it to see whether it really will do what you want at this point.

睫毛溺水了 2024-09-15 20:19:29

我建议将 D2 与 Phobos 一起使用。到了这个阶段,语言就变得足够有趣、足够稳定,可以弥补因实现问题而偶尔造成的挫败感。

I recommend using D2 with Phobos. It's at the point where the language is enjoyable enough and stable enough to make up for the occasional frustrations caused by implementation issues.

女中豪杰 2024-09-15 20:19:29

我知道目前有两个标准库(Phobos 和 Tango),所以我假设可能有人试图统一它们。

由于许可证的差异,“统一”的可能性极小。当 Tango 被移植到 D 2.0 时,您将能够将它与 Phobos 一起使用,这在 D 1.0 中是不可能的(容易)。

此外,我不久前听说这些语言在 GCed/非 GCed 代码的边界上存在问题。我在D网站上找不到任何相关参考资料,那么这个问题仍然存在吗?

我相信,如果您不小心管理内存,就会出现问题。如果对 GC 分配的对象的所有引用都存储在标记为 GC 根的内存区域之外,则 GC 将认为该对象未被引用并将其删除。

如果我今天必须选择 D 作为 C 的替代品,您会建议使用什么 D(v 1.0 或 v 2.0)以及什么标准库?

火卫一和探戈正朝着有些不同的方向发展。 Phobos(D 2.0 中)与 D2 的新功能密切相关。 Tango 的功能更加丰富,并且包含 Phobos 中不存在的模块,例如 HTTP/FTP 客户端支持、各种加密类等。它们还遵循不同的设计理念(Phobos 更命令式/元编程风格,而Tango 非常严格地类似于 OOP,因此在这方面与 Java 类似)。

I know that there are currently two standard libraries (Phobos and Tango), so I assume that there might be people trying to unify them.

"Unification" is extremely unlikely due to differences in licenses. When Tango will be ported to D 2.0, you will be able to use it alongside Phobos, which isn't (easily) possible in D 1.0.

Additionally I heard some time ago that the languages has problems on the boundaries of GCed/non-GCed code. I couldn't find any reference about that on the D website, so is this problem still true?

I believe there are only problems if you're not careful with how you manage memory. If all references to a GC-allocated object is stored outside the memory regions marked as GC roots, the GC will consider the object unreferenced and will delete it.

If I had to choose D as a C replacement today, what D (v 1.0 or v 2.0) and what standard library would you suggest?

Phobos and Tango are going in somewhat different directions. Phobos (in D 2.0) ties in closely with D2's new features. Tango is more feature-packed, and contains modules which aren't present in Phobos, e.g. HTTP/FTP client support, various cryptography classes, etc. They also follow different design philosophies (Phobos is more imperative/meta-programming-ish, while Tango is very strictly OOP-like, and thus similar to Java in that regard).

风吹雨成花 2024-09-15 20:19:29

我想知道 D 的成熟度和稳定性如何,以及它是否可以很好地替代 C/C++。

我会对使用任何尚未得到 ANSI、ISO 或 ECMA 等标准机构支持的语言持谨慎态度。这或许是成熟的标志。也就是说,例如 Java 和 Delphi 就属于这一类,虽然我不使用这些语言,但它们可能可以被描述为“成熟”。

另一个衡量标准可能是为该语言编写的书籍和文章的数量和质量。据我所知,Andrei Alexandrescu 写了一本关于 D 的书。他还为 Dr. 的语言撰写了一篇长文章 .Dobbs,他专门处理标准库问题。

I'm wondering how mature and stable D is, and if it might be a good replacement for C/C++.

I would be wary of using any language that was not yet backed by a standards body such as ANSI, ISO or ECMA. That is perhaps an indicator of maturity. That said Java and Delphi for example would fall into that category, and while I do not use those languages, they could probably be described as "mature".

Another measure might be the number and quality of books and articles written for the language. There is one book for D that I am aware of by Andrei Alexandrescu. He has also written a long article on the language for Dr. Dobbs, where he specifically deals with the standard library issue.

人事已非 2024-09-15 20:19:29

我在使用 Phobos 和 SDL 在 D1 中编写一个小游戏时获得了很好的经验,但这是一个相当小的项目。

在我看来,D 缺乏:

  • 一个官方网络论坛,人们可以在其中获得帮助并搜索答案(不是新闻组)
  • 一个用于许多转换为 D 的 SDK 的官方存储库(例如 SDL、Gtk 等。这些通常很难找到和使用) ,当它们存在时。)

I've had a good experience writing a small game in D1 with Phobos and SDL, but it a was a pretty small project.

In my opinion, D lacks:

  • an official web forum where people can get help and search for answers (NOT newsgroups)
  • an official repository for many SDKs converted to D (for example SDL, Gtk, etc. These are often difficult to find and use, when they exist at all.)
夏日落 2024-09-15 20:19:29

我认为取代 C 的问题不是关于潜在替代品在理论层面上是否足够“好”或“成熟”,而是关于实际考虑以及 C 对于它的用途来说“足够好”这一事实。除非一种语言具有适用于每个主要操作系统的完整本机构建和运行时环境,否则它对于 C 的用途来说并不实际。 C 是 POSIX 语言这一事实​​是整个问题的一个重要部分。

当然,像 D 这样的其他半低级语言也可以在专业领域有很大的应用。但是您不太可能看到用 D 编写的主要多平台软件(Web 服务器、数据库服务器、文字处理器、Web 浏览器等),因为没有主要操作系统(更不用说所有操作系统)附带 D 构建或运行时环境。

I don't think the question of replacing C is about whether a potential replacement is "good" or "mature" enough on a theoretical level, but rather about practical considerations and the fact that C is "good enough" for what it's used for. Unless a language has complete native build and runtime environments for every major operating system out there, it's not really practical for what C is used for. The fact that C is the language of POSIX is a big part of the whole issue.

Surely other semi-low-level languages like D could have great applications in specialized fields. But you're unlikely to see major multiplatform software (web servers, database servers, word processors, web browsers, etc.) written in D because no major OS (much less all of them) comes with a D build or runtime environment.

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