Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #5168 > unrolled thread
| Started by | Gene Wirchenko <genew@ocis.net> |
|---|---|
| First post | 2011-06-09 23:03 -0700 |
| Last post | 2011-06-17 11:43 -0300 |
| Articles | 20 on this page of 81 — 21 participants |
Back to article view | Back to comp.lang.java.programmer
Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-09 23:03 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 07:33 +0000
Re: Call by Result Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-06-10 10:03 +0100
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 09:47 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-10 08:23 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 13:12 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-10 15:44 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-12 16:29 +0000
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-12 23:00 +0200
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-12 23:06 +0200
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-14 10:52 +0000
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-14 17:13 +0200
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-14 17:58 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-14 21:18 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-14 20:14 -0300
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-15 07:13 -0300
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-15 12:50 +0000
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-15 18:52 -0300
Re: Call by Result lewbloch <lewbloch@gmail.com> - 2011-06-15 07:06 -0700
Re: Call by Result Michael Wojcik <mwojcik@newsguy.com> - 2011-06-15 21:33 -0400
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-16 11:03 +0000
Re: Call by Result "H.J. Sander Bruggink" <sander.bruggink@uni-due.de> - 2011-06-16 13:09 +0200
Re: Call by Result Lewis Bloch <lewisbloch@google.com> - 2011-06-16 06:59 -0700
Re: Call by Result "John B. Matthews" <nospam@nospam.invalid> - 2011-06-16 23:14 -0400
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:31 -0700
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-12 14:27 -0300
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-10 07:20 -0700
Re: Call by Result Patricia Shanahan <pats@acm.org> - 2011-06-10 09:30 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:44 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:26 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-11 15:07 +0000
Re: Call by Result Abu Yahya <abu_yahya@invalid.com> - 2011-06-11 23:00 +0530
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-11 19:36 +0000
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-11 21:06 +0000
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-12 10:53 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-12 09:28 -0700
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-12 17:48 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-12 13:19 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-11 15:39 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-12 11:07 +0000
Re: Call by Result markspace <-@.> - 2011-06-12 07:02 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-12 09:39 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-14 10:29 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-14 09:14 -0700
Re: Call by Result markspace <-@.> - 2011-06-14 09:21 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-14 09:53 -0700
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-14 09:57 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:44 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:40 -0700
Re: Call by Result Patricia Shanahan <pats@acm.org> - 2011-06-10 01:30 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:45 -0700
Re: Call by Result Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-10 07:50 -0400
Re: Call by Result Silvio <silvio@moc.com> - 2011-06-10 15:35 +0200
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-10 13:56 +0000
Re: Call by Result Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-06-10 07:22 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:56 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:57 -0700
Re: Call by Result Patricia Shanahan <pats@acm.org> - 2011-06-10 13:50 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:53 -0700
Re: Call by Result Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-06-13 07:20 -0300
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-13 08:08 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-11 16:35 -0700
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-12 11:05 +0000
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:56 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-14 00:40 -0700
Re: Call by Result Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-06-11 21:18 +0000
Re: Call by Result markspace <-@.> - 2011-06-10 08:43 -0700
Re: Call by Result RedGrittyBrick <RedGrittyBrick@spamweary.invalid> - 2011-06-10 17:01 +0100
Re: Call by Result Martin Gregorie <martin@address-in-sig.invalid> - 2011-06-10 16:55 +0000
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:59 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-11 16:24 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-12 21:59 -0700
Re: Call by Result Paul Cager <paul.cager@googlemail.com> - 2011-06-13 07:53 -0700
Re: Call by Result Wojtek <nowhere@a.com> - 2011-06-14 00:43 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-10 11:55 -0700
Re: Call by Result Steven Simpson <ss@domain.invalid> - 2011-06-11 09:09 +0100
Re: Call by Result Cholo Lennon <chololennon@hotmail.com> - 2011-06-16 11:30 -0300
Re: Call by Result Paul Cager <paul.cager@googlemail.com> - 2011-06-17 02:38 -0700
Re: Call by Result Gene Wirchenko <genew@ocis.net> - 2011-06-17 12:06 -0700
Re: Call by Result lewbloch <lewbloch@gmail.com> - 2011-06-17 06:40 -0700
Re: Call by Result Cholo Lennon <chololennon@hotmail.com> - 2011-06-17 11:43 -0300
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
| From | markspace <-@.> |
|---|---|
| Date | 2011-06-12 07:02 -0700 |
| Message-ID | <it2gts$bi7$1@dont-email.me> |
| In reply to | #5232 |
On 6/12/2011 4:07 AM, Andreas Leitgeb wrote: > I guess, even the "Sz" is just the Hungarian(language) version of a > plain "S"(which in Hungarian language would be pronounced like "sh" > if not followed by a "z"). "Sz" iirc indicates that the string is zero terminated. Yes, Hungarian notation is that fine grained.
[toc] | [prev] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-06-12 09:39 -0700 |
| Message-ID | <WKWdncRx2tg6dmnQnZ2dnUVZ_jWdnZ2d@posted.palinacquisition> |
| In reply to | #5232 |
On 6/12/11 4:07 AM, Andreas Leitgeb wrote: > Peter Duniho<NpOeStPeAdM@NnOwSlPiAnMk.com> wrote: >> In Hungarian, a function would never ever be named "sMyFunction". It >> might be named something like "StrMyFunction" or "SzMyFunction" or >> "PstMyFunction", etc. depending on the actual return type. > > The only "difference" seems to be the multichar type prefix and that > the prefix starts with uppercase letter. Did I miss something? Yes. Besides the fact that the single letter "s" is not a part of the convention's pre-defined tags for string types, Hungarian requires function names to start with an upper-case letter (and indeed, for each word or type tag within a function name to be capitalized). > I guess, even the "Sz" is just the Hungarian(language) version of a > plain "S"(which in Hungarian language would be pronounced like "sh" > if not followed by a "z"). One should never confuse the actual Hungarian language with anything found in the Hungarian naming convention. The human language has absolutely nothing to do with the convention. As "markspace" says, "sz" simply means a null(zero)-terminated string. The "st" tag means a Pascal-style string. > I doubt, that the original HN would have essentially more fans than > the MS-variant. There is no one "MS-variant". The actual Hungarian convention was used within Microsoft as well, but primarily within their Applications Division (when the company was organized between "Applications" and "Systems"). It just happens that the "Systems" (non)variant is what more people have seen, because it wound up in the Windows programming API. As for which has more fans, I have no idea. But since the "Systems" variant is so awful and useless, I would guess it has very few fans. And that's probably the one you're describing as "the MS-variant". The people who continue to voluntarily use Hungarian (and there are few remaining) surely are using the original, which is actually useful and meaningful. So on that basis, I have to doubt your doubt. :) Pete
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Date | 2011-06-14 10:29 +0000 |
| Message-ID | <slrnivee05.phi.avl@gamma.logic.tuwien.ac.at> |
| In reply to | #5245 |
Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> wrote: > On 6/12/11 4:07 AM, Andreas Leitgeb wrote: >> I guess, even the "Sz" is just the Hungarian(language) version of a >> plain "S"(which in Hungarian language would be pronounced like "sh" >> if not followed by a "z"). > One should never confuse the actual Hungarian language with anything > found in the Hungarian naming convention. The human language has > absolutely nothing to do with the convention. > > As "markspace" says, "sz" simply means a null(zero)-terminated string. > The "st" tag means a Pascal-style string. Thanks to you and markspace for correcting my misbelief. In Java, there's of course no need to distinguish those ancient(*haha*) string-variants, so St and Sz as prefixes wouldn't make sense here. > As for which has more fans, I have no idea. But since the "Systems" > variant is so awful and useless, I would guess it has very few fans. > And that's probably the one you're describing as "the MS-variant". I was once "contaminated" when programming some C++ under WfW 3.11. Although I try to avoid Windows wherever possible (out of my experience/ taste, not out of "religion"), I do sometimes name a local variable like bIsSnaFu, rather than just isSnaFu. Also, my classes' fields not rarely have an "m_" prefix, and sometimes even a one-lc-letter type-code if it helps to convey the form of representation (e.g. decimal string versus int) used at that spot. I tend to see it as having further evolved from original HN in the same way as e.g. Italic has evolved from Latin.. > The > people who continue to voluntarily use Hungarian (and there are few > remaining) surely are using the original, which is actually useful and > meaningful. And I'd bet, it's just a question of personal taste than anything else. > So on that basis, I have to doubt your doubt. :) I do *not* doubt your doubt on my doubt, but don't share it, either :-)
[toc] | [prev] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-06-14 09:14 -0700 |
| Message-ID | <GPqdnTlCEuNyFWrQnZ2dnUVZ_jmdnZ2d@posted.palinacquisition> |
| In reply to | #5299 |
On 6/14/11 3:29 AM, Andreas Leitgeb wrote: > [...] > In Java, there's of course no need to distinguish those ancient(*haha*) > string-variants, so St and Sz as prefixes wouldn't make sense here. True. Instead, in Java (and .NET, Cocoa, etc.) instead we have mutable and immutable strings. (Thankfully, at least by standardizing on an encoding, APIs have also removed one other of the other ways different string objects vary in C/C++).
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-06-14 09:21 -0700 |
| Message-ID | <it81pq$h6a$1@dont-email.me> |
| In reply to | #5305 |
On 6/14/2011 9:14 AM, Peter Duniho wrote: > On 6/14/11 3:29 AM, Andreas Leitgeb wrote: >> [...] >> In Java, there's of course no need to distinguish those ancient(*haha*) >> string-variants, so St and Sz as prefixes wouldn't make sense here. > > True. Instead, in Java (and .NET, Cocoa, etc.) instead we have mutable > and immutable strings. I don't think so. String is final and immutable. You can't make a mutable object that is-a string. You can make a CharSequence mutable, and Strings are CharSequence's, but you can't make a mutable String.
[toc] | [prev] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-06-14 09:53 -0700 |
| Message-ID | <toydnYWQfriVD2rQnZ2dnUVZ_gidnZ2d@posted.palinacquisition> |
| In reply to | #5306 |
On 6/14/11 9:21 AM, markspace wrote: >> True. Instead, in Java (and .NET, Cocoa, etc.) instead we have mutable >> and immutable strings. > > I don't think so. String is final and immutable. You can't make a > mutable object that is-a string. I never said you could. I said that Java has mutable and immutable strings. The mutable string type is java.lang.StringBuilder and the immutable type is java.lang.String. (There is also, of course, the mutable java.lang.StringBuffer, which I prefer to ignore :) ). > You can make a CharSequence mutable, and Strings are CharSequence's, but > you can't make a mutable String. I never said you can "make a mutable String". I said Java has a mutable string. If and when I can use the keyword "string" in Java to refer to java.lang.String, then you can at least accuse me of vagueness. For now, your complaint rings hollow. :p Pete
[toc] | [prev] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-06-14 09:57 -0700 |
| Message-ID | <_dmdnZ182bBnD2rQnZ2dnUVZ_sGdnZ2d@posted.palinacquisition> |
| In reply to | #5305 |
On 6/14/11 9:38 AM, Stefan Ram wrote: > Peter Duniho<NpOeStPeAdM@NnOwSlPiAnMk.com> writes: >> True. Instead, in Java (and .NET, Cocoa, etc.) instead we >> have mutable and immutable strings. > > In Java there are strings and string buffers/builders. See my reply to "markspace". Both java.lang.String and java.lang.StringBuilder are "strings". > A string buffer/build is not a string, just a char sequence. A StringBuilder most certainly is a string. Just because it's not type-assignable to/from String doesn't keep it from being a string.
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-06-12 21:44 -0700 |
| Message-ID | <775bv65di5ltbe8n3iou0h1r40mgsthrk6@4ax.com> |
| In reply to | #5220 |
On Sat, 11 Jun 2011 19:36:22 +0000 (UTC), Martin Gregorie
<martin@address-in-sig.invalid> wrote:
>On Sat, 11 Jun 2011 23:00:08 +0530, Abu Yahya wrote:
>
>> On 6/11/2011 8:37 PM, Andreas Leitgeb wrote>
>>> So, actually the method here would be named sGetString(), that's fine
>>> with Java's *case*-conventions (but perhaps not with others...)
>>>
>>>
>> What does the initial "s" signify here?
>
>I think its because GW is using a variant of the so-called Hungarian
>Notation which AFAIK is a Microsoft invention, initially applied to C and
>C++.
>
>The idea is to make the name of a function or method document the type of
>object it returns by prefixing the name with an alphabet soup of
>initials, so a function returning a string might be called
>sMyFunction(). The catch with it is that, if you need to change the type
>of the returned value, you need to change all references to it as well,
>e.g if the function should rather return a pointer to the string you have
>to rename it to psMyFunction() and then hunt through the source file(s)
>changing all references to it as well.
And it is a big catch.
My prefixes do not indicate types but functions. For example,
"c" is count. "cClients" is number of clients. The type might be
short, int, or long. If I change the type, I do not change the name.
Sincerely,
Gene Wirchenko
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-06-12 21:40 -0700 |
| Message-ID | <225bv69cj14vsf18fj733vim1kl9ct5qcv@4ax.com> |
| In reply to | #5204 |
On 11 Jun 2011 15:07:12 GMT, Andreas Leitgeb
<avl@gamma.logic.tuwien.ac.at> wrote:
>Gene Wirchenko <genew@ocis.net> wrote:
[snip]
>> I have used a number of languages. One of the things that I
>> dislike about Java is the small letter first style. It is
>> particularly bothersome, because my variable naming convention often
>> has HN-like prefixes.
>
>So, actually the method here would be named sGetString(), that's fine
>with Java's *case*-conventions (but perhaps not with others...)
Actually, I do not use prefixes on method names. I have
considered it, but never done it. My prefixes do not indicate
variable type but variable use/function.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-06-10 01:30 -0700 |
| Message-ID | <nrWdnYdq2p6SS2zQnZ2dnUVZ_jednZ2d@earthlink.com> |
| In reply to | #5168 |
On 6/9/2011 11:03 PM, Gene Wirchenko wrote: > Dear Java'ers: > > I wish to call by result with a method. Is it possible? If not, > can it be easily simulated in an unnasty way? > > I am writing a simple preprocessor. I have a few spots where a > string needs to be parsed. I want to call something like this: > String ReturnString=""; > boolean DidItWork=GetString(ReturnString); > if (!DidItWork) > // too bad > It is not acceptable to have a special String value mean failure. I > want the method to be able to return any potential string. Exceptions provide an alternative. Rather than returning a didItWork boolean, return the String if it did work, and throw an exception if it did not work. In addition to allowing the method to return its primary result, it also allows for passing back more information in the case of failure, which can lead to better reporting. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-06-10 11:45 -0700 |
| Message-ID | <ggp4v6d19lue04fltqhq0906ig42qcq7so@4ax.com> |
| In reply to | #5171 |
On Fri, 10 Jun 2011 01:30:03 -0700, Patricia Shanahan <pats@acm.org>
wrote:
[snip]
>Exceptions provide an alternative. Rather than returning a didItWork
>boolean, return the String if it did work, and throw an exception if it
>did not work.
if-else does so, too, and is more compact.
>In addition to allowing the method to return its primary result, it also
>allows for passing back more information in the case of failure, which
>can lead to better reporting.
So does call-by-result, and in less space.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2011-06-10 07:50 -0400 |
| Message-ID | <ist0g3$as9$1@dont-email.me> |
| In reply to | #5168 |
On 6/10/2011 2:03 AM, Gene Wirchenko wrote:
> Dear Java'ers:
>
> I wish to call by result with a method. Is it possible? If not,
> can it be easily simulated in an unnasty way?
>
> I am writing a simple preprocessor. I have a few spots where a
> string needs to be parsed. I want to call something like this:
> String ReturnString="";
> boolean DidItWork=GetString(ReturnString);
> if (!DidItWork)
> // too bad
> It is not acceptable to have a special String value mean failure. I
> want the method to be able to return any potential string.
There are lots of ways to do what I think you want (the phrase
"call by result" is new to me). One is
class ResultHolder {
String returnString;
// ... other stuff, if desired
};
ResultHolder result = new ResultHolder();
result.returnString = ""; // if desired
boolean didItWork = getString(result);
if (didItWork)
System.out.println("Result is " + result.returnString);
else
System.err.println("Woe is me!");
The same thing, really, in a quick-and-dirty form:
String[] result = new String[1];
boolean didItWork = getString(result);
if (didItWork)
System.out.println("Result is " + result[0]);
else
System.err.println("Woe is me!");
Still another variation is to put the String and the boolean
in the same holder class (I'd be tempted to rename the boolean to
something like isValid).
Of course, there's a completely different approach:
try {
String result = getString();
System.out.println("Result is " + result);
} catch (ItsNoGoodException ex) {
System.err.println("Woe is me!");
}
... and I'm sure there are possibilities beyond these.
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | Silvio <silvio@moc.com> |
|---|---|
| Date | 2011-06-10 15:35 +0200 |
| Message-ID | <4df21db0$0$49046$e4fe514c@news.xs4all.nl> |
| In reply to | #5168 |
On 06/10/2011 08:03 AM, Gene Wirchenko wrote: > Dear Java'ers: > > I wish to call by result with a method. Is it possible? If not, > can it be easily simulated in an unnasty way? > > I am writing a simple preprocessor. I have a few spots where a > string needs to be parsed. I want to call something like this: > String ReturnString=""; > boolean DidItWork=GetString(ReturnString); > if (!DidItWork) > // too bad > It is not acceptable to have a special String value mean failure. I > want the method to be able to return any potential string. > > Sincerely, > > Gene Wirchenko This is a perfect case for the Scala Option and the Haskell Maybe construct. You could Google for them and create such a beast in Java yourself. It would be a good replacement for most places where you now use null... Silvio
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Date | 2011-06-10 13:56 +0000 |
| Message-ID | <slrniv48jr.phi.avl@gamma.logic.tuwien.ac.at> |
| In reply to | #5168 |
Stefan Ram <ram@zedat.fu-berlin.de> wrote: > Gene Wirchenko <genew@ocis.net> writes: >> I wish to call by result with a method. > I am surprised about all the answers, whose authors seems > to have understood what Gene wanted to convey with this. Ok, I admit, I was a bit confused, too, at first, but the example was good at clarifying what the OP meant.
[toc] | [prev] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-06-10 07:22 -0700 |
| Message-ID | <4DF2289B.5030909@NnOwSlPiAnMk.com> |
| In reply to | #5168 |
On 6/10/11 6:47 AM, Stefan Ram wrote: > [...] > But I was able to look it up in an online encyclopedia: > > »When the reference is passed to the callee > uninitialized, this evaluation strategy may > be called "call by result".« > > http://en.wikipedia.org/wiki/Evaluation_strategy > > Did you all knew this before you answered? The reference > has to be /uninitialized/ for an evaluation strategy to be > called "call by result"! Maybe that's true technically. But the OP's code initializes the variable before calling the method. I think it's just as likely that he's not using the term precisely as defined in your reference, and that all of the answers do get to the heart of what he's _really_ asking. That is, it seems more likely that what the OP cares about is the "modify the argument, return a boolean" aspect more than he cares about the "was the argument initialized" aspect. Pete
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-06-10 11:56 -0700 |
| Message-ID | <v4q4v692negiqpr4ohapuu0opbuis1kjql@4ax.com> |
| In reply to | #5182 |
On Fri, 10 Jun 2011 07:22:20 -0700, Peter Duniho
<NpOeStPeAdM@NnOwSlPiAnMk.com> wrote:
>On 6/10/11 6:47 AM, Stefan Ram wrote:
>> [...]
>> But I was able to look it up in an online encyclopedia:
>>
>> »When the reference is passed to the callee
>> uninitialized, this evaluation strategy may
>> be called "call by result".«
>>
>> http://en.wikipedia.org/wiki/Evaluation_strategy
>>
>> Did you all knew this before you answered? The reference
>> has to be /uninitialized/ for an evaluation strategy to be
>> called "call by result"!
>
>Maybe that's true technically. But the OP's code initializes the
>variable before calling the method. I think it's just as likely that
>he's not using the term precisely as defined in your reference, and that
>all of the answers do get to the heart of what he's _really_ asking.
Java requires initialisation.
>That is, it seems more likely that what the OP cares about is the
>"modify the argument, return a boolean" aspect more than he cares about
>the "was the argument initialized" aspect.
Yes.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-06-10 11:57 -0700 |
| Message-ID | <56q4v6h1afrmkktk7rqiolgdqqkms387tv@4ax.com> |
| In reply to | #5182 |
On 10 Jun 2011 14:37:09 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
wrote:
>Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> writes:
>>That is, it seems more likely that what the OP cares about is
>>the "modify the argument, return a boolean" aspect more than
>>he cares about the "was the argument initialized" aspect.
>
> Ok, the OP contained:
>
>>>>String ReturnString="";
>>>>boolean DidItWork=GetString(ReturnString);
>>>>if (!DidItWork)
>
> For my taste, the object-oriented way to do this is:
>
>final Getter getter = new Getter();
>getter.get();
>if( getter.isValid() )result = getter.value(); else ...
>
> , while the Java way to do this is
>
>try{ s = getString(); }
>catch( final Exception exception )...
I care about getting the job done. I use OOP when it is
appropriate and do not use it when it is not appropriate.
> . The OP used upper-case names of variables and methods,
> so he might be a beginner in Java, in which case it might be
> more appropriate for him to learn how things are natively
> done in Java than to learn how to emulate features of other
> languages (such as call by result) in Java.
I am also someone who has been programming professionally for
about twenty-five years. In that time, I have worked out conventions
across different languages for variable-naming.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-06-10 13:50 -0700 |
| Message-ID | <UrydnYJqW_8vHm_QnZ2dnUVZ_sidnZ2d@earthlink.com> |
| In reply to | #5199 |
On 6/10/2011 11:57 AM, Gene Wirchenko wrote: ... > I am also someone who has been programming professionally for > about twenty-five years. In that time, I have worked out conventions > across different languages for variable-naming. ... I much prefer to have my code in each language look like conventional code in its language. Code is not going to be more than very superficially readable by someone who does not know its language, so the reading audience is generally programmers who are familiar with the language. Those programmers will usually also be used to the corresponding conventions, and will more easily read code that follows those conventions. I'm not sure what the number of years programming has to do with anything. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-06-12 21:53 -0700 |
| Message-ID | <jk5bv6leckk75rthdbg3ds0f00u8vibnnn@4ax.com> |
| In reply to | #5201 |
On Fri, 10 Jun 2011 13:50:53 -0700, Patricia Shanahan <pats@acm.org>
wrote:
>On 6/10/2011 11:57 AM, Gene Wirchenko wrote:
>...
>> I am also someone who has been programming professionally for
>> about twenty-five years. In that time, I have worked out conventions
>> across different languages for variable-naming.
>...
>
>I much prefer to have my code in each language look like conventional
>code in its language.
Much code looks the same in multiple languages. Which language
is
a=b*c+d
in?
>Code is not going to be more than very superficially readable by someone
>who does not know its language, so the reading audience is generally
>programmers who are familiar with the language. Those programmers will
There is a lot of commonality in notation. Compare the switch
statements in C, Java, and JavaScript.
>usually also be used to the corresponding conventions, and will more
>easily read code that follows those conventions.
There are plenty of arguments over which format is best. It is
quite possible that there is no one best way. Given that, I prefer to
use something that I like.
>I'm not sure what the number of years programming has to do with anything.
It suggests that I have worked with a number of languages.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-06-13 07:20 -0300 |
| Message-ID | <HvlJp.1814$z67.488@newsfe10.iad> |
| In reply to | #5282 |
On 11-06-13 01:53 AM, Gene Wirchenko wrote: > On Fri, 10 Jun 2011 13:50:53 -0700, Patricia Shanahan <pats@acm.org> > wrote: > >> On 6/10/2011 11:57 AM, Gene Wirchenko wrote: >> ... >>> I am also someone who has been programming professionally for >>> about twenty-five years. In that time, I have worked out conventions >>> across different languages for variable-naming. >> ... >> >> I much prefer to have my code in each language look like conventional >> code in its language. > > Much code looks the same in multiple languages. Which language > is > a=b*c+d > in? Ideally none. Which brings us back to Patricia's point: what you would _actually_ use in place of 'a' tends to look different based on what language you're using. >> Code is not going to be more than very superficially readable by someone >> who does not know its language, so the reading audience is generally >> programmers who are familiar with the language. Those programmers will > > There is a lot of commonality in notation. Compare the switch > statements in C, Java, and JavaScript. [ SNIP ] There is indeed. Some constructs, like the usual assortment of control statements, are similar (or identical) across dozens of languages. Probably most competent programmers with a good deal of varied experience can parse code in quite a few languages to establish _general purpose_ of a program, including code written in languages they have never used. On the other hand, I wouldn't expect a programmer to be capable of conducting a code review unless they were familiar with the language (i.e. they could write good-quality original code in the target language). You could call the distinction above the difference between superficial and non-superficial understanding. I wouldn't attempt to classify this myself; I'd simply assert that the closer two languages are to each other in genealogy, the easier it is for a programmer who knows one of them well to understand programs written in the other. I'll bet most programmers have eventually been in situations where they are writing a program in language X and borrow implementation ideas from code examples written in language Y. You don't have to know language Y all that well in order to do this. To return to the original point, languages do have conventions. It helps to follow them. That a given language, say language X, happens to be close enough to language Y that the two share a lot of conventions (or what seems to be often the case, they deliberately don't) is not that important. What's important is to be aware of what substantive and common conventions exist for a given language. Or for that matter, for a given organization or team. Or single coder: single coders are allowed to have conventions too. To seize on one specific related to the last, a convention like the one that you follow, Hungarian notation in its original, Simonyi sense, makes a lot of sense. I've used forms of it myself. For me this is not a convention specific to a language, it's specific to a problem that's being solved. I could use it in Java or C++ or F#, and it wouldn't be wrong to use it, because it's a problem-specific tailored notation, not a language convention notation. AHS
[toc] | [prev] | [next] | [standalone]
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
Back to top | Article view | comp.lang.java.programmer
csiph-web