Hacker News new | past | comments | ask | show | jobs | submit login
[flagged] Python is not a great programming language (gist.github.com)
74 points by robertakarobin 30 days ago | hide | past | web | favorite | 153 comments

> 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 programmer knowing (only/mainly) JavaScript causes you to be.

> I guess I just didn't realize how bad a programmer knowing (only/mainly) JavaScript causes you to be.

Hey now - not all of us ECMA devs are total crap, but, I guess I know a fair bit of other languages. This guy is just totally ... I have words for it but I'd rather not get the mods on me.

I struggled with an appropriate way to say this but I think he's super pretentious and just sounds frustrated with learning a new language. I mean, we've all been there but typically we don't post ignorant BS to HN/GitHub about it... Every time I jump into a new language I'm always stubbing my toes on things I find "awkward", only to learn later that there's usually a reason people design languages certain ways.

If he wants to shoot his social media reputation in the foot as a developer then so be it I guess =/

I struggle with learning new languages from time to time and there's always been a learning curve from starting out to being proficient.

But while Python itself I think provides an awesome developer experience, django seems less than awesome, and it's taken a while for me to feel proficient in Django.

Personally, I'm not a huge Django fan, but then again lots of people aren't huge Laravel/Symfony fans which is my web framework of choice if I'm building a monolith web app/API "software bus" sorta solution without roping in Java.

That all said, I do love me some Python though! I use it as a general purpose tool to get semi-complex things done that are more scripting/job oriented vs. needing the orchestration that Django brings to the table. You could say it's a "cog" for me vs. the overall machine/engine.

It's on my TODO list to get into some other Python framework libraries because I've seen lots of promising ones pop up since Django, if anyone has suggestions of what to poke my nose into I'm all ears!

After reading what the author wrote, including gems such as

> Too many other weirdo bits of magic syntax, like [list comprehensions].

I sadly have to agree with you.

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.

The tuple notation is one of those places where the obvious way is a distraction. A non-empty tuple doesn't need the ()s - it's the "," which makes the tuple! The following two are equivalent:

  x = 1,
  x = (1,)
Of course, then there's no way to express the empty tuple using commas, which is where () comes in.

Using (a,) is the belts-and-suspenders way of saying "this is a 1 element tuple".

Which is just further elaboration on the syntax being excessively special cased.

Oh, agreed. Just wanted to point out that I think the transition from "()" to "a," is the underlying problem, not from "(a)" to "(a,)"

I think there exists a lot of space between being “not a great programming language” and “not being super clean” though.

For the single element tuple case - what else would you suggest? You can always do Tuple(3) instead of (3,) if you'd like.

Could use something other than parens for bracketing tuples, so you don't have the conflict with the order-of-operations use of parens.

Such as?

All the brackets are currently spoken for: [] = list {} = set / dict <, > = less / greater than

I suppose you could overload <, > but I'm not sure that's much better.

Honestly, the more I've learned different languages the more I've come to the conclusion that little syntax changes like this are minor, for the most part, and what really changes the power and feel of a language are the abstractions that it allows for.

<> avoids syntactic ambiguity just fine-- There won't be an identifier or constant before it. <1,2,3> <1> and <> are all plausible-looking and you don't need to guess how to do 1 element or 0 element things if you know <1,2,3>.

> Honestly, the more I've learned different languages the more I've come to the conclusion that little syntax changes like this are minor, for the most part,

Sure, it's minor. But it's one of the few things I tripped over learning python and had to google repeatedly to get to stick in my head.

The fact that python has relatively few cases of weirdness like this-- compared to say, perl-- is a big part of what makes python nice.

How about how condescending of a programmer not knowing JS causes you to be :-)

Either way, if the number of idiosyncracies in your language is confusing to junior developers it's absolutely something worth considering.

Complaining about things you don't understand is pretty bad practice. The parent poster was pointing that out. Sure, the Javascript dig is unnecessary, but the language currently holds a position as the spot of first language many junior engineers employ.

>Either way, if the number of idiosyncracies in your language is confusing to junior developers it's absolutely something worth considering.

Why? Aiming for the lowest common denominators and the simplest systems tends to not create scalable long term solutions.

You also seem to really undercount what a properly trained junior developer is capable of understanding.

Most popular programming languages got popular by aiming for the LCD in some capacity, e.g. Java. It's the reason why we're not all writing LISP or Haskell.

