• (cs)

    evil constants?

    private final int I = 1; private final int V = 5; private final int X = 10; private final int II = I + I; private final int III = I + I + I; private final int IV = V - I; private final int VI = V + I; private final int VII = V + I + I; private final int VIII = V + I + I + I; private final int IX = X - I; . . .

    • or -

    private final int l = 1; private final int l0 = l * 10; // ten private final int l00 = l0 * l0; // one-hundred private final int l000 = l0 * l0 * l0; // one-thousand private final int l000000 = l000 * l000; // one-million private final int l000000000 = l000000 * l000; // one-billion . . .

  • void (unregistered) in reply to ben

    See, here's the beauty of number constants:

    To fix string30, you just have to set

    private int TWENTYNINE = 30;
  • n_slash_a (unregistered) in reply to pjt33
    pjt33:
    ben:
    Nice. One question: We have seen number-constants many times; under what circumstances do they make sense? (I don't mean e.g. E and PI but ONE, TWO, ...) I know the first answer everyone thinks of is "if they ever change the value of 1 and 2". But my question is meant semi-seriously. (for code-generation?)
    They're sometimes handy for non-trivial types (e.g. big integers).
    To expand on this a bit, it can be handy when you want to specify types.

    static const int ONE_INT32 = 1; static const unsigned int ONE_UINT32 = 1u; static const short ONE_INT16 = 1; etc...

    I also agree that doing this is a bit extreme, I usually see it alongside other such constants like PI and FEET2METERS.

  • gnasher729 (unregistered) in reply to jEDI
    jEDI:
    Sometimes the reason for using a billion is because the number you want is a billion?

    ONE_BILLION=1000000000 uk_gdp_in_billions = uk_gdp / ONE_BILLION

    I think he wants you to write

    NUMBER_TO_DIVIDE_GDP_IN_POUNDS_BY_TO_GET_GDP_IN_BILLION_POUNDS 1000000000 uk_gdp_in_billions = uk_gdp / NUMBER_TO_DIVIDE_GDP_IN_POUNDS_BY_TO_GET_GDP_IN_BILLION_POUNDS

  • Steve (unregistered)

    Having seen code like this, I'm really surprised that the values of the numeric constants weren't loaded from an XML configuration file.

  • Jeremy (unregistered) in reply to Medinoc
    Medinoc:
    ben:
    Nice. One question: We have seen number-constants many times; under what circumstances do they make sense? (I dont mean e.g. E and PI but ONE, TWO, ...) I know the first answer everyone thinks of is "if they ever change the value of 1 and 2". But my question is meant semi-seriously. (for code-generation?)
    It's actually a way to give lip service to a "no magic numbers" policy that mandates the use of named constants. Usually in such policies you are supposed to give meaningful names to constants such as SURNAME_COLUMN_WIDTH or SSN_BUFFER_LENGTH (or in extreme cases, NUMBER_OF_PI_IN_CIRCLE), possibly using several constants with the same value. Sometimes someone will be lazy and just use a constant named after the number they wanted. This completely defeats the purpose of the policy, it's just as bad as using the member directly.

    Indeed. They THINK this qualifies, but it's the exact same problem pushed back a bit. string30(str) is really no different than string_prefix(str,30) where 30 is a magic number.

    Somewhere there should be a DESCRIPTION_PREFIX_LENGTH = 30; or whatever that imparts specific meaning to an otherwise arbitrary 30.

  • (cs) in reply to gnasher729
    gnasher729:
    jEDI:
    Sometimes the reason for using a billion is because the number you want is a billion?

    ONE_BILLION=1000000000 uk_gdp_in_billions = uk_gdp / ONE_BILLION

    I think he wants you to write

    NUMBER_TO_DIVIDE_GDP_IN_POUNDS_BY_TO_GET_GDP_IN_BILLION_POUNDS 1000000000 uk_gdp_in_billions = uk_gdp / NUMBER_TO_DIVIDE_GDP_IN_POUNDS_BY_TO_GET_GDP_IN_BILLION_POUNDS

    More likely the "in billions" version is for display purposes, so (YIHBTOIDGTJSGMAW)(*) you want:
    GDP_DISPLAY_RATIO = 1000000000
    uk_gdp_for_display = uk_gdp / GDP_DISPLAY_RATIO

    (*) Yes I Have Been Trolled Or I Didn't Get The Joke So Give Me A Whoosh.

  • Dan (unregistered) in reply to William
    William:
    How do I get in to this Highly Paid Consultant racket? I apparently have the qualifications already, as in I can use a keyboard to type in words.

    Ethicectomy required. Lobotomy helpful.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered) in reply to e1532234
    e1532234:
    This is very bad. They should have created 21 subclasses of a common superclass, each containing an object with common function name but different truncation functionality.

    Then they could instantiate a subclass object each time a truncation is needed and abandon it for garbage collection immediately afterwards. Using a factory, of course.

    It's not really object oriented if you do it otherwise.

    If they had done this in C++ they could have used templates, amirite? Or better yet, raw #define macros:

    #define String00(x,y,z) return (in.length() > x) ? in.substring(ZERO, y) : in; #define String30(x) String00(x, THIRTY, TWENTYNINE) #define String31(x) String00(x, THIRTYONE, THIRTY) ... #define String50(x) String00(x, FIFTY, FORTYNINE)

    (I figured I'd introduce them to the ?: operator to encourage future WTFs.)

    Take that, Java! #define, fuck yeah! Java droolz, C++ roolz!

  • sigh... (unregistered) in reply to William
    William:
    How do I get in to this Highly Paid Consultant racket? I apparently have the qualifications already, as in I can use a keyboard to type in words.

    If you have to ask, you can't be one. HPC know everything so they never need to ask a question!

  • The President's Daughter (unregistered)

    My father was a Highly Paid Consultant™ once, and I can assure you it was no laughing matter.

  • (cs) in reply to gnasher729
    gnasher729:
    I think he wants you to write

    NUMBER_TO_DIVIDE_GDP_IN_POUNDS_BY_TO_GET_GDP_IN_BILLION_POUNDS 1000000000 uk_gdp_in_billions = uk_gdp / NUMBER_TO_DIVIDE_GDP_IN_POUNDS_BY_TO_GET_GDP_IN_BILLION_POUNDS

    I'm patiently waiting until the moment he finds out that the preprocessor he is using truncates all constant names to the first eight characters.

    According to TV Guide, hijinks will ensue.

  • Scott (unregistered)

    I tend to assume we're doing well if Highly Paid Consultants can successfully feed themselves.

  • Paul Neumann (unregistered) in reply to Roby McAndrew
    Roby McAndrew:
    This demonstrates what a great metric lines-of-code is. Never mind the quality, feel the length!
    That's what he said?!
  • bobp2005 (unregistered) in reply to ben
    ben:
    Nice. One question: We have seen number-constants many times; under what circumstances do they make sense? (I dont mean e.g. E and PI but ONE, TWO, ...) I know the first answer everyone thinks of is "if they ever change the value of 1 and 2". But my question is meant semi-seriously. (for code-generation?)

    It can be handy to prevent certain typos and to enhance documentation. If you want to use 2 it is harder to put in THREE instead of TWO than it is to type 3 rather than 2. At least it is harder to do accidentally. Also a s/TWO/FOUR/ will likely have fewer mis-hits than s/2/4/ at least in code that I have written. And,yes it does cover you from the case where TWO is now FOUR as in "the length of an integer has changed from 2 bytes to 4.", but IMHO if you are using it like this you will probably introduce more bugs that are more obscure and hard to find than special constants.

  • Shill (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    lscharen:
    In that case I would always implement two constants, Foo.ZERO and Foo.ONE which contained static objects that represented the appropriate values for the multiplicative and additive identities, i.e. foo.times(Foo.ONE).equals(foo)
    If they are the add/mult identities, then ffs call them that, not ZERO and ONE. Otherwise the poor schmuck who is maintaining your code will wonder why you used ONE in a situation, while in "foo.times(Foo.MULT_IDENT).equals(foo)" the "times" and "MULT" should be the clue that you are doing something sane.

    While I understand where you are coming from, the OP is justified in his calling the constants ONE and ZERO. It is standard in mathematics to refer to the multiplicative identity and additive identities in a ring as 1 and 0 respectively, even if the ring doesn't contain numbers. In some cases the ring might even contain the traditional 1 and 0 and these will NOT correspond to the ring's 1 and 0.

  • Meep (unregistered) in reply to Trello
    Trello:
    Even the most naive compiler would be at least as quick doing 1+2 as ONE+TWO - if not it's trivial to identify literals and produce code like ONE=1, TWO=2 and use those instead during parsing.

    No, the most naive compiler, by definition, would not. That's what the word "naive" means.

    And it's not trivial to do so, either. You're essentially creating an interpreter for your language and running it at compile time.

  • Brendan (unregistered) in reply to faoileag
    faoileag:
    I had a peek at some code today and it was littered with the magic number "100000000". Searching for that number revealed at least one occurrence in the code where 1000000000 is used.

    Question: typo (one zero to many) or intention?

    If HUNDRED_MILLION would have been used instead of 100000000 that question would not arise.

    Humans solved this problem many centuries ago; and there are no reasons why languages couldn't use the exact same solution: magnitude suffixes. 100_M and 1_G (and their relatives 100_Mi and 1_Gi) are all quite clear and distinct.

  • Evan (unregistered) in reply to Pock Suppet
    Pock Suppet:
    gnasher729:
    Indifferent:
    Yes- if your big constant is MAX_PRODUCTION_RUNS=1000000000 But not ONE_BILLION=1000000000 surely?
    For ONE_BILLION it starts making sense. There's a good chance of a fatal typo if you repeat that constant. Would be nice if underscore characters were allowed in numbers; 1_000_000_000 is much more likely to be correct than 10000000000.
    No, it doesn't. There has to be a reason you're using 1 billion instead of 10 billion or 100 million; work that into your constant name.

    MAX_AIRSPEED_OF_AN_UNLADEN_SWALLOW_IN_MICROMETERS_PER_HALF_HOUR=1000000000

    Working the units in doesn't do anything to help solve the problem, which is you (or at least I) can't look at 1000000000 and tell immediately what it is. 1 billion? 100 million? 10 billion? You have to count zeroes. Come back to that code a couple weeks later? Count them again.

    If you say "MAX_AIRSPEED_BLAH_BLAH_BLAH = 1*BILLION" there is no question.

    I personally do this long before that... starting in the 10 or 100 thousands if it's an even multiple of 1000.

    gnasher729:
    For ONE_BILLION it starts making sense. There's a good chance of a fatal typo if you repeat that constant. Would be nice if underscore characters were allowed in numbers; 1_000_000_000 is much more likely to be correct than 10000000000.
    I feel like something like that is being talked about for C++1y. I've gotten a bit out of touch with that scene though.
  • (cs) in reply to Jeff Grigg
    Jeff Grigg:
    I was on a project where TWO of those Highly Paid Consultants couldn't figure out why their "string copy" function, written in C, wasn't working. They were using an assignment statement (the "=" operator) to assign one function parameter to the other. The debugger seemed to be showing them that their destination parameter had the right string value. They just couldn't figure out why it kept "disappearing" when their "string copy" function returned. I gave them some hints, but they were not listening. Eventually, after a few hours, they figured it out. :-/

    Sounds to me like they were used to Fortran. Fortran passes all arguments by reference, whereas C passes all arguments by value. You need to use a level of indirection to get back to the original data in C, but it "just works" in Fortran (this dates back to the Fortran II days in the 60's).

  • (cs) in reply to faoileag
    faoileag:
    Actually, I am a bit dissapointed. I half expected the leaked MtGox code to be todays wtf...

    Turn-around time on this site was recently proven to be about 3 years.

  • JArkinstall (unregistered) in reply to Shill

    The ring itself would never have the concept of 1 and 0 other than the multiplicative/additive identities. Representations, maybe - but then you're no longer talking about the ring itself, just a manifestation of it.

    There's no justification in using ONE and ZERO as constants. In your case, MULTIPLICATIVE_IDENTITY and ADDITIVE_IDENTITY maybe. Mathematicians use 1 and 0 because they hold intuitive sense to themselves, the reader, and it's quick to write and everyone is happy. Spelling it out as ONE or ZERO is, invariably, short-sighted and pretty stupid if you want it to actually make sense later on.

    As for the specific point of the conversation, variable/method names should hold semantic meaning, not necessarily refer to the variable itself. For an arbitrary vector, you don't have a method getTheSquareRootOfXSquaredPlusYSquared() - you use getMagnitude(), or for those still stuck in the backwards world of god-awful naming conventions, mag().

    For logic to be expressed in its most effective format - especially for future maintenance - it has to present itself logically. Shortcuts are great in derivations - Dirac and Feynman are great examples of people who think outside the box to make stuff easier to think about - but in implementation it should be a punishable crime not to be clear-cut.

    Or, in other words, if you have to explain to someone what an accessible variable/method MEANS given the name - and you've moved on since the naming restrictions of Fortran < 1991 - one of you need some education.

    Captcha: dolor - Lorem ipsum dolor sit amet.

  • (cs) in reply to Meep
    Meep:
    "I'm not even going to go into what would happen if someone passed in a null pointer."

    I'm going to take a wild assed guess that it would throw an NPE.

    TRWTF is strongly typed languages that include values you have to check for at runtime.

    Go back to Haskell

    that's a compliment

  • (cs) in reply to n_slash_a
    n_slash_a:
    pjt33:
    ben:
    Nice. One question: We have seen number-constants many times; under what circumstances do they make sense? (I don't mean e.g. E and PI but ONE, TWO, ...) I know the first answer everyone thinks of is "if they ever change the value of 1 and 2". But my question is meant semi-seriously. (for code-generation?)
    They're sometimes handy for non-trivial types (e.g. big integers).
    To expand on this a bit, it can be handy when you want to specify types.

    static const int ONE_INT32 = 1; static const unsigned int ONE_UINT32 = 1u; static const short ONE_INT16 = 1; etc...

    I also agree that doing this is a bit extreme, I usually see it alongside other such constants like PI and FEET2METERS.

    It's not so much having a number versus having a constant as it is that the name of the constant is nearly meaningless. I know what 1 is, but why is it being used?

    This makes more sense:

    static const int IQofHPC1 = 1; 
    static const unsigned int IQofHPC2 = 1u; 
    static const short IQofHPC3 = 1; 
    
  • (cs)

    TRWTF is Snoofle, for writing out a ternary operator on three separate lines. Seriously, who does that?

  • Gunslinger (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    lscharen:
    In that case I would always implement two constants, Foo.ZERO and Foo.ONE which contained static objects that represented the appropriate values for the multiplicative and additive identities, i.e. foo.times(Foo.ONE).equals(foo)
    If they are the add/mult identities, then ffs call them that, not ZERO and ONE. Otherwise the poor schmuck who is maintaining your code will wonder why you used ONE in a situation, while in "foo.times(Foo.MULT_IDENT).equals(foo)" the "times" and "MULT" should be the clue that you are doing something sane.

    +1

  • (cs) in reply to Zylon
    Zylon:
    TRWTF is Snoofle, for writing out a ternary operator on three separate lines. Seriously, who does that?
        public string stringPrefix(string str, int maxLen)
        {
            return (str == null ? null : (maxLen < 1 ? string.Empty : str.Length <= maxLen ? str : str.Substring(0, maxLen)));
        } 
  • (cs) in reply to Evan
    Evan:
    Working the units in doesn't do anything to help solve the problem, which is you (or at least I) can't look at 1000000000 and tell immediately what it is. 1 billion? 100 million? 10 billion? You have to count zeroes. Come back to that code a couple weeks later? Count them again.

    If you say "MAX_AIRSPEED_BLAH_BLAH_BLAH = 1*BILLION" there is no question.

    I personally do this long before that... starting in the 10 or 100 thousands if it's an even multiple of 1000.

    Counting zeroes is so tough!

  • (cs) in reply to Prime

    I have done something similar a few times. Back in .Net 3.5, there was no class for complex numbers, so I wrote a class to do what I needed in VB.Net. It included:

      Public ReadOnly Shared I As New clsComplex(0, 1)
      Public ReadOnly Shared Zero As New clsComplex(0, 0)
      Public ReadOnly Shared One As New clsComplex(1, 0)
    
  • Edward Meshuris (unregistered)

    But this lets you change what the values are. For example, ZERO could be 10...

  • Lord of All! (unregistered)

    I am a highly paid consultant myself, but I would never stoop to these standards!

  • (cs) in reply to Steve The Cynic
    Steve The Cynic:
    gnasher729:
    Indifferent:
    Yes- if your big constant is MAX_PRODUCTION_RUNS=1000000000 But not ONE_BILLION=1000000000 surely?
    For ONE_BILLION it starts making sense. There's a good chance of a fatal typo if you repeat that constant. Would be nice if underscore characters were allowed in numbers; 1_000_000_000 is much more likely to be correct than 10000000000.
    Ah, you want FORTRAN, then.

    The peculiarities of FORTRAN parsing mean that

          I=1000000000

    and

          I = 1 000 000 000

    are the same thing...

    And in C you can write

        I = 1, 000, 000, 000; 

    So much more obvious than the fortran. It'll compile just fine too.

    On a slight change of tack, one reason for not using magic numbers was exemplified in a codebase I worked on. There are 86,400 seconds in a day. Except in the bit of code that thought there were 84,600 seconds in a day.

    To add to the fun, 6pm was an important time. 6pm is 64,800 seconds after midnight. And yes. Somewhere those two numbers got mixed up.

  • (cs)
    MAX_AIRSPEED_OF_AN_UNLADEN_SWALLOW_IN_MICROMETERS_PER_HALF_HOUR = 1000000000 //one billion
    

    that was tough

  • (cs)

    I am already HPC mode developer here. After completing Prince 2 methodology and PMP certification, here I come.

  • Spencer (unregistered) in reply to Evan
    Evan:
    Pock Suppet:
    gnasher729:
    Indifferent:
    Yes- if your big constant is MAX_PRODUCTION_RUNS=1000000000 But not ONE_BILLION=1000000000 surely?
    For ONE_BILLION it starts making sense. There's a good chance of a fatal typo if you repeat that constant. Would be nice if underscore characters were allowed in numbers; 1_000_000_000 is much more likely to be correct than 10000000000.
    No, it doesn't. There has to be a reason you're using 1 billion instead of 10 billion or 100 million; work that into your constant name.

    MAX_AIRSPEED_OF_AN_UNLADEN_SWALLOW_IN_MICROMETERS_PER_HALF_HOUR=1000000000

    Working the units in doesn't do anything to help solve the problem, which is you (or at least I) can't look at 1000000000 and tell immediately what it is. 1 billion? 100 million? 10 billion? You have to count zeroes. Come back to that code a couple weeks later? Count them again.

    If you say "MAX_AIRSPEED_BLAH_BLAH_BLAH = 1*BILLION" there is no question.

    I personally do this long before that... starting in the 10 or 100 thousands if it's an even multiple of 1000.

    Why not use exponential notation? You know exactly how many zeroes there are then. MAX_AIRSPEED_OF_AN_UNLADEN_SWALLOW_IN_MICROMETERS_PER_HALF_HOUR = 1*10^9

    There could be problems if you have a dodgy compiler that was programmed by someone who failed primary school math and doesn't understand order of operations. 2*10^9 ends up becoming 512 billion instead of 2 billion

  • My C is better than that (unregistered) in reply to thosrtanner
    Ah, you want FORTRAN, then.

    The peculiarities of FORTRAN parsing mean that

          I=1000000000

    and

          I = 1 000 000 000

    are the same thing...

    And in C you can write

        I = 1, 000, 000, 000; 

    So much more obvious than the fortran. It'll compile just fine too.

    You're kidding, right? In C, you can write

        I = 1, 000, 000, 000; 

    but it doesn't mean what you think. I gets assigned the value 1 and the comma operators effectively cause the 0's to be ignored.

  • (cs) in reply to My C is better than that
    My C is better than that:

    And in C you can write

        I = 1, 000, 000, 000; 

    So much more obvious than the fortran. It'll compile just fine too.

    You're kidding, right? In C, you can write

        I = 1, 000, 000, 000; 

    but it doesn't mean what you think. I gets assigned the value 1 and the comma operators effectively cause the 0's to be ignored.

    I didn't say it'd do what you wanted to. I just said it'd compile. I'm not quite as daft as you think.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered) in reply to herby
    herby:
    Sounds to me like they were used to Fortran. Fortran passes all arguments by reference, whereas C passes all arguments by value. You need to use a level of indirection to get back to the original data in C, but it "just works" in Fortran (this dates back to the Fortran II days in the 60's).
    FORTRAN can make some quality WTFs when the compiler compiles constant parameters as anonymous initialized variables, and re-uses them in multiple places. Being able to change the value of the number "1" globally with call-by-reference is always great for pranks and jokes.
  • Met (unregistered) in reply to faoileag

    Lines of code is a great metric to use - as long as no one knows you are using it. Anytime a metric is known programmers will game it hard.

    You can find high performers and low performers based on how little or how much code they write. Some high performers write a lot of code and some write a little code. Some low performers write a little code and some write a lot of code. Normally, these two groups do not end up with an average amount of code. You can use these stats as hint to look at the actual code to judge it.

  • Kyle Huff (unregistered) in reply to faoileag
    faoileag:
    e1532234:
    Using a factory, of course.

    It's not really object oriented if you do it otherwise.

    I like the idea...

    IStringTrimmerFactory factory = new StringTrimmerFactory();
    IStringTrimmer strTrimmer42 = factory.createStringTrimmer(FORTYTWO);
    String strW42Chars = strTrimmer42.trim('The quick brown fox jumped over the lazy dolor sit amet');
    // do something with strW42Chars...
    

    .NET port using XML. IDispose rulez all. using(StringTrimmerFactory factory = new StringTrimmerFactory()) { XmlNode nodes = xmlDoc.SelectSingleNodes(string.Format("numbers//number[@id={0}]", FORTYTWO); try { int size = int32.Parse(node.Attributes.GetNamedItem("value").Value); using (IStringTrimmer strTrimmer42 = ((IStringTrimmerFactory)factory).createStringTrimmer(size); {

    		String strW42Chars = strTrimmer42.trim('The quick brown fox jumped over the lazy dolor sit amet');
    		...
    	}
    }
    catch (...)
    {
    }
    

    }

    Could probably be improved with XML and regular expressions, but I'll leave that to someone else.

  • Jeff Grigg (unregistered) in reply to herby
    herby:
    Jeff Grigg:
    I was on a project where TWO of those Highly Paid Consultants couldn't figure out why their "string copy" function, written in C, wasn't working. ...

    Sounds to me like they were used to Fortran. ...

    Actually, they were COBOL "experts."

    Later, I replaced their stupid external C function with the equivalent Microfocus COBOL native functionality. "Learn to read the manual!" dudes. :-/

    (I normally do C, C++, Java, C#, etc. But I have used more primitive technologies to pay the bills sometimes.)

  • (cs)

    It's not like they could have just done

    function stringPrefix(str, len) {
        if (str) return str.substr(0, len);
        return null;
    }
    

    or just called str.substr() wherever they needed it.

  • Cheong (unregistered) in reply to ben
    ben:
    Nice. One question: We have seen number-constants many times; under what circumstances do they make sense? (I dont mean e.g. E and PI but ONE, TWO, ...) I know the first answer everyone thinks of is "if they ever change the value of 1 and 2". But my question is meant semi-seriously. (for code-generation?)
    One thing I can think of is DCB stopbit constants to show the legal values that can be passed into the structure, but then an enum with explicit index could have done a better job.
  • (cs)

    Wait, I was always under the impression that any decent compiler (VS, say) would take something like "int num = 3*47 + 121;" and do the calculation during compilation so the generated assembly code only contained "num dw 262".

    I might have to go back and touch up a few things...

  • Felt Tip (unregistered) in reply to faoileag

    In a case like that I would use something like

    static const long MAX_PRODUCTION_RUNS = 100 * 1000 * 1000;

    The compiler will resolve it to the same value at code generation time, but the intention is much clearer, similar to how 100,000,000 is a lot more readily human-parsable than 100000000.

  • Julian (unregistered) in reply to gnasher729
    Would be nice if underscore characters were allowed in numbers;
    The Ada programming language allowed that.
  • Le Forgeron (unregistered)

    About ONE_BILLION... which side of the pond is it, and is it old enough ?

    It seems north America has it at 1e+9 whereas old English granny took it at 1e+12. (depend on long vs short scale... )

  • Clev (unregistered)

    Reminds me of my Atari BASIC days.

    A1=1:A2=A1+A1:A3=A2+A1:A4=A2+A2:A5=A3+A2, etc..
  • Jurjen (unregistered) in reply to lscharen

    That is cheating a bit: in a ring, the "numbers" 0 and 1 are actually not numbers, but ring elements named 0 and 1. So there is a very good reason to have constants called ZERO and ONE, but there are not just 0.0 and 1.0

  • Anonymous Coward (unregistered) in reply to ben

    Not sure if this answers your question.

    ONE == 1, TWO == 2 etc. don't make much sense. But numeric consts such as MAX_BUFFER_SIZE = 1024 * 64, MIN_PASSWORD_LENGTH = 6 etc. do make sense.

    Essentially, you should have a constant when it contains a number which is arbitrary, from the implementation's point of view, and might be changed at will by the business side decision makers. If you do use constants, you should name them according to what they are used for, not what they contain.

Leave a comment on “Screwing Up the Screw Up”

Log In or post as a guest

Replying to comment #:

« Return to Article