📜 ⬆️ ⬇️

Destroying common myths about D

Original text: semitwist.com/articles/article/view/dispelling-common-d-myths
Reddit: www.reddit.com/r/programming/comments/118y4m/dispelling_common_d_myths

Introduction


As a regular user and fan of the D language , I could not help noticing a number of misconceptions and misunderstandings that regularly occur among newcomers.

All these errors are quite understandable. Many are associated with problems that have played an important role in the past, so it is not surprising that these outdated perceptions continue to exist. It seems to me that these are precisely the areas that the D community should as well as possible explain to the rest of the programmers. These topics are:
')


For D there is an IDE


There were times when IDE with D support hardly existed a little more than a banal syntax highlighting. But now it is not. If you like full development environments, there are three main options, each of which is actively supported:


DSource fades away, but D projects are more active than ever.


With regularity in a couple of months, questions like this arise: “D is dead? I went to DSource and all projects looked outdated and unsupported, and the forums are empty. One gets the feeling that D is dying. ”

DSource was the de facto place to host projects on D. Note - WAS. Currently, most active projects have moved to Github and Bitbucket. In fact, even the repositories with the reference compiler D and the standard library have been located on Github for more than a year now. And during this time, the pace of development has accelerated significantly, and not vice versa.

There were some efforts to update DSource in order to make it easier to find active projects among the dead (don't forget that any hosting of open-source projects is doomed with time to collect a lot of projects). But due to the huge popularity that Github and Bitbucket received, the value of the efforts in this direction was considered insignificant.

Although, I must admit, I am sad to say this about DSource. I have always appreciated this site and at one time its existence was damn necessary and useful for the D1 infrastructure, long before Github and Bitbucket became commonplace for almost every open-source programmer. The site, the network channel and the hosting itself were donated to the D community (and they still are!), So it’s unpleasant for me to talk about DSource in the spirit of panegyric. But in any case, although DSource is almost not used in modern infrastructure D, the language itself is not only very, very alive, it is developing right before our eyes.

As for the way to search for active projects on D, in addition to the banal search engines, I would recommend the D Wiki . Yes, I admit, we were far from perfect in maintaining the page with the current list of projects, but I swear here and now that I will do my bit and will remind other D users to do the same.

Separation on D1 and D2 is no longer


D2 is the current state of affairs. D2 is already considered a stable branch, D1 is a relic of the past. Forget about D1, you can not even poke a stick, it is dead.

And when I say "dead", I do not mean the same kind of death, which can be represented by analogy with Python 2. I mean that almost no one else uses D1. Everything is already on D2, even late. D1 is little used that its official support ends at the end of this year (as announced a year ago). Nobody cares about D1. That's the point.

There is only D2.

(Translator's note: the author got a little overwhelmed here with "dead", rather "nobody uses D1 for new projects, this is pure legacy")

Is Phobos a standard library? What about tango?


You may have heard about the confrontation of Phobos vs Tango. Looking back into the past, it was an undoubted error D, but the problem was identified and corrected. In short, the bottom line: Phobos is the standard D library, period. Tango is now an optional and optional, but fully Phobos-compatible library. Something like this.

But it was not always so. A bit of history for those who are interested:

Long ago, when D1 was young, long before Andrei Aleksandrescu joined the team, the state of the standard library of Phobos was far from being the best. It was developed from and to a single person (Walter Bright), who, of course, being the main developer of the language, was too busy working on the language and the compiler. And for several reasons, it was not a full-fledged open-source then.

Therefore, a group of talented developers gathered and decided to fix this problem by creating a full-fledged standard library. It was called Tango and it was so much better than the unfinished Phobos that it became the de facto standard.

Unfortunately, for Tango to work properly, it was necessary to replace some of the low-level parts of Phobos related to the runtime environment. Libraries became incompatible - there was no way to use both at the same time. This, of course, became a nightmare for PR D.

Meanwhile, Phobos became completely open-source, Andrei Alexandrescu took the lead in his development and little by little Phobos became more beautiful and more final. He was damn good in some places, but it didn’t help with the key incompatibility problem between Phobos and Tango. But fortunately, the D developer community heard numerous complaints about the two standard libraries and focused on solving the problem.

At that time, D2 developed as the main unstable branch, while D1 became a stable branch in which changes that break backward compatibility are prohibited. And for D2, all the functionality that created the incompatibility between Phobos and Tango was redesigned and rendered into a separate Druntime entity. So tper and Phobos, and Tango use Druntime and are fully compatible. No conflict exists anymore.

Which one should I use? Phobos, if you have not had any specific need for Tango functionality. Be that as it may, Phobos is still the real standard library.

What can make you turn to Tango? The same reasons as for any additional library: if you like its design more, as an option. Tango is stylistically much more like Java and may be liked by those who have come from this language. Or you needed something from Tango , which is not corny in Phobos. For example, Tango implements the world's fastest XML parser . At the same time, the XML module from Phobos is among the things that oh, how to take and rewrite from scratch. (Don't worry, the rest of the Phobos is just great.)

D - open source


There are 3 main compilers for D:


GDC and LDC is a real open-source, without any but, and even included in the relevant sections of the repositories of some Linux distributions. The standard library and runtime environment, Phobos and Druntime, are licensed under a Boost license approved by the Open Source Initiative.

All DMD sources are available on Github . The front-end, which is also used by the GDC with the LDC, has an OSI Artistic approved license and also a GPL license.

The only thing that is not formally open-source is the DMD back-end. The reason is that things licensed from Symantec were used at the time and Walter cannot just change the license. But the source is publicly available and pull requests are always welcome. Are you worried about the spread? Don't: just ask Walter himself . The license obliges him to demand to ask his permission (Note of the translator: I am glad to advise how this copyright incident can be formulated in Russian normally) , but this is a purely technical formality. Ask him and immediately get permission. Not yet a single case of failure. And yes, do not forget, this applies only to DMD, more precisely, the back-end DMD. All the rest is open-source without any “but”, including two full-format compilers, GDC and LDC.

D - open source. It was not always there, but without any doubt this is now.

D allows manual memory management


Although D assumes the presence of a default garbage collector , this does not mean that you cannot control it , replace it or remove it at all , or use manual memory management.

In D, there are pointers (elegantly limited to memory-safe operations in @ safe mode) and direct function calls to C. You have malloc / free at your disposal and you can place anything in the memory thus obtained using emplace . Or try stacked scoped classes . Or reference counters . Or RAII . Plus, now a system of customizable allocators is under development.

Static typing does NOT mean unproductive.


D is a statically typed language, but this should not cause you to associate with the C ++ or Java style:
% cat funWithRanges.d import std.algorithm; import std.range; import std.stdio; void main() { // All done lazily: auto squares = sequence!((a,n) => n^^2)(0); auto fibonacci = recurrence!((a,n) => a[n-1] + a[n-2])(1, 1); auto fibEven = fibonacci.filter!(x => x%2 == 0)(); foreach(v; zip(squares, fibonacci, fibEven).take(6)) writeln(v[0], "\t", v[1], "\t", v[2]); } % rdmd funWithRanges.d 0 1 2 1 1 8 4 2 34 9 3 144 16 5 610 25 8 2584 

D is not only thoughtful and effective , but also safe and correct .

Add more useful things for parallel exploration , simple templates and metaprogramming tools , as well as various utilities that have become commonplace .

Source: https://habr.com/ru/post/154345/


All Articles