I don't think that's the main reason why and is probably a small factor at best.

Java rode a couple of different trends at the same time: it provided a somewhat smooth upgrade path from C++, cross-platform compatibility, and an astronomical marketing budget.

Many languages in the top-10 that we believe are popular or mainstream got there by having one of platform lock-in, smooth upgrade from a prior language, or a killer, exclusive app. It's a lot less about what is good or objectively better and more about being in the right place at the right time.

I've heard some claim that Python got there by being slow and steady. At one point I think I would have agreed but it does have a killer app and that's in the analysis, scientific and machine learning communities.

I don't think Python has any issues with popularity.

JavaScript is full of idiosyncrasies.

What drives me nuts about doing JS is that the browser execution model seems vague.

In python, I can have the

if __name__=='__main__': main()

at the end if a script, and easily import the script's functions into

- pytest for testing

- some other module for larger modules

- into a cli.py file to slap a Click interface on it.

What a great blend of flexibility while retaining coherence.

Part of the problem here is clearly this person is mapping JavaScript idioms to python; in particular "Needing to put dict property names `{'in': 'quotes'}": these aren't object properties, these are keys in a map, and they can be and often are variables themselves, (also, can be any hashable type, not just strings) and I don't see how that can detract from the 'greatness' of python.

Also "foo['bar'] returns a KeyError", then saying sometimes this is resolved by "getattr(foo, 'bar', None)" -- the split between attributes and items are one of the best things about python.

I don't know why list comprehensions are "magic syntax", and you can't complain about having to type list(map(...)) and then complain that you don't like list comprehensions!

"You have to cast your data back to a list/tuple after using enumerate() and map()." -- I don't know what that means

"Different syntaxes for lists and tuples." -- Again, what? They're different types!

How is r'a\nd' less "goofy" than String.raw`a\nd` in JS or any other language with prefixed strings?

Python is clearly not for everyone nor for every problem, but in my opinion it is a great programming language.

> "Different syntaxes for lists and tuples." -- Again, what? They're different types!

Lists and tuples have different syntax in a weird and surprising way. List syntax is straightforward, just square brackets and commas. Tuple syntax pretends to be list syntax with parentheses but it's actually only about commas except when it isn't.

Typically you write `(a, b)`, but the parentheses are only for precedence, and can be left out if it's unambiguous: `a, b`. You can write a 1-list as `[a]`, but a 1-tuple is `(a,)` because `(a)` is just `a`. An empty tuple on the other hand is `()`, without any commas, and with parentheses doing something other than precedence. It's very ugly.

I can't think of a better way to fit it into the rest of the syntax but I still count it as a flaw.

It’s the one of those common situations where there’s no perfect solution, so one from a number of suboptimal ones needs to be chosen. This rubs random folks in random ways, and is endemic to language design. Just try to design one without no such compromise.

In this case the problem stems from the overloading of parentheses. There aren’t any more paired delimiters in ascii available unfortunately. Perhaps t[] could have been chosen, but as you see it isn’t exactly elegant either.

Ah, yeah I see; there's an ambiguity in parsing expressions and tuples which could lead to subtle typing bugs. There's another ambiguity that (a for a in b) is not a tuple, but a generator, while [a for a in b] is a list.

> "You have to cast your data back to a list/tuple after using enumerate() and map()."

I think he means you don't get a list/tuple back after applying enumerate and map. That's actually lazy evaluation and it's a plus. If you just want to iterate over the values, why create a list that you are going to throw away? Twice the effort for nothing.

I agree with you that this reads as someone expecting JS behavior in Python.

On the dict property name thing, you can do:

  {'a':1, 'b':2, 'c':3}

  dict(a=1, b=2, c=3)
I find the second syntax easier to read and write for dicts where all of the keys are static strings that are valid Python variable names.

> "You have to cast your data back to a list/tuple after using enumerate() and map()." -- I don't know what that means

I'm assuming that the author has a problem with the fact that those two functions return a generator and not a list.

They return an iterator, not a generator.

You are correct, I typed without thinking. But my point remains the same.

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.

I’ve always been super happy using Ruby. Never had any experiences that would cause me to label it in the way that you have. However, I am interested to know what those flaws are. Could you elaborate?

Disclaimer: I do ruby for my day job, and python for fun Disclaimer 2: I don't hate ruby, despite all these criticisms. If I had to pick a worst dynamic language it would be PHP.

