
Porting a Golang and Rust CLI tool to D - nurettin
https://pingfrommorocco.blogspot.com/2020/08/porting-golang-and-rust-cli-tool-to-d.html
======
1f60c
> For example, it fetched rpassword, a tool that hides password characters as
> you type them into a terminal, much like Python's getpass function.

I want to note that you can call actual C functions from D without much extra
effort.

Here’s a program that calls getpass:
[https://glot.io/snippets/fqf04b6wg2](https://glot.io/snippets/fqf04b6wg2)

~~~
Scroph
Thanks! I added it in this PR: [https://github.com/azihassan/hashtrack-
client/pull/11](https://github.com/azihassan/hashtrack-client/pull/11)

~~~
1f60c
Oh, oops.

I forgot to edit my comment to add that, for some reason, it doesn’t seem work
on macOS. But if that’s not a problem for you, then I’m happy I could help.

Edit: I just read the code, and it seems like you found out about that before
I could warn you. :)

~~~
Scroph
I didn't know actually, I only did it so that it would also compile on Windows
(which I haven't tested yet tbh). Good to know it would still compile on macOS

------
mhh__
I'm surprised that the rust binary is 3.5 times bigger. D is already templated
to the nth degree, what more is rust doing? On top of that D links in a whole
GC whereas rust does not?

~~~
PudgePacket
Rust is statically linked by default, not sure how D works. Rust still
includes some debug features that can give you a stack trace. Size will also
depend on the compile options, if LTO was enabled, how much generics were
used, how much string printing was used (print is a macro in Rust that
generates code at the callsite), etc. Most, if not all, of these can be
resolved.

See [https://github.com/johnthagen/min-sized-
rust](https://github.com/johnthagen/min-sized-rust) for aiming for small
binary size.

This article shows a 93% size reduction, 2.7m -> 200kb, with some relatively
simple modifications [https://www.collabora.com/news-and-
blog/blog/2020/04/28/redu...](https://www.collabora.com/news-and-
blog/blog/2020/04/28/reducing-size-rust-gstreamer-plugin/).

Here is someone using Rust for a 3kb demoscene program
[https://www.codeslow.com/2019/12/tiny-windows-executable-
in-...](https://www.codeslow.com/2019/12/tiny-windows-executable-in-
rust.html).

~~~
mhh__
D is usually dynamic although I try to be static for the most part. IIRC The
runtime is linked statically (or not at all) but Phobos is dynamic by default

Rust compiles seem to blow up pretty easily, e.g. I was cleaning out my SSD
the other day an I noticed that a rust GUI framework (Iced?) was sat on about
2Gb of dependencies despite being significantly incomplete (but very
promising)

~~~
destructionator
> Phobos is dynamic by default

That depends on your distro. The packages from dlang.org all do the static
link config out-of-the-box, but some distro packages dynamic link by default
instead.

Given the size of that file, it looks static linked. It dynamic links libc,
pthread, and a couple other OS-level things, but all D libs including
druntime, phobos, etc, are statically linked.

Might just be difference in dependencies.

------
hu3
How can D use so little memory despite sporting a GC?

    
    
        Go Memory usage: 13mb
        Rust Memory usage: 9mb
        D Memory usage: 7mb

~~~
nestorD
Another answer for this particular case is that the D program has less
features. Quoting the blogpost:

> Rust downloaded a lot of crates, but that's probably because the Rust
> version of the code has more features than mine has. For example, it fetched
> rpassword, a tool that hides password characters as you type them into a
> terminal, much like Python's getpass function. That's one of the many things
> I don't have in my code.

~~~
Scroph
Thanks, that could be part of it. I added some of the missing features, namely
colored terminal output and getpass (thanks to the reply above), but the
memory usage didn't fluctuate much. The D version is still missing websocket
support for the "watch" command, but none of the clients use it in the
benchmark.

------
finder83
I've never really dived into D, but why was it never more popular? It seems
like it was posed to take off, but never quite did.

~~~
tastyminerals2
D had an unfortunate early history. For a long time being a one man project,
surviving through Python2 to Python3 akin transition and slowly maturing
during all these years. Many top D features were added along the way but were
not available from the start. Also in the beginning D focus was to be a better
C++ with GC which is not something that excited C++ crowd who smirked as soon
as they heard about GC and never actually approached the language. It is only
later that it became clear that it is a separate unique language. I think D
just grew and matured naturally into something very solid. D has a small but a
very skilled team of seasoned C++ veterans and language designers. I dare to
say, I am yet to see better forum answers than on forum.dlang.org both on the
account of the language and programming in general.

~~~
finder83
Interesting, thanks for the synopsis. :) Sounds worth looking into.

------
monadic2
...go Lang AND rust? Why would anyone do this to themselves?

~~~
detaro
If only there was a link to a post with more context somewhere, like in the
first sentence on the page.

~~~
monadic2
That doesn't resolve the question. It's a very odd combination of languages to
decide to sling together arbitrarily.

~~~
detaro
Two statically compiled languages that get a lot of attention for writing
tools in doesn't seem that odd choice to compare?

~~~
monadic2
I mean you can statically compile a lot of languages and literally every
language is used to write tools.

Go doesn't even use a stack compatible with the system abi and has probably
the worst FFI of any language I've ever used, it has a very, err, unique type
system. I mean there's a shit ton of great stuff too (compile times, great
test patterns and pretty good tooling, the http stack and string manipulation
and green threading is fantastic), I don't have it out for go! Meanwhile rust
has a completely different memory model and type system and concurrency model,
has probably the best FFI of any language outside of maybe some lisps and
cpython and probably D (never used it), and they've taken forever to role out
production ready http client/server stacks (though I think this is finally
smoothing out!) I just don't see why they're tied together except a) static
compilation and b) they emerged at roughly the same time.

Rust and go are very, very different languages aimed at completely different
niches.

