www.digitalmars.com         C & C++   DMDScript  

D - ideas and questions

reply Matthias Becker <Matthias_member pathlink.com> writes:
Here are some ideas, I'm not realy sure about:

Everybody starts the name of a type with an uppercase letter. Only D's types
start with a lowercase letter. Perhaps they should start with an upper case
letter as well: Int, UInt, Char, ... .


------------------------------------------------------------------

An modifier no_side_effect micht be helpfull for optimisations. Eg, if you write
the following:

result = (x + y) * (x + y);

where everything is a suerdefined type, the operator + has to be executed twice,
as it could have side effects. With this modifier, the compiler knows that the
function (in this case the operator +) has no side effect and can use the result
of the operation twice. This is only true if the function is deterministic (it
has the same reult if the arguments are the same). So you would eigther need
another attribut "deterministic" or "no_side_effect" would guarantie that the
function is deterministc as well.

If you have the code, the Compiler might know on it's own, whether a function
has side effects or not, but if it's already compiled code, e.g. part of an
external library, the compiler has no chance to find it out. And it might be
(too?) hard to find out whether a function has side effects for the compiler.


------------------------------------------------------------------

An then I want to ask a question to Walter: Youintroduced a new Cast to D that
is realy cool, but you only use C-style casts on your own. (I look in the fildes
that came with the D-compiler). Why?

And I have another question:
As I mentioned I looked at some code of the standard-modules. In conv.d I fould
the following (from toInt):

{
if (cast(uint)v > 0x80000000)
goto Loverflow;
v = -v;
}

There are many constructs like this.

if the condition is true you jump to Loverflow (cool name :) ). There
conv_overflow() is called. And if you look at this function you see the only
thing it does is throwing an exception.

I don't get it. Instead of this strange goto you could directly call the
function or even throw directly. It seems not to have any sense.

{
if (cast(uint)v > 0x80000000)
conv_overflow(s);
v = -v;
}

This code would be as informative and wouldn't use an additional goto. goto
should only be used if there is a real reason for it not just for fun. But
perhaps I missed something.

It's the same with  goto Lerr. There only conv_error() is called which directly
throws.

I would replace 

goto Loverflow;

with

throw new ConvOverflowError(s);

or if it's too long in your opinion with

conv_overflow(s);
Nov 17 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Matthias Becker" <Matthias_member pathlink.com> wrote in message
news:bpb0i3$24nn$1 digitaldaemon.com...
 Everybody starts the name of a type with an uppercase letter. Only D's

 start with a lowercase letter. Perhaps they should start with an upper

 letter as well: Int, UInt, Char, ... .

D follows the C/C++ tradition of all keywords being lower case.
 An modifier no_side_effect micht be helpfull for optimisations. Eg, if you

 the following:

 result = (x + y) * (x + y);

 where everything is a suerdefined type, the operator + has to be executed

 as it could have side effects. With this modifier, the compiler knows that

 function (in this case the operator +) has no side effect and can use the

 of the operation twice. This is only true if the function is deterministic

 has the same reult if the arguments are the same). So you would eigther

 another attribut "deterministic" or "no_side_effect" would guarantie that

 function is deterministc as well.

 If you have the code, the Compiler might know on it's own, whether a

 has side effects or not, but if it's already compiled code, e.g. part of

 external library, the compiler has no chance to find it out. And it might

 (too?) hard to find out whether a function has side effects for the

A D compiler usually has far more information about functions in different files than C/C++ compilers do. However, you are right, and some way to say that a function has no side effects is a useful property for optimization.
 An then I want to ask a question to Walter: Youintroduced a new Cast to D

 is realy cool, but you only use C-style casts on your own. (I look in the

 that came with the D-compiler). Why?

Sloth. <g>
 And I have another question:
 As I mentioned I looked at some code of the standard-modules. In conv.d I

 the following (from toInt):

 {
 if (cast(uint)v > 0x80000000)
 goto Loverflow;
 v = -v;
 }

 There are many constructs like this.

 if the condition is true you jump to Loverflow (cool name :) ). There
 conv_overflow() is called. And if you look at this function you see the

 thing it does is throwing an exception.

 I don't get it. Instead of this strange goto you could directly call the
 function or even throw directly. It seems not to have any sense.

 {
 if (cast(uint)v > 0x80000000)
 conv_overflow(s);
 v = -v;
 }

 This code would be as informative and wouldn't use an additional goto.

 should only be used if there is a real reason for it not just for fun. But
 perhaps I missed something.

 It's the same with  goto Lerr. There only conv_error() is called which

 throws.

 I would replace

 goto Loverflow;

 with

 throw new ConvOverflowError(s);

 or if it's too long in your opinion with

 conv_overflow(s);

It's a habit of mine to collect all the errors into one spot using a goto. It's not right or wrong, just a personal style.
Nov 18 2003
next sibling parent Helmut Leitner <helmut.leitner wikiservice.at> writes:
Walter wrote:
 
 It's a habit of mine to collect all the errors into one spot using a goto.
 It's not right or wrong, just a personal style.

Shared. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Nov 18 2003
prev sibling parent reply Hauke Duden <H.NS.Duden gmx.net> writes:
I would replace

goto Loverflow;


 I agree with you - a stripper is the way to go.

Is it just me, or are the discussions in this newsgroup going downhill somewhat? ;) Hauke
Nov 19 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
A couple of strippers is just what this newsgroup needs ;).

C

"Hauke Duden" <H.NS.Duden gmx.net> wrote in message
news:bpfdbf$2ihe$1 digitaldaemon.com...
I would replace

goto Loverflow;


> I agree with you - a stripper is the way to go. Is it just me, or are the discussions in this newsgroup going downhill somewhat? ;) Hauke

Nov 19 2003