3 ms·
I have looked at D repeatedly over the last couple of years, and I really hope it will become more popular. It looks pretty much like what one would want C++ t
by krylon 11y ago
I have looked at D repeatedly over the last couple of years, and I really hope it will become more popular.
It looks pretty much like what one would want C++ to be like if one were to start over again, free of the need for backwards compatilibity with C (at the syntax level)
I haven't had the A-Ha moment with D, I have to admit, not the way I had with Go. Right now, Go feels more aligned with the way I tend to think.
But I still think that D is a brilliant language that people will come to like if they are not tied to the ground by legacy code they have to maintain. I don't think D will ever replace C++, but if Alexandrescu is behind it, that might go a long way.
- luismarques 11y agoTry programming with (std.)ranges and (std.)algorithm's. It's something completely refreshing, replacing a mess of loopy code with a clean pipeline of algorithms. The lazy nature of the standard algorithms and the clean syntax you get with the UFCS feature produce some really neat results. Even if you end up not using D any further, it can change your view of programming.
- eco 11y agoYeah, it's a lot like lisp in that regard. I'm glad I learned D even though I don't use it professionally if only because it changed the way I look at some things. The algorithm chaining enabled by UFCS and the range based standard library can lead to some very beautiful code (at least as far as C-family languages go). It also made me painfully aware of how often I copy strings in C++ (string_view cannot come soon enough). Here's a snippet of code I hacked together in D for a bot to scrape titles from pages of urls in irc messages. matchAll(message, re_url) .map!( match => match.captures[0] ) .map!( url => getFirst4k(url).ifThrown([]) ) .map!( content => matchFirst(cast(char[])content, re_title) ) .cache // cache to prevent multiple evaluations of preceding .filter!( capture => !capture.empty ) .map!( capture => capture[1].idup.entitiesToUnicode ) .map!( uni_title => uni_title.replaceAll(re_ws, " ") ) .array .ifThrown([]); It uses D's fast compile-time regex engine to look for URLs, then it downloads the first 4k (or substitutes an empty array if there was an exception), uses regex again to look for a title, filters out any that didn't find a title, converts all the html entities to their unicode equivalents (another function I wrote), replaces excessive whitespace using regex, then returns all the titles it found (or an empty array if there was an exception). There's stuff to improve upon but compared to how I would approach it in C++ it's much nicer.
- krylon 11y agoThis looks pretty cool! I think I know what I am going to do over my next vacation! :)