Things I don't like about ruby: - two string types, symbol and string, with string being the mutable by default one.

This means given a random thing back from an api, you don't know whether to do thing[:id], thing["id"], or thing.id

This has been acknowledged as a pain point by Matz, which is why in ruby 3 strings will be immutable by default.

- Simultaneously too many names for things and not enough.

Is it .length or .size or .capacity (probably not capacity)? is_a?, kind_of?, or instance_of?? Why can I do .select or .keep_if but not .filter?

- Too many function types.

Do you want a method, a block, a proc, or a lambda? There are subtle differences between each, so choose wisely. I'll note that python suffers from this too (method, function, lambda, comprehension).

- Too much emphasis on magic

Novice rubyists get frequently bitten by all the advanced (and very hard to google) ruby concepts. How do you know what arr.map(&:id) is without already knowing that it's calling symbol.to_proc? How about $1 $? $! (if you know what all these do, you're a better rubyist than I am).

Since the author of the referenced post criticizes django for being too magical, try rails. In addition to the names of files mattering a ton, there's the routes DSL, the migrations DSL (which is not well specified in the guides), and ActiveSupport, which you only realize you're using when it's gone.

- Horrible error messages

undefined method :[] for nil:NilClass (when you try to get something out of a hash and it's nil) cannot convert Symbol into Integer (this is on an array being returned where a hash is expected) Also, if you get a stack trace, it's completely inscrutable. Python's stack traces (at least ipython's) show you both the line number and the line in question (often with context).

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

Well in an industry where people are often “Code should be written to make sense for humans first, machines second.“ syntax concerns seem pretty valid.

As a Python coder going back to 2008, I can see the point the author makes in isolation.

I disagree with the title though. Even though I mostly write Rust, Go, and C anymore, I am fine with digging into Python as needed. I cringe at thoughts of using Ruby or JS

Something not mentioned in list that I had never considered until a conversation last year: meaningful whitespace is biased towards sighted programmers. According to a blind acquaintance, it is much easier to keep track of opening and closing parentheses and braces. Meaningful whitespace forces blind programmers to always check the number of tabs at the beginning of each line to make sure scope hasn't changed.

Couldn't whatever tool they use just apply a transformation from indentation change to brace?

Interesting aspect. Kind of sad that our tooling is typically too simple to map something like this: Having cues for indentation changing would be easy, but it's a niche feature and thus probably won't be there.

even if you can see, it's harder to copy paste. which could be a feature or a bug

This is so surface level it's not even worth addressing

> The syntax for classical inheritance. Half of each Django app is super().__init__(args, *kwargs)

Care to show proof? I don't see this a lot.

The code of the official Django site for example has 8 occurences: https://github.com/django/djangoproject.com/search?q=super+_...

> 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 typing as I’m spoiled by TypeScript and static languages that have a better development experience and prevent certain classes of mistakes.

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.

I /feel/ like this gist is largely on the money, and also uninteresting at the same time. All languages suck, and often suck in different ways for different users. We just have to pick the one that is working best at the time, and that we're best at working with.

I will say that I do like the act of writing a pro and con list for a language or tool though(which is why I read the linked doc), and I often push co-workers to do so when they're suggesting things. Sometimes it shakes a bad choice out just with the simple act of jotting down a 5-point list.

Unless, of course, there actually is an ideal language out there. In which case I retract my point ;)

There is, and it starts with L. (Lua, of course.)

There are plenty of things about Python that are not good, and only two are touched on in this list (the cumbersome double-underscore syntax and "magic methods" in general, although the author clearly has experienced python mainly through Django, which has other problems). The rest read like someone who doesn't really know the language that well and hasn't a lot of experience in general.

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

Then complaining about list comprehensions as a “weirdo” thing. Clearly not understanding the functional paradigm and the beauty of expressions (see Smalltalk for the ultimate example of beauty and expressiveness).

> any immutable object as a key

Any hashable object, technically. Especially with custom objects, the two (immutability and hashability) don’t necessarily have to overlap, although it’s often a bad idea to have hashable, mutable objects

Mutable objects can't be hashed right?

As the comment you responded to says: An object can be mutable and hashable. E.g. any custom class by default has mutable and hashable instances.

How can you get both mutable and hashable instances at the same time?

the only requirement on a hashable instance is that it implements a proper __hash__ function. The default implementation in CPython returns the address of the memory the object is stored at, so all instances are considered unique, values play no role at all.

