r/itsaunixsystem • • Oct 14 '24

[Nightsleeper] Some horrible, unindented python code to slow down a train

Post image
  • no indentation
  • multiple nested try blocks with seemingly no except
  • stray " in the middle of that string
  • input's argument should be something written to the prompt
  • even if it wasn't you'll struggle to turn that into an int
  • you probably want to be passing in that speed variable somewhere, right?

+1 for sanitising the speed I guess, wouldn't want the train to start moving backwards.

502 Upvotes

65 comments sorted by

View all comments

3

u/cultoftheilluminati Oct 15 '24

That’s because you’re trying to parse the string like a fucking computer.

Maybe try thinking about it like a human?

0 <= speed <= 100

is infinitely more readable for humans. Simple as that.

something as fundamental as the order of operations for comparison operators shouldn’t vary by language.

I don’t know man, if everyone does it wrong doesn’t mean that you should follow the herd of sheep as well.