View mode: basic / threaded / horizontal-split · Log in · Help
June 30, 2004
Re: Why D doesn't have warnings
In article <cbsfns$2n3g$1@digitaldaemon.com>, Walter says...

>I'll go with my experience implementing the C and C++ standards - it's
>better to conform to the standards. Fixing what I consider to be suboptimal
>decisions in those standards has turned out to be a failure.

I'm shocked.  Is this another C/C++ compiler?  I thought it was supposed to be
something better.  And pardon my ignorance, but as a mere mortal programmer, I
haven't the slightest idea why

#    if (a == b) a == c;

should compile.  Sooner or later, someone is going to die over errors like that.
June 30, 2004
Re: Why D doesn't have warnings
Sean Kelly wrote:
> In article <cbqmu9$2e7$1@digitaldaemon.com>, Walter says...
> 
>>
>>"Derek Parnell" <derek@psych.ward> wrote in message
>>news:cbqep2$2nut$1@digitaldaemon.com...
>>
>>>In the code below, is the non-use of the function argument 'a' an error or
>>>not? If its an error then why does D allow it?
>>
>>It is not an error. There are many legitimate cases where one would have
>>unused arguments.
> 
> 
> I had thought that D treated unused variables as errors.  Is this not the case
> for unused arguments?  Not that I'm complaining--I agree that there are
> legitimate uses for this technique.
> 
> 
> Sean


DMD compiles either unused variables or unused arguments without complaint:


int whatever(int i, int j, int k)
{
    return 1;
}


void main()
{
    int m;
    int n;

    n = whatever(n, n, n);
}


That's fine with me. I might not want to use all of the variables or 
arguments.

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
June 30, 2004
Re: Why D doesn't have warnings
In article <cbtc94$toq$1@digitaldaemon.com>, J C Calvarese says...
>DMD compiles either unused variables or unused arguments without complaint:

I think that's just plain nuts.  Unused variables usually implies a programming
error, and a warning is most appropriate.  Of course, sometimes it means you
have just commented out some code for debugging.

Sometimes it means that you have no use for a returned argument, but I have
rarely seen code with enough warnings to be a problem.

I give up.  For a language that's supposed to be not for purists, it seems like
D is getting to be a very strange mixture of fire and purity.  Typesafe
conditional statements are too pure, but warnings are not pure enough.

I guess real programmers don't need no stinkin' warnings to tell them they
screwed up.  I'm pretty sure by that criterion I'll never qualify as a real
programmer.
June 30, 2004
Re: Why D doesn't have warnings
On Wed, 30 Jun 2004 04:12:11 +0000 (UTC), Rex Couture wrote:

> In article <cbtc94$toq$1@digitaldaemon.com>, J C Calvarese says...
>>DMD compiles either unused variables or unused arguments without complaint:
> 
> I think that's just plain nuts.  Unused variables usually implies a programming
> error, and a warning is most appropriate.  Of course, sometimes it means you
> have just commented out some code for debugging.
> 
> Sometimes it means that you have no use for a returned argument, but I have
> rarely seen code with enough warnings to be a problem.
> 
> I give up.  For a language that's supposed to be not for purists, it seems like
> D is getting to be a very strange mixture of fire and purity.  Typesafe
> conditional statements are too pure, but warnings are not pure enough.
> 
> I guess real programmers don't need no stinkin' warnings to tell them they
> screwed up.  I'm pretty sure by that criterion I'll never qualify as a real
> programmer.

I'm with you, Rex. I'm a firm believer in peer reviews and automated tools
to *assist* the coder. A compiler, to me, is supposed to be a tool to help
us poor humans. By all means, don't have the compiler /stop/ us doing
stupid things, but at least let us know when we might be doing such.

-- 
Derek
Melbourne, Australia
30/Jun/04 2:44:28 PM
June 30, 2004
Re: Why D doesn't have warnings
"Rex Couture" <Rex_member@pathlink.com> wrote in message
news:cbt6f5$l92$1@digitaldaemon.com...
> In article <cbsfns$2n3g$1@digitaldaemon.com>, Walter says...
> >I'll go with my experience implementing the C and C++ standards - it's
> >better to conform to the standards. Fixing what I consider to be
suboptimal
> >decisions in those standards has turned out to be a failure.
> I'm shocked.  Is this another C/C++ compiler?  I thought it was supposed
to be
> something better.

Yup - here I was referring not to C/C++ in particular, but to my experience
with the utility of implementing slightly non-standard compilers.

> And pardon my ignorance, but as a mere mortal programmer, I
> haven't the slightest idea why
>
> #    if (a == b) a == c;
>
> should compile.  Sooner or later, someone is going to die over errors like
that.

If a==c actually calls a function opCmp, and one is writing code that wants
to 'tickle' that function. This comes up sometimes in writing test coverage
code, or in profiling code. This can also come up in generic code if one
wants to verify that a and b are "comparable", but not care what the result
is. It can also come up as the result of the combination of various
optimizations and function inlining.
June 30, 2004
Re: Why D doesn't have warnings
"Regan Heath" <regan@netwin.co.nz> wrote in message
news:opsadrjmq55a2sq9@digitalmars.com...
> I agree, they are 2 different processes, they are only linked in that they
> look at the same imput. I think the best soln is to seperate them.
>
> It paves the way for a competitive market for good lint-like applications.

It wouldn't be hard to use the existing DMD front end source as a starting
point for such an app.
June 30, 2004
Re: Why D doesn't have warnings
On Mon, 28 Jun 2004 19:01:52 -0700, Walter <newshound@digitalmars.com> 
wrote:
>
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cbqep2$2nut$1@digitaldaemon.com...
>> In the code below, is the non-use of the function argument 'a' an error 
>> or
>> not? If its an error then why does D allow it?
>
> It is not an error. There are many legitimate cases where one would have
> unused arguments.

