718
you are viewing a single comment's thread
view the rest of the comments
[-] PrettyFlyForAFatGuy@feddit.uk 4 points 6 months ago* (last edited 6 months ago)

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;
}
[-] luciferofastora@lemmy.zip -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.

this post was submitted on 21 Apr 2024
718 points (97.0% liked)

Programmer Humor

32380 readers
765 users here now

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

Rules:

founded 5 years ago
MODERATORS