A better language

Chris Nicholson-Sauls ibisbasenji at gmail.com
Mon Apr 17 10:38:38 PDT 2006


renox wrote:
> NN wrote:
> [cut]
> 
>> 2.
>> Make all postfix:
> 
> 
> One thing which could be made postfix is pointers instead of having
> *p=5; using p@=5; would be better: no need to use parenthesis to 
> distinguish between *(f()) and (*f)(), it becomes f()@ and f@() .

Its an interesting idea, although the latter case is not neccessary, I don't believe, even 
if one uses a C-style function pointer.  D automagically dereferences for member accesses 
and function/delegate invocations.

> And no need to have the C shortcut pst->field, it just becomes pst at .field

We don't have this, already.  With pointers, you just use the dot (.) operator.  Also, the 
most common occurance of pointers with fields -- class instances -- does not apply to D, 
because class variables are references.  So...

# Foo x = new Foo;
# x.field = 123;
#
# Bar* y = &foo;
# y.field = 321;
#
# assert(x.field == 321);

> Having postfix pointer dereferencing is better IMHO, what I'm not sure 
> is if postfix is better for getting the address of an object, that is 
> replacing p = &x ; by p = x.get_address; here I'm not sure that there is 
> a real advantage.

I think the address operator should be left alone.  Besides, it reads well as "address-of" 
in this position.

> I would add one point: replace C like type declaration (which sucks a 
> lot) by Pascal like type declaration.
> Pacal like type declaration still sucked because it was too verbose: C 
> terseness with Pascal like variable declaration would be ideal IMHO.
> 
> Something looking like: x: @[10]->int; (the variable x is a pointer to 
> an array of 10 int) but I've not yet thought enough about it.

// your idea: x: @[10]->int;
// currently: int[10]* x;

Knowing that in D types are read right-to-left in declerations, I really don't think we 
need this big of a change.  Especially since we do have the 'function' keyword for doing 
function pointers.

# void function (int, int) fn;
#
# void sumsqr (int dA, int dB) { return pow(dA + dB, 2); }
#
# fn = &sumsqr;

> Regards,
> Renox

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list