A D vs. Rust example

Don Allen donaldcallen at gmail.com
Fri Oct 21 02:46:47 UTC 2022


On Thursday, 20 October 2022 at 21:28:19 UTC, Steven 
Schveighoffer wrote:
> On 10/20/22 4:33 PM, Don Allen wrote:
>> On Thursday, 20 October 2022 at 19:51:41 UTC, surlymoor wrote:
>>> On Thursday, 20 October 2022 at 13:37:07 UTC, Don Allen wrote:
>>>> [...]
>>>
>>> Thanks for the write-up.
>>> I'm not endorsing this point of view, but I think the 
>>> argument made by Rust proponents (fanatics?) would be that 
>>> your code is unidiomatic, and your point is thereby moot.
>> 
>> Kool-aid does strange things to the human mind :-)
>
> I would caution against judgment of Rust based on a newcomer's 
> perspective, though I think it's probably a fair assessment of 
> the *ease of learning* of Rust.

I've written about 10,000 lines of Rust over several years, 
revised many times in consultation with a couple of people in the 
Rust community who were particularly helpful. I've been writing 
code professionally and otherwise for longer than most of you, 
since I'm now 80 (first line of code in 1960 -- IBM 1620 assembly 
language). I understand Rust pretty well at this point, so I 
don't think the "newcomer" description applies.

The language is more difficult to master than other I've used (a 
lot). And if you insist on never writing "unsafe", there are 
things that are simply impossible to do that are routine in more 
traditional languages.

But, much like Haskell, once you satisfy the compiler, your 
program will be correct, modulo
logic errors or doing something stupid in an "unsafe" block. You 
won't ever see a segfault due to de-referencing an uninitialized 
pointer and things of that ilk.

>
> I will note that you are not using closures in your D code, but 
> nested functions. Is there not a way to do that in Rust?

No. Nested functions don't see their enclosing environment in 
Rust.

>
> Many people discount D because their attempts to make it do the 
> things in the way they are used to result in horrible 
> performance, or weird problems.

I did run into that in D, mostly in the area of needing to be 
aware of preventing the GC from snatching strings I'd passed to C 
code (sqlite) (you and I shared that adventure last year). This 
came about in my case because I was porting C code to D, which is 
mostly very easy, but I missed this gotcha.

>
> -Steve




More information about the Digitalmars-d mailing list