D - more or less power than C++?

Walter Bright newshound at digitalmars.com
Fri Mar 3 20:02:35 PST 2006


"Andrew Fedoniouk" <news at terrainformatica.com> wrote in message 
news:dub0rk$2eje$1 at digitaldaemon.com...
> 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.

There are assign-at-compile-time and assign-once variables. What major niche 
does a guarded variable serve?

>> 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.

You can do so by only allowing private functions access to the underlying 
data. There is no notion of "const-correctness" or const as a type modifier 
in any of those languages.


> 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.

Are you suggesting D must have a preprocessor, too?


>> 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.

True, one can get into trouble doing that wrong, but it isn't conceptually 
any different from the following C++ code:

    int *p;
    void foo()
    {    int i;
        p = &i;
    }

    void test()
    {
        ... = *p;
    }

So I would not argue that it is a defect *in comparison to C++*.


> D inner classes for example - strange halfly implemented Java feature.

How so?

> Scope guards are generally good
> but without clear and strict definition of execution model - almost 
> useless - syntactic noise.

I strongly disagree there. I thought I had answered your questions about 
that in the scope guard thread.

> "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.

The private/protected stuff works like it does in C++.

> 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.

Java/C#/Python do not have lightweight and fast strings. There are some 
layers of complexity there that are hidden, but are there. 





More information about the Digitalmars-d mailing list