digitalmars.D - Debug arguments?
- bearophile (40/40) May 13 2014 Sometimes you want to give arguments to a function that are only
- Daniel Murphy (3/6) May 13 2014 I don't think this is a good idea. I've never liked code that did this
- Gary Willoughby (5/9) May 13 2014 I think i have to agree with Daniel. Without trying to sound
- bearophile (11/15) May 13 2014 I think often OOP obfuscates the actual flow of data between
- Ary Borenszweig (2/15) May 13 2014 IMHO the compiler should be able to remove the unused arguments for you.
- bearophile (5/7) May 13 2014 That doesn't happen even for global module-private functions.
- Dmitry Olshansky (4/6) May 13 2014 NO.
- Walter Bright (3/6) May 13 2014 Optional arguments interact badly with overloading. They make overloads ...
Sometimes you want to give arguments to a function that are only used for debug builds. So is it a good idea to introduce debug arguments (only allowed as trailing arguments, like the arguments with a default value)? import std.stdio; void foo(ref int x, debug int y) { x++; debug writeln(y); } void main() { int a, b; foo(a, debug b); } That is equivalent to code like: import std.stdio; debug { void foo(ref int x, int y) { x++; writeln(y); } } else { void foo(ref int x) { x++; } } void main() { int a, b; debug { foo(a, b); } else { foo(a); } } This avoids to pass useless arguments, and it documents (in the code) that certain arguments are not used in a function in non-debug builds. (The "debug" at the calling point is not necessary, but it documents better the meaning of the code). Bye, bearophile
May 13 2014
"bearophile" wrote in message news:dmpcwdctnuenxdlpfysl forum.dlang.org...Sometimes you want to give arguments to a function that are only used for debug builds. So is it a good idea to introduce debug arguments (only allowed as trailing arguments, like the arguments with a default value)?I don't think this is a good idea. I've never liked code that did this using macros, and it wasn't just because it was using macros.
May 13 2014
On Tuesday, 13 May 2014 at 09:38:51 UTC, bearophile wrote:Sometimes you want to give arguments to a function that are only used for debug builds. So is it a good idea to introduce debug arguments (only allowed as trailing arguments, like the arguments with a default value)?I think i have to agree with Daniel. Without trying to sound condescending, if you need to pass certain arguments only in debug builds something has gone terribly wrong with the design of your program. IMHO good OOP design would remove the need.
May 13 2014
Gary Willoughby:Without trying to sound condescending, if you need to pass certain arguments only in debug builds something has gone terribly wrong with the design of your program. IMHO good OOP design would remove the need.I think often OOP obfuscates the actual flow of data between functions (methods). So I even suggested to give D a kind of its opposite: https://d.puremagic.com/issues/show_bug.cgi?id=5007 In the debug build inside some functions I print some of the current state, as modified by a function. The extra arguments for the debug build are needed to produce a better or more complete print. But in release builds I'd like to avoid passing extra arguments that are useless. Bye, bearophile
May 13 2014
On 5/13/14, 2:35 PM, bearophile wrote:Gary Willoughby:IMHO the compiler should be able to remove the unused arguments for you.Without trying to sound condescending, if you need to pass certain arguments only in debug builds something has gone terribly wrong with the design of your program. IMHO good OOP design would remove the need.I think often OOP obfuscates the actual flow of data between functions (methods). So I even suggested to give D a kind of its opposite: https://d.puremagic.com/issues/show_bug.cgi?id=5007 In the debug build inside some functions I print some of the current state, as modified by a function. The extra arguments for the debug build are needed to produce a better or more complete print. But in release builds I'd like to avoid passing extra arguments that are useless. Bye, bearophile
May 13 2014
Ary Borenszweig:IMHO the compiler should be able to remove the unused arguments for you.That doesn't happen even for global module-private functions. Thank you for all the answers. Bye, bearophile
May 13 2014
13-May-2014 13:38, bearophile пишет:Sometimes you want to give arguments to a function that are only used for debug builds. So is it a good idea to introduce debug argumentsNO. -- Dmitry Olshansky
May 13 2014
On 5/13/2014 2:38 AM, bearophile wrote:Sometimes you want to give arguments to a function that are only used for debug builds. So is it a good idea to introduce debug arguments (only allowed as trailing arguments, like the arguments with a default value)?Optional arguments interact badly with overloading. They make overloads very hard to reason about, and overloading is complex enough already.
May 13 2014