> 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}

how is that a trick? you still can't access without quotes? the real trick is a Dict class that in the __init__ sets self.__dict__. but why would you do that just to save trying quotes

To be fair it is pretty confusing how Python and JS have two features that look very similar on the surface (dictionaries and objects) but actually work very differently. As someone who uses both languages infrequently, it trips me up.

Actually nowadays it's discouraged to use list comprehensions in Haskell. Even though he didn't complain about it, Python has very poor facilities for functional programming overall.

I think I agree.

Here are a couple of more, from someone who has worked for years in a number of languages:

- few limitations means you can easily make a serious mess, which means you are more dependent on good programmers to avoid the mess.

- lack of typing information isn't "free solo" hard but it certainly makes life a lot less pleasant.

> 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/ 2. https://github.com/HypothesisWorks/hypothesis

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 languages?

Genuine question - what are the benefits of starting something new in python (assuming all things being equal - i.e. equal knowledge in java/golang/c# and no legacy reasons forcing you)? Why would anyone pick writing type-hinted python Vs a fully explicitly typed compiled language?

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

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.

I think that sort of thing is coming, with e.g. `mypyc` that compiles typed Python into C.

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

It doesn't matter about its quirks. The most important thing nowadays is that it's reached critical mass. We're at the point where even non-developers can now cobble together a bit of python code to do simple things to make their jobs easier. This means it's here forever, IMO.

I remember our salesmen back in 90's cobbling together some Visual Basic or whatever it was called. So where it is now?

I'm not disagreeing with this, but you'd be surprised just how much VB still exists in the wild. Literally billions of dollars in revenues in financial service industry alone. Some trading desks use VB and Excel for the majority of trading. It's an abomination of epic proportions and well beyond critical mass, but it still exists precisely because of the reasons you mention - non-developers with some technical competency depending on it.

Whole other debate on benefits and drawbacks if this sort if thing however..

Has the same happened to Python yet? No? So bookmark this thread, and come back in here when the very same happens to Python :)

I just made a note. I do not really give a flying hoot to what happens to Python. I only use it in places I do some consulting since they require it. I do not use it for my own products.

Did Microsoft not kill VB in the 2000s? I could be wrong.

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.

name one except python

Space is visible to me.

In the era that python was created in, autoformatters were not a thing and I appreciated the forced indentation. Nowadays with autoformatters being standard, the downsides of semantic white space is not worth it.

I don’t totally mind it. Poor PEP8 implementations can drive me nuts and so can the type of indentation allowed. But otherwise I can get over it.

And then there’s Bython... https://github.com/mathialo/bython

It makes scope visual and consistent. IMO it's less dumb than having scope defined by pairs of curly braces which are impossible to read without indentation and require extra effort to keep matched - unless you try to automate the matching with a good IDE.

There are a lot of tools that shred whitespace but not curly braces.

I think the adage goes “Python is the best at being the second best at... almost everything”

I've never heard that one, and not going to take a stance... but I WILL make the argument that if true, that's a HUGE strength!

There’s plenty to criticize Python about relating to performance and developer operations (pypi, virtualenvs, cumbersome version juggling), but most of these language features mentioned have a valid need to exist, or are purely stylistic, and therefore not admissible to the “not a great programming language” debate imo.

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.


Called uniform function call syntax, an I idea I first saw in Nim and found really cool, but then found really dumb. Can't remember the reasoning for both opinions, which is a strong indicator of "probably doesn't matter".

For a while I was entertaining a thought regarding mutability and returning copy's. Like foo.bar() would mutate, bar(foo) return a modified copy. Don't know if that concept has a name or if it actually makes sense at all.

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.

Maybe it's fine, but I'd be concerned about polluting the global namespace

It's certainly not a perfect language (no multi-line lambdas, double underscore keywords everywhere, converting generators, significant white space means problems working in other environments, typing, isn't called lisp), but you know what...

I've been pleasantly surprised how shallow the "general python rabbit-hole" is.

If i can express this in words, one of the ways I like to judge a language when I program: i think of something a computer could theoretically do, then I look for ways to express it in that language. How many independent jumps I have to take down the conceptual rabbit-hole before I get to the solution is a nice little arbitrary metric.

Does python do everything the way I'd do it? No. You get over yourself and just accept that's the way it is in this language.

Once I've done that, so far most problems in python have been pretty shallow: do this arbitrary thing and then this arbitrary thing and you're done.

