Live data from Hacker News

New Ways to Be Told That Your Python Code Is Bad

nickdrozd.github.io

111–120 of 262 posts

Re: New Ways to Be Told That Your Python Code Is Bad

#111

Earlier quoted context omitted.

When I first started using python, I assumed it had a normal (c-like) ternary operator and was a little surprised to discover the syntax we're talking about. But after some time, it actually feels very natural to me, and is arguably more intuitive than ?: syntax. I assume this is where the author is coming from.

Arguably? It can be read like a sentence. ;-)

I assume they're talking about the meaning, not how you spell it.

So you can read both as a sentence. The arguable part is more about "condition and then thing" versus "thing if condition".

Re: New Ways to Be Told That Your Python Code Is Bad

#112
post #73

While I appreciate the idea of bounded loops, it's a mistake to think that a `for` loop is necessarily bounded. It's pretty easy to write a generator that produces an infinite sequence. That generator, of course, would need a `while` loop, but that loop can be in an external dependency which the linter is not checking. You also can read way more than you expected if you use a `for` loop to read from a socket, or a fi…

Or bounded… by the heat death of the universe. I think there’s a point though, if you’re writing a stack machine or something like that where it makes sense, you’d know. But many novice programmers reach for the old while-bool-var construct and set it to false in the loop body (and often reset it to true later. So confusing. )

Re: New Ways to Be Told That Your Python Code Is Bad

#113
post #52

I really hope that the condescending tone of the article was because the author was tired or something, and that it's not the attitude they use when contributing to a linter. The authors comes out as arrogant and self-centered, the "reactions" are strawmans, the tone is aggressive. Sure that nice Beeping Busy Beaver uses only one loop, very cool. The "guessing game" program that almost everyone wrote when learning pr…

Maybe the tone is fully representative. One could start to wonder what kind of people would be attracted to working on linters. 'Now I get to tell everybody what is good or bad'.

Re: New Ways to Be Told That Your Python Code Is Bad

#114

I have a much better time with Python just doing what I want instead of following the Python community's sometimes arbitrary and capricious standards.

The article is not representative of the community, quite the opposite.

In fact, the community is embracing "black" these days, the python equivalent of gofmt, exactly because we have better things to do than arguing over PEP 8.

Re: New Ways to Be Told That Your Python Code Is Bad

#115
post #56

Earlier quoted context omitted.

I shouldn't need to read the code extremely closely or repeatedly to have to figure out what it does when the while loop does it clearly (and in a bounded way that you can literally mathematically prove). Also, I would scream if some opinionated dev gone crazy with their linter added pylint disables and comments explaining it every time we use a while loop in our codebase. Why does the linter rule not, instead, check…

> Why does the linter rule not, instead, check if the while loop is unbounded and warn the user of that? Indeed, the linter only needs to incorporate of the many known solutions to the halting problem.

unBounded = null

Re: New Ways to Be Told That Your Python Code Is Bad

#117
post #97

Unbounded computation is necessary when working on either event driven architecture (block/wait for something, run it, block/wait again) or working with frames. I can’t imagine making a game (though not sure who makes games in python) without a while loop to run on the main thread.

Right, luckily it's not enabled by default. Some other fields in which unbounded computation is common are IOT and robotics.

Re: New Ways to Be Told That Your Python Code Is Bad

#118

> Anyway, this is just a style thing. It doesn’t affect program correctness or structure in a meaningful way. The nice thing about ternaries is that they're expressions, so they don't "infect" our code like statements (e.g. 'if'). For example: if xCond: x = x1 else: x = x2 if yCond: y = y1 else: y = y2 if zCond: z = z1 else: z = z2 foo(x, y, z) This lint rule will tell us to do the following instead: x = x1 if xCond…

I think I might be in the minority here that I prefer the fully laid out statements.

Sure in small cases this small ternary use is great! However too many times I've seen people chain them for far too many characters just to be "on one line".

We don't use one letter variable names anymore, so in the same reasoning why should we do the same to our code?

Re: New Ways to Be Told That Your Python Code Is Bad

#119
Most of the time when I see python ternary in the wild, it makes the code less readable, not more. Why not just define something like this if you want oneliners?

  def if_then_else(cond, true_case, false_case):
      if cond:
          return true_case
      return false_case

  x = if_then_else(condition, 4, 5)

Re: New Ways to Be Told That Your Python Code Is Bad

#120
post #113
post #52

I really hope that the condescending tone of the article was because the author was tired or something, and that it's not the attitude they use when contributing to a linter. The authors comes out as arrogant and self-centered, the "reactions" are strawmans, the tone is aggressive. Sure that nice Beeping Busy Beaver uses only one loop, very cool. The "guessing game" program that almost everyone wrote when learning pr…

Maybe the tone is fully representative. One could start to wonder what kind of people would be attracted to working on linters. 'Now I get to tell everybody what is good or bad'.

I don't think we should extrapolate to what kind of people work on linters or even on how the author thinks. I think the article and the contributions both come from good intentions, and I even agree with the two linting rules. What I don't like at all is the tone of the article. Part of the role of linters is education, and education shouldn't be done with that tone.
Post reply on HN