Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 27, 2003 static exceptions? | ||||
---|---|---|---|---|
| ||||
While writing another post on the topic of warnings in switch statements I got an interesting idea. I'm not sure whether it is really new, so please bear with me if it has already been implemented in some language from 1965 or something ;). One of the main problems with compiler warnings is that sometimes they can hint at a coding error, but at other times they get issued for perfectly legal code that you know is right. If you're like me and lots of warnings in your code irritate you (they make it harder to find the real errors), then at one time or another you probably have changed parts of your code to prevent the warning from occuring. Or maybe switched off the warning completely using some pragma. The problem with changing your code is that you only have to do it because the compiler is "a whiny bitch". You cannot write code in what may be the best way in a particular situation. This is really only a minor issue because circumventing warnings is usually pretty easy, but it is still a valid gripe. And disabling warnings with a pragma is a hack. It can also be dangerous because many people tend to do it globally for a file (or even the whole project). So maybe they won't get the warning in another part of the code where it actually IS a mistake. Realizing that I thought about the recent tendency in new languages to mimick runtime behaviour for compile time issues. D's static asserts are just one example of that. So why not have static exceptions? I.e. the ability to "catch" warnings that occur at compile time and prevent them from being printed? The syntax would be a lot cleaner than littering the code with pragma's and at the same time it would be explicitly obvious that you know about the warning and it can be safely ignored. Here's an example of what it might look like: static try { int foo(int x) { while (x) { blahblah if (blah blah) return 3; } } } static catch(NoReturnWarning) { //ignore } or maybe the try could be implicit... int foo(int x) { while (x) { blahblah if (blah blah) return 3; } } static catch(NoReturnWarning) { //ignore } I'm still not sure whether something like this is actually a good thing. I just thought I'd write it down before it slips my mind again ;). Hauke |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hauke Duden | i always threat all warnings as errors and correct them in a way both me and the compiler are happy. a warning means he is not sure about something is fine. explain him in a nice way that it is: by solving his issue. thats best imho. proper coding is a good thing:D In article <bq624f$2iej$1@digitaldaemon.com>, Hauke Duden says... > >While writing another post on the topic of warnings in switch statements I got an interesting idea. I'm not sure whether it is really new, so please bear with me if it has already been implemented in some language from 1965 or something ;). > >One of the main problems with compiler warnings is that sometimes they can hint at a coding error, but at other times they get issued for perfectly legal code that you know is right. > >If you're like me and lots of warnings in your code irritate you (they make it harder to find the real errors), then at one time or another you probably have changed parts of your code to prevent the warning from occuring. Or maybe switched off the warning completely using some pragma. > >The problem with changing your code is that you only have to do it because the compiler is "a whiny bitch". You cannot write code in what may be the best way in a particular situation. This is really only a minor issue because circumventing warnings is usually pretty easy, but it is still a valid gripe. > >And disabling warnings with a pragma is a hack. It can also be dangerous because many people tend to do it globally for a file (or even the whole project). So maybe they won't get the warning in another part of the code where it actually IS a mistake. > >Realizing that I thought about the recent tendency in new languages to mimick runtime behaviour for compile time issues. D's static asserts are just one example of that. > >So why not have static exceptions? I.e. the ability to "catch" warnings that occur at compile time and prevent them from being printed? The syntax would be a lot cleaner than littering the code with pragma's and at the same time it would be explicitly obvious that you know about the warning and it can be safely ignored. > >Here's an example of what it might look like: > >static try >{ > int foo(int x) > { > while (x) > { > blahblah > if (blah blah) > return 3; > } > } >} >static catch(NoReturnWarning) >{ > //ignore >} > > >or maybe the try could be implicit... > > >int foo(int x) >{ > while (x) > { > blahblah > if (blah blah) > return 3; > } >} >static catch(NoReturnWarning) >{ > //ignore >} > > > >I'm still not sure whether something like this is actually a good thing. > I just thought I'd write it down before it slips my mind again ;). > > >Hauke > > |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | davepermen wrote:
>i always threat all warnings as errors and correct them in a way both me and the
>compiler are happy. a warning means he is not sure about something is fine.
>explain him in a nice way that it is: by solving his issue.
>
>thats best imho. proper coding is a good thing:D
>
>
Me to. In C++, I turn warning up to max level and put the switch "treat all warnings as errors" on. It's has saved me many problems later down the track. I've very rarely (1/1000000) found a warning/error that I couldn't fix (without using an ignore pragma). D should have need for this pragma hack (or anything similar), although I do wish that it would take on more of C++'s warnings, as error messages.
-Anderson
|
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | I havent used .76, but up to now there were no warnings, only errors is still the case ? C "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bq7tkr$2ba5$1@digitaldaemon.com... > davepermen wrote: > > >i always threat all warnings as errors and correct them in a way both me and the > >compiler are happy. a warning means he is not sure about something is fine. > >explain him in a nice way that it is: by solving his issue. > > > >thats best imho. proper coding is a good thing:D > > > > > > Me to. In C++, I turn warning up to max level and put the switch "treat all warnings as errors" on. It's has saved me many problems later down the track. I've very rarely (1/1000000) found a warning/error that I couldn't fix (without using an ignore pragma). D should have need for this pragma hack (or anything similar), although I do wish that it would take on more of C++'s warnings, as error messages. > > -Anderson > |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | no clue. haven't had any warnings myself in D as well, including 0.76.. and i think thats a good thing. eighter it should be correct code, or not. but not "uhm.. could be good, could be bad, you know?" fuzzy logic code.. what could be cool would be sort of an "implicit created data" report. like where it created implicit conversions, like.. [printout] the statement float x = width/height*2 + foo + bar; got interpreted as float = to_float( int idiv int imul 2 ) fadd foo fadd bar; [/printout] or [printout] class Obj got an implicit constructor, and destructor. [/printout] just some.. information on what the compiler did by itself. where needed, that is.. (would be great for an ide to just select a line, and get some "informations" about what the compiler thinks about it). no warnings. errors only. code is good, or bad. In article <bq8010$2et6$1@digitaldaemon.com>, Charles Sanders says... > >I havent used .76, but up to now there were no warnings, only errors is still the case ? > >C > >"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bq7tkr$2ba5$1@digitaldaemon.com... >> davepermen wrote: >> >> >i always threat all warnings as errors and correct them in a way both me >and the >> >compiler are happy. a warning means he is not sure about something is >fine. >> >explain him in a nice way that it is: by solving his issue. >> > >> >thats best imho. proper coding is a good thing:D >> > >> > >> >> Me to. In C++, I turn warning up to max level and put the switch "treat all warnings as errors" on. It's has saved me many problems later down the track. I've very rarely (1/1000000) found a warning/error that I couldn't fix (without using an ignore pragma). D should have need for this pragma hack (or anything similar), although I do wish that it would take on more of C++'s warnings, as error messages. >> >> -Anderson >> > > |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | Yea i agree I like the errors only, that would be cool for the compiler, although Im not sure where or if it makes any of these conversions, its really strongly typed which I love. C "davepermen" <davepermen_member@pathlink.com> wrote in message news:bq809l$2fc8$1@digitaldaemon.com... > no clue. haven't had any warnings myself in D as well, including 0.76.. and i think thats a good thing. eighter it should be correct code, or not. but > not "uhm.. could be good, could be bad, you know?" fuzzy logic code.. > > what could be cool would be sort of an "implicit created data" report. > > like where it created implicit conversions, like.. > [printout] > the statement float x = width/height*2 + foo + bar; > got interpreted as > float = to_float( int idiv int imul 2 ) fadd foo fadd bar; > [/printout] > > or > [printout] > class Obj got an implicit constructor, and destructor. > [/printout] > > just some.. information on what the compiler did by itself. > > where needed, that is.. (would be great for an ide to just select a line, and > get some "informations" about what the compiler thinks about it). > > no warnings. errors only. code is good, or bad. > > > In article <bq8010$2et6$1@digitaldaemon.com>, Charles Sanders says... > > > >I havent used .76, but up to now there were no warnings, only errors is still the case ? > > > >C > > > >"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bq7tkr$2ba5$1@digitaldaemon.com... > >> davepermen wrote: > >> > >> >i always threat all warnings as errors and correct them in a way both me > >and the > >> >compiler are happy. a warning means he is not sure about something is > >fine. > >> >explain him in a nice way that it is: by solving his issue. > >> > > >> >thats best imho. proper coding is a good thing:D > >> > > >> > > >> > >> Me to. In C++, I turn warning up to max level and put the switch "treat > >> all warnings as errors" on. It's has saved me many problems later down > >> the track. I've very rarely (1/1000000) found a warning/error that I > >> couldn't fix (without using an ignore pragma). D should have need for > >> this pragma hack (or anything similar), although I do wish that it would > >> take on more of C++'s warnings, as error messages. > >> > >> -Anderson > >> > > > > > > |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | Oh i see , yea that would be kickass. C "davepermen" <davepermen_member@pathlink.com> wrote in message news:bq809l$2fc8$1@digitaldaemon.com... > no clue. haven't had any warnings myself in D as well, including 0.76.. and i think thats a good thing. eighter it should be correct code, or not. but > not "uhm.. could be good, could be bad, you know?" fuzzy logic code.. > > what could be cool would be sort of an "implicit created data" report. > > like where it created implicit conversions, like.. > [printout] > the statement float x = width/height*2 + foo + bar; > got interpreted as > float = to_float( int idiv int imul 2 ) fadd foo fadd bar; > [/printout] > > or > [printout] > class Obj got an implicit constructor, and destructor. > [/printout] > > just some.. information on what the compiler did by itself. > > where needed, that is.. (would be great for an ide to just select a line, and > get some "informations" about what the compiler thinks about it). > > no warnings. errors only. code is good, or bad. > > > In article <bq8010$2et6$1@digitaldaemon.com>, Charles Sanders says... > > > >I havent used .76, but up to now there were no warnings, only errors is still the case ? > > > >C > > > >"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bq7tkr$2ba5$1@digitaldaemon.com... > >> davepermen wrote: > >> > >> >i always threat all warnings as errors and correct them in a way both me > >and the > >> >compiler are happy. a warning means he is not sure about something is > >fine. > >> >explain him in a nice way that it is: by solving his issue. > >> > > >> >thats best imho. proper coding is a good thing:D > >> > > >> > > >> > >> Me to. In C++, I turn warning up to max level and put the switch "treat > >> all warnings as errors" on. It's has saved me many problems later down > >> the track. I've very rarely (1/1000000) found a warning/error that I > >> couldn't fix (without using an ignore pragma). D should have need for > >> this pragma hack (or anything similar), although I do wish that it would > >> take on more of C++'s warnings, as error messages. > >> > >> -Anderson > >> > > > > > > |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | > >i always threat all warnings as errors and correct them in a way both me and the > >compiler are happy. a warning means he is not sure about something is fine. > >explain him in a nice way that it is: by solving his issue. > > > >thats best imho. proper coding is a good thing:D > > > > > > Me to. In C++, I turn warning up to max level and put the switch "treat all warnings as errors" on. It's has saved me many problems later down the track. I've very rarely (1/1000000) found a warning/error that I couldn't fix (without using an ignore pragma). Indeed. The only one I can think of is GCC 2.X's stupid assertion that having const and non-const versions of the same operator was unwise. Thankfully 3.X does not do that. Although, you must have written a *lot* of code to come to that statistic ;) |
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | Charles Sanders wrote:
>I havent used .76, but up to now there were no warnings, only errors is
>still the case ?
>
>C
>
>
>
That's not what I meant. I like D not having warnings. (All my warnings are errors in C++, anyways). I think D should adopt more (not all) of C++'s warnings as errors (not as warnings -> which D doesn't have and Walter strongly disagrees with).
-Anderson
|
November 28, 2003 Re: static exceptions? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | Matthew Wilson wrote:
>>Me to. In C++, I turn warning up to max level and put the switch "treat
>>all warnings as errors" on. It's has saved me many problems later down
>>the track. I've very rarely (1/1000000) found a warning/error that I
>>couldn't fix (without using an ignore pragma).
>>
>>
>
>Indeed. The only one I can think of is GCC 2.X's stupid assertion that
>having const and non-const versions of the same operator was unwise.
>Thankfully 3.X does not do that.
>
>Although, you must have written a *lot* of code to come to that statistic ;)
>
>
>
Or I get a lot of error messages ;) But seriously, that’s an over exaggeration. I’ve probably seen 2 (which I can’t remember of hand).
Although I have written a lot of code -> how much is considered a lot?
Probably about 1million lines, considering that my last project was just under 100,000. I bet most of the professional programmers in this group have written much more then me. Walter would probably be over the hundreds of millions and I hope that’s not an insult :(.
But whose counting ;) One persons line is another person’s china wall.
-Anderson
|
Copyright © 1999-2021 by the D Language Foundation