Live data from Hacker News

Python has brought computer programming to a vast new audience

economist.com

151–160 of 268 posts

Re: Python has brought computer programming to a vast new audience

#151

Earlier quoted context omitted.

> can you name some OOP features Java has that Python doesn't have? Encapsulation. In Python you can write code in an OO style and benefit from inheritance, but it’s really only good for people writing libraries and frameworks. For end user code, objects are best avoided because they can pick up state in unexpected ways, which leads to problems that are extremely difficult to debug.

Could you give some examples? What encapsulation features does Java have that Python doesn't? You can get private methods with double underscores. It's true that attributes in Python objects are all public by default and in Java you have to be more explicit to get public attributes, so maybe that counts, but otherwise what do you mean by "objects can pick up state in unexpected ways"?

So let's so you have:

  class Foo():
      def __init__(self):
          self.bar = 1
Then let's say you have foo_instance imported in your module, and you see that foo_instance.bar has a value of 2.

You can see that foo_instance is imported from module A. So you go there, and see that the instance wasn't created there, it was imported from module B. But wait, it wasn't created there either, it was imported from module C, etc.

Somewhere along the way bar picked up the value of 2. But it's almost impossible to figure out where because there isn't any requirement use a uniquely-named accessor to modify the instance, so you can't just grep through the code to see where that method was called. (And maybe the name of the instance has changed a few times along the way, for whatever reason.)

And what's worse, the code that modified the instance might not even be visible in any of the modules, it's possible that someone took advantage of Python's ability to change the way the importing system works to mess with either the class or the instance. Or maybe there is some global middleware that's messing with objects or instances, or unrelated module Z is secretly monkey patching module B somewhere in the middle of this process. Who knows, and good luck figuring out.

Whereas if you just write the user-code logic in functions then it's not possible for developers to create situations like this. That obviously isn't possible for a library where the entire point is to make everything extensible and where you don't know how people will want to use something in advance, but hopefully the people writing libraries and frameworks have good enough judgment not to completely abuse the tools.

I'm not sure if I can really articulate how this is different than Java or Swift or whatever, but for whatever reason it just feels different.

Re: Python has brought computer programming to a vast new audience

#152
post #85

Earlier quoted context omitted.

Even IoT sensors are easier to program with micropython. What I find worrying is the the language is changing to suit those people, e.g. type hints, rather than teaching them learning to use the language. You don't complain you can't use a hammer as a screw driver, you just don't use a hammer.

I agree that sensors are easier with Micropython and will use that if I can (unfortunately the C++/Arduino ecosystem is much, much larger). However, type hints are a fantastic feature and I can't recommend them enough to anyone who writes software for a living. It makes maintenance at least an order of magnitude easier.

1). C++/Arduino for micro controllers ends up using more memory than micropython. I've managed to get the binary sizes to 1/4 by doing cross compiles and linking things my self.

2). Types hints are a terrible non-pythonic kludge to solve a people problem in code. People who want to write java with whitespace and no curly brackets love them. CPython has made a number of bad decisions lately that make the language less usable. I've moved quite a bit of my everyday code to PyPy. Since they eat their own dog food they are keeping their dialect sane.

Re: Python has brought computer programming to a vast new audience

#153
post #112

Earlier quoted context omitted.

No, I'm not referring to duck typing. An abstract base class enforces the interface. Explicitly. Some benchmarks might be slower, but I don't know anyone doing high-performance computing with PHP. I do see the topic at Python conferences.

abstract base class != interface

Right, they're even better than Interfaces: both a contract and a partial implementation. No need for an "Interface" when you've got ABCs.

Re: Python has brought computer programming to a vast new audience

#154
post #90
post #59

Earlier quoted context omitted.

In Python 2.x the loop variable is part of the containing scope: >>> a Traceback (most recent call last): File " ", line 1, in NameError: name 'a' is not defined >>> [a*2 for a in (1,2,3)] [2, 4, 6] >>> a 3 In Python 3.x, it is not: >>> a Traceback (most recent call last): File " ", line 1, in NameError: name 'a' is not defined >>> [a*2 for a in (1,2,3)] [2, 4, 6] >>> a Traceback (most recent call last): File " ", li…

I’m the same, I would never use that side effect in production code but I do miss having it in ipython though my use is slight different. I often did: >>> [d for d in drawings] >>> [d. ...] Because I’m lazy and I want the autocomplete to be there for me. It’s actually the only thing I miss from python 2 and I will admit that a couple of times the sideffects have caught me out in production code so I’m happy with the…

[deleted]

Re: Python has brought computer programming to a vast new audience

#155
post #94

Earlier quoted context omitted.

The evidence is in the usage. As I said, Javascript decided it was a bad idea, despite its popularity in Python. Your phrasing is a little aggressive, so I'm guessing this is one of those discussions where there's no real chance to change your mind, but I'll give it a shot. Consider one of the most friendly languages, SQL. Python comprehensions follow the same pattern as SQL. SELECT expression FROM table WHERE condit…

