Live data from Hacker News

Wc in D: 712 Characters Without a Single Branch

dlang.org

11–20 of 89 posts

Re: Wc in D: 712 Characters Without a Single Branch

#11
post #6

I find D easier to grok coming from a Java/Python background.

My only issue is that it's far more complicated than Java and for a language that fills that same niche it's hard for me to justify putting my resources into learning it even though I do like a lot of the features.

In what way is more complicated than Java?

Re: Wc in D: 712 Characters Without a Single Branch

#12
post #7

"without a single branch" I thought it meant actually a branchless version of wc. Turns out it's just no explicit if statements.

If you were careful, it seems pretty plausible to be able to use some indexing tricks and CMOV to write a jump/branchless version of wc. You are basically counting newlines and runs of whitespace.

Re: Wc in D: 712 Characters Without a Single Branch

#13

I'm wavering between D and Rust for which one could be used as a better alternative to C++. (Though I don't see C++ getting replaced anytime soon.) Even if Rust is getting most of the attention, D also seems to be a strong candidate.

D is fun! It's so easy to get started. Rust has an initial learning curve that just doesn't doesn't seem to fun to me, but I guess I'll have to actually scale it some day.

Re: Wc in D: 712 Characters Without a Single Branch

#14
Perhaps I'm just being pedantic or maybe I am misunderstanding.

The author claims to be IO bound toward the end. But they are comparing to two versions that are faster.

It is my understanding that IO-bound means that the IO subsystem is the thing which limits run time of the program. But the author clearly demonstrates that the IO subsystem of their machine is capable of supporting faster wc binaries.

So what am I missing here?

Re: Wc in D: 712 Characters Without a Single Branch

#17

I find D easier to grok coming from a Java/Python background.

I've only toyed with D a bit. IMHO, if you come from a typical OO programming language background (which to me includes C++, Java, Python...), the majority of D will immediately feel familiar, and to a great extent, obvious.

The syntax is familiar and the ideas are familiar. You don't have to learn anything new (not immediately anyway) like you do in Rust (where you basically need to learn EVERYTHING new).

Where this idyllic scenario starts falling apart with when you start actually using it for anything half-serious. Some of the bits feel extremely unintuitive and the documentation is difficult to navigate. There are few examples and the tutorial is a bit spartan. For example, I needed a deque-like container (double-ended queue), but it took me ages to figure out that a) the language actually has one and b) how to use the bloody thing.

There is also a bit of schizophrenia going on, with the "new" ideas and the "old" ideas clashing in some places. For example, they claim that you can run D without a GC (the new), but apparently a good chunk of the stdlib requires the GC (the old), so you're stuck.

I find this all to be unfortunate because D, to me, feels like it could be a better, saner C++.

Re: Wc in D: 712 Characters Without a Single Branch

#18
post #6

Earlier quoted context omitted.

My only issue is that it's far more complicated than Java and for a language that fills that same niche it's hard for me to justify putting my resources into learning it even though I do like a lot of the features.

In what way is more complicated than Java?

well, java isn't really complicated. it's just verbose. but my understanding is that d has many of the features of c and modern cpp. that alone makes it more complicated than java...

Re: Wc in D: 712 Characters Without a Single Branch

#19
post #7

"without a single branch" I thought it meant actually a branchless version of wc. Turns out it's just no explicit if statements.

If you were careful, it seems pretty plausible to be able to use some indexing tricks and CMOV to write a jump/branchless version of wc. You are basically counting newlines and runs of whitespace.

CMOV aside, I remember it was proved MOV itself is turing-complete.

Re: Wc in D: 712 Characters Without a Single Branch

#20
post #19

Earlier quoted context omitted.

If you were careful, it seems pretty plausible to be able to use some indexing tricks and CMOV to write a jump/branchless version of wc. You are basically counting newlines and runs of whitespace.

CMOV aside, I remember it was proved MOV itself is turing-complete.

https://github.com/xoreaxeaxeax/movfuscator

posting for anyone wondering

Post reply on HN