Live data from Hacker News

Python has brought computer programming to a vast new audience

economist.com

81–90 of 268 posts

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

#81
post #59

Earlier quoted context omitted.

> My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded. Can you elaborate? I'm not sure what this is referring to.

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…

When you use iPython you can just drop into the context of the error with %debug after it occurred, and then print the line there. No need for the bleeding scope on the language level.

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

#82
post #48

Earlier quoted context omitted.

What other language are you comparing Python's flaws and tradeoffs to?

Java, PHP, C#, heck, even JavaScript/ES[6,7]. I feel like Python has a lot of its own ways of doing things, whereas a more idiomatic approach is imho a better way to go. Why the hell in the world would you call a class constructor as __init__? Pretty much every popular OOP language does it either by naming a constructor the same name as the class name or through some form of a `construct` notation. Why `self` and not…

Java, C# and modern PHP have a very similar style that's not at all universal. If you're used to those, Python is odd, but it can get a lot weirder. At least Python has classes.

__init__ is called that because it initializes the object. It could have been called "__construct__", but I think "__init__" is a lot clearer about what it actually does - the object is already created when it enters __init__, __init__ just prepares it.

Calling it "self" instead of "this" is super traditional. Smalltalk did it.

The __name__ == '__main__' pattern is ugly, and I'm not a huge fan of it. You don't always need it, it's just a guard to let you tell whether a script is run directly or imported as a module. The key is that Python only has runtime. A function declaration or class declaration is a fancy variable assignment. The content of the file is executed sequentially.

Python is not especially weird, but it is different from what you're used to. Wrapping your head around it takes a while, like with all languages, but things start to click eventually.

It helps to experiment. The REPL is great for that. If you don't understand why something is the way it is, mess with it until you think you understand its behavior, then mess with it some more.

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

#83
post #6

Earlier quoted context omitted.

Can you explain implicit type conversions problems in python?

It is not a problem, it was just non expected behavior for someone trained in strong typed languages. For example, you want to calculate the performance of your ML algorithm by counting the correct predictions / total. My expectation was that the result of a division of integers, would be a float, specially if the modulo is not 0.

That result should be a ratio, surely

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

#84

Read the comments here. Look at the diversity of opinions and the number of them that, while professing love for Python, directly contradict each other. Python is verbose|concise, simple|advanced, disciplined|experimental, modern|classical. It goes to show: something doesn't need to be actually-better. It doesn't need to be actually-simpler. It doesn't need to make your job easier or better. It needs to make people t…

Not all of those are contradictory. For example, Python mostly stays away from cryptic syntax and implicit behavior, making it verbose, but it finds powerful ways to express common patterns, making it concise. You get a small amount of readable explicit code. The words are antonyms if you pick their meanings carefully, but they don't have to be. Python's design isn't revolutionary, but it's good and the language happ…

> Not all of those are contradictory. For example, Python mostly stays away from cryptic syntax and implicit behavior, making it verbose, but it finds powerful ways to express common patterns, making it concise.

Unsurprisingly, I disagree with this opinion. Python code is typically nearly as much as a slog as Go code, but adopts all the brutally hard parts of the common lisp's functional world by only exposing wrap-primitives.

> JavaScript's design had much less impact on its success than Python's design did on Python's success. It was doing the right thing in the right place at the right time, and how it did that wasn't all that important - once it turned into a web standard it wasn't going away.

The Python community would have us believe this. I think it's a profoundly biased and one-sided reading of the history that paints a bullseye around the target. Python's primary innovation is a community that doesn't embrace differences and growth, but rather hates and hazes it. And when change finally does happen, it happens in the way most likely to cause everyone heartache, as if to fulfill the prophecy the community made.

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

#85
post #22

There seems to be a sentiment that Python is a kids language - but I think of Python as a language that scales with your experience. You can do some really interesting and complex things and I’m really appreciative of my deep understanding of the language through a decade of heavy use, open source contribution, and project ownership. Recently I released a package which allows you to dynamically create or change funct…

> There seems to be a sentiment that Python is a kids language I only hear this from developers that have never used Python or work in problem domains where the language is genuinely not better (e.g. low-latency distributed services, embedded devices/IoT sensors). I've scaled Python & PHP web apps to a hundred million monthly visitors on Top 20 US destinations on very limited hardware (6-10 machines). It's surprising…

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.

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

#86
post #52

Earlier quoted context omitted.

Other than interfaces and generics (which would make no sense to add in Python, since it's dynamically typed), can you name some OOP features Java has that Python doesn't have?

This may sound super n00b but I really like that Java is explicit about everything. So for instance, you explicitly specify variables, methods as private with the keyword 'private'. In python you have to use an underscore, and its still not really private, its obfuscated. That's just one example, but in general I really like that kind of by-the-book verbosity, instead of having to mentally map it into the OOP concept…

Why would you want to actually enforce privacy? That makes it harder for the user to patch. Better to provide a mild discouragement via "_name".

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

#88

Am I the only who thinks that "90% of American parents want their kids to be computer scientists" is rather unsettling? The market is currently full of people who are in for the money and will continue to be. It will be filled with people until supply meets demand. That the salaries will drop significantly is a natural result of this. We had this pork cycle for teachers, doctors and other highly trained people. No on…

Maybe it makes sense to encourage your kids to go into blue collar jobs. In a future teeming with code monkeys, plumbers and electricians are going to be highly valuable.

As for the current career programmers, maybe we should unionize before our jobs are being taken by kids coming out of 2 week bootcamps (who have been taking programming classes since kindergarten).

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

#89

Earlier quoted context omitted.

W/O going into the war of I'm better than you (Python vs JAVA)... Python is built to make it easy to write good programs... where as JAVA is built to make it hard to write bad programs.... same objective but different thinking/approach to achieve it... hence one(Python) would eventually have larger adoption....

I agree with this sentiment but it is a bit of a double edged sword for Python professionally. There is some really good Python code out there but there is also a lot of bad stuff too. I know this can be said for every language but I think I have seen it most in languages like JS and Python because of the ease of access.

A better measure would be the amount of bad code produced conditioned on the skill/experience of the author. I'd be more worried about a beginner C programmer than a beginner Python programmer.

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

#90
post #59

Earlier quoted context omitted.

> My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded. Can you elaborate? I'm not sure what this is referring to.

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 change.

It’s worth noting that the latest python pep is going to give you a way to assign the variables in the outer scope again:

https://www.python.org/dev/peps/pep-0572/#simplifying-list-c...

Post reply on HN