News for hackers. Stuff that matters.
Re:How I Came to Write D (2014) by lordnacho on Sunday June 03, 2018 @12:33PM (#17220326)
I hear so many great things about D, but I haven't started coding in it yet. A friend of mine has gotten in there, coding up his new trading platform in it. Also virtually all his social media posts are about D, so he's keen.

Suppose I am a c++ guy who does a lot of time sensitive code. Who else has made the leap, and what were your impressions? How often do you turn up nothing on stackoverflow? How often do you find there's no lib where you'd expect to have a few in c++?

Re:How I Came to Write D (2014) by qznc on Sunday June 03, 2018 @01:46PM (#17220692)
There is this guy who does VST plugins in D and sells them: https://www.auburnsounds.com/blog/2016-02-08_Making-a-Window...

"This is a touchy topic that already has filled entire blog posts. Virtually everyone in real-time audio is using C++ and it's probably still the sanest choice to make. [...]

I worked with both languages for years and felt qualified enough for the inevitable bullet point comparison. The most enabling thing is the D ecosystem and package management through DUB, which makes messing with dependencies basically a solved problem. Development seems to "flow" way more, and I tend to like the end result better in a way that is undoubtedly personal."

Re:How I Came to Write D (2014) by p0nce on Sunday June 03, 2018 @03:46PM (#17221360)
(author of the above quote) I'll add that shorter compile times is the gift that keeps on giving. It's easy to underrate the importance of shorter build-test cycles.
Re:How I Came to Write D (2014) by specialist on Sunday June 03, 2018 @02:13PM (#17220830)
"...makes messing with dependencies basically a solved problem."

Huh. Now I'm interested.

One constant in my professional (and hobby) careers has been "DLL Hell". I'd pretty much do anything to be hassle free.

Thanks for the tip.

Re:How I Came to Write D (2014) by p0nce on Sunday June 03, 2018 @03:58PM (#17221429)
On that point. In the D world there is a habit to use "derelict" bindings which are dynamic loaders for dynlibs. This has the advantage of supporting multiple dynlib versions, and also does not complicate the build with a linking option... If you are making anything cross-platform it is a boon.
Re:How I Came to Write D (2014) by ByThyGrace on Sunday June 03, 2018 @05:33PM (#17222314)
Can you please expand on that? Are there examples to look at of derelict bindings?
Re:How I Came to Write D (2014) by p0nce on Sunday June 03, 2018 @06:06PM (#17222564)
For example you want to depend on SDL.

You add the "derelict-sdl2" package to your DUB dependency list. DUB will download and build that "derelict-sdl2" library. This is a small library that will load functions pointers in the SDL2 dynlib (aka dynamic loading).

You'll still have to distribute your cross-platform app with SDL2, however there is no linker option, the linker doesn't need to know about an import library. Voila, same build for all platforms.

Conversely in C and C++ you would probably only have static bindings as a choice, and it can be a pain for cross-platform builds. On Linux, it has to be packaged. On Windows, you must find the right .lib.

There can be considerable list of libraries in linker settings, essentially because there is no package manager that makes dependencies something _composable_: dependencies would then leak on linker settings across the chain. C++ forums are full of people failing to build, that's not the case with D.

Documentation: http://derelictorg.github.io/loading/loader/

Re:How I Came to Write D (2014) by keldaris on Sunday June 03, 2018 @06:48PM (#17222847)
How is this dynamic loading implented? Is it effectively a cross-platform wrapper over LoadLibrary/GetProcAddress/etc. (and their POSIX equivalents) or is there more to it? Is it possible to make link time optimization work with dynamic loading?
Re:How I Came to Write D (2014) by CyberShadow on Sunday June 03, 2018 @07:45PM (#17223217)
> Is it possible to make link time optimization work with dynamic loading?

No, but nor can you with regular ol' linking against shared libraries. Or against static libraries (except for some mundane stuff like function reordering). LTO requires toolchain support and occurs before code generation.

Re:How I Came to Write D (2014) by p0nce on Sunday June 03, 2018 @07:05PM (#17222961)
> Is it effectively a cross-platform wrapper over LoadLibrary/GetProcAddress/etc.

Yes it's just that.

> Is it possible to make link time optimization work with dynamic loading?

Not that I know of (not sure).

Re:How I Came to Write D (2014) by annywhey on Sunday June 03, 2018 @08:54PM (#17223587)
I've evaluated D for games. It's good in terms of giving you a palette of data modelling options from "I don't care yet" to "I need to track every byte", and having the support of multiple compiler implementations gives it a trustworthy "not going to disappear" feeling. You really don't have to lean on the GC given all the other options for memory management, but it is the canonical default and is likely to stay that way unless everyone keeps piling on the -betterC train.

However - it's another big language with a lot of accumulated history to it and a lot of stuff that isn't immediately needed in the day-to-day. That makes it intimidating to learn and more geared towards "megacorp" codebases when I really want something small and suitable for hobby/education projects that go near the metal. So I've also searched for a dedicated "better C" which led me to Zig. It's still in its early stages so it doesn't face the tightrope act of D development. And the language is uncomplicated, polishing up pretty much every wart and major source of error that's in C(even manual memory stuff - not by eliminating the footguns, but by making safe usage idioms easy), while playing really well with existing C code.

Re:How I Came to Write D (2014) by bachmeier on Sunday June 03, 2018 @03:00PM (#17221113)
> How often do you turn up nothing on stackoverflow?

D's forum/mailing list was established well before SO was a thing, so the answer is "pretty often", but with the addition "you don't need SO because you can talk directly to the D developers". I've not seen another major language where the core developers, and even creators of the language, were so available.

https://forum.dlang.org/

Doesn't even require registration.

Re:How I Came to Write D (2014) by mhh__ on Sunday June 03, 2018 @01:45PM (#17220688)
Time sensitive code can be written fully in D. Avoiding the GC is trivial, if you have sensible expectations: The Standard Library (phobos) largely requires it, although it should be said that the D garbage collector currently only runs when (say) explicitly called to allocate memory so it's not as pervasive as Java's (say).

Calling C++ directly is very much an option, although interlingual exception handling is a WIP.

Re:How I Came to Write D (2014) by dfox on Sunday June 03, 2018 @02:45PM (#17221039)
GCs that run somehow in background and are not primarily trigerred by allocation are quite rare, IIRC all GCs shipped with LVM are also only triggered by allocation.

In fact only two production cases of primarily background GCs that I can think of at the moment are some Lisp Machines (IIRC LMI) with HW assisted incremental copying GC and Azul's GC, which uses quite similar approach.

Re:How I Came to Write D (2014) by dbaupp on Sunday June 03, 2018 @05:41PM (#17222391)
Java also doesn't run collection unless there's interaction with the GC. This is why people put a lot of effort into avoiding allocation in inner loops via primitives and object pools, because doing so ensures that the GC won't cause problems.
Re:How I Came to Write D (2014) by krylon on Sunday June 03, 2018 @02:07PM (#17220804)
FWIW, I only played around with D briefly (I was not unhappy with D, but I prefer Go for its simplicity), but the community on the D Forums[0] is awesome - very welcoming to newbies and very helpful, too.

[0] https://forum.dlang.org/

Re:How I Came to Write D (2014) by rufius on Sunday June 03, 2018 @12:45PM (#17220395)
This is sort of a sideways answer... I wrote some D code for a bit and I enjoyed it. The FFI story is solid and that made interop nice. That said, GC may be a concern for timing sensitive code.

That said, since Rust hit 1.0 and the language got cleaned up, I’ve stopped writing D at all. Not plugging Rust, just the facts. Better language for my space.

Re:How I Came to Write D (2014) by VHRanger on Sunday June 03, 2018 @01:27PM (#17220591)
You can link to c++ code in D (you do need to declare function signatures on the D side, etc.) but overall c++ compatibility is good, so it's less of a problem than you'd expect
Re:How I Came to Write D (2014) by lordnacho on Sunday June 03, 2018 @01:57PM (#17220749)
Yeah but then I need a compelling reason to glue those things together in a new language?
Re:How I Came to Write D (2014) by johannes1234321 on Sunday June 03, 2018 @03:47PM (#17221370)
The reason is that you are more comfortable or efficient in the new language, but want to access legacy.

Having to recreate everything for scratch is a massive effort, however gradually refactoring an application and having access to huge amounts of third-party libs is an enabler. (while all those libs will use non-idiomatic patterns, so it has to be contained)

Re:How I Came to Write D (2014) by WalterBright on Sunday June 03, 2018 @04:11PM (#17221517)
If you want checkable memory safety, for example.
Re:How I Came to Write D (2014) by p0nce on Sunday June 03, 2018 @04:12PM (#17221519)
Be aware this may ruin you as a C++ programmer, since you'll hardly want to use C++ after. That is pretty common.