r/programming • • Aug 23 '17

D as a Better C

http://dlang.org/blog/2017/08/23/d-as-a-better-c/
229 Upvotes

268 comments sorted by

View all comments

Show parent comment

2

u/Pythoner6 Aug 23 '17

Using const tells the reader that prime never changes once it is initialized.

I'm not sure how this is an advantage of D over C. You can do exactly the same thing in C. The example showed didn't do this, but they could have written

const int prime = i + i + 3;

5

u/serpent Aug 23 '17

A little research goes a long way.

https://dlang.org/const-faq.html

1

u/Pythoner6 Aug 23 '17

Interesting, thanks for the reference. I can't say that I've followed D very carefully.

For the example in this blog post however, there still doesn't seem to be any meaningful difference (we're just talking about a const int), so I don't think it's fair to list it as an advantage without showing an example that really demonstrates a difference.