• (disco)

    I remember doing something like this on my ti 83+ calculator once... IIRC, it was to decode a string to get psuedo-properties on an "object" described by said string (i.e. Dialog, Textbox, Label, etc).

    Windows Ti never did make it very far off the ground....

  • (disco)

    since the fields are delimited by pipes, there won’t be any lurking “run-over” bugs, where the substring of two IDs mashed together is a valid ID.

    But since the lookup doesn't check for boundaries, there are lurking substring bugs if the numbers ever roll-over and need another digit...

  • (disco)

    On the bright side ... there won’t be any lurking “run-over” bugs, where the substring of two IDs mashed together is a valid ID

    TRWTF is anyone seeing a bright side to string-comparisons for numbers. There will be plenty of lurking bugs if anyone ever asks to validate an ID < 10000, or an ID >= 100000 is added to the lists. Or if it ever runs on a machine where the prevailing culture does something weird in ToString(), such as inserting commas every third place. FFS, three hard-coded arrays of ints would involve negligibly more typing and would actually function correctly...

  • (disco)

    Another stupid, the method is declared static but not the constant strings.

  • (disco) in reply to Julia
    Julia:
    TRWTF is anyone seeing a bright side to string-comparisons for numbers.

    It was sarcasm.

  • (disco) in reply to David_Taylor

    Or if you just search for e.g. "29".

  • (disco)

    #Top Ten Ways To Display The Number One! ##Only Discourse UsersVictims Will Get This

    1.  
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
    10.  
  • (disco) in reply to boomzilla

    #Top Ten Ways To Display The Number Two! ##Only Discourse UsersVictims Will Get This

    1.  
    2.  
    3.  

                    2.  &nbsp;
    
    1.  

    2.  

    3.  

    4.  

    5.  

    6.  

  • (disco)

    For later expendability, those strings are not consts. That's Doing It RightTM.

    But why is metricId.ToString() evaluated three times? Wouldn't it be more effective to do it this way:

    string metricId_MS_string = metricId.ToString();
    string metricId_FN_string = metricId_MS_string;
    string metricId_CM_string = metricId_FN_string;
    

    And to avoid possible length clashes:

    if (("|"+caMSMetricIdList+"|").Contains("|"+metricId_MS_string+"|"))
    {
        return "MS";
    }
    
    // etc.
    

    Then tell your intern that integer arrays are more effective, leading to (in C#):

    int [] caMSMetricIdList = new int[] { 29477, 29478, 29479, 29480, 29481, ... };
    // etc.
    

    and

    if (("|" + string.Join("|", caMSMetricIdList.Select<int, string>((int i => i.ToString()).ToArray()) + "|").Contains("|" + metricId_MS_string + "|"))
        {
            return "MS";
        }
        
        // etc.
    

    Then your intern learns that string concatenations should be done by a StringBuilder for efficiency:

    ( code omitted for sanity reasons )

  • (disco) in reply to PWolff
    PWolff:
    But why is metricId.ToString() evaluated three times? Wouldn't it be more effective to do it this way:
    Technically yes, but the compiler will optimise it away anyway ;)
  • (disco) in reply to RaceProUK

    Only if the compiler is aware of int.ToString() yielding always the same result for the same number. (Should be the case, but you never can tell.)

    Maybe I should introduce a variable IFormatProvider fmtProv and call metricId.ToString(fmtProv) ?

    Filed under: Psychology : post mortem rationalisation of Doing It WrongTM

  • (disco) in reply to PWolff
    PWolff:
    Only if the compiler is aware of int.ToString() yielding always the same result for the same number.
    Which it will; the lexical, semantic, and flow analyses will make sure of that ;)
  • (disco) in reply to RaceProUK
    RaceProUK:
    Which it will; the lexical, semantic, and flow analyses will make sure of that

    I know in theory, but it is hard to get used to that if you've learned programming when assembler was still a thing for applications and you had to cram all your binaries and data into maybe 2 KiByte of memory.

  • (disco) in reply to PWolff

    After changing from a string to an array integers, you might end up with good code. Assuming you keep the array sorted (which, of course, is a potential source of bugs), you can then do a binary search across the array, which would be just as fast as a dictionary lookup. I'm not certain what language the WTF was using, but I know that both C and C++ have standard library functions for efficiently searching a sorted array.

    Building a dictionary (or STL map in C++) may produce the most efficient code for searching, but there is overhead to building the dictionary in the first place. Depending on how many numbers are in the list and how many times this lookup will be performed during a single run of the process, it might be more efficient to binary-search a static array of integers instead of building a dictionary at startup.

  • (disco) in reply to RaceProUK
    RaceProUK:
    Which it will

    Without confirming by examining the machine code generated from the IL, I'd really hesitate to assume that.

  • (disco) in reply to David_C
    David_C:
    you might end up with good code

    I know, and it's not exactly easy to avoid, especially if the sane solution is obvious and shorter.

  • (disco) in reply to David_C
    David_C:
    I'm not certain what language the WTF was using
    Looks like C#, based on the conventions used
  • (disco) in reply to David_C

    I think swich case can get optimized to a lookup table.

    Oh the downside is having to write case thousands of times, and depending on code formatting style, thousands of lines.

    Probably a good thing if you are paid per line or byte of code though.

  • (disco)

    It's a tough problem. You know, it's really too bad that we don't have a tool, like some kind of data...base...that we could use to look up things like this.

  • (disco)

    The worst thing about the ancient proprietary language our codebase uses is that it's old enough that doing string lookups was faster than using a database when it was designed, and so it never got any tools for dealing with a real database, only it's own pure text database.

    It doesn't have lists or arrays either, as far as I know, and everything ever can be null (which is represented as an empty string). (^(x)>=) is what a null check looks like, where x is a variable name. We do have tables at least, but those are always part of the database, so you can't just make one to use as a list.

    So typically to do a lookup, you have to do something like _BLAH_BLAH2_BLAH3_{_^(x)>_ (Find _x_ in _BLAH_BLAH2_BLAH3_.

    Glad to be working on a C# project here now.

  • (disco) in reply to CoyneTheDup

    Sure, a database will get the job done, but is it worth the overhead?

    If the table is large and can change dynamically while the system is running, then it might be a good idea. But if the table is not too large, and only changes rarely (e.g. when the software itself updates), then that's a lot of overhead.

    I don't think I'd want to impose the overhead of something like SQLite for something as trivial as this unless there are other product-level requirements that can justify it.

  • (disco) in reply to David_C
    David_C:
    Depending on how many numbers are in the list and how many times this lookup will be performed during a single run of the process, it might be more efficient to binary-search a static array of integers instead of building a dictionary at startup.

    Couldn't the construction of a default-allocator, constant (as in declared const) map be basically performed at compile-time? Or are compilers not quite smart enough to do that yet? ;)

  • (disco) in reply to Julia

    The internet has a few big binary discussions: "which side should the toilet paper hang?", "water on your toothbrush before or after putting the tooth paste?", "does 90.999... equal 1?" etc. The discussion whether IDs should be stored as int or string also seems to split the internet.

    It's like the Beatles or the Stones, I guess.

    Edit: Props to who had seen it :+

  • (disco) in reply to YellowOnline

    Toilet paper should hang out so that I don't have to touch the wall accidentally, or risk shoving the paper against the wall. Sanitation saves millions of lives. The opposing side, claims aesthetics.

    Water your toothbrush before and after for best results.

    .9999.... cannot be properly expresses in finite space. Therefore we chose to represent it as 1.

    Do you add IDs?

    Who are these Stoney Beetles?

  • (disco) in reply to xaade

    que the flame war...

    digs trench to hide in

    :smile:

  • (disco) in reply to tarunik
    tarunik:
    Couldn't the construction of a default-allocator, constant (as in declared const) map be basically performed at compile-time? Or are compilers not quite smart enough to do that yet? ;)
    I think it will depend on the language.

    The 1998 version of C++ doesn't have any kind of static constructor for std::map. Some code must execute to populate it.

    The 2011 and 2014 versions of the language allow maps to be constructed from an initializer list, which (I think) can be generated statically. I don't know if the map itself can be statically initialized when such a list is used, however, because it will need to generate the internal data structures (typically an RB-tree, but others are theoretically possible). The code will be syntactically cleaner than calling a function to populate the map, and may be more efficient than inserting nodes individually, but I don't think it can be done entirely at compile time.

    Other languages, of course, may have different kinds of containers and may support compile-time initialization.

  • (disco) in reply to Magus
    Magus:
    It doesn't have lists or arrays either, as far as I know, and everything ever can be null (which is represented as an empty string). `(^(x)>=)` is what a null check looks like, where x is a variable name. We do have tables at least, but those are always part of the database, so you can't just make one to use as a list.

    So typically to do a lookup, you have to do something like _BLAH_BLAH2_BLAH3_{_^(x)>_ (Find _x_ in _BLAH_BLAH2_BLAH3_.

    Someone should tell your manager that Brainfuck was never intended to be used in production systems.

  • (disco) in reply to xaade
    xaade:
    Toilet paper should hang out so that I don't have to touch the wall accidentally, or risk shoving the paper against the wall. Sanitation saves millions of lives. The opposing side, claims aesthetics.
    If it's in your home, I hope you will keep the bathroom clean enough that it won't matter. If it's a public restroom, then you may have a point, but you also can't do anything about it.

    I prefer it hanging in front of the roll, because I find it more usable, especially when I'm half asleep.

    But if you have pet cats, that can be an invitation for them to unwind the entire roll onto the floor. When it hangs on the wall-side of the roll, a cat pulling on the front of the roll won't end up unwinding anything.

  • (disco) in reply to David_C
    David_C:
    But if you have pet cats, that can be an invitation for them to unwind the entire roll onto the floor. When it hangs on the wall-side of the roll, a cat pulling on the front of the roll won't end up unwinding anything.

    I can see how that would be a problem in public bathrooms.

    [spoiler]Or in homes where the residents don't know how to close doors[/spoiler]

    [spoiler]If you have cats that can open doors.... you should look around for some way to profit off of that.[/spoiler]
  • (disco)

    Well, all men know how painful swollen listicles are...

  • (disco) in reply to Dragnslcr

    The language was designed 30 years ago by a lawyer. We're kind of stuck with it. Interestingly, the whole ^()> thing just denotes some kind of symbol rather than text. The > is actually non-printing character that we display as a right-facing triangle, but we have a VS plugin that auto-closes them, so we don't need to worry terribly about them.

    For a builtin function call, between the ^ and (, you'd put the name. For a user defined one, you have to use ^FUNCTION(FunctionName)> and procedures have another call. The function name is the name of the function file.

  • (disco)

    I was given some stupid FORTRAN to maintain once which was to return whether a particular date was a public holiday or not. Every year we had to edit the program and add the string of comma-separated numbers which were the days of that year (can't remember the format) into a new Data statement and then recompile all the code into all the libraries that used this data.

    I suggested that it might be better to rewrite it to stick it into a file and get the program to initialise itself from that file. Oh no, far too big an overhead, was the bletheringly stupid answer from the silly old woman who happened to be the boss at the time. No, it was not time critical, it was hardly ever used in fact -- but when it was used it was important.

    Sorry but it's far more important in my mind to make sure that such information is easily maintained and managed -- especially so, because only used once a year, the knowledge of how to do it is not at the forefront of the brain.

    Utterly stupidly stupid place. I'm glad I left.

  • (disco) in reply to Magus

    (^(x)>=) looks way too much like ASCII art. Is this a programmer's version of day-doodling?

  • (disco) in reply to xaade

    Beatles and Stones can lock themselves in a room to fight it out, while real men listen to Motörhead.

  • (disco) in reply to xaade
    xaade:
    [spoiler]If you have cats that can open doors.... you should look around for some way to profit off of that.[/spoiler]

    My family had a cat that we're pretty sure figured out how to open doors. One of the bedrooms where we would shut him in if we had visitors had a bureau next to the door, and he figured out that he could get on top if the bureau and reach across to turn the doorknob. He would also try to turn the doorknob on the door from the house into the garage, but luckily he was a couple inches too short to reach it from the floor.

  • (disco) in reply to Tsaukpaetra

    The ^ is called a hat, and the thing I denote with > is called a shoe.

  • (disco) in reply to Magus

    and =) is the rocket exhaust?

  • (disco)

    "Only 90s Kids Will Get this" You mean TRWTF is that he doesn't use XML, right? RIGHT?

  • (disco) in reply to Tsaukpaetra

    No, that's an equals sign, a null, and a closing paren. The only strange thing about it is that the null is just not anything. Putting a space there would make it check against space rather than null, and we have no null keyword of any kind. Interestingly, a tab in there would be ignored.

  • (disco) in reply to Dragnslcr

    You know, if you're going to code in something that looks like line noise , you really should just cut your losses and use Brainfuck. Good luck getting that on a requirements doc, though...

  • (disco) in reply to YellowOnline
    YellowOnline:
    The discussion whether IDs should be stored as int or string also seems to split the internet.

    They should of course be stored as doubles. How else are you going to have room for them all?

  • (disco) in reply to Mikael_Svahnberg
    Mikael_Svahnberg:
    YellowOnline:
    The discussion whether IDs should be stored as int or string also seems to split the internet.

    They should of course be stored as doubles. How else are you going to have room for them all?

    Don't be ridiculous. GUIDs or GTFO. :stuck_out_tongue:

  • (disco)

    Gee, I don't know, I thought I invented that way to find if an item is in a set. The code could be a bit faster by prepending a "|" so the string search might run a bit faster than looking for a digit.

  • (disco)
    David_C:
    dictionary lookup
    +1

    That being said, I’m surprised no one has noticed this pattern (here’s my rewrite):

    I started a rewrite to use integer conditionals (assuming every Id had a range as that seemed mostly apparent from the snippet my browser displayed), but when I copy/pasta'd the code into Notepad++, I got the full strings and saw that pattern did NOT work as anticipated. -_-

    xaade:
    Toilet paper should hang out so that I don't have to touch the wall accidentally, or risk shoving the paper against the wall. Sanitation saves millions of lives. The opposing side, claims aesthetics.
    Wow, someone actually came up with a good argument for which way to hang the toilet paper! I have been “converted.”
    David_C:
    But if you have pet cats, that can be an invitation for them to unwind the entire roll onto the floor. When it hangs on the wall-side of the roll, a cat pulling on the front of the roll won't end up unwinding anything.
    LOL. Now I’m glad the only pets I have are birds. ;-)
  • (disco) in reply to David_C
    David_C:
    The 2011 and 2014 versions of the language allow maps to be constructed from an initializer list, which (I think) can be generated statically. I don't know if the map itself can be statically initialized when such a list is used, however, because it will need to generate the internal data structures (typically an RB-tree, but others are theoretically possible). The code will be syntactically cleaner than calling a function to populate the map, and may be more efficient than inserting nodes individually, but I don't think it can be done entirely at compile time.

    Other languages, of course, may have different kinds of containers and may support compile-time initialization.

    I'm talking about the compiler basically building the initial RB-tree at compile time...

    That would be an interesting optimization question for our resident compiler experts. @dkf?

  • (disco) in reply to YellowOnline
    YellowOnline:
    "does 9.999... equal 1?"

    I should think this one gets a unanimous "no," but I'm sure there's someone out there who doesn't read very carefully.

    <yes, I know what he meant....math gramming!

  • (disco) in reply to boomzilla
    boomzilla:
    I should think this one gets a unanimous "no,"

    If you at any point ever, and i do mean at any point, terminate that repeating sequence of nines, then the answer is absolutely no, if you literally have an uncountably infinite number of nines there after the decimal point..... possibly? if you're dealing with something in the real world then "if you've got enough 9's there it's close enough that within experimental tolerance it's indistinguishable from 1"

    ..... FICK! i missed where exactly the decimal point is.

    :epic nooooooooooooo.png:

  • (disco) in reply to boomzilla
    boomzilla:
    YellowOnline:
    "does 9.999... equal 1?"

    I should think this one gets a unanimous "no," but I'm sure there's someone out there who doesn't read very carefully.

    Well, no, it really shouldn't be considered to equal 1, but last I checked, no current hardware supports any representation for infinitesimals. Call it round-off error, I guess, not that that helps any.

    EDIT: Damn, I missed where the decimal point was, too. D'oh!

  • (disco) in reply to YellowOnline
    YellowOnline:
    "does 9.999... equal 10?"

    Assuming an infinite recurrence of 9s, you can prove that using logarithms

  • (disco) in reply to xaade
    xaade:
    If you have cats that can open doors.... you should look around for some way to profit off of that.
    My cats can definitely open doors. At least ones that they need to push to open. Pulling is beyond their abilities (I hope.)

    In my home, most door-handles are lever type. A cat can reach up and attempt to pull the handle down. It sometimes works.

    In my previous house, which had more normal knobs, the two cats would work together. One would stand on his hind legs and attempt to turn the knob, while the other pushed the door. We put child-safety covers on the doorknobs to stop that.

Leave a comment on “Listicle”

Log In or post as a guest

Replying to comment #454852:

« Return to Article