this post was submitted on 21 Apr 2024
708 points (97.1% liked)

Programmer Humor

32318 readers
207 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 62 points 6 months ago (4 children)
  1. You can call it "Java" to enrage other programmers
  2. You can compare numbers against strings without wasting time converting them
[–] [email protected] 11 points 6 months ago (1 children)

Array(16).join("wat" - 1) + " Batman!";

[–] [email protected] 5 points 6 months ago* (last edited 6 months ago)

JavaScript: :wide eyed and smiling: Sure why not! You're the boss!

Python: Sighing and downing half a bottle of Advil: Sure. Why not, you're the boss.

[–] [email protected] 7 points 6 months ago (1 children)

If you're living in 2002 and not using the strict equality operator, that's on you

[–] [email protected] 1 points 6 months ago (1 children)

But what if I don't want strict comparison? What if my frontend contains a text field for a numeric input and I wanna manually check against each possible valid input value if (input_val == 1) {...} else if (input_val == 2) {...} else if... without having to convert it first or check that it's actually a number or fix my frontend?

(I'm sure there are valid use cases for non-strict comparison, I just can't think of one right now)

[–] [email protected] 4 points 6 months ago* (last edited 6 months ago) (1 children)

why wouldn't you just convert inline? (Number(input_val) === 2)

Converting would mean you could use a switch statement with your example rather than an if else ladder

switch(Number(input_val)) {
  case 1:
    doTheFirstThing();
  break;
  case 2:
    doTheSecondThing();
  break;
  case 3:
    doTheThirdThing();
  break;
}
[–] [email protected] -1 points 6 months ago* (last edited 6 months ago)

If you're looking for good code, you missed the point of my comment 😄

If I was looking for an enumeration of valid inputs, I'd make it a selection box rather than a text field that's supposed to contain a number and give the selections reasonable names. If I want an integral quantity, I'd use a number input field.

If I have no control over the frontend, that means I'm writing a backend in JS for a bullshit frontend, and no amount of good coding practice is going to salvage this mess.

I'm also blessedly far away from WebDev now. I work in Data Analytics and if I ever have to do any of this for a living, something has gone very wrong.

Converting texts into numbers or dates still haunts me though - fuck text inputs for numbers and dates.

[–] [email protected] 2 points 6 months ago

The scripting language formerly known as Java.