Live data from Hacker News

Python is not a great programming language

gist.github.com

111–120 of 156 posts

Re: Python is not a great programming language

#111

TLDR: if you’re a new programmer, don’t take this seriously. This person clearly doesn’t understand programming languages so well. Sorry to make this response an “ad hominem” one, I should revoke the claims. But it’s impossible if they don’t understand basic concepts of programming languages. For example, complaining that a dictionary key must be place in quotes. It’s not that “the key needs quotes”, but that you’re…

> For example, complaining that a dictionary key must be place in quotes. It’s not that “the key needs quotes”, but that you’re using “a string” as a key. In fact in Python, you can use any immutable object as a key (tuples, for example). They clearly come from Javascript, Python works differently (and arguably better), and they’re complaining that it doesn’t work the way they’d like it to work.

Agreed. However, there's a trick to use strings without quotes:

    dict(foo=1, bar=2) == {'foo': 1, 'bar': 2}

Re: Python is not a great programming language

#112
post #94
post #91

Earlier quoted context omitted.

What special-case syntax? The only brazenly pythonic thing in there was the (iterative) tuple unpacking, as in (for) k, v in dic.items() which is just k, v = ( , ) for every key value pair in the dictionary

There are a number of precedence rules you need to keep track of to parse the list comprehension. There are two different syntaxes that do the same thing. Arguably you need to do the same if you don't already know how the threading macro in the my second example works. I posted due to your claim regarding all other languages necessitating increased verbosity. I should have left it lie, as I didn't intend to promote a…

No language war intended, just curious how something I see as a wheel could be improved.

Re: Python is not a great programming language

#113
post #55

Earlier quoted context omitted.

I personally find list comprehensions in python pretty horrible. They seem to exist only to do lots of stuff in one single line of code. You end up with totally impenetrable unreadable perl-esq garbage write-once-read-never code that is too clever for its own good. And people say python is easy to learn and good for beginners...! A better approach would be something like Java Streams/.net Lync/RxX pattern IMO. Explic…

You can decompose any list comprehension into it's equivalent for loop fairly easily. I don't see what is so magic about them other than the language having a special compiler level optimization for them? g = [i for i in list if x == 3] -> g = []; for i in list: if x == 3: g.append(i);

I see people frequently say that list comprehensions are special-cased and highly optimized by the compiler, but I did a few experiments recently with `timeit` and found that using `map()` is on the order of 1.5x faster in all the cases I tested. I think that either winds up being faster than a manual for loop, though

Re: Python is not a great programming language

#114

These all just seem related to syntax, not actual program structure or capabilities. The only program structure thing I see is list comprehensions, which is one of Python's great strengths. Ironically they say Ruby is more pleasant to write, when Ruby has the deepest structural flaws of any dynamic programming language.

Of _any_ dynamic language? That's a pretty bold claim.

Re: Python is not a great programming language

#115
post #5

I love Rob Pikes idea that is dumb to have scope determined by invisible characters

Python doesn’t really have scope in that way. Variables declared inside an if statement can be accessed outside of the if statement.

Control-flow blocks aren't scoped in most popular programming languages.

Re: Python is not a great programming language

#116
post #29

I wish more languages did something like the D feature where method syntax and function syntax are really just syntax - i.e., str.len() is equivalent to len(str), and you use the syntax that best improves readability at your call site.

MATLAB of all languages does this! Although as usual it's quirky about performance: the foo(bar) syntax (which used to be the only syntax) is faster.

Re: Python is not a great programming language

#117
post #108
post #75

> you have to do foo.get('bar')... or in some cases getattr(foo, 'bar', None) This is a mistake based on thinking in Javascript: in JS the index operator is effectively the same as the dot operator, for example foo[“bar”] == foo.bar. In Python those are different. [] corresponds to get in dicts, and . corresponds to getattr in objects. My personal biggest gripe with Python is that there isn’t a better story for typin…

How about post 3.5 type hints?

Every time I mention typing in Python, people point out the existence of type hints and type checkers. However, I’ve yet to be able to meaningfully use one in practice. I have used MyPy but it didn’t offer nearly as much benefit as say, TypeScript, and brought problems of its own. There’s been some work done but for example, Django middleware is problematic here. A lot of Pythonic code would be extremely challenging to actually cover with robust typechecking.

Not to mention, a lot of software treats type hints very differently. PyCharm is able to do powerful inference that MyPy can’t do.

Re: Python is not a great programming language

#118
post #4

Earlier quoted context omitted.

> lack of typing information isn't "free solo" hard but it certainly makes life a lot less pleasant. One of the projects I work on has switched to full type hinting along with heavy mypy¹ usage, and it has become an absolute pleasure to work with. Along with hypothesis², I can't recommend mypy enough. It must be said that retrofitting either to an existing project is a lot of work though. 1. http://www.mypy-lang.org/…

What I can't reconcile with myself is, if I'm going to add type hinting in Python, why not use a language where my efforts of adding type hints result in performance gains? I get why it's nice for a team, but it seems like a lot of work for half the potential benefit of a typed language.

Cython can. However, machine performance doesn’t matter a lot of the time.

Re: Python is not a great programming language

#119
post #4

Earlier quoted context omitted.

> lack of typing information isn't "free solo" hard but it certainly makes life a lot less pleasant. One of the projects I work on has switched to full type hinting along with heavy mypy¹ usage, and it has become an absolute pleasure to work with. Along with hypothesis², I can't recommend mypy enough. It must be said that retrofitting either to an existing project is a lot of work though. 1. http://www.mypy-lang.org/…

I note with interest that modern python has type hints. Years ago the lack of visible types was often flouted as a benefit (i.e. terser code, less boiler plate, easier for learners to understand etc). I eagerly await the addition of optional "scope hints" of { and } ! ;-) Sarcasm aside, now that there are type hints and python programmers need to type as much as Java/golang/c# programmers, why not just write in those…

> I eagerly await the addition of optional "scope hints"

Scope hinting is simply called braces; `from __future__ import braces`.

> Genuine question ...

IMO assuming all things are equal seems to miss how things actually are. The pluses still fall on Python some times, and other languages at other times. Things do vary; developer availability, library availability, target system support, certification story, tooling, even curbside appeal can be legitimate on some occasions.

I'm trying not to pick on your individual language examples, as firing digs seems to be missing the point we're discussing. Or perhaps it is the very point, as two of them wouldn't have even been in my list.

Re: Python is not a great programming language

#120
post #13

> a big part of my frustration comes from having a JavaScript background Yeah, I thought so when I was reading the list of "problems". In fact, many of those are features (e.g. lists & tuples being different, list comprehensions, lazy evaluation, distinction between maps/dicts and objects, ...) but the author doesn't actually understand them. I hate to sound so negative, I guess I just didn't realize how bad a progra…

There's some annoyances that have accumulated in python, like the inheritance patterns and too many underscored things. Decorators are kinda weird, too.

I think Python is pretty awesome, but to pretend that it's super clean is a bit of a stretch.

(a,) for a single-elem tuple-- avoiding colliding with (a) as a paren'd expression-- is wonky, too.

Post reply on HN