Compared to some of my past languages where you have to go 4 or 5 levels deep with N compulsory but conceptually irrelevant steps, it's pretty damn good. Makes for a reasonable quick pathway to actually getting anything done...

Purely my subjective opinion.

As usual, the worst things about a thing are also the best things about it, and the best things about it are the worst things about it.

I personally hate virtualenv. I just install pip dependencies in a vendor directory and point PYTHONPATH to it.

That's just like, your opinion, man

There are two kinds of languages. Those that people complain about, and those that nobody uses.

I hate python, but it is still invaluable to me for its ability to let me get shit done. Getting meaningful data from a 100mb CSV? No problems. Everything I need can be found in the STDlib.

From my main perspective (scheme programmer): I am constantly amazed by the bad code python programmers write in scheme. Take a nice recursive function, sprinkle it with set! (which leads to boxing and general slowness in many implementations) and if that wasn't slow enough for you, wrap it in a call/cc to be able to return from arbitrary places in the function. As a bonus, forget to discard the captured continuation to make your program use insane amounts of memory.

Then proceed to complain on Reddit.

You can write your dicts as keyword args to the dict() cast if you don't like putting your keys in quotes, but it looks like shit.

There are two paths to take when one encounters something new; adapt and learn, or reject and mock. This sounds like the latter.

This list is so deliciously sophomoric. The best one is, and I quote: """To many other weirdo bits of magic syntax, like [list comprehensions]""" Obviously without actually proposing how comprehensions could be made better one has to hope the author would say he likes the equivalent Haskell better, but there is a strong doubt that is not the case.

Complaining about having to cast generators to list... seems like the kind of dev that has their code randomly run out of memory until a senior dev comes and fixes it.

It is annoying! And doesn't always save memory. In theory a "sufficiently smart language" should have a feature to understand that `thing[3]` can be translated to "call `next()` 3 times and gimme the last thing", not in "turn this completely to a list, that may take a ton of memory, although I only need that one third element".

Generators should be treatable as lazy lists in the end, and lists should have a common interface whether they are lazy or eager. Someone should figure out a way to have us write code at a higher abstraction level and have same interface for lazy vs eager data structures.

...but it's not gonna happen in a dynamic language like Python. And I can't say I like the "solution" of having the entire language be lazy like Haskell either :|

We're stuck with "casting generators" for now, I guess, but it really does suck!

You don't need to cast the generator, you can do: next(itertools.islice(my_generator, n, n+1))

With that said...

> In theory a "sufficiently smart language" should have a feature to understand that `thing[3]` can be translated to "call `next()` 3 times

This might be a newbie trap, because next() isn't the same as indexing. What happens if I perform `thing[7]` followed by `thing[5]`? Should performing `thing[7]` put 1-6 in memory and turn the object into a generator-list hybrid?

> Should performing `thing[7]` put 1-6 in memory and turn the object into a generator-list hybrid

You're right here. Probably can't work like that since generators are too general, you can't expect them to be rewindable or to not have side effects... prob you'd need a more specialized concept like a "lazy list" that would be a subtype of generator with some extra restrictions that would make it possible to implement the "hybrid" structure as an implementation detail without changing semantics.

Anyway... it would be too much work and probably would turn into a footgun.

that one is legit. sometimes I do something like map(int, [x,y,z]) and I always trip over that it's a generator

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. Explicit, clear, no magic, logical.

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

I personally find them extremely readable, and a lot clearer than for loops about the lack of side effects.

I disagree. It’s basically set-builder notation, which probably predates any programming language. It’s a concise way to express filtering.

dic = {k: v for k, v in dic.items() if k in other_dic and v == "bar"}

How could that be improved? That's 3-4 LOC minimum in any other language

My main grip is python's ternary operators, since the True value is evaluated before the condition, if you are doing ternaries on things that might throw exceptions the False value has to come first

value = 0 if key not in dic else dic[key] * 5

