D - more or less power than C++?

Andrew Fedoniouk news at terrainformatica.com
Fri Mar 3 19:17:10 PST 2006


"Walter Bright" <newshound at digitalmars.com> wrote in message
news:duaqm9$25at$1 at digitaldaemon.com...
>
> "Andrew Fedoniouk" <news at terrainformatica.com> wrote in message 
> news:duajvt$1re3$1 at digitaldaemon.com...
>>> What does D have to do to have more power than C++?
>> 1) C++ has ctors/dtors for stack allocated objects. This problem
>> is known in D as luck of struct ctor/dtor.
>
> The following:
>    auto Foo f = new Foo();
> has ctor/dtor semantics. It isn't allocated on the stack at the moment, 
> but there is no semantic reason why it couldn't be. Allocating it on the 
> heap is an artifact of dmd, and not of the language.

This is not only about stack allocation but also about the whole
thing:  "- Definable assignment/copy semantics for structs. " / Oskar Linde

There is no way currently in D to implement "guarded variable":

something s = ....;

I cannot write code which will allow to catch
assignment to the variable (concrete memory region if you wish).
Just nothing for that in D at all - variables are naked.

>
>> 2) C++/C both have const.
>>
>> These two are corner stones in C++ (among others).
>> The whole std:: namespace without them is just impossible.
>>
>> I cannot imagine serious *library* design without 'const' for example.
>> Library here means design of robust code used by millions.
>> Phobos imho will never be considered as something rock-solid without
>> 'const'.
>
> I don't really understand this, as many languages have serious libraries 
> without const - such as Java, Python, C#, etc.


1) All these have builtin immutability. For example strings there
are immutable objects. D has no strings so it must have
some features in the language allowing to implement such
objects as a library.

2) D has raw pointers - D is comparable with C/C++ but not with Java.
D will not replace Java in most of cases.  Completely different execution 
model.
D in this respect is wery close to C/C++. So D competes with C/C++
but not with Java, Python or C#. And this would be extremely cool if
D can win C++. At least as language for GUI. GUI is most OOP task known.

If you can do something in C/C++ you must
be able to do it in D. This is it.

Postulate: D must include all features C++ has now.

>
>> E.g. I have tried three or four different approaches
>> to reproduce string value type in D. Just no way.
>> Everything what I've seen so far is non-comparable
>> with even std:string and I am yet silent about .NET and Java.
>
> I don't understand what you mean.

Immutable yet effective strings and ranges.

>
>> Big picture: templates (at some extent) and
>> definitely delegates are superior in D than in C++.
>> Other features are more or less elegantly reproducible in C++.
>
> Try doing nested functions elegantly in C++ <g>.

Agree, they are useful. But if used with care.
As soon as you can get address of such inner function
then you are in trouble - result of later call of such function
is non-deterministic.
It is not like in JavaScript where function frames are
valid if referenced somewhere.

Following:

var tt;
function test()
{
  var s0 = "Hello";
  function testtest()
  {
    stdout << s0;
  }
  tt = testtest;
}

test();
tt();

stdout << " World!";

will print in JS (my TIScript here) :

>Hello World!

D will GPF on something like this I guess.


>
>> D used to have clean,consistent and simple syntax and execution model
>> (e.g. GC "from the shelf") but holes 1) and 2) on the bottom of this ship
>> are just shining.
>
> I'm not sure why (1) and (2) didn't exist in the way D used to be.
>

Sorry, two different sentences here:
1) D used to have clean,consistent and simple syntax and execution model
(e.g. GC "from the shelf") - not anymore, IMO. D inner classes for example -
strange halfly implemented Java feature. Scope guards are generally good
but without clear and strict definition of execution model - almost 
useless - syntactic
noise. "auto zoo" there too.  Over-qualified 'static' All that 
private/protected stuff
is just not finished yet - I was fighting with it in Harmonia - never win.

2)  holes 1) and 2) on the bottom of this ship are just shining.
These are the only features of C++ which D cannot handle at all.

OT: I was proposing readonly ranges and pointers as a simple alternative / 
palliative
of problem #1. At least they allow to have lightweight and fast strings as 
in Java/C#/Python.

Andrew.





More information about the Digitalmars-d mailing list