Can you give us one or two?

The only ones I can think of are for example...

void doSomething(char *foo, int bar, int reserved)
{
..use foo and bar..
}

where reserved is for a future possible extension to this function.

Default function parameters *solve* this case IMO. Instead of the above 
you have...

void doSomething(char *foo, int bar)
{
..use foo and bar..
}

then you can extend it...

void doSomething(char *foo, int bar, long[] baz = null)
{
..use foo and bar and baz..
}

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 30, 2004
Re: Why D doesn't have warnings
On Wed, 30 Jun 2004 14:46:38 +1000, Derek Parnell <derek@psych.ward> wrote:

> On Wed, 30 Jun 2004 04:12:11 +0000 (UTC), Rex Couture wrote:
>
>> In article <cbtc94$toq$1@digitaldaemon.com>, J C Calvarese says...
>>> DMD compiles either unused variables or unused arguments without 
>>> complaint:
>>
>> I think that's just plain nuts.  Unused variables usually implies a 
>> programming
>> error, and a warning is most appropriate.  Of course, sometimes it 
>> means you
>> have just commented out some code for debugging.
>>
>> Sometimes it means that you have no use for a returned argument, but I 
>> have
>> rarely seen code with enough warnings to be a problem.
>>
>> I give up.  For a language that's supposed to be not for purists, it 
>> seems like
>> D is getting to be a very strange mixture of fire and purity.  Typesafe
>> conditional statements are too pure, but warnings are not pure enough.
>>
>> I guess real programmers don't need no stinkin' warnings to tell them 
>> they
>> screwed up.  I'm pretty sure by that criterion I'll never qualify as a 
>> real
>> programmer.
>
> I'm with you, Rex. I'm a firm believer in peer reviews and automated 
> tools
> to *assist* the coder. A compiler, to me, is supposed to be a tool to 
> help
> us poor humans. By all means, don't have the compiler /stop/ us doing
> stupid things, but at least let us know when we might be doing such.

I think you should give Walter a chance to give you an example where you'd 
want to have an un-used parameter, I suspect the times you'd want one have 
all been solved by having default function parameters, see my post asking 
walter for examples, for an example if this.

To be fair an un-used parameter does not cause a crash, it might not cause 
the desired behaviour, as it's not being used to do whatever it is 
supposed to do, but, you should notice this either in a DBC out block OR 
in a unittest OR the first time you run your code.

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 30, 2004
Re: Why D doesn't have warnings
In article <opsad6jgkc5a2sq9@digitalmars.com>, Regan Heath says...
>
>On Wed, 30 Jun 2004 14:46:38 +1000, Derek Parnell <derek@psych.ward> wrote:
>
>> On Wed, 30 Jun 2004 04:12:11 +0000 (UTC), Rex Couture wrote:
>>
>>> In article <cbtc94$toq$1@digitaldaemon.com>, J C Calvarese says...
>>>> DMD compiles either unused variables or unused arguments without 
>>>> complaint:
>>>
>>> I think that's just plain nuts.  Unused variables usually implies a 
>>> programming
>>> error, and a warning is most appropriate.  Of course, sometimes it 
>>> means you
>>> have just commented out some code for debugging.
>>>
>>> Sometimes it means that you have no use for a returned argument, but I 
>>> have
>>> rarely seen code with enough warnings to be a problem.
>>>
>>> I give up.  For a language that's supposed to be not for purists, it 
>>> seems like
>>> D is getting to be a very strange mixture of fire and purity.  Typesafe
>>> conditional statements are too pure, but warnings are not pure enough.
>>>
>>> I guess real programmers don't need no stinkin' warnings to tell them 
>>> they
>>> screwed up.  I'm pretty sure by that criterion I'll never qualify as a 
>>> real
>>> programmer.
>>
>> I'm with you, Rex. I'm a firm believer in peer reviews and automated 
>> tools
>> to *assist* the coder. A compiler, to me, is supposed to be a tool to 
>> help
>> us poor humans. By all means, don't have the compiler /stop/ us doing
>> stupid things, but at least let us know when we might be doing such.
>
>I think you should give Walter a chance to give you an example where you'd 
>want to have an un-used parameter, I suspect the times you'd want one have 
>all been solved by having default function parameters, see my post asking 
>walter for examples, for an example if this.
>
>To be fair an un-used parameter does not cause a crash, it might not cause 
>the desired behaviour, as it's not being used to do whatever it is 
>supposed to do, but, you should notice this either in a DBC out block OR 
>in a unittest OR the first time you run your code.
>
>Regan.

By all means, if there is some guaranteed mechanism to warn you of unused
variables -- whatever it is -- that's fine.  But I wonder if there is any
practical difference between this and a compiler warning.  It probably has to
warn you every time to be of any significant use.

I think Walter has a different objective than most programmers.  He wants to
sell software to someone, and doesn't want it to ever generate a warning.  Most
of us need the compiler to tell us about unused variables, most of the time.
There are simple ways of suppressing warnings if you really must.

By the way, the strict boolean issue is not going to go away.
June 30, 2004
Re: Why D doesn't have warnings
Not in reply to anyone in particular....

In C and C++, the function:

#    void f(int n) // unused parameter
#    {
#        (void) n; // note this line
#    }

will compile without error or warning, as I believe it should. That strange void
line tells the compiler *I DON'T WANT TO USE THIS VARIABLE*.

I'm in favor of unsused variables being a compile-error, unless explicitly
indicated by the programmer, as above (or using some other, D-specific, syntax).

Arcane Jill
1 2 3 4 5
Top | Discussion index | About this forum | D home