Just an example, why D rocks, and C++ s***s...

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Thu Mar 17 13:37:47 UTC 2022


On Thursday, 17 March 2022 at 07:38:52 UTC, Carsten Schlote wrote:
> On Wednesday, 16 March 2022 at 11:56:33 UTC, bauss wrote:
>> There's also a clear difference in the philosophy of the two 
>> languages.
>>
>> D aims a lot to be general purpose, C++ aims to be flexible 
>> and usable in all areas, even low-level or obscure systems.
>
> In BetterC mode or with GC disabled you can use D for low-level 
> as well.

Sure, but there are D and C++ have different cultures, and 
actually C++ has multiple cultures (and so does D, even if the 
scale is much smaller).

So in C++ you have the original 80s/90s C++ culture of making C 
more high level, where the somewhat annoying stream concept comes 
from. That abstraction is mostly useful for prototyping (and that 
applies to most of the containers too)… but as computers have 
become more powerful C++ has become less and less sensible for 
higher level programming and other options such as Java, C# and 
TypeScript has eaten into application areas that used to be done 
in C++. When you do lower level programming in C++ you usually 
use the platform APIs and even the C-API is considered too 
abstract and limited. So, what you usually would do is that you 
encapsulate the platform specific code in you application and 
translate that limited platform dependent code to new platforms 
as you expand.

While it is tempting to think that is possible to create a 
portable file API, it actually isn't. The only reason that it 
seems possible is that POSIX has historically been a target for 
common operating systems for personal use. However, when you go 
diskless and use cloud file systems you are in a field where you 
have to do things differently. Which means major rewrites if your 
application assume a conventional file system. That said, the 
"read whole file at once" and "write whole file at once" probably 
is the most portable abstraction, but you also need to deal with 
other aspects of a file system than that (like transactional 
aspect or archiving/journaling features)… so abstractions are 
problematic and their usefulness is limited in time.

In D you have at least two different cultures, those that use D 
as a native higher level language/scripting language and those 
that use D as a C++ replacement. The more expansive standard 
library of D enables more scripting like programming, although 
there are areas where the more limited C++ standard library is 
more complete.

In short, C++ has aimed for minimalistic standard library and D 
has aimed for a Python-like standard library. There are 
advantages and disadvantages in both approaches and what makes 
most sense depends on the usage scenario.




More information about the Digitalmars-d mailing list