News for hackers. Stuff that matters.
Re:Python Is Eating the World by takeda on Monday August 12, 2019 @11:57AM (#20676608)
Python is a dynamic language, that's what dynamic languages do, you don't have a type checker but have greater flexibility, but you don't have to settle on that, you can actually use mypy and annotate types and get best out of both worlds.

> And another one, I typoed a variable name as groups_keys instead of group_keys (or vice-versa, I don't remember). Instead of just throwing an error, Python happily went along with it, used an uninitialized value, and then all the logic broke.

This isn't what Python would do, if the variable was undefined Python will throw an error, so you must have defined it with this name or you're misremembering what have happened.

Re:Python Is Eating the World by ben509 on Monday August 12, 2019 @12:41PM (#20677108)
It has nothing to do with static vs. dynamic. There's no reason that being an early-binding language that a string has to be iterable itself, and the proposal to change this was only rejected as it broke too many things[1] and couldn't be automatically fixed.

Point in the GP's favor: Fixing it would definitely not be a problem with an early-binding language! In fact, the nigh-impossibility of automated refactoring puts lie to the notion that late-binding languages are more "agile."

It's a design flaw, in the same way Python 2's allowing comparisons between different types was a flaw, e.g. "a" < 3 succeeds. Python 3 now, correctly, throws a TypeError because there's no sensible ordering between the two things.

(While I'm griping: Another design flaw is conflating iterables and iterators, which makes generators almost useless. Say a generator is pass to a function expecting an iterable. If the function uses it twice, the second time it silently returns nothing!)

> This isn't what Python would do, if the variable was undefined Python will throw an error

I think GP must have assigned to the name, in which case Python will create a lexically bound name.

Python's rules for naming can make perfect sense or be quite surprising:

    try:
        x = four()
    except Thing:
        x = 5
    print(x)  # 4 or 5

    for a in [1, 2, 3]:
        pass
    print(a)  # 3 ?!
[1]: https://mail.python.org/pipermail/python-3000/2006-April/000...
Re:Python Is Eating the World by karmakaze on Monday August 12, 2019 @09:36PM (#20682014)
It's only surprising if you expect it to behave like another language. Python variables are function (not block) scoped.
Re:Python Is Eating the World by nabdab on Monday August 12, 2019 @02:16PM (#20678255)
What’s supposed to be the surprising thing? Are you confusing pass and break and expecting it to print 1?
Re:Python Is Eating the World by ben509 on Monday August 12, 2019 @02:26PM (#20678342)
What's surprising, for people used to block semantics, is that `a` survives outside the for loop at all.
Re:Python Is Eating the World by PaulMest on Monday August 12, 2019 @01:06PM (#20677420)
I'm pretty sure this is what they meant...

  def my_func():
      group_keys = 'My thing'
      while group_keys == 'My Thing':
          if some_logic() == 42:
              groups_key = 'My other thing'  # typo here
Re:Python Is Eating the World by tsm on Monday August 12, 2019 @01:25PM (#20677657)
I don't see how that's avoidable in any language that doesn't require explicit variable declaration
Re:Python Is Eating the World by CydeWeys on Monday August 12, 2019 @01:51PM (#20677989)
Yeah, that's the point. Python doesn't have it. It'd be better if it did.
Re:Python Is Eating the World by ickyforce on Monday August 12, 2019 @05:14PM (#20680076)
compiler/IDE would complain about "unused local variable"
Re:Python Is Eating the World by mochomocha on Monday August 12, 2019 @12:54PM (#20677281)
mypy is a great effort, but very experimental. Try using it on any real-world large enough project and it loses most of its value as there are still a lot of unimplemented things, or because you'll depend on a third party module that hasn't support for it yet.
Re:Python Is Eating the World by Jeff_Brown on Monday August 12, 2019 @03:10PM (#20678804)
Case in point: Pandas, the foundation of data programming in Python, does not provide the Series or DataFrame (that's a table) types in a way that MyPy can use.