February 02, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Y.Tomino | I always liked this from delphi , but as has been discussed prolly not for D. Good ideas though keep em coming. C "Y.Tomino" <demoonlit@inter7.jp> wrote in message news:bvhb5v$2uc4$1@digitaldaemon.com... > Many functions are written as follows: > > int func(...) > { > int result; > ... > result = ... > ... > return result; > } > > I feel it's needless bother. > I prefer auto-declared "result" variable like Eiffel or Delphi. > > int func(...) > { > ... > result = ... > ... > } > > It simplifies code. > > And return is one of jump statements. > Although I don't dislike a jump statement, I don't want to use it where jump > is unnecessary. > Even if result introduced, the compatibility will be kept if return will set > result before exit. > > Thanks. > YT > |
February 02, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | In article <bvjken$k2t$1@digitaldaemon.com>, Andy Friesen says... > >Y.Tomino wrote: > >> >> And return is one of jump statements. >> Although I don't dislike a jump statement, I don't want to use it where jump >> is unnecessary. >> Even if result introduced, the compatibility will be kept if return will set >> result before exit. >> >> Thanks. >> YT >> > >I think everybody can agree that it's just sugar, which is fine, really. > Everything above machine code is technically sugar, it's just a matter >of how much work that sugar does for you. > >Is there any case where adding this to the language would save more than two lines of code? Two very simple, obvious lines of code, no less. I don't think so. So, to be blunt, why bother? > > -- andy And so it should be possible for an IDE to not only add the braces, but the declaration and return statements as well. Howsabout that? |
February 02, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | In article <bvjs4s$11bf$1@digitaldaemon.com>, Sean L. Palmer says... > >If you want to boost that, do a one-character reply next time. ;) > >Sean > >Matthew wrote: >| It does nothing for my ego control that my succinct, but entirely >| on-point, response has spawned discussion at a current ratio of 86:3. >| >| :) > > Is there a WingDing or Unicode character of "the finger"? |
February 03, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to The Lone Haranguer | > Is there a WingDing or Unicode character of "the finger"?
? ?
peek...
|
February 03, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Serge K Attachments:
| grr... encodings... ✌ ☠ 270Ch, 2620h |
February 05, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Y.Tomino | Y.Tomino wrote: > "return" has two functions(return value and exit), > I think it's unnatural syntax sugar that makes redundant code. It's not even "sugar"... I think return variable syntax is also natural because space for return variable is pre-allocated on the stack, and it gives you the feeling and the compiler the ease to write into it directly. C/C++ must do return optimisation for that. > However, as you wrote, in the language which already has return, it's > unavoidable that another method seems to pointless. > Thank you. I doesn't seem to be true. Delphi has 4 ways of returning a result: - assign to function name, which is an implicit return variable, then wait for function exit. I think it breaks when used within classes. - assign to implicit varible Return, then wait for function exit. This is used most often. - return a value directly using a return statement. - assign to one of the abovenamed imlicit return variables, then exit function with a return statement without value, IIRC. Delphi makes strong compile-time control to ensure that each function returns a valid result, but Walter finds such things annoying because they sometimes go wrong. Thus the no return assertion and this design will probably be held - although it's not of much advantage IMHO. -eye |
February 05, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | >Is there any case where adding this to the language would save more than two lines of code? Two very simple, obvious lines of code, no less. I don't think so. So, to be blunt, why bother?
>
Hey it's two lines and two lines are two lines. As my methods are commonly very short two lines do matter.
|
February 05, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to matthias becker | matthias becker wrote: >>Is there any case where adding this to the language would save more than two lines of code? Two very simple, obvious lines of code, no less. I don't think so. So, to be blunt, why bother? >> > > > Hey it's two lines and two lines are two lines. As my methods are commonly very > short two lines do matter. I've been in the habit of writing long functions. I'm trying process data using shorter functions these days, but two lines still doesn't seem like it could be a huge savings. Can you give an example of a typical short function that you'd write (that would benefit from using result)? You could do a before and after, maybe? I've written short functions like this ... char[] toString() { if(mvalue) return "True"; else return "False"; } or bit value(){ return mvalue; } but they wouldn't even benefit from "result". Also, I'm not convinced we could be saving two lines. It seems to me we're only really saving one line. I think a real example (no ...'s) could help me understand the actual benefit of this proposal. My two cents... -- Justin http://jcc_7.tripod.com/d/ |
February 06, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | >It's not even "sugar"... Sorry, I said exaggeration. >I think return variable syntax is also natural because space for return variable is pre-allocated on the stack, and it gives you the feeling and the compiler the ease to write into it directly. C/C++ must do return optimisation for that. Yes. Pascal handle the returing area as the variable, and C's statement copy a value to the returning area. (However, although these are same when optimized, The method of Pascal looks natural to me.) > - return a value directly using a return statement. ?? Delphi don't have C-style "return" statement. > Delphi makes strong compile-time control to ensure that each function returns a valid result, but Walter finds such things annoying because they sometimes go wrong. Thus the no return assertion and this design will probably be held - although it's not of much advantage IMHO. I think no problem, because D Compiler initialize local variables to the default value. YT |
February 06, 2004 Re: How do you like result variable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Y.Tomino | Y.Tomino wrote: > Sorry, I said exaggeration. You really don't have to excuse yourself. These are all opinions. I say tons of wrong stuff. >>- return a value directly using a return statement. > > ?? > Delphi don't have C-style "return" statement. Whoops! True, i just looked up. I think it's extension by GNU Pascal and alike. So it doesn't count. > I think no problem, because D Compiler initialize local variables to the > default value. The problem is, result variable would mean that a function would have to have implicit return at the end. Currently, it is different, at the end there is an implicit debugging assertion statement, which helps guard against programming errors in functions which have multiple return points and should always return in the middle and not in the end. Implicit return would give up safety. I would believe Walter would be against, and i don't see enough merit either. Every one-liner which uses a result asseignment translates into a one-liner of return statement. For longer functions, it doesn't matter that much anyway. What could be done, is automatically pre-declare result variable and make return statement without argument return it. Would save 1 1/2 lines on longer functions, and possibly make easier to read. But i still don't see much sense. -eye |
Copyright © 1999-2021 by the D Language Foundation