Live data from Hacker News

How an Engineering Company Chose to Migrate to D

dlang.org

11–20 of 170 posts

Re: How an Engineering Company Chose to Migrate to D

#12

> Nowadays, whenever D is publicly evaluated, the younger languages Go and Rust are often brought up as alternatives. Here, we need not go into an in-depth comparison of these languages because both Rust and Go lack one feature that we rely on heavily: nested functions with access to variables in their enclosing scope. Maybe I've misunderstood, but aren't Rust's closures [1] exactly what the author is describing? Spe…

Maybe "access to variables" means write access. I know that in Java variables referenced by a lambda need to be final.

Re: How an Engineering Company Chose to Migrate to D

#13

> Nowadays, whenever D is publicly evaluated, the younger languages Go and Rust are often brought up as alternatives. Here, we need not go into an in-depth comparison of these languages because both Rust and Go lack one feature that we rely on heavily: nested functions with access to variables in their enclosing scope. Maybe I've misunderstood, but aren't Rust's closures [1] exactly what the author is describing? Spe…

Go also certainly supports this. Here's a playground example: https://play.golang.org/p/_BLguocGBRn

Re: How an Engineering Company Chose to Migrate to D

#16

> Nowadays, whenever D is publicly evaluated, the younger languages Go and Rust are often brought up as alternatives. Here, we need not go into an in-depth comparison of these languages because both Rust and Go lack one feature that we rely on heavily: nested functions with access to variables in their enclosing scope. Maybe I've misunderstood, but aren't Rust's closures [1] exactly what the author is describing? Spe…

The only difference I see is if you need recursive local functions, which is harder (but not impossible) to do with anonymous closures.

Re: How an Engineering Company Chose to Migrate to D

#17

> Nowadays, whenever D is publicly evaluated, the younger languages Go and Rust are often brought up as alternatives. Here, we need not go into an in-depth comparison of these languages because both Rust and Go lack one feature that we rely on heavily: nested functions with access to variables in their enclosing scope. Maybe I've misunderstood, but aren't Rust's closures [1] exactly what the author is describing? Spe…

Closures are, but functions defined using "fn" syntax cannot capture from the environment. This is a useful feature, and I can see why people would want it, but it was considered ultimately not consistent with Rust's aims to be excellent at the low level. See [1] for more discussion of the tradeoffs and why Rust chose not to include the feature.

[1] https://users.rust-lang.org/t/inner-functions-not-closed-ove...

Re: How an Engineering Company Chose to Migrate to D

#18

D has support for nested functions: I love nested functions. It's good when you need a quick local function, and don't want to expose it to the rest of the code base. But, how do you systematically unit test nested functions?

> But, how do you systematically unit test nested functions?

You expose it.

If you want to test a local nested function, you test the enclosing function.

Re: How an Engineering Company Chose to Migrate to D

#19

> Nowadays, whenever D is publicly evaluated, the younger languages Go and Rust are often brought up as alternatives. Here, we need not go into an in-depth comparison of these languages because both Rust and Go lack one feature that we rely on heavily: nested functions with access to variables in their enclosing scope. Maybe I've misunderstood, but aren't Rust's closures [1] exactly what the author is describing? Spe…

Maybe "access to variables" means write access. I know that in Java variables referenced by a lambda need to be final.

Here's a tweak to the Go example above that demonstrates writing: https://play.golang.org/p/H9vCt93Qz2B

Here's a Rust version that does the same (without heap allocation!): https://play.rust-lang.org/?gist=bb5406062970b62088d58fb8a9f...

Re: How an Engineering Company Chose to Migrate to D

#20

> Nowadays, whenever D is publicly evaluated, the younger languages Go and Rust are often brought up as alternatives. Here, we need not go into an in-depth comparison of these languages because both Rust and Go lack one feature that we rely on heavily: nested functions with access to variables in their enclosing scope. Maybe I've misunderstood, but aren't Rust's closures [1] exactly what the author is describing? Spe…

Maybe "access to variables" means write access. I know that in Java variables referenced by a lambda need to be final.

Write access works. https://play.rust-lang.org/?gist=573c941b91657bb0dbac80c33d0...

Once "non-lexical lifetimes" lands, the inner scope won't be necessary. That may have tripped the OP up.

Post reply on HN