Hacker News new | ask | show | jobs
by ogezi 3884 days ago
D is a really amazing language that manages to correct the mistakes of c++ but still retain its good parts. it's a shame that it's not more popular.
2 comments

To me, while D fixes many warts of C++, D is still too similar to C++ to justify the change. It still has implicit numeric cast, exception unsafety and strange behaviors.[1]

In addition, the D authors are generally opposed to disciplined approaches, e.g. type classes, region-based memory management, which are being added to C++. Especially regarding the former, while "design by introspection" may have its merits (Andrei Alexandrescu's presentation on allocator is worth watching[2]), I think many still prefer explicit interfaces over implicit ones, so I don't see D take off in the near future, at least until the wanted features are added to the language.

[1] http://forum.dlang.org/thread/htmkdnmlqyvkidkrsmri@forum.dla...

[2] https://www.youtube.com/watch?v=mCrVYYlFTrA

> It still has implicit numeric cast,

Implicit numeric casts that lose bits are not allowed anymore.

> exception unsafety

??

> Implicit numeric casts that lose bits are not allowed anymore.

That's good to hear, but I want implicit conversion to be forbidden unconditionally (even int * float -> float). I've been bitten by even widening conversions, so I just want to let them go away. It might be great if such an option could be applied to module level.

> ??

Sorry if my understandings or my words were wrong, but I got the impression that D also suffers from destructors that throw. (double-throw) Is this not the case in D? If so, could you elaborate how it achieves that?

I'm personally rather fond of purging exceptions from the language level completely, like Go did(Of course panics are technically exceptions, but their usage is culturally discouraged). Of course, this is just my personal opinion, but I would be happy if D had a story on this problem.

Concerning exceptions, I personally hate how Go implemented their error handling. This Quora answer explains it perfectly: https://www.quora.com/Do-you-feel-that-golang-is-ugly

Not that I'm a huge fan of exceptions either, but Go is definitely not a reference when it comes to error handling. My personal favorite, by far, is still CL's condition system.

Still, I've never had any issues with exceptions in D. Even exceptions thrown in destructors will raise a core.exception.FinalizeError with all the relevant information attached to it.

I've worked on large (1M+ LoCs) C++ codebases with exceptions disabled. Threading error codes all over the place, everywhere, is not pretty. Someone always forgets a check somewhere and you then spend 2 weeks figuring out why it crashes. It also pollutes the instruction stream with branches all over the place.

D also has assertions, unittests, preconditions, postconditions and invariants built into the language.

Also, unless there's actually an exception raised, frame handlers are faster than return code checks (its implemented as 3 MOV instructions per try block instead of test+jumps on every function call).

I rather like the implicit conversions. Especially in D where they only happen where its safe.

There's the 'to' function to perform checked conversions and the standard cast operator to perform unchecked conversions.

int foo = 256; ubyte bar = foo.to!ubyte; // throws ConvException ubyte baz = cast(ubyte) foo; // overflows as expected

If I want more type-safety than this, I'll create simple wrappers:

struct Seconds { int value; alias value this; }

That way I can still pass seconds everywhere an int is expected, but I can now declare arguments to only accept Seconds and not ints.

std.typecons.Typedef does something similar: http://dlang.org/phobos/std_typecons.html#.Typedef
> I want implicit conversion to be forbidden unconditionally

Not going to happen in a language with 11 integer types.

> (double-throw)

Exceptions are chained together.

Walter, is there any chance that we will see the source code to Digital Mars C++ release at some point? Or is it encumbered in ways that would make such a release impossible?
You can buy a copy of the source code from Digital Mars if you like. It's a bit old fashioned, though. At some point I'll probably just make it free, though it'll still have the Symantec license on it.
I often wonder if it were released today as "new" if it would of gained plenty of more hype. One thing I think that Go has that D is lacking is the standard library. With Go you can write a web server, a mail server, and plenty of things right away out of the box. Where in D and other lovely languages you either need to get a package manager, or make your own. Outside of this small detail I think D is amazing at what it's done, and I hope to work on more projects in D in the future. I only wish schools used D in more classes. I guess the last thing it's lacking is a serious IDE. I've seen and tried a couple, but at the end of the day I end up using a text editor with a hoard of plugins.
C++ and D aren't the kind of languages that get hype because they're the kind of languages that see serious use right away. If you're deep in the trenches writing C++ and/or D code, you don't have the time or the need to generate hype. You're getting actual work done. Things are different for languages like Ruby or Go. These were used more as flights of fancy for certain people, many of whom were not getting real work done. So they had time to write lengthy blog articles, make YouTube videos, host conferences, and write really weird and absurd tutorials. These are the kinds of things that generate hype. Hype is a product of everything but code; actual code is the anti-hype.
There's the dub package manager for D. http://code.dlang.org/

I don't think I'd want web and mail servers straight into the standard library out of the box. Those are way too specific. For example, there's already vibe.d for web servers and its doing an excellent job. They even have compile-time HTML templates!

As for IDEs, on Windows I've recently used VisualD and it did a good job. It's not yet as complete as the C# integration of Visual Studio (especially when taking ReSharper into account), but it definitely feels like an IDE. It already has improved hugely over when I last used it last year.