D mentioned on Rust discussions site

Paulo Pinto pjmlp at progtools.org
Mon May 25 14:20:39 UTC 2020


On Monday, 25 May 2020 at 13:04:42 UTC, IGotD- wrote:
> On Monday, 25 May 2020 at 11:33:21 UTC, Dibyendu Majumdar wrote:
>>
>> First is memory safety - I believe the only way to write OS in 
>> D or Rust is to use unsafe constructs in parts. Arguably this 
>> can be done in C++ too - mostly use smart pointers for 
>> example, and make restricted use of unsafe code.
>
> Memory management in OS development is special and differs a 
> lot from writing normal applications. In C++, you usually don't 
> use STL at all because it is usually configured for some other 
> operating system and will not compile at all. Just including 
> std::shared_ptr will include a lot of other things and 
> compilation will fail. Second, there are hidden allocations in 
> the STL containers and you don't want those when writing 
> operating systems. With operating systems you want to control 
> every allocation in order to minimize memory use and 
> fragmentation. Linux is full of "smart pointers" ie. reference 
> counting but they are done manually. Same would be in C++, 
> reference counting is done manually. You want to minimize the 
> increase/decrease of counters in such environment, something 
> you might not care that much about in applications.
>
> There are other things that you avoid in C++, like 
> std::function that has hidden allocations. Operating systems 
> developers usually make a special library that is tailored for 
> such development. Also forget about exceptions and RTTI.
>
> Right now C++ seems to be the best fit for operating system 
> development. Extra safety like bounds checking in D is a good 
> thing but the full feature set of C++ still out-competes D as 
> you have to use betterC.
>
> The memory safety in for example Rust is just in the way when 
> writing operating systems. You have to resort to so many tricks 
> outside the safe language that it is more or less useless. Also 
> Rust is a highly annoying language when it comes many classical 
> data structures. D is in a middle spot here but lacks features 
> like full polymorphism in betterC which still makes C++ a 
> better choice.

Apparently people writing high integrity kernels in languages 
like Ada/SPARK don't find bounds checking a nuisance.

Which by the way, also applies to C and C++ written kernels via 
static analysis tooling validation like MISRA and AUTOSAR.


More information about the Digitalmars-d mailing list