• Pjrz (unregistered)

    "So, as written, this method only ever returns 5.12. It’s been in use, in production, for a few years now. Not only is in overly complex, it also just doesn’t work. Marnie fixed the code with a much simpler version"

    Having been in use for years without anyone noticing, this implies all the other code that called it actually required and expected a return value of exactly 5.12. Marnie fixing this code actually broke the rest of the code base. She was then fired.

  • someone (unregistered)

    Depending on your chosen level of cynicism, TRWTF is:

    • TypeScript
    • JS transpilation
    • Modern JavaScript development

    And based on the things I was reading a few minutes ago, I'm definitely going with the last one.

  • someone (unregistered) in reply to someone

    And The Other WTF is that unordered lists have no bullet points.

  • cygnus_alpha (unregistered)

    Your solution does not fit the 'assumed' requirement. I assume that there are 3 possible outputs for 3 slightly fuzzy inputs.

    The regex /^-?\d+(?:.\d{0,1})?/ when given 1.64 gave me 1.6.

    Ok, it's not pretty or right and I'm assuming a lot or whatever but just dividing is going to give more than the expected output. A spec comment would be nice.

  • TheDaveG (unregistered) in reply to Pjrz

    Yep, especially when you consider that the return value is a string, not a number. One more WTF.

  • Dan Bugglin (google)

    "Now, this is TypeScript, so there is no guarantee that, at runtime, _bandwidth will actually be a number."

    That would be true in JavaScript, but the TypeScript compiler will validate all calls to this function to ensure it is only passed numbers. Of course, if the developer is mixing TypeScript and JavaScript, this is not possible to do so there is a possibility JavaScript will call it without a number. In addition given some of the convulted tricks JS can do with eval and string evaluation of property names, the compiler may not recognize all calls to the function as such (but those strange calls would generate their own compiler warnings or errors for being strange). That said, if the code is clean enough and variable types declared properly, it should be fine. The developer did not bother to type define many variables even in this code sample so I would not hold my breath.

  • bvs23bkv33 (unregistered)

    GPS transfers over one million symbols per second? I thought it's only about cords and position, can I have GPS internet?

  • Chronomium (unregistered)

    Why would you divide by 1.25 when you can instead multiply by 0.8?

    /maximum_pedantic

  • Zadkiel (unregistered) in reply to bvs23bkv33

    Sure, if you can deal with ~600ms minimum latency

  • Bill (unregistered) in reply to bvs23bkv33

    That would be the spread spectrum chip rate, not actual useful data transfer.

  • I'm not a robot (unregistered) in reply to Chronomium

    Because if you did it the other way, someone would come along and say "Why would you multiply by 0.8 when you can instead divide by 1.25?"

  • Mr. TA (unregistered)

    I have to agree that trying to use JavaScript for anything but browser based user interfaces is stupid. The only reason we put up with JavaScript is because it's almost impossible to switch given how many devices out there access the internet. All these server JavaScript frameworks betray their creators' fundamental misunderstanding of technology.

  • Cybey (unregistered)

    The solution should also be const symbolRate rather than let.

  • Anonymous Fool (unregistered) in reply to I'm not a robot

    Because multiplying is faster

  • (nodebb) in reply to Dan Bugglin

    Yes; the whole point of typescript.

    Addendum 2018-07-12 11:32: -- don't know how to "reply" herein.

  • (nodebb)

    How about: Convert the input to numeric. Drop it into a bin with edges defined in a rather obvious way. Use the bin number to look up the desired output "number" . Much more fun, plus no multiplication or division.

  • Kurbein (unregistered) in reply to Anonymous Fool

    "Premature optimization is the root of all evil" Donald Knuth Computing Surveys, Vol 6, No 4, December 1974

  • Darkenon (unregistered) in reply to bvs23bkv33

    Technically yes but GPS is only designed to communicate one way.

  • I Am A Robot (unregistered)

    Really it needs a database with a look up table of the possible values.

  • (nodebb) in reply to I Am A Robot

    Really it needs a database with a look up table of the possible values.

    This could only work if the database contained a table with all possible real, irrational, and imaginary numbers for all possible bandwidths that could be supported in the future. This, of course, would also need to include negative values -- which would designate bandwidths using GPS protocol.

  • I dunno LOL ¯\(°_o)/¯ (unregistered) in reply to Bananafish

    Yes, but it's a database, you see, so they can add new values whenever they need to, without even having to take the application down! It's absolutely brillant!

  • o11c (unregistered) in reply to Chronomium

    1.25 can be represented exactly. 0.8 cannot be.

  • (nodebb) in reply to I dunno LOL ¯\(°_o)/¯

    Yes, but it's a database, you see, so they can add new values whenever they need to, without even having to take the application down! It's absolutely brillant!

    We all know "database" works best when it's a read-at-run XML or, better yet, CSV file, so a running process doesn't have to worry about new data.

  • Should be working (unregistered) in reply to o11c

    1.25 can be represented exactly. 0.8 cannot be.

    Would you expand on this? What do you mean?

  • Chris (unregistered) in reply to o11c

    Fine. Use the best of both worlds. Multiply by 4, then divide by 5!

  • Chronomium (unregistered) in reply to o11c

    Sure but that's unlikely to matter in the majority of situations, and in this case you get non-binary fractions for results either way.

    The only real reason for deciding between /1.25 and *0.8, in a modern language where one isn't super more expensive than the other, is whether you want it to be read as "the input is 25% faster" or "the output is at 0.8x speed".

  • Olivier (unregistered) in reply to Zadkiel

    Latency is not much an issue, you can wait half a second before your web page starts loading.

    My major concern about using GPS for internet would be that it is a one way protocol, a GPS receiver only receives the signal and the GPS satellites only transmit signal (at least to us mere mortals).

    While Internet unidirectionnal routing exist and is actually working (over satellite for example), it far from a full Internet access.

  • löchlein deluxe (unregistered) in reply to I'm not a robot

    Let's meet in the middle and divide by 0.8 on even days, multiply by 1.25 on odd days, and do both on intercalendary days.

  • Hasseman (unregistered)

    Never underestimate the bandwidth of a lorry full of CD's

  • Senior Dev Robot (unregistered)

    Isn't this one of those algorithms that only works on quantum computers?

  • Sole Purpose of Visit (unregistered) in reply to Carl Witthoft

    Basically, yes. Yes, very much. It's like interpolation, in a way: you have discrete numerical values to aim at, and you treat the discrete values as a "numerical spread" and figure out where your input number goes.

    The mind boggles as to how anybody could think that a regexp is a suitable tool for the job. Then again, we live in a stringified universe.

    A propos nothing much, I had a boss recently who liked to take Agile-cheap tickets (his time was rated at zero, which in one sense was correct and yet in a measurement sense was not) who managed a very similar thing in Linq. His task? To find the right bucket. His solution? Always pick the first one.

    Sigh.

  • So it matters a bit (unregistered)

    Multiplying by 0.8 is a standard deviation worse in terms of error than dividing by 1.25.

    https://snag.gy/YZzuQr.jpg

  • someone (unregistered) in reply to Should be working

    Using the [https://en.wikipedia.org/wiki/IEEE_754](IEE 754 floating-point standard), the value 1.25 can be accurately represented as it is a multiple of a power of two (5 * 2^-2) but 0.8 must be approximated as it repeats when expressed in binary.

    In binary,

    • 1.25 = 1.01 (exactly)
    • 0.8 = 0.11001100...
  • Richard O'Keefe (unregistered) in reply to Chronomium

    Why divide by 1.25 instead of multiplying by 0.8? Perhaps because 1.25 can be represented exactly but 0.8 cannot.

Leave a comment on “A Symbol of Bad Code”

Log In or post as a guest

Replying to comment #:

« Return to Article