r/d_language • • Sep 26 '17

I absolutely love programming in D

I cannot express how much I love programming in D. I have found it a good way to learn a lot of aspects of computer science (I am doing that course next year) but also as a good way to almost get your head into the world of programming in C (which I mess around with here and there).

I cannot express how well of a language D has been designed. Both its syntax (the design of the language's textual representation) as well as the semantics which make for such a great programming system.

There is just so much to love about this language.

UPDATE: And don't forget the amazing developers and community of D; they're spectacular.

52 Upvotes

21 comments sorted by

14

u/FeepingCreature Sep 26 '17

It is pretty nice. GC could be better.

One "issue" with D is that it kind of ruins you for bad languages, and it itself isn't perfect so I feel like long-time D users have a more skeptical view of it and programming in general because it makes you aware how much nicer programming could be, then doesn't quite 100% deliver.

Still the nicest language I've ever used (that wasn't a language I made myself).

4

u/theofficialdeavmi Sep 26 '17 edited Sep 26 '17

I'm interested a lot on language design and implementation.

I wrote an extremely small language (like it didn't do much besides some maths and input and output - that's it; really basic) using D. I wrote a transpiler in it that would generate Pascal code (because why not). And then, because it was a "spurr of a moment thing" and not properly planned I then invoked, by hand, the free pascal compiler to compile the generated code into machine code.

So that was fun. I also really enjoyed the data structures I created for doing the code generation. It was very fun.

2

u/theofficialdeavmi Sep 26 '17

What languages have you designed? I'm interested :)

5

u/FeepingCreature Sep 26 '17

My own thing is Neat, though it's pretty much personal use only. It's basically a grab-bag of every syntax I could think of on top of a D-lite core. Good language intro is the cheat-sheet.

Most significant feature that I wish D adopted is expression aliases, ie. alias x = y+z;.

2

u/theofficialdeavmi Sep 26 '17

Wow, expression aliases. I can see how that would be handy. Maybe you use a formula a lot all over your code like (calculating the mass or weight of something) and you don't want to repeat yourself. Now that's neat-0!.

If I may ask. What is a "D-lite core"? What does that mean?

By the way, that is such sexy documentation. How simplistic yet readable (yeah I know there ain't such a word but that documentation made my jaw drop (in a good way) - just like D's did so too).

3

u/FeepingCreature Sep 26 '17

Yay :)

D-lite meaning that I copy the basic syntax and data types of D while staying away from some of the more involved features like the overpowered templates, contracts, ctfe...

The really cool thing is that you can use expression aliases in structs.

struct Rect {
  int x, y, width, height;
  alias area = width * height;
}

Also handy sometimes:

int* pointer = new int;
alias i = *pointer;

2

u/theofficialdeavmi Sep 26 '17

Ah I see, the pointer dereferencing one is pretty handy if you don't want to * your pointers all the time.

2

u/jbb67 Oct 11 '17

Very nice work. I want to work on my own language but so many other things I want to do first :(

Plus D is 95% good enough for me.

1

u/theofficialdeavmi Sep 26 '17

No language is perfect. But I still like D :) hehe

1

u/canoo478 Sep 28 '17

and it itself isn't perfect so I feel like long-time D users have a more skeptical view of it and programming in general because it makes you aware how much nicer programming could be, then doesn't quite 100% deliver.

Could you please elaborate on what in D you think could be better?

What is stopping these parts from being improved?

0

u/[deleted] Sep 26 '17

[deleted]

5

u/FeepingCreature Sep 26 '17

There's been some work on fixing this but I don't know it's in the language yet. Last I checked, D uses a conservative mark&sweep GC, meaning all threads have to be stopped to scan the memory and programs are vulnerable to false pointers keeping memory alive, ie. the compiler can't tell the difference between "an int member of a class" and "a pointer member of a class", so an int that happens to have the address of a garbage collected area of memory will keep that area alive indefinitely. The solution to this is to keep a complete runtime type map of every piece of data in memory so you can objectively tell pointers from nonpointers, which is entirely doable but afaik hasn't actually been done yet. (And may also allow for memory compaction, at least for data that isn't referenced in non-gc-visible memory.)

At least int[] arrays aren't scanned as pointers.

5

u/netbioserror Sep 29 '17

Next to Clojure, I feel like D is a glimpse of what languages could be, and we're just weighed down by so much inertia from established languages that we may not see a world of great languages in production for some time.

That reminds me, a Clojure spinoff implemented in D with the D runtime might be great, if the GC were tidied up into a generational model...

2

u/theofficialdeavmi Sep 29 '17

But yes. D really does aim at being prettu much brilliant in my eyes. I recall watching a video where Andrei made a remark about Walter - saying that he had an eye for language design and hell yes was he right.

2

u/theofficialdeavmi Sep 29 '17

I agree that we are being wayed down by inertia of the current languages that follow the standard formula. D is beautiful.

1

u/theofficialdeavmi Sep 29 '17

Clojure is somethint I want to try out. As a Java user I really like that it uses Java bytecode as the compilation target as know the Clojure generated Java bytecode means the existing Java libraries and/or Kotlin can interoperate.

I'm putring Clojure back onto my todo list.

2

u/netbioserror Sep 29 '17

Clojure is like the perfect counter-point to D: Bytecode-compiled, a Lisp descendant, dynamically typed, runtime metaprogramming (as opposed to D doing it at compile time), code as data, data as code, and my favorite feature which I miss in D due to static typing: Arbitrarily nested heterogeneous data structures.

It turns out, representing the world - project configs, server configs, user files, save games, program states, calculation results, test data - as arbitrary nestings of lists and hash-maps and sets of all kinds of mixed data types is so natural that you long for that ability when you move back to static typing.

I'm sure that there's research to be done in this area: Using D's metaprogramming and templating, I'm sure somebody can implement very natural and simple-to-use arbitrary data structures. But that would take a lot of runtime type checking, as std.json already has to do.

3

u/jbb67 Oct 11 '17

Loving DLANG to the point where I have to write in C++ for work and find it frustrating now.

GC is great, it makes the code smaller, safer, sometimes faster and much easier to read and reason about. It's not always suitable though, and D does need a better story as a system programming language for when you need consistent latency and custom allocations. (But you don't need any of that most of the time).

I like having the syntax for slices and the way string works, and being able to iterator over a tuple. And if I ever have to write a compile time expression in C++ I think constexpr.. ugh.. and give up but in D it mostly just happens automatically.

And templates for anything but the simplest case in C++ are like writing in some alien language but in D it looks much more like regular code.

And modules just work. And thread_local stuff has advantages and disadvantages but you can choose not to use it and probably it's the best default.

I hated the distinction between class and struct at first as a C++ programmer but now I really appreciate the difference between value and reference classes. I like the copy and postblit thing too.

And being able to assume variables are initialized to zero (or whatever) means that I can write code that doesn't need a constructor because I can design it so that zero values work for that.

And writeln that can write anything out, and has a sane syntax unlike std::cout, oh and in fact being able to NOT prefix everything with the namespace to write safe code but being able to when you need it.

unittests, static initialization blocks. Small things but they make things so nice.

So many small things. It's like C++ done right.

1

u/theofficialdeavmi Oct 11 '17

It is like C++ done right. It is like the next C (in someway) (what C++ was meant to be).

2

u/theofficialdeavmi Sep 26 '17

Anyone agree with me ? :)

1

u/bruce3434 Sep 26 '17

yup. I'd love it if automem gets into the standard library though.

0

u/theofficialdeavmi Sep 26 '17

Coding in the car was my challenge today.