Hacker News new | ask | show | jobs
by daenz 2506 days ago
Close, but values from os.environ are always string, and not guaranteed to be parsable numbers.
1 comments

This is a bit clearer:

    def getSocketAPIPort(defaultport): 
      return int(os.getenv('socketPort', defaultport))
Closer, but int can throw a ValueError. The original Haskell code defaulted to the defaultPort if the specified port could not be cast to an int.
I see. Though I think it's better to throw an error. I wouldn't want my app just coming up on default port if I had configured it incorrectly.
It might be in Python, but it's sorta oranges to apples for you to just not do the same thing your Rosetta code is supposed to do.

What's the value of your exercise if you just redefine the problem to get rid of the tricky part?

I’d say the original code was wrong. anyway catching an exception isn’t tricky.
If it's easy then why did you fail twice at even making a valid python expression?

When we talk about the oppressive nature of Python culture—how the "there is only one way to do it" culture leaks out of the place where it's applicable and starts to be focused on other communities that have different requirements—we think of examples like this. "Your code in a language I don't now or use is wrong."

Over focusing on how the example code polls the environment is the least interesting thing you could hyperfocus on. What's more, I think it's a bit more normal to use something like optparse-applicative, which leads to inevitable complaints about using infix operators that every Haskell novice knows but that armchair Haskell programmers hem and haw about asking, "is this too many operators?"