D is great

String printing in D is typically handled with the write* body of functions which are stylistically similar to C's printf. While the community debates whether C#-style string variable interpolation should be added, did you know that D lets you implement it yourself easily?

string mwriteln(string str) @safe pure {
size_t istart;
bool inword = false;
auto result = appender!(string[]);
auto vars = appender!(string[]);
foreach (i, dchar c; str) {
if (!inword) {
if (c == '{') {
result.put(str[istart .. i]);
istart = i+1;
inword = true;
}
} else {
if (c == '}') {
result.put("%s");
vars.put(str[istart .. i]);
istart = i+1;
inword = false;
}
}
}
if (!inword && istart < str.length)
put(result, str[istart .. $]);

return format!`writefln("%s", %s);`(result.data.join, vars.data.join(`, `));
}

void main() {
int x = 4;
float y = 3.5;
mixin(mwriteln(`X:{x} Y:{y} Larger:{x>y?"X":"Y"}`));
}


The beauty of this lies in D's CTFE. All the code in the mwriteln function runs at COMPILE TIME-- no hideous preprocessor macros or lengthy interpreted language bloat. When you get right down to it, the compiler is simplifying the above code to this:

void main() {
int x = 4;
float y = 3.5;
writefln("X:%s Y:%s Larger:%s", x, y, x>y?"X":"Y");
}


It's a trivial example, but it should give you a hint to the power of CTFE. What takes C or C++ or C# pages of code and complex eye-bleeding macros can be done in D in a single easily readable block, and the end result is as efficient as C, with better memory safety.

Attached: 1630651959090.png (1024x778, 75.7K)

Other urls found in this thread:

beeflang.org/
code.dlang.org/packages/crypto
twitter.com/NSFWRedditImage

Based D appreciator. Why is D so slept on?

It just doesn't have a shiny enough package or motivated shills pushing it to the big boys like Unity/Unreal/Apple, even though there's hobbyists already using it for that. It's a shame because the language is so damn good.

It's not Unity, but Godot has D language bindings. I need to get into D again.

Absolutely my favorite language right now. It's peak comfy bros.

Unfortunately I think a large part is the name, bad marketing and bad timing.

It was originally going to be called Mars I think, but was then changed to D, which makes it seem much more generic. Originally, version 1.0 of the language was basically a "C++, but which doesn't suck as much" but which has tons of library comparability issues and a weak standard, but things completely changed for D 2.0 and it turned into a monstrous code gen power house of a language that basically beats the shit out of Rust in most practicality metrics. But without corporate backing people who don't already know about it aren't drawn to it.

Just about every big tech company tried it and gave up on it. If a big tech company isn't using it, the language isn't serious. Those guys are pros and already vetted the cost analysis whether it would help or hurt the company. If it's not good enough for them, it's not good enough for anyone and is just a toy.

>If a big tech company isn't using it, the language isn't serious.
>Those guys are pros
>If it's not good enough for them, it's not good enough for anyone and is just a toy.
That's all reductivist and assumes a rather odd "our betters decide for us" mentality. It's also factually incorrect.

cool user, but have you tried making a real project with it besides just printing a string on your console?

it's Any Forums, you know that they don't actually code and just wasting their time making fizzbuzz.

I have, actually. I've been using D commercially for around 8 years, with many many years of C/C++ before that (and all the usual accompanying languages for tools and secondary development). I figured I'd keep things simple since simple things are what are usually discussed on Any Forums

do you write proprietary software in D?

Yep, no FOSS for me, gotta pay the bills.

Attached: 1642609797374.png (1004x650, 52.65K)

D is cool.

D is cool I use it for a game but I hate the terrible docs and some weird choices they made. It should have strictly been a simpler cpp but it somehow gets really complicated fast. Only use it because of modules and fast compile times.

>dchar
ni[b][b]a just use 1 byte chars and utf-8
stop keeping multibyte chars alive

Attached: tired pepe square.png (452x432, 18.71K)

thanks but i'm sticking with LPWSTR

I would love a C++: Good Version but D is just a mishmash of features half-implemented in radically different ways, aka C++. BetterC is simply broken and without it you're stuck with a garbage collected runtime and what's the fucking point? If I was willing to make that concession I'd go play with goofy shit like Kotlin instead of C++ Without The Reason Anybody Uses It

beeflang.org/

>garbage collected
>great

Attached: 2242746_1323827412730.72res_500_281.jpg (500x281, 103.29K)

i am actually learning D myself because i want to learn how to create binding for C libraries and want to learn network programming but not in C or c++ because they are kinda scary and translating a lot of the concepts in those books to C is super easy and clean, i am really enjoying D but there are some libraries which i am trying to use myself but they all fail on windows, i.e code.dlang.org/packages/crypto this fails on windows and gives error that it cannot find some external symbols i have googled those and and apparently all those functions are available in wincrypt.h and crypt32.lib on windows yet dlang still cannot find them,
when dealing Dlang i actually came to learn a lot about things like linkers and object file formats and incompatibility between compiler outputs and stuff and come to realize this user is probably right, there are ton of edge cases at least on windows.