97 points · by iflywithbook · 7y ago · 116 comments
My main beef with python is that it is harder to deploy projects to other people, without them setting up a virtual environment or things like that. I know that there are some tools to help compile but they aren't easy to use.
Also, it is hard to create GUI applications vs languages like C#!
Other than that I love using python and I think it is a great tool to use in embedded development along with c/c++.
As far as deployment goes, we've had good luck with pex files (executable zip files containing everything but the interpreter). https://github.com/pantsbuild/pex. Your deployment target still needs the right version of the Python interpreter and .so files that your dependencies might link against.
Personally, I've found that Go solves most/all Python issues without introducing too many of its own--and anyone writing Python (sans mypy) doesn't get to chastise Go for lacking generics! :)
Why do you say this point in particular? Python's duck typing makes generics very easy, no? i.e., you can write an algorithm in python that just assumes a particular method is callable and you don't have to code gen individual implementations for different types. plus the dunder (e.g., `__iadd__`) methods give a lot of useful basic functionality
Usually when people refer to generics they're referring to a static type system that allows for expressing generic algorithms. (Untyped) Python inherently has no static type system, so necessarily can't support generics by that definition. The other definition of generics that _is_ satisfiable by (untyped) Python--the definition you presumably had in mind--is equally satisfiable by Go via its `interface{}` type. So regardless of which definition you adhere to, "Go lacks generics" is no more valid a criticism for Go than for Python.
Practically speaking, there's some syntax ceremony involved in using `interface{}` in Go; coming from Python or another dynamic language, this ceremony will probably offend your sensibilities--why is it so hard to opt out of the type system!? But that's by design--Go generally tries to keep you on the path of correctness without being overbearing (as many find stricter languages--e.g., Haskell--to be).
It’d be better if it were a self contained executable with a GUI but not worth the time to figure that out.
I messed around with TkInter a while back, not sure if anything's new since then. For executables there was py2exe, cx_freeze, and PyInstaller, but the situation with packaging DLLs into an executable that would actually work on someone else's computer was iffy last I checked.
Reimplementing - in a buggy incompatible way - the Windows loader (which is what that code is doing) from scratch, is a gross hack and should not be used to build anything that's meant to be reliable.
Note that pyinstaller and cx_freeze do not suffer from these issues. Do not use py2exe.
If it's for an internal only tool, does that fit under all the GPL / LGPL requirements?
So a UI rewrite would make it much friendlier to other users, but it'd be a time investment I can't justify over the "just don't give it bad data" strategy.
The inputs and outputs are all handled manually so reliability isn't a huge focus as long as someone can poke around for a bit and make it work. Only user is me for now, so ¯\_(ツ)_/¯
# TODO: make it less shittyThat's why it is best used in small teams for data science and scripting; run once and never look back. Most complaints about python IMO fail to appreciate its design philosophy.
I've maintained and/or written more than a few large desktop apps in both python and C++. The python ones are a hell of a lot easier to maintain, i.m.o. Python _is_ strongly typed unlike JS, and I don't feel like the dynamic typing aspects have ever really bit me from a maintenance perspective. At least in my experience, I've seen a lot of either verbose/repetitive or highly cryptic C++ written to in situations that dynamic typing makes straightforward and i.m.o easier to maintain.
To be fair, though, I have a pretty accurate mental model of what python's doing under the hood, and I still regularly find myself mystified by certain C++ language features and what the compiler actually does in slightly ambiguous situations. I've nominally been using C++ longer, but I've used python a lot more frequently. (I'm primarily in scientific computing.)
As a whole, I've always found python to be a nice language from a maintenance perspective, though I'll grant that people have more room to do bizarre things in some circumstances. I've definitely seen some unmaintainable and unreadable python, but I've seen that every bit as frequently in static-typed languages.
I feel that python is quite well-suited to desktop application development. Part of this boils down to Qt being a nice library regardless of whether you're working in C++ or python. However, python codebases tend to be more succinct and readable. In the end, I've consistently found that to be a larger advantage in maintenance than static typing.
On the other hand, I think python has more "batteries included" than other scripting languages and for many projects you can usually figure out how to eliminate dependencies.
QT for Python and The Fman build system would allow you to deploy in some cases a single executable. https://wiki.python.org/moin/PyQt/Deploying_PyQt_Application...
That being said I had issues getting everything installed correctly with Pipenv and then locking the specific versions that are compatible. fman and pyside2.
A GUI builder comes with the Pyside2 package qtdesigner.exe I think.
For C# on Linux Avalonia looks promising. https://avaloniaui.net/
While this is a problem, for many projects, I have overcome this by including a local web-server, that accepts requests from 127.0.0.1 and serves a web app as a GUI.
It's not a perfect solution, but It worked for me in many projects.
Why do I really need a class, when:
- Instance fields can be added and removed at runtime
- Private fields and methods are not actually private ("we're all consenting adults here")
- No pattern matching on types and `if isinstance(foo, Bar):` is an anti-pattern because it's a duck-typed language
- Interfaces are neither available nor necessary due to late binding. Abstract Base Classes are the closest thing to an interface, but they're also unnecessary because again, it's duck-typed.
- Inheritance is widely considered to be a mistake ("Prefer composition over inheritance" etc)
- Classes tend to complicate testing
I can use classes to write custom data structures, I guess, but in a language as high-level as Python, I can just model trees and graphs with dicts. If I need a more performant data structure, I'm not writing it in Python in the first place.
I've seen some very experienced Pythonistas recommend using namedtuple instead of classes for most use cases, and I tend to agree with them. That gets you immutability as well as dot notation for accessing fields.
Clojure programmers seem perfectly happy with just lists and maps, and after experiencing that, classes feel like a bolted-on misfeature in Python.
I like classes over dictionaries because I can look at the class definition to see what the variables my function gets are, and what functions (methods) exist to work with them.
I used to work with a code base that passed dictionaries around, and there were a lot of hacks where people had some data somewhere that they needed somewhere else, and the dict was available both places, so why not add it to that... Different pieces of code added different things and you were never quite sure which version of the data was passed this time for the "layers" parameter. Somehow it doesn't happen as much with classes.
It was like duck typing to the extreme. I call it smurf typing, if it smurfs like a smurf, smurfs like a smurf and smurfs like a smurf, nobody knows what's going on anymore.
Immutable value classes, those are good.
Like you said, isinstance() is an anti-pattern - I don't want to define a function that behaves differently based on explicit testing of input type, because that wrecks the duck typing. Right?
When I do have a datatype that needs to be handled differently based on some condition, I tend to use ABC's with only one level of concrete subclasses, just to make that implicit method interface explicit.
Among other cases, you need a class where natural, convenient, consumer-friendly use of a data structure should leverage features like operators and standard protocols that rely on the existence of particular methods (often special methods.)
> If I need a more performant data structure, I'm not writing it in Python in the first place.
While Python is linearly slow, that’s no excuse to use data structures with poor big-O performance (small n may be, but that's no more or less true of Python than of a more performant language.)
> I've seen some very experienced Pythonistas recommend using namedtuple instead of classes for most use cases
Namedtuple is just a function that returns a fresh class; you can't use “namedtuple instead of classes”, as it's a convenience mechanism for creating a class with certain commonly-useful features.
> Clojure programmers seem perfectly happy with just lists and maps
And vectors. And sets. And records. And a bunch of other common data structures.
But, yes, the use of multimethods for type-based dispatch that clojure uses replaces classes. But Python doesn't have multimethods built-in and the core language and stdlib don't use them (they are available in a non-standard library).
I understand and I can't disagree, this just seems much, much narrower in scope than what classes are used for in typical Python code I see every day. Which is perhaps due to influence from other languages like Java/C++ etc.
>>>import this
"Beautiful is better than ugly.Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
"For example, semantic whitespace is arguably implicit, hard to read, invites density (compared to an extra line for braces), and (again arguably) is ugly.
Yes, some of these things are subjective, but it's hard for me to confidently recommend Python to someone with these values.
Because logic in python is interpreted via indentation, it's very difficult for python to realize when a line is indented incorrectly. It just assumes that if a line is indented a certain way, it was intentional.
In programming languages like Ruby or Javascript, indentation is stylistic and has no effect on the logic. You can actually use the "auto-indent" feature of many editors, and you can use linting tools to ensure formatting. If you have an extra "end" or an extra ending bracket, your IDE can immediately warn you. Not so with python!
If you are using notepad as an editor then maybe this could be an issue?
Every other editor I've used validates the syntax and quickly catches misaligned statements. Auto formatting works too.
How is this different from some language not realising that a statement should be inside of the curly brackets instead of outside?
How is it implicit and hard to read? If anything it's very explicit, instead of just a single { and } to denote "the next part is the body", it explicitly requires visibly indenting the body.
That's easier to read, and is the expected "good practice" in C and similar "brace" languages anyway (you're not supposed to use { and } without also indenting your code there either).
Python's semantic whitespace is more visible than having a { and } in C e.g. and not indenting, or having a for/if/etc without braces with a single statement attached and not indenting.
Not sure what's ugly about:
def double(n):
return n*2
compared to: function double(int n) {
return n*2;
}
or worse: function double(int n) {return n*2;}
(especially with larger bodies -- in fact this non-required whitespace property is where 90% of the "obfuscated-C" ability is based on)Whitespaces forces programmer to make code readable. Obviously today with tools like gofmt, rustfmt it seems easy and those are inspired by Python.
Python PEP process has been adopted by many programming language. Try JCP process and see what I am talking about.
> Special cases aren't special enough to break the rules.
> There should be one-- and preferably only one --obvious way to do it.
Python is complicated enough that the language and standard library often have multiple ways of doing the same thing. And there are still a number of “special cases” in the language, or at least non-intuitive results. Certain things are mutable (probably for performance?) when they shouldn’t be, some things behave in odd ways, and certain distinctions are made blurry but then it comes back to bite you when you do something non-trivial and the differences become apparent.
When I hear people describe Python as simple and elegant, it feels like they're using a different language than the one I know.
The difference between split and join is kind of weird, I'll grant. I'm not sure why it was done that way.
`sort` is in place. You're telling an object to order itself: "hey you! Sort yourself!" `sorted` returns a copy of an object, but... sorted. You're asking for the sorted version of that thing.
What I got was a list that started with at least three points that are already obsolete, because only valid for Python 2, which is already declared obsolete.
Every language with some history has its humble start and is evolving. To carry the errors of the past is just not fair. You could of course drag along the first Java version and conclude that Java is bad -- but you would really invalidate your own opinion.
Maintaining a conda forge package has been, for us, a complete nightmare. If you depend on another conda-forge package you can have the issue that the library is configured to suit whoever first wrote the conda-forge package - i.e. by disabling parallelism or providing only shared/static libraries, and have that maintainer be completely unresponsive or unwilling to change it.
Needing to name the requirements file and needing to activate venv are not pain points I feel.
Wrapping native libraries and not invoking a C compiler at package install time means some trade-offs. https://cffi.readthedocs.io/en/latest/cdef.html
In which case the decision between the two seems to be between a thing and a slightly better version of itself. I totally respect that many people see this differently and probably exactly opposite but to me it always feels really hard to justify using python for this reason.
Just for fairness sake I'm not trying to trash python. I think it's a great language.
Performance was definitely an issue, but for the sort of programming we were doing it normally wasn't a big issue.
Duck typing could definitely be an issue — one had little confidence that code would run as desired.
Overall, I really liked Python, but these days I'd sooner use Go or Lisp.
In addition to the GIL, other problems I'd point out with Python:
1. At one point, Python was "batteries included". This is largely no longer the case any more--most projects are largely dependent on PyPI, and there's been a growing sentiment in the last few years that "the standard library is where modules go to die". PyPI libraries are of inconsistent quality and have a high turnover rate; the "standard" for what to use changes fairly rapidly. And if you manage to make good choices of mature libraries and not have to change them every year or so, you still have to manage dependencies, which complicates deployments.
2. Fracturing community: there are now a bunch of different non-standard ways to install Python and Python dependencies, which conflict with each other, and none of which fit all use cases, so you have to use all of them and deal with conflicts. This exacerbates issues with 1.
3. Increasing dependency on non-pure-Python dependencies which don't build trivially. There are reasons for this: Python often isn't performant enough for certain tasks, and other languages have some very good tools. However, this means you can't just `pip install` a library and expect it to work--even very common libraries like Pillow don't without fiddling. Again, this exacerbates problems with 1.
4. Lack of a good desktop UI framework. It's apparent that not as many people are using Python for native UIs any more. tk is cludgy and doesn't result in pretty UIs, and despite being part of the standard library, it doesn't work out of the box on MacOS. wxWidgets doesn't build on MacOS without significant work, and documentation is for the C++ version of the library. This is sort of the intersection of 1, 2, and 3, but in desktop UIs they combine to form a perfect storm. If you're developing a desktop UI, there are better languages, but I'm not going to post them here because I'd rather keep this as a constructive criticism of Python than a language competition.
5. Introspection being used to change language syntax without solving the problems the language syntax solves. I'm really looking at Django here, but they're not the only guilty ones. When you call a function, i.e. route_on_http_method(GET=get_handler, POST=post_handler), functions can fairly easily check arguments and throw an exception from a logical spot--i.e. route_on_http_method(GIT=get_handler) throws an exception immediately. But when you have `class MyView(GenericView): def git(self, request): ...` you get no exception until you try to call the view, in which case you get a wonderful cornucopia of meaningless line numbers in a useless stack trace. Sure, Django code looks nicer and more organized, but as I said, syntax isn't that important. Debugging IS important. Using the bikeshedding example, this is breaking the nuclear power plant to fix a problem with the bike shed. And this is a generous example: it's fairly simple and Django is one of the libraries that does a better job of this. If you really want configuration-oriented programming, you'd be better off parsing in JSON files and doing explicit error checking when you parse them in, rather than introspecting out a syntax that's not really code and not really configuration. Introspection hasn't played out well as a Python feature.
You'll note that all these problems are CULTURAL problems, rather than problems with the language itself. And that's my point, because those are the problems you can't easily work around, and it's the problems you can't easily work around that make or break the language.
I say all this because I love Python. I've worked in Python for the last 6ish years, and don't see that changing any time soon.
I agree with the first part but not the second. One can only write
arraylist.add(arraylist.size() - 1, arraylist.get(arraylist.size() - 1) + 1)
before wondering if there’s a better way to do this.You'll have forgotten the pain of writing that function within an hour. I'll never forget the pain of debugging a {bar: 1}.baz returning undefined (failing silently) and then going into a future inside a minified 0.0.2 versioned library that doesn't do any constraint checking before finally throwing an exception. Nor will I forgive JavaScript for this.
list[-1] += 1
array.last += 1
*(vector.end() - 1)++;
Having reasonable syntax and a strong type system are not mutually exclusive.Because of this mechanism that ensures concurrency safety Python does not support parallel execution of threads. I am wondering if the rest of the HN community finds it as a major disadvantage.
However, yesterday I was playing with python’s async/await and I came to the conclusion that it is a bit... useless.
Not a big deal, because i can use other stuff to accomplish the same I was trying to do.
Or maybe I was doing it wrong.
There should be one-- and preferably only one --obvious way to do it.
> Strings were just a sequence of bytes in Python 2, but now are Unicode by default. Much better.
whelp, not trusting this guy's judgement anymore
I've migrated literally, 10s of thousands, of files from py2 to 3. I've yet to encounter an issue with surrogateescapes or sys.stdin. Unicode issues yes, but mostly because we were previously being fast-and-loose with unicode vs. bytes, and mishandling, for example, emojis.
If you're only using the original ASCII (ordinals 0-127), all is well, and the py3 distinction between strings and bytes seems to get in the way. But as soon as you have a single character in your input or data which is not ASCII, a lot of things stop working and it isn't even clear why, or how to fix it -- often, the error comes from a library-within-a-library-within-a-library, which did some manipulation that (wrongly) assumed some encoding or its properties.