D - How do you like result variable ?
- "Y.Tomino" <demoonlit inter7.jp> Jan 31 2004
- Georg Wrede <Georg_member pathlink.com> Jan 31 2004
- "Matthew" <matthew.hat stlsoft.dot.org> Jan 31 2004
- "Y.Tomino" <demoonlit inter7.jp> Feb 01 2004
- Ilya Minkov <minkov cs.tum.edu> Feb 05 2004
- "Y.Tomino" <demoonlit inter7.jp> Feb 05 2004
- Ilya Minkov <minkov cs.tum.edu> Feb 06 2004
- Mark T <Mark_member pathlink.com> Feb 01 2004
- Roel Mathys <roel.mathys yucom.be> Feb 01 2004
- The one Haranguer <The_member pathlink.com> Feb 01 2004
- "Sean L. Palmer" <palmer.sean verizon.net> Feb 01 2004
- "Matthew" <matthew.hat stlsoft.dot.org> Feb 01 2004
- Roel Mathys <roel.mathys yucom.be> Feb 01 2004
- "Sean L. Palmer" <palmer.sean verizon.net> Feb 01 2004
- "Matthew" <matthew.hat stlsoft.dot.org> Feb 01 2004
- The Lone Haranguer <The_member pathlink.com> Feb 02 2004
- "Serge K" <skarebo programmer.net> Feb 02 2004
- "Serge K" <skarebo programmer.net> Feb 02 2004
- Juan C <Juan_member pathlink.com> Jan 31 2004
- Roel Mathys <roel.mathys yucom.be> Feb 01 2004
- Stephan Wienczny <wienczny web.de> Feb 01 2004
- Roel Mathys <roel.mathys yucom.be> Feb 01 2004
- Georg Wrede <Georg_member pathlink.com> Feb 01 2004
- Andy Friesen <andy ikagames.com> Feb 01 2004
- "Y.Tomino" <demoonlit inter7.jp> Feb 01 2004
- Andy Friesen <andy ikagames.com> Feb 01 2004
- Juan C <Juan_member pathlink.com> Feb 02 2004
- matthias becker <matthias_member pathlink.com> Feb 05 2004
- J C Calvarese <jcc7 cox.net> Feb 05 2004
- "C" <dont respond.com> Feb 01 2004
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
Jan 31 2004
I agree. The shorter your functions, the more you suffer from this. Borland has done a number of things right, and this is one of them. In article <bvhb5v$2uc4$1 digitaldaemon.com>, Y.Tomino says...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
Jan 31 2004
Pointless sugar. Sorry "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
is unnecessary. Even if result introduced, the compatibility will be kept if return will
result before exit. Thanks. YT
Jan 31 2004
"return" has two functions(return value and exit), I think it's unnatural syntax sugar that makes redundant code. However, as you wrote, in the language which already has return, it's unavoidable that another method seems to pointless. Thank you. YT
Feb 01 2004
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
Feb 05 2004
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
Feb 05 2004
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
Feb 06 2004
In article <bvhdr9$19n$1 digitaldaemon.com>, Matthew says...Pointless sugar. Sorry
agreed - because D is meant to attract C, C++, Java programmers that are use to a certain idiom, at this point I would find reading "result" code to be confusing after so many years of "return" I think Walter made this pretty clear when he laid out his design goals for D."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
is unnecessary. Even if result introduced, the compatibility will be kept if return will
result before exit. Thanks. YT
Feb 01 2004
Matthew wrote:Pointless sugar. Sorry
pointless remark, sorry not speaking about this particular case, but there are lots of thingies in a programming language that are meant as sugar, e.g. in D there are multiple ways of defining: - function pointers - templates - ... or delegates, and the list goes on bye, roel
Feb 01 2004
In article <bvj62m$2tvl$1 digitaldaemon.com>, Roel Mathys says...Matthew wrote:Pointless sugar. Sorry
pointless remark, sorry not speaking about this particular case, but there are lots of thingies in a programming language that are meant as sugar,
Feb 01 2004
One man's pointless is another man's crusade. It's all personal opinion, and should be taken as such. At least it didn't take much time to read his reply! Sean The one Haranguer wrote: | In article <bvj62m$2tvl$1 digitaldaemon.com>, Roel Mathys says... || || Matthew wrote: || ||| Pointless sugar. ||| ||| Sorry ||| || || pointless remark, || || sorry || || || || not speaking about this particular case, but there are lots of || thingies in a programming language that are meant as sugar, || | Ah, but not _pointless_ sugar.
Feb 01 2004
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. :) "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bvjn05$ob7$1 digitaldaemon.com...One man's pointless is another man's crusade. It's all personal opinion, and should be taken as such. At least it didn't take much time to read
reply! Sean The one Haranguer wrote: | In article <bvj62m$2tvl$1 digitaldaemon.com>, Roel Mathys says... || || Matthew wrote: || ||| Pointless sugar. ||| ||| Sorry ||| || || pointless remark, || || sorry || || || || not speaking about this particular case, but there are lots of || thingies in a programming language that are meant as sugar, || | Ah, but not _pointless_ sugar.
Feb 01 2004
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. :) "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bvjn05$ob7$1 digitaldaemon.com...One man's pointless is another man's crusade. It's all personal opinion, and should be taken as such. At least it didn't take much time to read
hisreply! Sean The one Haranguer wrote: | In article <bvj62m$2tvl$1 digitaldaemon.com>, Roel Mathys says... || || Matthew wrote: || ||| Pointless sugar. ||| ||| Sorry ||| || || pointless remark, || || sorry || || || || not speaking about this particular case, but there are lots of || thingies in a programming language that are meant as sugar, || | Ah, but not _pointless_ sugar.
see ya, rm
Feb 01 2004
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. | | :)
Feb 01 2004
k "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bvjs4s$11bf$1 digitaldaemon.com...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. | | :)
Feb 01 2004
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"?
Feb 02 2004
Is there a WingDing or Unicode character of "the finger"?
? ? peek...
Feb 02 2004
Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable grr... encodings... =E2=9C=8C =E2=98=A0 270Ch, 2620h
Feb 02 2004
I prefer auto-declared "result" variable like Eiffel or Delphi.
<snobbery> It seems to me that "scripting" languages do this, and "programming" languages require declaration of variables. D is a programming language, and I am a programmer, not a script writer. Although some scripting languages are now quite powerful (Perl and Java), and perhaps some programming languages are less powerful (C# and VB), there is still a distinction and times when a scripting language just won't cut it. </snobbery>
Jan 31 2004
Juan C wrote:I prefer auto-declared "result" variable like Eiffel or Delphi.
<snobbery> It seems to me that "scripting" languages do this, and "programming" languages require declaration of variables. D is a programming language, and I am a programmer, not a script writer. Although some scripting languages are now quite powerful (Perl and Java), and perhaps some programming languages are less powerful (C# and VB), there is still a distinction and times when a scripting language just won't cut it. </snobbery>
Delphi is a compiled language and not a "scripting" language, don't know whether this is standard pascal though. btw: its compile times are fast, really, really fast. I don't like Java, but it's rarely spoken about as a scripting language. And if I'm not mistaken efforts are underway to generate a native binary from Java source code. My scripting language of choice would be Python :-) bye, roel
Feb 01 2004
Roel Mathys wrote:Delphi is a compiled language and not a "scripting" language, don't know whether this is standard pascal though. btw: its compile times are fast, really, really fast.
Delphi uses a language called Object Pascal. It uses modules and some kind of precompilation. Stephan
Feb 01 2004
Stephan Wienczny wrote:Roel Mathys wrote:Delphi is a compiled language and not a "scripting" language, don't know whether this is standard pascal though. btw: its compile times are fast, really, really fast.
Delphi uses a language called Object Pascal. It uses modules and some kind of precompilation. Stephan
you mean each unit is precompiled into an object file and only recompiled whenever the source in it has changed? This speeds up the *generation* process, just like VC++ with precompiled headers and other languages that use some kind of modules :-) This way compilation only happens for a few files, but linking still needs to be done. or do you mean don't "don"t know whether this is standard pascal though" => I knew delphi = pascal with (borland property) object extension In the meantime I looked it up in one of my old (and I mean old) Pascal manual, and the "result" shortcut was certainly in it. bye, roel
Feb 01 2004
In article <bvingb$27ve$1 digitaldaemon.com>, Roel Mathys says...Stephan Wienczny wrote:Roel Mathys wrote:Delphi is a compiled language and not a "scripting" language, don't know whether this is standard pascal though. btw: its compile times are fast, really, really fast.
Ever since Turbo Pascal 1.0 (23 years ago) they've been very proud of having the fastest Pascal compilers, and because of the language itself, also faster than any C compiler. Object Pascal, as they call the language, is the de facto standard today. (Even if Richard Stallman &co try to belittle this factoid.)Delphi uses a language called Object Pascal. It uses modules and some kind of precompilation.
The Delphi compiler is split in two stages, a "front" and a "back". The "back" is the same for Delphi and Borland C++. (I guess Walter does the same with D and his C++ ??)In the meantime I looked it up in one of my old (and I mean old) Pascal manual, and the "result" shortcut was certainly in it.
I've always been under the impression that this was one of the original thoughts when N. Wirth published the language. One of the main ideas was to cut through unnecessary writing, where possible. The language was to be smooth, consistent, easy to learn, yet powerful enough for serious programming. Pascal is actually older than C. It was developed during the late 1960's. In my bookshelf I found "The Pascal Language" published by Helsinki University of Technology - Laboratory of Information Processing Science, 1980. The "result shortcut" is presented as an integral part of Pascal. At the end is an appendix about differences between some implementations of the day, and the result shortcut is not among them.
Feb 01 2004
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
Feb 01 2004
Everyone will call "return" as syntax sugar, supposing "result" was implemented previously. I'm sorry. YT
Feb 01 2004
Y.Tomino wrote:Everyone will call "return" as syntax sugar, supposing "result" was implemented previously.
Right. Either can be easily simulated with the other.I'm sorry.
Don't be. It's better to have the ideas out in the open than never even considered. -- andy
Feb 01 2004
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?
Feb 02 2004
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.
Feb 05 2004
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/
Feb 05 2004
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
is unnecessary. Even if result introduced, the compatibility will be kept if return will
result before exit. Thanks. YT
Feb 01 2004









Georg Wrede <Georg_member pathlink.com> 