News for hackers. Stuff that matters.
Re:Porting a Golang and Rust CLI tool to D by mhh__ on Thursday August 20, 2020 @05:37AM (#24221526)
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?
Re:Porting a Golang and Rust CLI tool to D by PudgePacket on Thursday August 20, 2020 @06:27AM (#24221785)
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 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....

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

Re:Porting a Golang and Rust CLI tool to D by mhh__ on Thursday August 20, 2020 @06:34AM (#24221830)
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)

Re:Porting a Golang and Rust CLI tool to D by destructionator on Thursday August 20, 2020 @08:46AM (#24222646)
> 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.

Re:Porting a Golang and Rust CLI tool to D by PudgePacket on Thursday August 20, 2020 @10:13AM (#24223448)
Oh boy I definitely understand you, in fact I built a Rust CLI tool to solve exactly that ;) https://github.com/tbillington/kondo
Re:Porting a Golang and Rust CLI tool to D by eggy on Thursday August 20, 2020 @09:31AM (#24223014)
The 3kb demoscene example is just to open a window, not a full, self-contained 64k demo in 3kb. Is the program basically calling the Win API through unsafe functions? I am trying to learn Rust, and I am wondering how it might actually be used here or more beneficial than C in this case if it is all done "unsafe"? I am still comparing Zig and Rust to see which I am going to go with. I don't think I'll ever give up C though.
Re:Porting a Golang and Rust CLI tool to D by littlestymaar on Thursday August 20, 2020 @11:00AM (#24223980)
> I am still comparing Zig and Rust to see which I am going to go with

This is really puzzling to me: in what context are you working to have hesitations between Rust and Zig? One is a production language, the other is an exciting experimental language mostly written by a single genius. Go for Zig if you want to have fun, and Rust if you want to actually build something. It's like hesitating between Kotlin and Idris!

Re:Porting a Golang and Rust CLI tool to D by eggy on Friday August 21, 2020 @05:30AM (#24233413)
For a low-level, systems programming language it really comes down to Rust and Zig if you are migrating from C. I like Idris, but I don't see it in this category, nor Kotlin, although Kotlin Native perhaps? Yes, Zig is exciting! I find it easier than Rust and I have given both equal time so far.
Re:Porting a Golang and Rust CLI tool to D by deckarep on Thursday August 20, 2020 @03:29PM (#24227631)
Haha at: written by a single genius. And so true.
Re:Porting a Golang and Rust CLI tool to D by steveklabnik on Thursday August 20, 2020 @09:37AM (#24223080)
That post is, but https://www.codeslow.com/2020/07/writing-winning-4k-intro-in... is a 4k demo.

And yes, a lot of it is unsafe, because it's calling into all of that stuff directly, and doing pointer arithmetic, etc. Check the post, it's good, the Conclusion section talks about this specifically.

Re:Porting a Golang and Rust CLI tool to D by cerebellum42 on Thursday August 20, 2020 @06:58AM (#24221959)
Most likely largely because of this:

>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.

Re:Porting a Golang and Rust CLI tool to D by kibwen on Thursday August 20, 2020 @06:20AM (#24221739)
Rust, like Go, statically links everything by default, and only uses dynamic linking if you ask it to. Is D using dynamic linking here?
Re:Porting a Golang and Rust CLI tool to D by nurettin on Thursday August 20, 2020 @05:45AM (#24221560)
Rust will generate a lot of guarding code similar to what ada does.
Re:Porting a Golang and Rust CLI tool to D by mhh__ on Thursday August 20, 2020 @06:38AM (#24221844)
D also generates significant amounts of said code (unless you turn it off, obviously)

One feature D stole from Ada that is an absolutely inexcusable ommision in a modern programming is contract programming. Every time I start a new python script I end up writing helpers for function pre and postconditions because otherwise I can't rely on anything in the language's syntax.

Invariant clauses in D (e.g. this integer in my struct must be less than 5 when the struct is in a valid state) are an absolute godsend although they do not aid compiler optimisations despite some people saying otherwise (it could have changed but last time I checked the invariant does not make it's way to LLVM or GCC)

Re:Porting a Golang and Rust CLI tool to D by noch on Thursday August 20, 2020 @11:18AM (#24224157)
> One feature D stole from Ada that is an absolutely inexcusable omission in a modern programming is contract programming.

Incidentally, Walter Bright considers contracts to be a low value feature of D that he considered removing. [0][1]

[0]: https://youtu.be/p22MM1wc7xQ?t=1h34m30s

[1]: https://digitalmars.com/articles/hits.pdf

Re:Porting a Golang and Rust CLI tool to D by ponsin on Thursday August 20, 2020 @06:44AM (#24221875)
how is that different than in c/c++ simply adding asserts at the start and end of functions?
Re:Porting a Golang and Rust CLI tool to D by mhh__ on Thursday August 20, 2020 @06:48AM (#24221894)
It's the same but it's a different switch to turn it on and off.

Having separate syntax is also very useful because it's much easier to see through my usual spaghetti to find what the code is actually supposed to do in the abstract (i.e. if the string should be a valid email, check it in the in {} clause rather than in the middle of the function)

Re:Porting a Golang and Rust CLI tool to D by kibwen on Thursday August 20, 2020 @06:28AM (#24221791)
The only "guarding code" that I can think of Rust generating would be for bounds checking on array access, which isn't going to be any significant contributor to binary size.

When it comes to generated code, I can imagine the panic unwinding code being a noticeable contributor to the size of a Rust binary, but since D has exceptions I imagine the D binaries have comparable code for unwinding.

Re:Porting a Golang and Rust CLI tool to D by mhh__ on Thursday August 20, 2020 @06:54AM (#24221946)
Exception unwinding is not particularly cheap on the compiler although I think it's in the sense that it muddles the CFG and the register allocation rather than inserting huge amounts of code. The LLVM codebase has exceptions turned off for those reasons and binary size (it plays a role at their scale) although its quite hard to compare exceptions Vs error codes or monads for obvious reasons (LLVM's coding standards are rightly or wrongly a C++ sleuths dream with their custom dynamic casts etc.)
Re:Porting a Golang and Rust CLI tool to D by nurettin on Thursday August 20, 2020 @06:42AM (#24221866)
Yes, it will generate Exception unwinding and bounds checks and godbolt seems to agree. Anything else you can think of? I think D is less strict when optimizing out exception code.