> The evidence is in the usage. That's not what I asked for. You're asking me to accept a concrete proposition that I obviously don't. To sway me, I'd like proof, not a single example labeled evidence.

Proof? Describe what proof means to you.

The fact that Javascript decided not to adopt the syntax seems like good evidence to me.

I'm not asking you to do anything. I'm offering you some insights. Normally people pay me for my time, but I suppose I feel like volunteering at the moment.

Re: Python has brought computer programming to a vast new audience

#156

The thing I love most about the language is its conciseness, on several levels. It's syntactically concise because of its use of whitespace and indentation instead of curly braces. Expressions are often concise because of things like list slicing and list expressions. It can be linguistically concise, because it is so easy to fiddle with the data model of your classes, to customize their behavior at a deeper level. F…

"Besides the odd gripe here and there, the language really gives me a warm glow." That's a perfect summary of my feeling towards it, too. If the PSF puts up a GoFundMe for sending Guido on a nice vacation of his choosing, I will be happy to chip in a few bucks. Same goes for Linus when he hands over the reins, and a few other maintainers who probably cannot be adequately compensated for the impact of their work.

Ask Naomi Ceder who is the chair of the PSF. She's super nice.

Re: Python has brought computer programming to a vast new audience

#157

The thing I love most about the language is its conciseness, on several levels. It's syntactically concise because of its use of whitespace and indentation instead of curly braces. Expressions are often concise because of things like list slicing and list expressions. It can be linguistically concise, because it is so easy to fiddle with the data model of your classes, to customize their behavior at a deeper level. F…

I went through a course in python about a decade ago and I enjoyed it! Then along the way, I picked it up here and there. Then used it at work for a few months to sort through a lot of data. Recently I started trying to learn swift through the Stanford course. And the curly brackets confused the heck out of me. They still do! They just seem to pop up out of nowhere. All to say , I completely agree with your second pa…

Usually braces define the scope (or lifetimes) of variables.

C/C++/Java use them quite a bit.

Re: Python has brought computer programming to a vast new audience

#158
post #94

Earlier quoted context omitted.

The evidence is in the usage. As I said, Javascript decided it was a bad idea, despite its popularity in Python. Your phrasing is a little aggressive, so I'm guessing this is one of those discussions where there's no real chance to change your mind, but I'll give it a shot. Consider one of the most friendly languages, SQL. Python comprehensions follow the same pattern as SQL. SELECT expression FROM table WHERE condit…

> The evidence is in the usage... It's possible it was not adopted because there's a cost involved in every feature that has inconsistent support across runtime. The benefit needs to outweigh that cost. > Putting the expression first makes the language more declarative The case for a specific order makes less sense in a declarative language, not more. And: [1,2,3,4].map((x) => x * 2) Doesn't seem substantially more o…

Listen to how people who don't program describe the task of transforming each element of something. In my experience they often say something along the lines of, "I want y for each x in z," rather than, "For each x in z, I want y." The latter is more common among people who've been programming in certain languages, not the average person. I don't have systematic data collection for this, just personal experience. But the Javascript decision adds some evidence, in my view.

> it's simply never been clear to me what comprehensions buy in terms of readability or semantics over map/reduce/etc

Ask some random person off the street to read your source code. They're more likely to get the gist of code using comprehensions than code using map/reduce/etc.

> SQL ... convenient only in [its] domain.

Which is exactly the domain we're talking about when discussing comprehensions.

Re: Python has brought computer programming to a vast new audience

#159
I think this comparison [1] in particular explains a lot of Python's continued success over the past 5-10 years. For a very long time, CRUD back-end programming was one of the biggest draws of new users to Python. In the last couple of years, interactive data analysis has completely overtaken it.

[1] https://trends.google.com/trends/explore?date=all&geo=US&q=%...

Re: Python has brought computer programming to a vast new audience

#160
post #152

Earlier quoted context omitted.

I agree that sensors are easier with Micropython and will use that if I can (unfortunately the C++/Arduino ecosystem is much, much larger). However, type hints are a fantastic feature and I can't recommend them enough to anyone who writes software for a living. It makes maintenance at least an order of magnitude easier.

1). C++/Arduino for micro controllers ends up using more memory than micropython. I've managed to get the binary sizes to 1/4 by doing cross compiles and linking things my self. 2). Types hints are a terrible non-pythonic kludge to solve a people problem in code. People who want to write java with whitespace and no curly brackets love them. CPython has made a number of bad decisions lately that make the language less…

> Types hints are a terrible non-pythonic kludge to solve a people problem in code.

I have a love/hate relationship with type hinting in Python. I've been using them for about 2 years, and it still just feels... unnatural. I usually add enough so that my IDE (PyCharm) has better autocomplete and that any Sphinx generated docs have sufficient coverage of types I may have missed when adding @params.

Post reply on HN