rather than (throws indexerror if key isn't in dic)

value = dic[key] * 5 if key in dic else 0

    dic = {k: v for k, v in dic.items() if k in other_dic and v == "bar"}
> "How could that be improved? That's 3-4 LOC minimum in any other language"

If I'm understanding the comprehension correctly,

    (into {} (filter (fn [[k v]] (and (get other-dic k) (= v "bar"))) dic))

Though, for readability, I'd likely write it as:

  (->> dic
       (filter (fn [[k v]]
                 (and (get other-dic k)
                      (= v "bar"))))
       (into {}))
Legibility is in the eye of the beholder.

Each to their own, but both the snippets you posted crossed my threshold for headache inducing parentheses tracking

Similarly, my parsing of special-case syntax in the Python.

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 = (<key>, <value>) 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 language war, just to post a counter example. My apologies.

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

It appears textually first but the evaluation order is the same as the classic ?: ternary. ```[][0] if False else 'foo'``` will not raise an IndexError.

I like comprehensions, but think this style has some advantages (and some disadvantages):

dic = dic.where((k, v) => k in other_dic and v == "bar").todict()

> dic = {k: v for k, v in dic.items() if k in other_dic and v == "bar"}

dic.iter().filter(|k, v| other_dic.contains(k) && v == "bar").collect();

it's one line, though I'd format it as 3 for readability (list comprehension is hard to read and functional style composes better.

" impenetrable unreadable perl-esq garbage write-once-read-never code " - I had about the same impression when I first saw it. I think ternary operator is as far as I am willing to go ;)

list comprehensions can be elegant and actually improve readability. However, I do agree that it can be easily misused. I have seen many junior Python programmers writing super long, complicated comprehensions that hurt my brain. They think it is pretty cool just because their solutions are one-liners.

List comprehensions are one of those abuse subject features (like most things) where light simple use is fantastic but some people just take it too far into unreadable nastiness.

"Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something."


For example, instead of putting someone's article down as sophomoric, you could explain what's different and possibly better about Haskell list comprehensions.

You could, but you'd lose the Socratic method and efficiency of thinking. There is a reason why many academics can be quite acerbic.

All these politeness comments are a speed bump that distracts from the real issues.

There's a huge difference between a classroom environment or academic symposium, and an internet forum. Here, when people attack and take swipes at each other, discussion slides downhill so fast that it becomes an existential issue for the forum. Having HN not destroy itself the way internet communities usually do has been the main goal here since pg created the site over a decade ago, and the guidelines here are written with all that experience in mind.

I used to think similarly about this to what you express, because I've always enjoyed reading about the sort of discourse in which devastating wit is exchanged. But eventually I realized that it doesn't translate into this context at all. This is a case of 'the medium is the message'. When you have millions of people who don't know each other all potentially interacting at the same time, the dynamics are so different as to be incommensurable with, say, small debates, literary journals, elite social events, and other places where the groups are small and highly cohesive. Here are some previous explanations about this:






I love python. I just really wish there was a typed equivalent of python like Typescript. The python3 types are very weak compared to TS.

I actually dislike Python, but this list ain't it.

One realizes the true cost of Pythons forced indentation when using MicroPython over a serial connection, for example It's a big PITAS, tbh. I see Python as a Vala-like glue language for C (as in Cython or FFI) but this singular weakness makes you pay attention to it in a context in which it' s truly beyond ridiculous. One may as well lisp for such use-cases...

If you complain in the same post: about top level functions like list and map, and about list comprehension, you've lost me. To have lazy and eager types and list processing, you either have to have functions or syntax for both. If you complain about existence of both, you either need to propose a new paradigm, or you're just grumpy about everything.

This reads like a list of complaints about Django. There's much, much more to python than Django!

Sure Python has many problems, but these aren't a great selection.

> The syntax for classical inheritance. Half of each Django app is super().__init__(args, *kwargs). At least you don't have to pass arguments to super anymore.

Yes, inheritance is hard to do well, but that's generally true. Much better to prefer composition (https://en.wikipedia.org/wiki/Composition_over_inheritance)

> Too many magic __double-underscore__ methods and properties that you have to just memorize.

Better to just start using http://attrs.org or dataclasses so you don't have to do all the manual work. Classes without boilerplate.

> Too many top-level built-in functions that (a) you have to just memorize, and (b) get really ugly. You end up with stuff like list(map(...)). I haven't used so many nested parentheses since my early days in PHP. Guido's explanation makes sense in theory, but is really annoying in practice.

I agree, there should be a pipeline operator |> like F# has. A similar proposal has been made for JS. https://github.com/tc39/proposal-pipeline-operator

> Too many other weirdo bits of magic syntax, like [list comprehensions].

List comprehensions are good, they just take 5 minutes of getting used to.

> Django specifically is so full of magic words, and its documentation is so convoluted, that I've basically given up on documentation altogether and just look at the Django source code now.

Pyramid has a much more principled design IMHO. https://trypyramid.com/

> Needing to put dict property names `{'in': 'quotes'}.

Or use `dict(foo=5)`. Python mappings can contain non-string keys, so `{5: 1.2, 6: 3.4}` maps ints to floats.

> You have to cast your data back to a list/tuple after using enumerate() and map().

Don't use map, use comprehensions.

> Different syntaxes for lists and tuples.

They are different objects, why would they have the same syntax?

> foo['bar'] returns a KeyError, so you have to do foo.get('bar')... or in some cases getattr(foo, 'bar', None), but not in others because getattr and .get are different things.

Python is a different language from Javascript.

> You can't just tack on flags to /regular_expressions/ig.

Yeah that's annoying.

> All the goofy string literals: f' ', u' ', r' ', etc.

That's a good thing, not a bad thing.

> Pipfile does not work that well.

Poetry works better. https://poetry.eustace.io

Sure Python has many problems, but these aren't a great selection.

Yes. I have my disagreements with Python, but those are not it. The article author is mostly complaining about ways Python differs from Javascript.

- Agree that the mechanism for talking about parent classes wasn't very good. Multiple inheritance usually adds complication without adding much necessary functionality. That's not just a Python problem. It's a leftover from viewing objects through an "A is-a B" lens, one of the dead ends of early AI.

- Python has too much gratuitous dynamism. Any thread can find and mess with any code and data in another thread. The implementation has to support that, which knocks out many valuable optimizations. The language model, and the original implementation, use "everything is a dict", which implies "slow".

- One consequence of the above is Python's terrible one thread at a time thread system, with the "global interpreter lock". The "multiprocessing" hack to get around that is ugly and uses too much memory, since each subprocess has its very own Python system instance. To some extent, the "async" add on is yet another hack to get around the limits of threading.

- Another consequence is a tendency to call C code where Python performance is terrible. The C code has to carefully obey the rules of the Python system. Mostly it does.

- Optional typing is a marginal idea, but unchecked marginal typing is just weird. Language design seems to be converging on implicit static typing - result variables are automatically typed whenever possible. Go, Rust, and now C++ (with "auto") took that route.

- And, of course, the botched Python 2 to 3 transition set Python back for a decade.

On the other hand, Python exceptions work out well. A reasonably sane exception hierarchy helps. Although the one for 2.x was better than the one for 3.x; the 2.x one made a clear distinction between external problems ("Environment errors") and internal problems.

The "with" clause system plays well with exceptions, and nested exception failures unwind correctly. It's far better than Go's "defer". C++ and Rust try to handle this sort of thing with RAII, which never handles trouble in a destructor well.

Regarding performance, I'm hoping alternate interpreters like pypy start thriving. Theres no reason python needs to be as slow as CPython.

Django is ok if you have a web site with content and forms that map nicely onto SQL tables. Any 1998 website, basically, with not too much of a load. Any other setup, and it gets messy.

> Needing to put dict property names `{'in': 'quotes'}.

Now that's a part I like.

The inclusion of that made me question the entire thing. It's just so...wrong.

Does the author not realize that you can use (almost) anything as a dict key?

    a = 123
    b = 'foo'
    d = {a:456, b:123, 2.3:'2.3'}

    >>> {123: 456, 'foo': 123, 2.3: '2.3'}

>Does the author not realize that you can use (almost) anything as a dict key?

You can do that in JS too, it's just coerced to string, so you can do e.g.

  {foo: "bar"}
where foo is not a variable, but assumed to be the string foo. In Python you can't, because you couldn't tell if it's foo the string, or a reference to an existing (or non-existing) foo variable.

That said, in JS, not only you're limited to using (real or coerced) strings as keys to Objects, but you also need to use the square bracket:

  {[foo]: "bar"}
syntax, so it can tell that you need it to use the value of the variable foo as the key (else it will understand {"foo": "bar"}).

That's different though. In python there is no coercion going on with the keys.

It seems he just doesn't want to type quotes and is OK with breaking everything else to get that. Which is fine, but no one else supports that change request.

Graphene + React is just fine.

I mean, one could complaint about many things in Django, but the documentation....??? Really?

Jack of all trades, master of none.

The article has a silly premise - I don't know anybody who would claim it's a great programming language. For the moment, it's just the most practical in certain areas (notably data science and machine learning.)

Python's power comes from the fantastic array of libraries to which it provides access. Much of my Python coding involves stringing together calls to SciPy, Matplotlib, lxml, and the like. It's a super productive language so long as you don't need multithreaded performance.

Too bad you can not use it to write those libraries ;)

