Live data from Hacker News

Python has brought computer programming to a vast new audience

economist.com

161–170 of 268 posts

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

#161

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.

I agree. I came to Python in 2000, after Perl (1996-1998), PHP (1999), Matlab (1992-1996), C++ (1990), Fortran (1989), C (1988), Pascal (1988), Assembly (1984-86) and Basic (1981-83).

After all those, I found Python, as the saying goes, really does "fit your brain" [1]. Since discovering Python 18 years ago, I have looked at Haskell, successfully avoided Java, and promised myself to "one day" do more JS. Still, Python remains 95% of what I do, and I don't see a problem with that :)

[1] "Python fits your brain" was the theme of the 9th International Python Convention in 2001.

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

#162
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…

Type hints are optional, why not just not use them?

How are you going to know the type of an object that gets passed to a function? Why is it better to go around the codebase looking for things instead of glancing at the function signature?

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

#163
post #44

For me it's somewhat strange that it is universally presented as a beginner's language. Python would be hugely confusing to me if I didn't keep the underlying C model -- dynamically allocated objects with reference counts -- in mind at all time. Together with a lot of protocol that is largely arbitrary.

In all this time I didn’t even know python uses reference counting instead of tracing gc...

It also uses mark-and-sweep.

    a = []
    a.append(a)
Can't collect that one with ref counting.

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

#164
post #73

This seems misspoken. Python hasn't necessarily brought computer programming to a new audience. A new audience is being brought to computer programming. They just happen to be given python as their first steps. There is nothing intrinsic to python that is helping these use cases. Some people like it. Some people don't. I have not seen studies showing any real advantage or disadvantage to it. Do those exist, and I've…

Perhaps. Or perhaps programming instructors like Python better. When I taught statistics, R was more popular and featureful for the task than Python, yet I chose to teach my students Python.

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

#165

Earlier quoted context omitted.

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. Somewhe…

I understand your point. I think this is partly related to the fact that instance attributes are public by default and do not require accessor or mutator methods (though you can easily create them with the @property decorator) and partly due to the fact that Python is a very dynamic language.

You can make instance variables "culturally private" by pretending the variable name with a single underscore, and you can name-mangle (to make it effectively private, unless someone really goes out of their way) with double underscores, but I know that's annoying to do for most/all variables and that making them private by default has advantages.

Python is just not as strict a language as Java, Swift, C#, etc. That has advantages and disadvantages.

Personally, this hasn't generally been an issue for me, because I've rarely directly modified instance variables in my own code unless I'm intentionally doing something really "meta", and it's not a pattern I've seen much of in other codebases.

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

#166
post #152

Earlier quoted context omitted.

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…

Type hints are optional, why not just not use them? How are you going to know the type of an object that gets passed to a function? Why is it better to go around the codebase looking for things instead of glancing at the function signature?

The type (class really) of an object tells you nothing about how it will behave. What you need to do is check the methods attached to the object, not class, at runtime:

1) Exist.

2) Behave how you want them to behave.

I've written plenty of code that got that done by using an assert just after the docstring.

People will monkey patch, if not in your code base, than in a library you're importing.

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

#167

Earlier quoted context omitted.

> Sometimes you do want to do math on bools.. Can you provide a concrete example for when this would be useful? I assume you're not talking about binary arithmetic.

Here are some examples from the Python standard library: multiprocessing/pool.py: self._number_left = length//chunksize + bool(length % chunksize) test/test_math.py: tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1) From NumPy and SciPy: numpy-1.11.0/tools/swig/test/testArray.py:385: sys.exit(bool(result.errors + result.failures)) scipy/scipy/signal/signaltools.py:2003: n_out = n_out // down + bool(n_out % d…

>Here's one from my own code, where I allow a query to be specified through --query , or as a hex-encoded query through --hex-query or as an input file through --queries, but I only allow one of them

This would be better written as a mutually exclusive argument group. Assuming you're using argparse: https://stackoverflow.com/a/13310109

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

#168

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. Ironically, the PEP to add this to py3k is what's causing all the fuss in pythonland lately.

Actually I think it was 'fixed' as a syntax change in Python 3, https://docs.python.org/3/whatsnew/3.0.html#changed-syntax "List comprehensions no longer support the syntactic form..."

He's talking about something a little different. Python is introducing assignment expressions (vs assignment statements).

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

#169

Earlier quoted context omitted.

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

I agree. I came to Python in 2000, after Perl (1996-1998), PHP (1999), Matlab (1992-1996), C++ (1990), Fortran (1989), C (1988), Pascal (1988), Assembly (1984-86) and Basic (1981-83). After all those, I found Python, as the saying goes, really does "fit your brain" [1]. Since discovering Python 18 years ago, I have looked at Haskell, successfully avoided Java, and promised myself to "one day" do more JS. Still, Pytho…

> "Python fits your brain"

For me, I find using python is like touching both data and code with my hands.

As much as it's trendy to bash Object Oriented languages, the way python allows to lookup all variables and method on a class or an object makes it like using your hands:

dir(MyClass) help(MyClass) dir(my_object) help(my_object)

etc...

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

#170

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…

do you know an ML language like sml, ocaml, or f#? if not, you should really give one a go, especially f#. the conciseness and cleanliness is just as good if not better than python, and there are far more options for data modeling and expression.
Post reply on HN