Live data from Hacker News

Python's pre-declared constants are kinda weird

sebsite.pw

231–234 of 234 posts

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

#231

Earlier quoted context omitted.

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

>"You can use it to cache values between function calls:" and I really hope nobody does that.

That default parameter is a mutable global variable and languages like Rust have effectively banned mutable statics for good reasons that I personally am discovering myself by messing around with UnsafeCell inside statics and even I personally am starting to think that mutable statics are at best a necessary evil, but not one you want to rely on as your go to solution.

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

#232

Earlier quoted context omitted.

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

>"You can use it to cache values between function calls:" and I really hope nobody does that. That default parameter is a mutable global variable and languages like Rust have effectively banned mutable statics for good reasons that I personally am discovering myself by messing around with UnsafeCell inside statics and even I personally am starting to think that mutable statics are at best a necessary evil, but not on…

I'm not concerned about the global. The problem is it's global but doesn't look like it, or looks like a mistake. You want a global cache in Python, there are easy and much better ways.

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

#233

Earlier quoted context omitted.

JS is a lot less weird than Python. And Python is what I started with and continue to use half the time. The article missed the most common one, __name__ == "__main__" like wtf

this isn't uniquely pythonic and JS isn't a great counterexample. https://nodejs.org/api/esm.html#importmetamain node also has __dirname and __filename from the good old days.

The JS one is at least a builtin instead of a magic string

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

#234

Earlier quoted context omitted.

Scripting languages are awful. Python is one of the nicest scripting languages.

Holy 2000s! Are we really still doing “programming” vs “scripting”?

My distinction is "systems" vs "scripting" but yeah.

I'm bringing Y2K back next!

Post reply on HN