I know a company, they have a floor filled with developers who think that Python is the best thing since sliced bread and any other language is abomination

The biggest beefs I have with Python are inconsistent syntax and dynamic typing. But I've basically decided that dynamic types are a waste of time for me personally, so I'm not really the target audience anyways.

The new static type analyzers like Mypy and PyType give it more of a static feel IMHO.

As I understand it those are not really complete though, are they? Do they offer algebraic data types and exhaustive pattern matching?

I'm not sure. There is Union[Foo, Bar] which matches instances of Foo or Bar [0] and there is @overload [1]. What would it need to be complete?

[0] https://docs.python.org/3/library/typing.html#typing.Union

[1] https://mypy.readthedocs.io/en/latest/more_types.html#functi...

Yes. Because python is a programming language.

He has insulted list comprehensions and therefore my honor!

I would agree about "magic" parts.

So be it. It is useful nevertheless.

Most of these are pretty dumb, but there are some inadvertently good points.[5]

> The philosophy of "one correct way to do things."

I miss those days. T_T

> A huge ecosystem of good third-party libraries.

Python also has a huge ecosystem of huge ecosystem managers, which is less than ideal.

> Half of each Django app is super().__init__( * args, * * kwargs)

Haven't used Django, but if I were providing a suite of classes people were extending, I'd provide lifecycle hooks.

