• (disco)

    Oh...

    "<FF"+"S/>"
    
  • (disco) in reply to CarrieVS
    CarrieVS:
    if ( $condition || ! $condition || FILE_NOT_FOUND)

    Fixed it

  • (disco)
    boolean isPaymentType;
    for (int i = 100; i < 199; continue)
        if (isPaymentType = (telegramType == i++))
            break;
    

    Fixed it, now approximated 2X fast, that will be $500 for my contractors fee.

  • (disco) in reply to DJSpudplucker

    Apparently. No.

  • (disco) in reply to Frykun

    I'm pretty sure the src="' + url + '" would prevent the browser's prefetch from downloading the script before the inline script is executed, since that expression can't be evaluated until the inline script is executed...

  • (disco) in reply to anotherusername

    Yeah, you're right. So it's a simple copy/pasta WTF...

  • (disco) in reply to PWolff
    PWolff:
    Or we could make use of a nested loop, for nested loops are cool

    What happens if telegramType = 90?

  • (disco)

    So nobody wants to point out that Chris' "fix" for that macro will break code that was expecting m_CalcOpt to be evaluated more than once?

  • (disco) in reply to PWolff

    And after the bug is finally noticed and reported it will be fixed accordingly:

    if (telegramType == i) {
        isPaymentType = (telegramType == i);
    } else {
        if ((isPaymentType != true) == true) {
            isPaymentType = (telegramType == i);
        }
    };
    
  • (disco)
    ...banned the use of the word “script” inside of a script.

    That one can actually write that without noticing that there might be a reason why you shouldn't use a <script> or </script> tag inside a script tag is TRWTF.

    But wait, I guess it went like this:

    ...banned the use of the word “script” inside of a script... HM? oh wait^H^H^H^H^H^H^H^H^H^H^H^H^H^HDAMMIT HIT THIS DAMN SEND BUTTON ALREADY

    The embarrassment must be unbearable.

  • (disco) in reply to bitti

    You have to avoid script-ception somehow, right? Otherwise, what's preventing you from

    <script><script><script>ing</script></script></script> away?
    
  • (disco)

    **Marcus M.’s```, Remy? I'm going to have to ask you to turn in your Markdown license....

  • (disco) in reply to foxyshadis

    For all anyone knows, that might actually have been valid Dick bb marks html.

    Oh, I am not going to try to fix that.

  • (disco) in reply to FrostCat
    FrostCat:
    So nobody wants to point out that Chris' "fix" for that macro will break code that was expecting m_CalcOpt to be evaluated more than once?

    How do you mean? The value for m_CalcOpt isn't updated (there is no assignment). CALCOPT_NOHITS is replaced with a statement that is equal to m_CalcOpt without the bits for CALCOPT_TRACEHITS or CALCOPT_TRACESUBHITS set, regardless of whether they were set previously (these are all integer bitmasks).

    As the original submitter, I would like to add that unless I've made a mistake, the "fix" has the intended logic. Whether or not the original version has the same logic, I'm 99% sure it does, but it's not a fun task trying to prove it.

  • (disco) in reply to prueg
    prueg:
    As the original submitter, I would like to add that unless I've made a mistake, the "fix" has the intended logic. Whether or not the original version has the same logic, I'm 99% sure it does, but it's not a fun task trying to prove it.

    All operations are bitwise or logical operators, so that's not difficult. Just let a computer make a truth table.

    I pasted the two #def lines into Visual C++, and called them with appropriate flag settings (so that each flag combination occurs exactly once in the lowermost bits).

    (After getting the result, it was simple to see which simple bitwise operation is equivalent to the first expression; this is what I put into CALCOPT_NOHITS_3

        #define CALCOPT_NOHITS_1          ( (m_CalcOpt & (CALCOPT_TRACEHITS|CALCOPT_TRACESUBHITS)) == (CALCOPT_TRACEHITS|CALCOPT_TRACESUBHITS) ? m_CalcOpt^(CALCOPT_TRACEHITS|CALCOPT_TRACESUBHITS) : ((m_CalcOpt&CALCOPT_TRACEHITS) ? (m_CalcOpt^CALCOPT_TRACEHITS) : (m_CalcOpt&CALCOPT_TRACESUBHITS)?(m_CalcOpt^CALCOPT_TRACESUBHITS):m_CalcOpt) )
        #define CALCOPT_NOHITS_2 (m_CalcOpt & ~(CALCOPT_TRACEHITS | CALCOPT_TRACESUBHITS))
        #define CALCOPT_NOHITS_3 (m_CalcOpt ^ CALCOPT_TRACEHITS)
    
        String ^msg = CALCOPT_NOHITS_1.ToString() + " / " + CALCOPT_NOHITS_2.ToString() + " / " + CALCOPT_NOHITS_3.ToString();
    

    (the result is btw "60 / 16 / 60" )

  • (disco) in reply to DJSpudplucker
    DJSpudplucker:
    kupfernigk:
    But now it won't run in more or less constant time, which may be a desired feature.
    Oh dear, you're right! There must be *some* way to improve it?
    
    #define FIFTY_MS 10 //50
    
    boolean isPaymentType = false;
    for (int i = 100; i < 199; i++) {
        if (telegramType == i) {
            isPaymentType = true;
            sleep((199 - i) * FIFTY_MS);
            break;
        }
    }
    

    Fixed?

  • (disco) in reply to obeselymorbid
    obeselymorbid:
     #define FIFTY_MS 10 //50
    We should evaluate the necessary value for FIFTY_MS dynamically.

    (Time estimate seems to be a bit more than a one-liner, though.)

  • (disco) in reply to PWolff
    boolean isPaymentType = false;
    unsigned int t, total = 0;
    for (int i = 100; i < 199; i++)
    {
        t = read_time();
        if (telegramType == i)
        {
            isPaymentType = true;
            sleep((199 - i) * (total / (i - 99)));
            break;
        }
        total += (read_time() - t);
    }
    

    Probably there's off-by-one error around 99, but I CBA to check.

  • (disco) in reply to obeselymorbid

    There, now those pesky hackers trying to determine whether our telegram is of payment type won't be able to, just by observing execution time.

  • (disco) in reply to CarrieVS
    CarrieVS:
    if ( $condition || ! $condition )

    Was $condition a function with side effects?

    grkvlt:
    Let's try Macbeth instead!
    if (dagger.visible                       // Is this a dagger I see
        && dagger.xPosition > this.xPosition) // Before me
    {...}
    
  • (disco) in reply to Jaloopa
    Jaloopa:
    Was $condition a function with side effects?

    No. It was a condition that the script used to use to decide if it should do a thing, and then there was a requirement to do the thing regardless of the condition. It apparently didn't occur to the developer to simply remove the if.

  • (disco) in reply to prueg
    prueg:
    How do you mean?

    It was kind of a joke, involving the fact that parameterized macros with ?: in them evaluate the parameters multiple times.

  • (disco) in reply to anotherusername
    anotherusername:
    I'm pretty sure the src="' + url + '" would prevent the browser's prefetch from downloading the script before the inline script is executed, since that expression can't be evaluated until the inline script is executed...

    This is actually a cargo cult from the days of 3rd and 4th generation browsers, when not only JS but the whole browser parsing was single-threaded and everything accordingly top down and linear. (The "document-stream" model.)

    Some amazing facts: The document object was only created as the HTML parser hit the body tag. (So, no reference to document inside a script executed in the head section at start up. If you head to check some implementation, like Netscape 4's document.layers, you had to trigger this from a script inside or after the body.) HTML was also rendered in a strictly linear fashion. E.g., if the parser hit an image tag and there was a valid height and width attributed, the browser could reserve the space and go on rendering the following content. But, if the dimensional attributes where missing, the browser would pause – with all previous parsed content visible – wait for the image file to be loaded and decoded – and resume only after the image had been inserted. (Actually, it would resume as soon as the dimensions where to be extracted from the file header, still leaving the user to the wonders of the image filling line by line as it were received and decoded.) You could actually use this as a means of sequential story telling.

    And yes, the page would absolutely break, if there was a string containing the sequence '<SCRIPT' (well styled HTML was considered upper case then) found in a script. This is, because the HTML-parsing took precedence over script parsing. The string '<SCRIPT...' would implicitly close the script to be executed, thus opening a new script that would be closed by the string '</SCRIPT>' in the document.write(), rendering the rest of the script as visible HTML content. (By this also inevitably breaking your document.write() statement.) Thus, you had to escape the string some way or the other.

    P.E., the code

    <script>
       var url = '/assets/somescript.js';
       document.write('<script language="javascript" type="text/javascript" src="' + url + '"></script>');
       alert('done');
    </script>
    

    would have been parsed as

    [script node]
       var url = '/assets/somescript.js';
       document.write(';       // syntax error!
    
    [script node, invalid src "'%20+%20url%20+%20'" (404)]
       // empty
    
    [text node]
       '); alert('done');
    
  • (disco) in reply to Jaloopa
    Jaloopa:
    grkvlt: Let's try Macbeth instead!

    if (dagger.visible // Is this a dagger I see && dagger.xPosition > this.xPosition) // Before me {...}

    Or (C#)

    private void wieldable_VisibleChanged(object sender, EventArgs e) {
      if ( (sender is Dagger)                                      // is this a dagger
           && (((Wieldable)sender).visible)                        // I see
           && (((Wieldable)sender).Location.x > this.Location.x)   // before me
          ) {
        // doStuff
      };
    }
    

    ...

  • (disco) in reply to PWolff
    private void wieldable_VisibleChanged(object sender, EventArgs e) {
      if ( (sender is Dagger)                                      // is this a dagger
           && (((Wieldable)sender).visible)                        // I see
           && (((Wieldable)sender).Location.x > this.Location.x)   // before me
           && (((Dagger)sender).handle.Location.x < ((Dagger)sender).blade.Location.x) //the handle toward my hand
          ) {
           try {
              this.clutch(sender); //let me clutch thee
           } catch (ObjectNotCorporealException e) {
              if ((((Wieldable)sender).visible)) {
                        //I have thee not
                       //and yet I see thee still
                      throw new FatalVisionException();
              }
          }
      };
    }
    
  • (disco) in reply to Yamikuronue

    Next project:

    class RomeoAndCleopatra

    Filed under: I didn't mix up anything, did I?

    (Maybe I'll edit this later; on mobile there are only the basic text input functions available)

  • (disco) in reply to PWolff
    PWolff:
    on mobile there are only the basic text input functions available

    You just have to learn Discodown and you'll be fine. Or committed to an asylum. ;) :hospital:

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
    You know what? Not only that, but this just doesn't feel....enterprisey enough. He needs to create an array and put his list of valid values in the array, then do foreach on the array elements. That way, it can be wrong in the enterprisey way.

    The proper enterprisey way is to store the value in an xml document and then use XPath to select it.

  • (disco) in reply to machtyn
    machtyn:
    if (conditional == true) { // do true stuff }

    Most people say that it's bad coding to do that (assuming conditional is a boolean), but I think it can make sense sometimes.

    For example, consider this code

    if (my_integer == 23      &&
        my_string  == "Hello" &&
        my_boolean == true    &&
        my_float   == 0.35   ) { ...
    

    Edit: OK, Discourse, that's just mean. What did I do wrong now?

    [image]
  • (disco) in reply to anonymous234
    anonymous234:
    my_float == 0.35

    AAAAAAAAAAAAAAAAAAAA :takes_breath: AAAAAAAAAAAAAAAAAAA…

    [spoiler](floating point equality comparisons are a personal bugbear)[/spoiler]

  • (disco) in reply to dkf

    Obviously the equality operator is overloaded to return true if the difference is smaller than 0.001 :trollface:

  • (disco) in reply to anonymous234
    anonymous234:
    The proper enterprisey way is to store the value in an xml document and then use XPath to select it.

    Even more enterprisey is to use a homegrown XML parser. That has - among others - the great advantage of tolerating not well-formedenterprisey XML.

  • (disco) in reply to anonymous234
    anonymous234:
    if (conditional == true) { // do true stuff }

    Most people say that it's bad coding to do that (assuming conditional is a boolean from a two-valued logic)

    FTFY

    An interesting approach - besides the clbuttic FILE_NOT_FOUND - is the last entry in this article

    anonymous234:
    Edit: OK, Discourse, that's just mean. What did I do wrong now?
    Let me play Captain Obvious: [spoiler]You used Discourse[/spoiler].
  • (disco) in reply to dkf
    dkf:
    You just have to learn Discodown and you'll be fine. Or committed to an asylum.

    Discasylum refuses to find "Discodown" for me: [image] Maybe the entry is really missing, though.

  • (disco) in reply to anonymous234
    anonymous234:
    Obviously the equality operator is overloaded to return true if the difference is smaller than 0.001

    That would be just irresponsible, as such a scheme falls down for denormals :tropical_drink:

  • (disco) in reply to riking

    Does epsilon equal zero?

  • (disco) in reply to anonymous234
    anonymous234:
    Edit: OK, Discourse, that's just mean. What did I do wrong now?

    https://meta.discourse.org/t/code-fence-and-pre-formatting-require-preceding-blank-lines-to-render-correctly-in-cooked/31239/9?u=pjh

  • (disco) in reply to ben_lubar
    ben_lubar:
    Does epsilon equal zero?

    I don't know about epsilon, but Epsilon does in C# (in the Immediate Window):

    ?(Single)Double.Epsilon==0
    true
    
  • (disco) in reply to PWolff

    ...... why did you cast Double.Epsilon to type Single in that comparison?

  • (disco) in reply to accalia

    Because I can, duh!

    And because otherwise that Epsilon wouldn't equal zero (tried it).

    Edit: And a bit because silly is the next state after tired. Has nothign to do with trying to increase my post count.

  • (disco) in reply to PWolff

    so..... what' you're saying is that Double.Epsilon doesn't actually equal 0, so you cheated to make it look like it equals 0?

    or am i missing something here?

    :rofl:

  • (disco) in reply to accalia
    accalia:
    cheated

    Tsk, tsk, what a harsh word!

    I'm just trying to adapt mentally to the providers of the stuff that keeps this site running.

  • (disco) in reply to accalia
    accalia:
    so..... what' you're saying is that Double.Epsilon doesn't actually equal 0,

    Epsilon's always greater than zero. Not much point otherwise.

  • (disco) in reply to boomzilla

    that's actually rather my point.

    Epsilon is a point that is positive and arbitrarily close to zero that is not zero. Sigma is a point that's smaller than Epsilon, but still not zero.

  • (disco) in reply to accalia
    accalia:
    Sigma is a point that's smaller than Epsilon, but still not zero.

    Except when it's a different variable.

  • (disco)
    boomzilla:
    Epsilon's always greater than zero. Not much point otherwise.

    Depends on what kind of Epsilon you mean. As an insect, it definitively is greater than nought.

    accalia:
    Epsilon is a point

    In C#, a Point is something with X and Y coordinates, and by default no > (and thus, >=, <, <=) operator is defined for such a class. Can be called epsilon or Epsilon, if you like.

    In mathematics, a point can be identified with a real number, but that's not very frequently done.

    As floating point numbers, I've seen Epsilon used both as the smallest entity greater than zero, the smallest normal entity greater than zero, and the smallest number that added to 1 gives something that differs from 1, from the set of representable numbers of a class. Insofar you're right.

    accalia:
    Sigma
    is used as the sum symbol (uppercase letter) or for the standard deviation (lowercase letter), mostly.

    Phew, after this pendantry I feel a bit better.

  • (disco) in reply to accalia
    accalia:
    Epsilon is a point that is positive and arbitrarily close to zero that is not zero.

    For float comparisons, epsilon is often best taken as an optional parameter so you can specify what you mean by “equal”. The general issue is that algorithms don't usually know the characteristic range of the data that you're feeding through them; you can't just say X significant figures since that gives unhelpful answers if you're close to zero.

    I hate doing float math…

  • (disco) in reply to dkf
    dkf:
    you can't just say X significant figuresdecimals
    FTFY

    Somewhere I have a function that compares the difference of two floats to their "Euclidean sum". Something like (value1 - value2)^2 / (value1^2 + value2^2). Plus checking for very small and very large numbers. Luckily not needed in a loop.

Leave a comment on “If You Want To”

Log In or post as a guest

Replying to comment #:

« Return to Article