• (cs)
    Alex Papadimoulis:

    In fact, now that I think about it, maybe it useful after all ... if the rate of the Earth's spin were ever to change, Daniel's coworker would have to only change PAUSE_BY_6_SECONDS from "6" to "6.23" ...

    Application.PauseSeconds := PAUSE_BY_6_SECONDS;

    The earths rate of rotation changes on a regular basis so the joke's on you!

    [;)]

  • (cs)

    :O Dude.  W.T.F.F.

    These look like the work of people who never understood the purpose of constants yet still somehow managed to remember their CS101 Prof's admonition that "literals in code are bad, use constants to define literals and use those in code."  Thus, instead of meaningful constants such as SIZE_OF_HEADER or BUFFER_SIZE you get INT_512.

  • LP (unregistered)

    You know, I was just checking about:config in my firefox, and I noticed general.config.obscure_value as well

    I found the explanation:

    The general.config.obscure_value preference specifies how the configuration file is obscured. Firefox expects that each byte in the file will be rotated by the specified value. The default value is 13. If this value is left unchanged, then the configuration file must be encoded as ROT13. Autoconfig will fail if the cfg file is not encoded as specified by this preference. A value of 0 indicates that the file is unencoded-- i.e. it is unobscured plain text. It is recommended that you set this value to 0. (This will allow you to skip the encoding step in part 3.)
  • (cs) in reply to dubwai
    dubwai:

    The earths rate of rotation changes on a regular basis so the joke's on you!

    [;)]



    Yep, that should be a function that varies on time of year, speed of solar winds, the alignment of the planet, and the number of people are walking east versus the number of people walking west.

    [:)]
  • (cs)

    Constants aren't, variables don't.

  • (cs)

    Hey, the good news is that at least the above code examples avoid the Magic Number Anti-pattern!

  • Mirandir (unregistered)

    One funny thing I just noticed is that Josh Buhler's coworker only seems to master "not" and "larger than" operators:

    if(!(val.indexOf(" ")>0) || !(val.length>TWO)) {
    instead of:
    (val.indexOf(" ") == -1 || val.length < TWO)

    And second half of above if-statement in reprise:
    if(!(val.length>TWO))

    And he probably would have used constants if there where any(It looks very much like Flash ActionScript 2.0).

    /Mirandir

  • (cs) in reply to dubwai
    dubwai:
    The earths rate of rotation changes on a regular basis so the joke's on you!

    [;)]



    I suppose calling it something like "duration of earth's rotation" would be too sensible...?
  • (cs) in reply to Mirandir
    Mirandir:
    One funny thing I just noticed is that Josh Buhler's coworker only seems to master "not" and "larger than" operators:
    er..um... It seems you haven't even gotten that far.....

    if(!(val.indexOf(" ")>0) || !(val.length>TWO)) {
    instead of:
    (val.indexOf(" ") == -1 || val.length < TWO)

    Make that....

    (val.indexOf(" ") == -1 || val.length <= TWO)

    (I should have fixed the first half of that as well, but we know what JB's Coworker really meant...)

  • Mark Staggs (unregistered)

    And this isn't even counting a submission a made a while back that has these defines in a C header file.

    #define FIELD_WITH_LENGTH_FIFTY      50
    #define FIELD_WITH_LENGTH_FORTY_SEVE     47
    #define FIELD_WITH_LENGTH_FORTY          40
    #define FIELD_WITH_LENGTH_THIRTY         30
    #define FIELD_WITH_LENGTH_THIRTY_ONE     31
    #define FIELD_WITH_LENGTH_TWENTY_FIVE    25
    #define FIELD_WITH_LENGTH_TWENTY         20
    #define FIELD_WITH_LENGTH_THIRTEEN       13
    #define FIELD_WITH_LENGTH_TWELVE         12
    #define FIELD_WITH_LENGTH_TEN            10
    #define FIELD_WITH_LENGTH_NINE            9
    #define FIELD_WITH_LENGTH_EIGHT           8
    #define FIELD_WITH_LENGTH_SEVEN           7
    #define FIELD_WITH_LENGTH_SIX             6
    #define FIELD_WITH_LENGTH_FIVE            5
    #define FIELD_WITH_LENGTH_FOUR            4
    #define FIELD_WITH_LENGTH_THREE           3
    #define FIELD_WITH_LENGTH_TWO             2
    #define SINGLETON_FIELD_LENGTH            1

  • (cs)
    Next is from Kyle, who found the root cause behind the failure of long-running daemons ...

    TODAY = today()
    YESTERDAY = yesterday()
    Am I missing something here? I can see how it's a dumb thing to do, but I don't see the connection between that and the failure of long-running daemons.
  • (cs) in reply to JamesCurran

    If that code isn't executed every day at midnight, the values will only be right for a certain amount of time, no? But then again, 24 hours or possibly 12 hours is not what I would call long-running for a daemon....

    And WTF if this code is executed at 23:59:59'99? TODAY, YESTERDAY, LASTWEEK and LASTMONTH (stupid capslockitis) might all be wrong then.

  • (cs) in reply to JamesCurran
    JamesCurran:
    Next is from Kyle, who found the root cause behind the failure of long-running daemons ...

    TODAY = today()
    YESTERDAY = yesterday()

    Am I missing something here? I can see how it's a dumb thing to do, but I don't see the connection between that and the failure of long-running daemons.

    I can only imagine that since TODAY is a constant, TODAY says the same thing as it did when the app was started as it does two weeks later.  So maybe they are comparing TODAY with TOMMORROW and determining whether to exit.

  • (cs) in reply to dubwai

    It might also to unwanted effects when the year changes, but I don't know in what format today() returns its information, i.e. if the year is included.

  • (cs)
    <font color="#000099">if</font> (totalGlue > EIGHT) totalGlue = EIGHT;

    // burried in a header file ...
    #<font color="#000099">define</font> EIGHT 16


    LOL that made my day, I have nothing to say but WTF!
  • diaphanein (unregistered) in reply to johnl
    johnl:
    dubwai:
    The earths rate of rotation changes on a regular basis so the joke's on you!

    [;)]



    I suppose calling it something like "duration of earth's rotation" would be too sensible...?

    Rate makes much more sense.  Duration implies that it starts and ends....  Would be awfully strange if the earth just upped and stopped rotating after 24 hours.  [:D]

  • (cs) in reply to diaphanein
    Anonymous:

    Rate makes much more sense.  Duration implies that it starts and ends....  Would be awfully strange if the earth just upped and stopped rotating after 24 hours.  [:D]



    Time would stop!  [:D]

    Haven't you ever seen Superman?
  • (cs) in reply to mizhi

    mizhi:
    Anonymous:
    Rate makes much more sense.  Duration implies that it starts and ends....  Would be awfully strange if the earth just upped and stopped rotating after 24 hours.  [:D]


    Haven't you ever seen Superman?

    Unfortuetly his code never references an IGyroscope so he cannot detect if the earth's rotation rate was changing.

    Also, anybody who previously said the Earth's retation is static was incorrect ( http://www.iers.org/iers/earth/rotation/ ), it does change slightly according to the distance of planets & moons in our immediate area.  Of course going with an average rotation is pretty reliable, I mean, it's not like his code is going to automate landing a probe from earth and it MUST land within a 6 inch square on Mars and he has no visual cues to go by.  Wait I take that back, he might have been a coder on previous Mars lander projects.

     

  • (cs)

    I am reminded of an early FORTRAN system I worked on that would allow you change the values of constants by passing a constant to a function which changed to value of the parameter.  So you give the constant value 3 a value of 5 so that wherever else 3 was used it use 5 so the expression 3 + 2 would calculate to 7.

    Then that fancy virtual memory came around and people started putting the values of number in protected pages and it took all the fun out of it.

  • (cs)
    Alex Papadimoulis:
    <font color="#000099">private const int </font>INT_ZERO = 0;
    <font color="#000099">private const int </font>INT_ONE = 1;
    <font color="#000099">private const int </font>INT_TWO = 2;
    <font color="#000099">private const int </font>INT_THREE = 3;
    <font color="#009900">'...</font> <font color="#000099">private const int </font>INT_TWENTY_SEVEN = 27;
    <font color="#000099">private const int </font>INT_TWENTY_SEVEN = 28;


    On the ZX81 home computer, using the built-in BASIC, it was a common coding practice to do something similar; e.g.
    10 LET I=1
    20 LET O=0
    because numeric literals required 5 extra bytes of memory for each occurence (for speed reasons, the system stored the float value along with the readable representation) and memory was very limited, 1KB in the basic model. So using this "constants" saved 5 bytes each time; the declaration of both costs est. 24 bytes, so it pays off soon.


    Next is from Kyle, who found the root cause behind the failure of long-running daemons ...

    TODAY = today()
    YESTERDAY = yesterday()
    WEEKAGO = weekago()
    LASTMONTH = lastmonth()

    Hard to say if this is a WTF without knowing the background; sometimes similar code is the right way to avoid a date switch-over during processing which would cause bad effects. Of course, your program should run into these lines at least once per day ;-)
  • AC (unregistered) in reply to loneprogrammer

    loneprogrammer:
    Constants aren't, variables don't.

    So true, thanks for the laugh

  • Anonymous (unregistered) in reply to AC

    I ended up doing this recently.  I think I was feeling allergic to new that day.

    private static final Integer INT_1 = new Integer(1);
    private static final Integer INT_2 = new Integer(2);
    public static final Integer MAGIC_COLUMN_A = INT_1;
    public static final Integer MAGIC_COLUMN_B = INT_2;
    public static final Integer MAGIC_THINGY_X = INT_2;
    public static final Integer MAGIC_THINGY_Y = INT_1;
    public static final Integer MAGIC_THIUGY_Z = INT_1;
    etc.

  • (cs)

    Thank god for design patterns, though.

    <FONT face="Courier New" size=2>public class MyAwesomeProgram
    {
      public static void main(String[] args)
      {
        MagicNumberFactory mnf = MagicNumberFactory.getInstance();
        int myMagicNumber = mnf.getMagicNumber(MagicNumberFactory.BIG);
        System.out.println("check out my magic number: " + myMagicNumber);
      }
    }
    class MagicNumberFactory
    {
      private static int count = 0;
      public static final int BIG = 1;
      public static final int COOL = 2;
      public static final int SUPERMAGIC = 3;
      public static MagicNumberFactory getInstance()
      {
        return new MagicNumberFactory();
      }
      public int getMagicNumber(int type)
      {
        ++count;
        int theMagicNumber = 0;
        switch(type)
        {
          case BIG:
            theMagicNumber = BIG * 14 * count;
            break;
          case COOL:
            theMagicNumber = COOL * 85 * count;
            break;
          case SUPERMAGIC:
            theMagicNumber = SUPERMAGIC * 132 * count;
            break;
          default:
            theMagicNumber = count;
            break;
        }
        return theMagicNumber;
      }
    }</FONT>

  • (cs) in reply to rogthefrog

    ROFLMAO @ rog.  If this place allowed karma awards, that'd get one.

  • Davey (unregistered) in reply to rogthefrog

    Wa?? @ Rog

    Anyways, I've been wondering why people make getIntance() methods. In what situations is this a good idea?

  • vhawk (unregistered)

    Looking at:

    // Name
    var val:String = name_txt.text;
    if (!(val.indexOf(" ")>0) || !(val.length>TWO)) {
    myMessage += "Please fill in your full Name\n";
    validate = false;
    }

    // Address
    var val:String = address1_txt.text;
    if (!(val.length>TWO)) {
    myMessage += "Please fill in your full Address\n";
    validate = false;
    }


    Wonder if
    '...' is more usefull as a FULL NAME or FULL ADDRESS than '.' or 'abc' or any other random 3 character  cr*p. 

  • (cs) in reply to vhawk

    BTW, on that last one:

    "Obscure" is to be thought of as a verb, not an adjective.

     

    Basicaly, this value is subtracted from the ascii value in config files, so that the files are "obscure"

  • Mirandir (unregistered) in reply to JamesCurran
    JamesCurran:
    Mirandir:
    One funny thing I just noticed is that Josh Buhler's coworker only seems to master "not" and "larger than" operators:
    er..um... It seems you haven't even gotten that far.....

    if(!(val.indexOf(" ")>0) || !(val.length>TWO)) {
    instead of:
    (val.indexOf(" ") == -1 || val.length < TWO)

    Make that....

    (val.indexOf(" ") == -1 || val.length <= TWO)

    (I should have fixed the first half of that as well, but we know what JB's Coworker really meant...)

     

    Haha What the hell was I thinking... ?? [:$] Can I join the "Have-made-a-big-wtf-club" now? [:P]

     

    /Mirandir

  • (cs) in reply to ammoQ
    ammoQ:

    On the ZX81 home computer, using the built-in BASIC, it was a common coding practice to do something similar; e.g.
    10 LET I=1
    20 LET O=0
    because numeric literals required 5 extra bytes of memory for each occurence (for speed reasons, the system stored the float value along with the readable representation) and memory was very limited, 1KB in the basic model. So using this "constants" saved 5 bytes each time; the declaration of both costs est. 24 bytes, so it pays off soon.



    The other common trick was to use

    10 LET I=PI / PI

    instead of

    10 LET I=1

    This was because the ZX81 used a tokenised BASIC, with PI only taking one byte. Therefore, PI / PI actually took 3 bytes to declare the numerical value '1' as opposed to 5.

    Ahhh, those were the days!
  • (cs) in reply to Davey

    Anyways, I've been wondering why people make getIntance() methods. In what situations is this a good idea?

    getInstance (or similar) is generally a symptom of the http://c2.com/cgi/wiki?SingletonPattern

    The link provided explains in excruciating detail what the pattern is about, advantages, pitfalls, how it is commonly abused and why, etc etc.

    If you've not come across the concepts of singletons before, I would strongly suggest buying the 'gang of four' book and spending some considerable time browsing the c2 wiki. This is liable to reduce the WTF:LOC ratio of your work considerably[1].

    Simon

    [1] Unless it doesn't, of course

  • (cs)
    Alex Papadimoulis:
    <FONT color=#000099>private const int </FONT>INT_TWENTY_SEVEN = 27;
    <FONT color=#000099>private const int </FONT>INT_TWENTY_SEVEN = 28;
    

    That's awesome.

  • (cs) in reply to spotcatbug

    This forum software, however, is not. :/

  • (cs) in reply to tufty

    Hey Tufty, thanks for that website.  They have a number of interesting things there. [:)]

  • (cs)

    Somehow this reminds me of $TEXMF/tex/latex/base/latex.ltx[/code:

    \def@vpt{5} \def@vipt{6} \def@viipt{7} \def@viiipt{8} \def@ixpt{9} \def@xpt{10} \def@xipt{10.95} \def@xiipt{12} \def@xivpt{14.4} \def@xviipt{17.28} \def@xxpt{20.74} \def@xxvpt{24.88}

    Seems like Roman eleven and twenty-four were half a percent smaller than ours, but to make up for this, seventeen was 1.6% larger, fourteen almost three percent and twenty as much as three point seven percent larger.

  • (cs) in reply to divVerent
    divVerent:
    Somehow this reminds me of $TEXMF/tex/latex/base/latex.ltx[/code: \def\@vpt{5} \def\@vipt{6} \def\@viipt{7} \def\@viiipt{8} \def\@ixpt{9} \def\@xpt{10} \def\@xipt{10.95} \def\@xiipt{12} \def\@xivpt{14.4} \def\@xviipt{17.28} \def\@xxpt{20.74} \def\@xxvpt{24.88} Seems like Roman eleven and twenty-four were half a percent smaller than ours, but to make up for this, seventeen was 1.6% larger, fourteen almost three percent and twenty as much as three point seven percent larger.


    The only way this makes any sense whatsoever is if it was mixing postscript and classical print point sizes. Although that still doesn't explain the roman numerals.

    I've been guilty of making one-time-use constants and placing then right before the function definition. >.>
  • Brian (unregistered)

    On the Power PC (and maybe on x86 too) constants may have bad data locality and take two instructions to load.  Using gConsts.zero rather than 0.0 may end up taking half as many instructions if a bunch of constants are used in a function.  This is because it only has to load the address of gConsts once then it can just use offsets to get the other values.

  • (cs) in reply to tufty
    simon:
    >If you've not come across the concepts of singletons before, I would strongly suggest buying the 'gang of four' book and spending some considerable time browsing the c2 wiki. This is liable to reduce the WTF:LOC ratio of your work considerably[1].


    Might I suggest that if you don't know what a singleton is that you get a book that you can actually read and follow through like "Refactoring to Patterns".  The GoF book is really good, but it's a reference book, not a book for learning.
  • (cs) in reply to loneprogrammer
    loneprogrammer:
    Constants aren't, variables don't.


    I believe the original was "Constants aren't.  Variables won't."
  • Alexander Vollmer (unregistered)

    Look like artifacts from an original source written in COBOL some decades ago. Often to be found in prgs for accounting and financial calcs.

    Found some which made their way from COBOL through dBase to Access aso. I have an idea of beeing a very old sick man in a hospital and there is a holographic avatar serving me ... and it looks like pacman. [*-)]

  • (cs) in reply to curtisk
    curtisk:
    <FONT color=#000099>if</FONT> (totalGlue > EIGHT) totalGlue = EIGHT;

    // burried in a header file ...
    #<FONT color=#000099>define</FONT> EIGHT 16


    LOL that made my day, I have nothing to say but WTF!

    Don't laugh... one day it will happen to you! I have seen this in lots of code before. What happens is some idiot writes the initial system, then all of a sudden it stops working because totalGlue is allowed to be 9, and not 8. So what's the easiest change to make? Just bump it up to 16. Of course the dickhead who did this without renaming the constant should be shot. And they should have renamed it to "MAX_GLUE_AMOUNT" or something.

     

  • Pax (unregistered) in reply to clockwise

    This goes back a looong way.  I beleive the original K&R suggested using the line
         #define PI 3.14159
    should "the value of PI change in future".


  • (cs)

    private const int INT_ZERO = 0;
    TODAY = today()

    At least he's prepared if 0 would change to 100,01 in the very near feature.

    Same with the fact that soon today will be known as 'the day after tomorrow'.

    Surely you've thought of that designing your apps ? [^o)]

  • (cs) in reply to foxyshadis
    foxyshadis:
    divVerent:
    \def\@vpt{5} \def\@vipt{6} \def\@viipt{7} \def\@viiipt{8} \def\@ixpt{9} \def\@xpt{10} \def\@xipt{10.95} \def\@xiipt{12} \def\@xivpt{14.4} \def\@xviipt{17.28} \def\@xxpt{20.74} \def\@xxvpt{24.88}

    Seems like Roman eleven and twenty-four were half a percent smaller than ours, but to make up for this, seventeen was 1.6% larger, fourteen almost three percent and twenty as much as three point seven percent larger.



    The only way this makes any sense whatsoever is if it was mixing postscript and classical print point sizes. Although that still doesn't explain the roman numerals.

    I've been guilty of making one-time-use constants and placing then right before the function definition. >.>

    Well, the Roman numerals are there because TeX does not allow digits in identifiers, so they're justified. And yes, it is a point size conversion - although it's still strange to define "20 pt" as "20.74" using a macro.

  • szeryf (unregistered) in reply to Pax
    Anonymous:
    This goes back a looong way.  I beleive the original K&R suggested using the line
         #define PI 3.14159
    should "the value of PI change in future".


    I'm pretty sure it wasn't K&R but some Xerox FORTRAN manual. It was used it many fortune files with this annotation.

  • Olle (unregistered) in reply to JamesCurran
    JamesCurran:
    Mirandir:
    One funny thing I just noticed is that Josh Buhler's coworker only seems to master "not" and "larger than" operators:
    er..um... It seems you haven't even gotten that far.....

    if(!(val.indexOf(" ")>0) || !(val.length>TWO)) {
    instead of:
    (val.indexOf(" ") == -1 || val.length < TWO)

    Make that....

    (val.indexOf(" ") == -1 || val.length <= TWO)

    (I should have fixed the first half of that as well, but we know what JB's Coworker really meant...)


    er..um... It seems you haven't even gotten that far...

    !(val.indexOf(" ")>0)

    allows spaces in the first position (position 0) while 

    val.indexOf(" ") == -1

    don't! And it is obvious that we should allow spaces in pos 0 ;-)

    /Olle

  • tekra (unregistered)

    Is it just me, or did I find PAUSE_BY_6_SECONDS to be completely  reasonable?  I.e. if I use the literal "6000", is it obvious that is six seconds? Far too easy to accidentally type "600" or "60000" ...

    tekra

  • (cs) in reply to tekra

    It should use a better name that doesn't include what the current literal amount is.  Like: PAUSE_DURATION.  If there are multiple pause durations(6 seconds, 12 seconds, 18 seconds for example), then you should append meaningful names like SHORT, MEDIUM, LONG.

    All IMO.

  • Hank Miller (unregistered) in reply to tekra
    Anonymous:
    Is it just me, or did I find PAUSE_BY_6_SECONDS to be completely  reasonable?  I.e. if I use the literal "6000", is it obvious that is six seconds? Far too easy to accidentally type "600" or "60000" ...

    tekra


    It is just you.   It should be
    PAUSE_FOR_LEGAL_MINIMUM_TIME
    That way when congress changes the legal minimun to be 9 you don't have to change the name of the constant.   6 seconds is the value today, but it might not work out for a faster machine in the future.
  • Hank Miller (unregistered)
    Alex Papadimoulis:

    Of course, we could all be wrong in thinking that constants named EIGHT are bad. Sometimes, you don't really want EIGHT to be 8, as demonstrated by this code submitted anonymously ...

    <font color="#000099">if</font> (totalGlue > EIGHT) totalGlue = EIGHT;

    // burried in a header file ...
    #<font color="#000099">define</font> EIGHT 16



    He just wanted to check F and 11 on the hacker purity test.   Not to mention 8C
    http://www.armory.com/tests/hacker.html

    That might be enoguh to get his score out of the single digets.
  • (cs) in reply to wakeskate
    wakeskate:
    simon:
    >If you've not come across the concepts of singletons before, I would strongly suggest buying the 'gang of four' book and spending some considerable time browsing the c2 wiki. This is liable to reduce the WTF:LOC ratio of your work considerably[1].


    Might I suggest that if you don't know what a singleton is that you get a book that you can actually read and follow through like "Refactoring to Patterns".  The GoF book is really good, but it's a reference book, not a book for learning.


    "Refactoring to Patterns" is indeed a great book!
    But I can also stronly suggest "Head First: Design Patterns"
    An amazing book!


    regards,

    Jeroen Vandezande

Leave a comment on “A Constant Barrage”

Log In or post as a guest

Replying to comment #38594:

« Return to Article