Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the D language have multiple standard libraries and issues with GC?

Tags:

d

phobos

tango

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?

like image 931
soc Avatar asked Jul 08 '10 15:07

soc


People also ask

Does D have garbage collection?

D is a systems programming language with support for garbage collection. Usually it is not necessary to free memory explicitly. Just allocate as needed, and the garbage collector will periodically return all unused memory to the pool of available memory.

Which programming language has more libraries?

The top three are: JavaScript. Java. Python.

How many standard libraries are there in C?

The ANSI C standard library consists of 24 C header files which can be included into a programmer's project with a single directive. Each header file contains one or more function declarations, data type definitions and macros. The contents of these header files follows.

Why D programming language is not popular?

it lacks good marketing; it doesn't have a high-profile corporate backer. it lacks compelling technical merit; there is nothing particularly special about it. it's too difficult to learn; it present too steep a learning curve. it's too big and complex; nobody likes big, complex languages.


2 Answers

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.

like image 146
Jonathan M Davis Avatar answered Sep 28 '22 09:09

Jonathan M Davis


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.

like image 24
Andrei Alexandrescu Avatar answered Sep 28 '22 09:09

Andrei Alexandrescu