A
Arne Vajhøj
Tom said:You evidently don't have the same keyboard as me!
The typing of code is usually an insignificant part of
a software project. The hard part is figuring out what
to type.
Arne
Tom said:You evidently don't have the same keyboard as me!
John said:<file name="cli/big/MegaInteger.java">
package cli.big;
import java.math.BigInteger;
public class MegaInteger {
public static final MegaInteger ZERO = new MegaInteger();
private final BigInteger value;
private MegaInteger() {
this.value = BigInteger.valueOf(0);
or[QUOTE="Lew said:this.value = BigInteger.valueOf(0);
or[QUOTE="Lew said:this.value = BigInteger.valueOf(0);
this.value = BigInteger.ZERO;
Well, not really, since in this case the number is 0, which i think is a
sufficiently well-known number that no clarity is gained by naming it.
[/QUOTE][QUOTE="Wojtek said:Well, not really, since in this case the number is 0, which i think
is a sufficiently well-known number that no clarity is gained by
naming it.
Polynomial said:Sure, that is what they all say. Then one day it bites you.
There is no run time overhead from using constants and huge benefits
for readability.
I am not saying that the value of zero will ever change, but you may
have another place where zero is used with a different meaning, which
one day does change. Now how do you determine which zero to change?
Other than going through the code line by line?
ie:
BigInteger.ZERO (== 0)
MyStuff.NO_VALUE (== 0 then changes to == -1 because 0 becaomes a
valid value)
John said:One might explicitly initialize the value to null
in the private, no-argument constructor
private MegaInteger() {
this.value = null;
}
to get something like Double.NaN:
public static final MegaInteger NaN = new MegaInteger();
I'm sure if it would be useful, but the odd value reminds me of the
ternary logic used in databases:
<http://en.wikipedia.org/wiki/Ternary_logic>
<http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/fundamentals.htm>
But I digress.
MyStuff.NO_VALUE (== 0 then changes to == -1
because 0 becaomes a valid value)
Lew said:It's not really a digression in that it fits quite well in the context
of "enhancing" the value of 'BigInteger'. It's especially relevant to
Wojtek's suggestion of
because an out-of-band value like 'null' is more immune to that kind
of refactoring than in in-band value like '0' or '-1'. (It is also
better not to change static final constants because compiler
dependencies follow different rules where they're concerned.)
I like ternary logic with UNKNOWN (sometimes called "NULL" or 'null')
for its usefulness. (Learning of it completed a lesson started back
in undergraduate logic class, finally scratching a long-standing
mental itch.) It has raised questions from some correspondents about
other possible out-of-band values - "Is it unknown because you just
haven't found out yet, because you cannot find out, or because you
don't care what you find out?" I don't know that we need additional
values as I've heard some argue, though. Would a quaternary logic be
useful, one that includes both UNKNOWN and UNIMPORTANT?
Would a quaternary logic be
useful, one that includes both UNKNOWN and UNIMPORTANT?
It's not really a digression in that it fits quite well in the context
of "enhancing" the value of 'BigInteger'. It's especially relevant to
Wojtek's suggestion of
because an out-of-band value like 'null' is more immune to that kind
of refactoring than in in-band value like '0' or '-1'. (It is also
better not to change static final constants because compiler
dependencies follow different rules where they're concerned.)
I like ternary logic with UNKNOWN (sometimes called "NULL" or 'null')
for its usefulness. (Learning of it completed a lesson started back
in undergraduate logic class, finally scratching a long-standing
mental itch.) It has raised questions from some correspondents about
other possible out-of-band values - "Is it unknown because you just
haven't found out yet, because you cannot find out, or because you
don't care what you find out?" I don't know that we need additional
values as I've heard some argue, though. Would a quaternary logic be
useful, one that includes both UNKNOWN and UNIMPORTANT?
Indeed, ternary logic has many dangers: <http://xkcd.com/246/>
In this newsgroup it's
public enum ResponseType {
YES;
NO;
JOKE;
SPELLING_TOPPOSTING_WRONG_NEWSGROUP_OR_OTHER_FLAME;
TROLL_FOOD;
ERROR_TIMEOUT;
ERROR_AIOE_DOWN_YET_AGAIN;
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.