3 ms·
Ask HN: Is Python getting too complicated for its own good?
For example, the following are valid modern Python code:
var: str = "Haha"
print(f"{var:_>20}")
print(f"{var:*^20}")
print(f"{str.lower() = }")
def concatenate[T: (str, bytes)](first: T, second: T) -> T:
return first + second
items = [1, 2, 3]
items [:]=[]
items = [1, 2, 3]
items *=0
bowl = ['water']
drink ,= bowl
n = 3
['a', 'b', 'c', *n* ['.']] #> ['a', 'b', 'c', '.', '.', '.']
a, *_ = (1,2,3)
- weatherlight 3y agoWhat's the issue? I don't know Python,are these features uncommon?
- stop50 3y agoThe first block are formatstrings, i don't recognize the third example. the second is an generic function. I don't recognize the third and the fourth is an obscure list manipulation, usually used to lengthen a list. im completly lost at the 5th and 6, but number seven takes specific values from an list/tuple and throws away the rest.
- abdullahkhalids 3y agoHard to follow your comment. String formatting. var: str = "Haha" print(f"{var:_>20}") print(f"{var:*^20}") print(f"{str.lower() = }") A function declaration with variable types declared. def concatenate[T: (str, bytes)](first: T, second: T) -> T: return first + second Should be written like items[:] = []. Here items[:], which is equivalent to items[0:3], is being set to an empty list. items = [1, 2, 3] items [:]=[] Extend the list 0 times. So items = [] after this. items *= 2 will create items = [1,2,3,1,2,3]. items = [1, 2, 3] items *=0 Again, not typical spacing used. drink, = bowl only works if bowl is a list/tuple/etc with only one item. Assigns first element of bowl to drink. Usually written as drink = bowl[0]. bowl = ['water'] drink ,= bowl # is a comment symbol in python, so ignore all stuff after it. n*['.'] creates ['.', '.', '.']. If we only had ['a', 'b', 'c', n*['.']] (no * before n), then we create ['a', 'b', 'c', ['.', '.', '.']]. The * before n unpacks the inner list so we create ['a', 'b', 'c', '.', '.', '.']. n = 3 ['a', 'b', 'c', *n* ['.']] #> ['a', 'b', 'c', '.', '.', '.'] This just assigns a = 1 and assigns _ = (2,3). *_ is syntax for "rest of the list/tuple/sequence/etc". a, \*_ = (1,2,3)
- codingdave 3y agoWhat is the complexity you are concerned about? All of those make sense to me even not having touched python in over a decade.
- cpburns2009 3y agoF-strings (PEP 498) were released the end of 2016 in version 3.6, almost 7 years ago. They're convenient. Just don't get cute with overly complex expressions. The new type parameter syntax (PEP 695) newly added in 3.12 is certainly busy. I like the feature but I wish there was a better concise syntax. Metatype programming looks ugly in every language I've seen. The rest of the statements have been around for ages, and I wouldn't call them recent or modern.
- runjake 3y agoThis is fine. F-strings are very useful in the absence of something more well-designed. My main issue with Python is the whole dependency management/venv situation. It's fine for single app/web-app deployment but when I have a hundred different Python projects on my computer and I need to easily run scripts from them several times a day. My solutions are... not elegant. My current scheme is to start moving my most frequently-used scripts into a monorepo under a single venv. (recommendations happily accepted)
- roland35 3y agoI use dev containers for any mildly complicated project. For simple scripts I try to use as few dependencies/late version features as possible
- nextos 3y agoNix works wonderfully well for this. As a bonus, it will solve the problem not only for Python, but also for any other dependencies you may have. The only two package managers that have never given me a single headache when installing Python + Torch + CUDA are Nix and Pacman. Nix will only become a bit problematic to use if you need to package exotic stuff on your own that makes too many assumptions about Unix FHS.
- sk11001 3y agodef concatenate[T: (str, bytes)](first: T, second: T) -> T: return first + second This isn't valid Python. items = [1, 2, 3] items *=0 bowl = ['water'] drink ,= bowl a, *_ = (1,2,3) These are actually useful. None of these are new btw, I don't know about why you're asking the question like it's some new development. One great thing about Python is that you can do a lot with it but the complexity is gradually exposed to you as you become a more advanced user which makes it both powerful and easy to get into.
- tmaly 3y agoI am starting to feel like Python is becoming C++ I looked up PEP 695 mentioned in another comment. What do you think?
- posix_monad 3y agoPython has some design mistakes (IMO): 1. No "var" or "let" keyword, which requires you to read code, particularly with loops, more carefully 2. No multi-line lambdas, which forces you to move snippets away from their usage and come up with a name for them 3. Emphasis on classes and annotations over free functions, which is partly due to (2) but also the lack of a pipe operator, like in R 4. Modifying arithmetic operators (*=, +=, ++, --, etc...). These try to do too much at once. Use more intermediate variables and parens; it's much clearer. 5. "with" statement is a decent idea, but it should be usable without increasing nesting
- sk11001 3y ago> No multi-line lambdas, which forces you to move snippets away from their usage and come up with a name for them This is a good thing. > Modifying arithmetic operators (*=, +=, ++, --, etc...) ++ and -- aren't a thing in Python.
- btdmaster 3y agoInterestingly enough, you have the syntax required to make them a thing. https://tio.run/##dY/NDoIwDMfve4oeh4hEvBiT3bj4FAuZRUmWsXTDzKefgGRIopcm/49fm9qXf/TmdLYUo9KNc3A1qkZ1YQA3bEHKznReSu5Qt3t4NnrAbAoBJucwG2KeuyoxhJYWZikT@oEMOE985cqyyhJje7dF1h7kAo6bNWOUQIP3v2DxC2RBfJ7k43lLnfE8ZIzlefhSRbGqGN8 https://tio.run/##dY/NDoIwDMfve4oeh4hEvBiT3bj4FAuZRUmWsXTDzK... No postfix inc/dec though.
- ildjarn 3y ago> This is a good thing. Why? Sometimes a mapper or a filter is best split across a few lines but a name adds nothing.
- aristofun 3y agoSorry to disappoint but Python was poorly designed (for professional demanding work) language to begin with. Even from purely syntax perspective. Its evolution has always been a sequence of compromises and tradeoffs.
- paulcole 3y agoAssuming you specialize in professional demanding work?
- aristofun 3y agoYes, I’ve had my 10000 hours of coding. I know it hurts somoeone’s feelings, but the truth is python was created in 80s as a scripting language for average Joe, with 80s mentality that is still there. Here is just one tiny tip of the iceberg of terrible features of it that makes it a poor choice for any big software https://news.ycombinator.com/item?id=36661754 https://news.ycombinator.com/item?id=36661754 For historical, business reasons and because average data scientist, math student are far from being a professional software developer (and also because pythonists downvote and cancel all criticism haha) it is widely popular in AI and scientific community. And rightfully so.
- paulcole 3y agoI mean this is what people always say. My work = professional demanding work. Your work = amateur hour clown show. You really don’t think people can do professional demanding work successfully with Python? Or are you aware that professional demanding work is done by people who aren’t you?
- aristofun 3y agoAnything can be done by anyone using anything. You’re off the point with your generalizations. The point is that python as a language has plenty of problems, I merely pointed out the reasons for some of them.
- roosgit 3y agoTo me, these features look very unappetizing. As a teenager I’ve been "traumatized" by Pascal, but I was lucky to find a refuge in HTML and CSS. After I got a job as a web designer I discovered Python and I realized that I could actually program. The people who came up with this new syntax have different needs that I do and probably have a different kind of brain than mine.