Live data from Hacker News

Python's pre-declared constants are kinda weird

sebsite.pw

201–210 of 234 posts

Re: Python's pre-declared constants are kinda weird

#201

Earlier quoted context omitted.

A lot of those are stuff I'd never do like `Test.prototype = null;`. Some are legit footguns, but they rarely get in your way. Python has weird file imports (no relative ones either), broken package management, historical differences between asyncio and blocking that still cause issues, threading/GIL caveats that trip up even experienced users, indentation for scope (esp weird given it was designed for REPL), weirdly…

> that everyone hits and is also annoying after I don't know why you think it should be so common, because mutating a parameter with a default value doesn't make a lot of sense in the first place. But also it's one of the single most well-documented things about the language, and it's also historically been found useful when invoked intentionally ( https://stackoverflow.com/questions/9158294 ). Also, we call that a l…

List default args are well-documented because everyone runs into it and no other language does it that way. "You can use it to cache values between function calls:" and I really hope nobody does that.

Python has "relative imports" in that you can import relative packages, not files. So the weirdness is, even within my little app, I have to define packages for everything rather than just doing like require("./common.js") like you'd expect in a scripting language. https://stackoverflow.com/questions/714063/importing-modules... . The __init__.py thing is weird in of itself because different Py versions have different rules, and without __init__.py you accidentally make it a namespace package: https://stackoverflow.com/questions/448271/what-is-init-py-f...

> Incorrect. `lambda`.

I meant for general functions, not single-line only. Python code tends to have lots of one-off defs. It's common in other langs to pass around anon functions like outer((var){ ... }). Instead Python covered a subset of those use cases with a whole separate context manager feature (`with`). Why are lambdas single-line only, probably because indents-as-scope would make multiline too weird.

> This is like saying "differences between cars and traffic jams". It makes no sense whatsoever.

I'm sure you've done async coding and run into the classic issue of accidentally doing blocking I/O in code that shouldn't be waiting. For a long time, Python had no such thing, so something like a web backend would use a thread pool which adds a lot of overhead the more IO-bound your handlers are. Then they added asyncio to Python. So now the libraries are mixed on whether or not they do things async. Even psycopg2 needed a whole rework to psycopg3 for this, and it still has caveats https://www.psycopg.org/psycopg3/docs/advanced/async.html#as... . Django has some complexity around async vs non-async too. I don't fault Python for not thinking of this back then, but the end result is confusing.

JS had an event loop from day 1, so it's much safer to assume there that IO is non-blocking. This was part of the motivation for Node.js. There's still code predating async-await, but it's easy to wrap that.

Re: Python's pre-declared constants are kinda weird

#202
post #163

Earlier quoted context omitted.

How is a language that has different semantics for referring to lambdas vs other functions consistent? Ruby's most important error is that it does not support namespaces. This by itself makes it a far less scalable language than Python.

Did you mean to say that Ruby doesn't link name spaces to file system paths? Ruby has namespaces and they're far more flexible than Python's... too flexible in my opinion, making it harder to find things.

Ruby namespaces force requiring everything and don't allow for relative imports among other features that are very important for larger software.

Re: Python's pre-declared constants are kinda weird

#203

Earlier quoted context omitted.

Yes, that's a Path object from pathlib. It has been around for while but likely still qualifies, site says from 3.4.

You are both focusing on Python improving in any way but the person you're responding to said "improve in any meaningful way, or to learn anything from their peers" Which I will say is overstated but I can see where they are coming from even when you bring into scope things like types, async, etc. First types. This is what the type hints in Python allow you to do: def foo(x: int) -> int: return x foo("hello") We can…

Not every improvement is perfect, that’s true. I in particular fought against walrus syntax and don’t use pattern matching for other reasons. Python is also boxed in by its history. Some of the things you want done are incongruent with its design.

Many people like them however. And you’re being way too charitable to that dumbass comment.

Re: Python's pre-declared constants are kinda weird

#204
post #181

Earlier quoted context omitted.

No, the “readable” shortcut would have been if __main__: There are no magic strings to remember and the IDE can help you look up variables.

Again, this is a CS/Math major kind of thinking. The term __main__ means nothing syntactically. If we care about language acquisition -- thus language adoption -- it is always better to make "very common terms" in the language understandable to someone who is completely illiterate to your formal language. I honestly think one of the main reasons why python is so successful is as simple as: print "Hello world!" ...and…

Idk what's better, console.log or print, cause way back as a beginner I was confused what it means to print something. Like with ink? They're both ok, unlike the C++ or Java ways.

But Python breaking hello world in version 3 was crazy.

Re: Python's pre-declared constants are kinda weird

#205
post #154

Earlier quoted context omitted.

What you put as an example isn't a footgun if you know how the language evaluation rules work. Once you understand that the "footgun" explains a dozen behaviors, which may be a weird behavior but it is consistent.

Which isn't really much of a refutation because you can say the exact same thing about what's on wtfjs.

No, the JS WTFs have to do with language quirks that result in conditionally different behaviors. The Python WTFs have to do with underlying mechanisms that are not conditionally different, but the condition may not be "obvious".

This is so much so that it is described in the Zen of Python: There's preferably One Way to do things, but that one way may not be obvious.

Re: Python's pre-declared constants are kinda weird

#206
post #149

Earlier quoted context omitted.

I'm not sure what world you live in but I remember quite well when prototypical inheritance was The Way in JS to do object-oriented programming. Then they copied the C#/Java syntax for classes. Then they aded a bunch of reactivity with Observable with a ton of quirks. Every single new, large feature in JS has been full of quirks. The same cannot be said for Python; the exceptions are few and far between and more ofte…

You've probably just gotten used to it so you don't notice it anymore: https://github.com/satwikkansal/wtfpython (Note some of these are outdated, but some of those only mention that towards the end of the section rather than the beginning)

If you read it you'll realize that, very much like I said, the Python WTFs have to do with mechanisms that not obvious but are consistent. This is far better than Javascript, where the underlying mechanisms may be superficially obvious in some subset of cases, but are not consistent and generate many special cases.

Re: Python's pre-declared constants are kinda weird

#207

A lot of Python design decisions have felt weird and off to me but they’ve long justified it by saying that it’s those little ugly design choices that make the language so usable and effective in practice compared to more well-designed languages that hardly anybody uses. I’m not enough of an expert to clearly say if that’s really true, but imo, there’s a repeated pattern of slightly weirdly designed languages becomin…

It's not the ugly design choices that make it popular. It's just that it was the first that did a decent job of being easy to read/write. Even if you write an objectively better language, you can't replace the ecosystem of libraries, education material and human support that comes with popularity. Popularity begets popularity, and since ease of use is the selling point, it's probably never going to practical to replace it as a general purpose go-to for beginners. And where people begin, they tend to stay. So instead we slowpy march on, bearing the burdens of original sin.

Re: Python's pre-declared constants are kinda weird

#208
post #149

Earlier quoted context omitted.

You've probably just gotten used to it so you don't notice it anymore: https://github.com/satwikkansal/wtfpython (Note some of these are outdated, but some of those only mention that towards the end of the section rather than the beginning)

If you read it you'll realize that, very much like I said, the Python WTFs have to do with mechanisms that not obvious but are consistent . This is far better than Javascript, where the underlying mechanisms may be superficially obvious in some subset of cases, but are not consistent and generate many special cases.

The Python wtfs are definitely more consistent than the JS wtfs.

Re: Python's pre-declared constants are kinda weird

#209
post #28

Earlier quoted context omitted.

I'm not mad, but curious - I use Python for years and only dabbled with JS. Could you elaborate what makes Python magnitide worse than JavaScript?

Don't mind the web designers calling themselves engineers. There's a lot of annoying issues with Python, but compared to the billions of dollars and thousands of man hours that has been spent trying to fix Javascript and how horrible it still is, it's a perfectly cromulent language.

cool insult, yet i chose those 2 languages exactly because they're popular and horrible as examples.

let me guess you work somewhere that hired you to bikeshed all day

Re: Python's pre-declared constants are kinda weird

#210

Earlier quoted context omitted.

You are both focusing on Python improving in any way but the person you're responding to said "improve in any meaningful way, or to learn anything from their peers" Which I will say is overstated but I can see where they are coming from even when you bring into scope things like types, async, etc. First types. This is what the type hints in Python allow you to do: def foo(x: int) -> int: return x foo("hello") We can…

Not every improvement is perfect, that’s true. I in particular fought against walrus syntax and don’t use pattern matching for other reasons. Python is also boxed in by its history. Some of the things you want done are incongruent with its design. Many people like them however. And you’re being way too charitable to that dumbass comment.

I guess what I’m trying to do is draw a distinction between “improvement” and “change”. We can agree to disagree but my view is the things I called anti-features are not improvements at all, but rather loaded footguns. Python would be more coherent language without async/unenforced type hints/non exhaustive pattern matching. Like you say, it’s constrained by its history and I feel a lot of the recent changes are to make Python more palatable to the devs who are using it for AI and ML rather than keeping it true to to its nature.
Post reply on HN