News for hackers. Stuff that matters.
Re:Driving with D by Diggsey on Tuesday June 01, 2021 @11:15AM (#27355663)
I used D for a while. It improves several things over C++, among them:

- More powerful metaprogramming capabilities.

- Better module and library system.

- Nicer syntax.

The problem IMO is it's just not enough to justify a total move from C++ -> D. The syntax of C++ can't really be fixed, but the other aspects can be improved without a new language.

Furthermore, many of the other downsides of C++ are still present:

- The complexity of the language, and then the sheer number of different ways of doing the same thing.

- Some pretty dark corners in the way stdlib/language feature were implemented that seemed hard to ever fix.

- The way behaviour is specified in the language is very tied to the underlying hardware: rather than explicitly describing behaviour in terms of an abstract machine, it works more in the way C++ is specified where we all know it operates on an abstract machine thanks to compiler optimizations, but the spec likes to pretend it doesn't...

And then there are problems that are introduced by D, such as the fact that a safe subset exists, but depends on GC, so there's a weird split where no "safe code" can be used in contexts where GC is unsuitable.

Contrast this to Rust, where:

- There is a true step-change in bringing safe code to all contexts, not just those where GC can be used.

- It's missing a lot of the complexity of C++. Rust is hard because it has concepts that are foreign to a lot of programmers, but the total number of features is low (compared to C++) so there are fewer surprising ways they can interact.

- Rust is a suitable replacement for C, not just C++, because it's not just adding more features.

Re:Driving with D by LAC-Tech on Tuesday June 01, 2021 @06:35PM (#27362351)
D is easy to pick up, and has three really fast compilers. It feels like a very practical language.

Rust in comparison feels much less practical - glacial compile times and byzantine rules about manging memory. It may be 'safer' but that's a moot point when I find it all so unintuitive that I'm not going to be able to make anything with it anyway.

And I really question what these situations are where you can't have garbage collection in 2021. Hard real time systems, sure, but that's not what 99% of people are using rust for. Maybe people just like the challenge.

Re:Driving with D by whatshisface on Tuesday June 01, 2021 @11:56PM (#27364664)
>And I really question what these situations are where you can't have garbage collection in 2021.

Game development, anything with a UI (GC pauses frustrate users), anything that needs high performance (scientific applications, data analysis), you name it. Ownership semantics have a side-benefit of automatic thread safety; something that is less important than memory safety (because many programs can work in one thread but almost no programs can work without allocation) but extremely valuable when needed.

Re:Driving with D by nec4b on Wednesday June 02, 2021 @02:12AM (#27365460)
>Game development

C# Unity, Lua Love 2D,...

>anything with a UI (GC pauses frustrate users)

Millions of C#, Java, Python, Javascript UI apps

>anything that needs high performance (scientific applications, data analysis)

Numpy, Julia,...

Using non garbage collected languages for 99% of apps today is a waste of time, and i'm saying this as mostly an embedded developer.

Re:Driving with D by whatshisface on Wednesday June 02, 2021 @10:22AM (#27369015)
You listed a bunch of engines written in C and C++.
Re:Driving with D by maleldil on Wednesday June 02, 2021 @02:44PM (#27372395)
How does that matter? You said "game development", not "writing a game engine". You said "data analysis", not "writing linalg algorithms", in which case we'd all have to bow to Fortran anyway.

Your argument also doesn't apply to GUI apps, anyway. C# and Java amount to a huge number of such apps, and they're self-hosted.

GC languages are vastly more productive that manual-memory languages, and for the vast majority of users, that is worth the performance hit.

Re:Driving with D by whatshisface on Wednesday June 02, 2021 @04:13PM (#27373503)
If your suggestion is, "GC languages can be used to write anything so long as whatever parts can't be written in a GC language are written in a non GC language," then yes that's true. But it's also a tautology.
Re:Driving with D by maleldil on Thursday June 03, 2021 @12:01AM (#27377082)
If you need to stay away from the GC because of some practical reason, you can always write C/C++/Rust. You implied that this is a frequent situation when it isn't. Your example of "anything with a UI" was quite a bad one.

Most projects are better off written in a GC language because the productivity benefits outweigh the performance costs.

Re:Driving with D by pkolaczk on Thursday June 03, 2021 @03:11AM (#27378076)
There is a lot being said about productivity gains from GCed languages, but can you actually point me to any research showing these gains are real?

My anecdotal, unscientific experience shows that GC is a double-edged sword that maybe makes writing simple programs slightly faster, at the expense of a much worse maintainability once the code base gets big. And non-memory resource management in GCed languages without RAII is a really huge PITA that kills all productivity gains.

GC allowed memory safety until Rust happened, and that was a big gain, but now that point is moot.

Re:Driving with D by pkolaczk on Thursday June 03, 2021 @06:51AM (#27379369)
In practice it is even not true, because there is a non-zero cost of interfacing between managed runtime and native non-managed code. Therefore not every piece of code that would theoretically benefit from writing in a non-managed language, could be actually rewritten.
Re:Driving with D by pjmlp on Wednesday June 02, 2021 @03:53PM (#27373259)
Unreal then,

https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScrip...

Or you prefer anything written in DirectX or Metal?

Chapter 5 from The Garbage Collection Handbook.

https://gchandbook.org/contents.html

Re:Driving with D by whatshisface on Wednesday June 02, 2021 @04:18PM (#27373565)
Unreal is written in C++ but, like Unity, can be scripted in other languages. Like unity it fits the "GC language for high level scripting of non-gc code" pattern. There is certainly no debate about the feasibility of implementing game logic in Lua. Reference counting in graphics drivers is not comparable to GC in Java or C# because its lack of generality permits the use of faster algorithms that don't GC pause. Swift is a workable systems language with reference counting built in, but you should bear in mind that it doesn't have "a garbage collector" per se, like you would imagine when you hear that a language is GC'd.
Re:Driving with D by pjmlp on Wednesday June 02, 2021 @04:52PM (#27373884)
Reference counting pauses when cascading deletions take place, it well known domino effect.

C# allows for GC free regions with GC.TryStartNoGCRegion, manual memory management via MarshalServices, stackalloc, Span<>() and value types.

Almost forgot Unreal C++ is GC based for entities and anything Blueprint related.

Re:Driving with D by abaga129 on Wednesday June 02, 2021 @01:26AM (#27365171)
Audio plugins is one case. Dplug disables the GC because of an issue on MacOS. So far there is no workaround so we have to write @nogc code.
Re:Driving with D by pjmlp on Wednesday June 02, 2021 @03:57PM (#27373311)
On Windows you can use C# for audio plugins.

https://docs.microsoft.com/en-us/windows/uwp/audio-video-cam...

Re:Driving with D by eggy on Tuesday June 01, 2021 @12:04PM (#27356666)
I am learning Rust and SPARK2014, and I would think SPARK2014/Ada would be a better fit for high-integrity software for verifiable, embedded software than Rust. This was the older article that stimulated me to look at Ada and then SPARK2014 again:

https://www.embedded.com/spark-2014-why-i-am-backing-a-predi...

EDIT: Cool list of SPARK2014/Ada embedded projects: https://blog.adacore.com/tag/embedded%20development

Re:Driving with D by nix23 on Tuesday June 01, 2021 @02:45PM (#27359394)
Ada is absolutely great, it's a shame that is was "closed" behind really expensive compilers and government work in the past.

GNAT Aux could use some help too:

http://www.dragonlace.net/

Re:Driving with D by nicoburns on Tuesday June 01, 2021 @12:59PM (#27357678)
That's probably true for now. But only because there's no equivalent to SPARK for Rust yet. Rust + something like SPARK could be really amazing.
Re:Driving with D by gavinray on Tuesday June 01, 2021 @01:13PM (#27357934)
There are some things that attempt to come close. Prusti by ETH Zurich is maybe the closest.

https://github.com/viperproject/prusti-dev

https://www.pm.inf.ethz.ch/research/prusti.html

    extern crate prusti_contracts;
    use prusti_contracts::*;

    #[requires(something)]
    #[ensures(result >= a && result >= b)]
    #[ensures(result == a || result == b)]
    fn max(a: i32, b: i32) -> i32 {
        if a > b {
            a
        } else {
            b
        }
    }
Ada seems like a fantastic language though, and the 202x edition brought some niceties to the language.
Re:Driving with D by eggy on Tuesday June 01, 2021 @09:21PM (#27363674)
I am an Ada/SPARK novice, but on first look Prusti seems to deal with contracts, but I am not sure how much more of the Ada/SPARK system it may covergg. I used to dislike Ada and SPARK due to their verbosity, but after studying some of the embedded work in them, and what they bring to the table, I am no longer put off by that or syntax. I've seen Julia and even Elixir projects in areas that would better suit Ada/SPARK, but I think it is due to their popularity rather than applicability. But things like Elixir's Nerves platform is very interesting in bringing the BEAM to the embedded world, and I love Pluto notebooks for Julia, but for high-integrity software I think I'll try and leverage Ada/SPARK's capabilities and pedigree for now. I will look further into Prusti this weekend.
Re:Driving with D by Jtsummers on Tuesday June 01, 2021 @01:18PM (#27358012)
Rust's type system still lacks the expressivity of Ada. Rust has a lot to teach Ada (and you see this coming out from AdaCore's blog recently with efforts to add lifetime analysis to SPARK), but Rust has a ton to learn from Ada as well.
Re:Driving with D by eggy on Tuesday June 01, 2021 @09:07PM (#27363594)
I agree, but I just turned 57 (been programming since 1978 for fun), and there is so much already done in Ada that powers SPARK that it will be a while for it to be tried and true. Although, with all the work on theorem provers and such, maybe it will be exponential and I'll be around to see it. I really like Zig too, but I am staying with Rust because of its inertia. At heart, I love J/APL, but I use them for wholly different reasons.
Re:Driving with D by philzook on Tuesday June 01, 2021 @08:04PM (#27363074)
Interesting work in that direction https://www.youtube.com/playlist?list=PL-uEDsw-7yRLYMEdlvh4u... Rust verification Workshop 2021
Re:Driving with D by brianush1 on Tuesday June 01, 2021 @12:22PM (#27356981)
> such as the fact that a safe subset exists, but depends on GC,

@safe works perfectly fine and exactly the same in @nogc code as in GC-enabled code.

Re:Driving with D by Diggsey on Tuesday June 01, 2021 @12:31PM (#27357145)
My mistake - SafeD was introduced since I stopped using D, so I was going off this article:

https://dlang.org/articles/safed.html#safed-subset

> When you enter SafeD, you leave your pointers, unchecked casts and unions at the door. Memory management is provided to you courtesy of Garbage Collection.

Does D provide the necessary tooling to be able to expose a safe API for something which needs to allocate memory, without needing a GC?

Re:Driving with D by alphaglosined on Tuesday June 01, 2021 @12:46PM (#27357438)
You are stuck with dropping to @trusted and calling the appropriate allocator API.

Following that you will want to check for null ext. to make it actually @safe in practice and not just typed as such.

Re:Driving with D by zombinedev on Wednesday June 02, 2021 @06:50AM (#27367140)
Re:Driving with D by PoignardAzur on Tuesday June 01, 2021 @04:40PM (#27360989)
That's a bit disingenuous. Memory allocations in D require either GC or non-local unsafe code.

I'm aware that D has @live, a WIP attribute that mimics Rust semantics, but it's not remotely ready for production.

Re:Driving with D by mhh__ on Tuesday June 01, 2021 @11:22AM (#27355820)
The idea that Rust is suitable to replace C and D isn't is odd to me. It's really not hard to do + we (unlike some languages, not sure about rust) actually test on embedded targets via GCC.
Re:Driving with D by Diggsey on Tuesday June 01, 2021 @11:57AM (#27356535)
What I meant by this is: if you are starting a project today, and have to choose between C and C++, there are certain reasons why you might choose C over C++.

Those same reasons would apply for choosing C over D. They might not apply for choosing C over Rust.

Re:Driving with D by mhh__ on Tuesday June 01, 2021 @12:03PM (#27356638)
I can't think of a reason that would apply here. For me at least if I were on a toolchain so crap I had to use C you'd have to pay me a lot of money not to work on something else.
Re:Driving with D by SLWW on Tuesday June 01, 2021 @02:08PM (#27358790)
All my embedded design work has been in C as i don't need all the extra cruft.

Also anything i want to be very fast on limited hardware i also use C and C only.

As for any hobby programming i do on the side, C is usually my goto choice, unless i want to be very esoteric.. following along the lines of: "The enemy of art is the absence of limitations."

Re:Driving with D by mhh__ on Tuesday June 01, 2021 @02:34PM (#27359218)
I find that C actually gets in my way compared to D when I am writing code with limited resources. The end result is semantically the same but with D I can avoid macros, inline asm is easier etc.
Re:Driving with D by SLWW on Wednesday June 02, 2021 @06:18PM (#27374732)
while this makes all the sense in the world to even a seasoned C programmer...

I've been doing it so long I could write macros in my sleep, and inline asm is a fun little exercise.

Though i absolutely agree, especially with someone newer, that could be a major road block. Might want to learn D just to be more efficient (even though I will never abandon my first love completely)

Re:Driving with D by stjohnswarts on Wednesday June 02, 2021 @12:44AM (#27364930)
Almost the only reason I would choose c over c++ for embedded would be if the c++ compiler was garbage for the platform or the team wouldn't allow it.
Re:Driving with D by haolez on Tuesday June 01, 2021 @11:36AM (#27356115)
Except that Rust compilers seem incredibly hard to implement, as opposed to C.
Re:Driving with D by pas on Tuesday June 01, 2021 @12:35PM (#27357221)
To give some perspective: mrustc is written mostly by one person, in C++ and it caught up to 1.39.0 recently - meaning it can "compile" rustc itself (without any type safety validation) as opposed to arbitrary Rust code.

Also C++ compilers are hard too. And optimizing C compilers are hard too...

Re:Driving with D by maxpert on Tuesday June 01, 2021 @12:22PM (#27356985)
That is very true but absolutely fine because then some fine set of engineers can do the hard lifting parts and rest of the ecosystem can thrive on stable base that core establishes. That is how things work in most of industries, not everybody is writing a compiler (or even suitable for writing one!), but the complexity compilers remove lets you build more complex pieces of engineering.
Re:Driving with D by echelon on Tuesday June 01, 2021 @12:01PM (#27356621)
I don't think minimal compiler complexity is a real requirement as much as safe and reliable software is.

CPU fabs aren't easy, yet we're fine with that.

Re:Driving with D by haolez on Tuesday June 01, 2021 @12:19PM (#27356942)
It matters for portability. I'm not saying it's the most important requirement, of course, but it's C strongest point.
Re:Driving with D by Zababa on Tuesday June 01, 2021 @12:33PM (#27357176)
Do you need to build an entire compiler or "just" the backend/code generation to port something? Although "just" a code generation for Rust means building one for LLVM, which I'm sure is harder than some C compilers out there.