Using super().__init__ is not a syntax problem as much as it's a semantics problem, because it's so fragile.[1]

> Too many magic __double-underscore__ methods and properties that you have to just memorize.

Yup, dunders are the ugly consequence of duck-typing. Maybe Python could tuck them away in some kind of traits system.

> Too many other weirdo bits of magic syntax, like [list comprehensions].

But the Python syntax is weird:

    [elem for outer in iterable for inner in outer]
Which is essentially:

    for outer in iterable:
        for inner in outer:
It's backwards. The PEP[2] doesn't explain why, but looking at the JS syntax[3] it does seem less worse.

Other weirdo syntax:

    while some_condition():
        if check_a_thing(elem):
        print("never broke from loop")
The meaning sort of makes sense if you think of `while` as an extension of `if`.

But I would have expected this:

    for x in y:
Or, really, a more descriptive keyword.

> You have to cast your data back to a list/tuple after using enumerate() and map().

I thought it was the coolest thing when generators got full support in py3k, but it's horribly broken.

This does not raise an exception:

    x = list(some_generator)
    y = list(some_generator)
y will be empty, which is a completely silent failure. The same is true for iterators. And everyone's been bit by strings being iterable[4].

Sometimes it's useful to do this:

    i = iter(some_generator)
    x = next(i)
    for elem in i:
But Python should not:

1. make iterators be iterable.

2. allow spent generators to be reused without exception.

3. make strings be iterable.

(All of which could be bypassed with a method call when you really want that behavior.)

> foo['bar'] returns a KeyError, so you have to do foo.get('bar')

LOL, only javascript devs could not have noticed the hours they've spent tracking down the source of some mysterious undefined. Python definitely got this one right.

[1]: https://fuhm.net/super-harmful/

[2]: https://www.python.org/dev/peps/pep-0202/

[3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[4]: https://mail.python.org/pipermail/python-3000/2006-April/000...

[5]: Wait, am I talking about the OP or this comment?

I wrote this package to provide model lifecycle hooks (similar to Rails callbacks) because I didn't like the frequency that my codebase was overriding __init__(): https://github.com/rsinger86/django-lifecycle

Django's ecosystem (mainly DRF and django-filters) makes it very productive for me, but I find Django core to be lacking for developer ergonomics in certain areas.

That's exactly what I was imagining. You can tell it's a nicely designed base class because the dunders are all tucked away so the only thing left is actual logic.

yeah i agree, it is so weird to see that python is the only language that haven't implemented in its own language atleast to my knowledge

That's not what the article is about. And most interpreted languages (bash, ruby, perl, JS, ...) are not implemented in themselves, because it makes no sense (who interprets the interpreter?).

However, Pypy is a Python interpreter that is written in (a compiled subset of) Python 2.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact