Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

471–480 of 718 posts

Re: I'm switching to Python and actually liking it

#471

Earlier quoted context omitted.

The official package manager is pip, it's broken, and there has been a new "permanent solution" replacement for it each year.

Poetry has been decent for years. uv is new but great and will likely continue to be.

uv is soooo much faster than Poetry, especially for dependency resolution.

Re: I'm switching to Python and actually liking it

#472

>> I prefer to use a monorepo structure There is nothing more annoying than tons of little repos all of which containing tiny projects with a few hundred lines of code but (of course) you need most / all of them to do anything. Use a mono repo until there is some obvious reason to split it up imo.

I got the impression that TFA speaks of a monorepo in the sense of not splitting the backend and the frontend into two different repos.

For personal projects, though, I get the value of an actual small projects monorepo.

Re: I'm switching to Python and actually liking it

#473

Earlier quoted context omitted.

> it's obvious that they are magic methods and not intended to be part of the public API Is there an alternative API? No. This is public API regardless of anyone's intentions. Though "it's weird" is really not a very strong argument against it.

There are several alternative API's. @dataclass is one, Pydantic offers another, there's also attrs, plus less general things like namedtuple. Admittedly it's obnoxious when you've got habits for one and you're on a team that uses another--totally flies in the face of the zen re: "there should be only one obvious way to do things". ...but that was always a rather ambitious goal anyway. I'm ok navigating the forest of…

@dataclass does a very specific subset of what overriding dunder methods does. It’s not duplicating an abstraction it’s layering them

Re: I'm switching to Python and actually liking it

#475
post #319

Earlier quoted context omitted.

This isn't really unique to the walrus operator, it's just a general python quirk (albeit one I find incredibly annoying). `for i in range(5): ...` will leave `i` bound to 4 after the loop.

Oddly enough, "except" variables don't remain bound! try: x = int('cat') except Exception as e: pass print(e) # So, it appears Python actually has three variable scopes (global, local, exception block)?

I may be rusty, but wasn't there a "finally" scope for those situations?

edit: writing from phone on couch and the laptop... looks far, far away...

Re: I'm switching to Python and actually liking it

#476

Maybe I'm the only one that finds Python simultaneously verbose and lacking? Either you need 500 dependencies to do something in a simple way, or you need dozens (if not hundreds) of lines to do trivial things. I avoid writing Python because there's so much bullshit to add. Much prefer Perl, I can actually get things done quickly. Python feels like programming for the sake of programming.

Have you met Java?

Re: I'm switching to Python and actually liking it

#477
post #98

Earlier quoted context omitted.

> Have you considered how much familiarity might shape your reaction to the two? It doesn't. > Both are specific patterns with arbitrary restrictions which new learners have to internalize, and that’s a fairly advanced task most people won’t hit until they are familiar with the language syntax. No, the Python methods are just ordinary methods with valid names. What 'arbitrary restrictions' are you referring to?

The arbitrary restriction is that you have to just learn a specific pattern and follow it. I can’t have my Python class use “addition” if I hate underscores or my C++ code use “mathematical_division” if I’m horribly pedantic. In both cases, it’s just a particular design decision by the language developers I have to learn, and in both cases I won’t think much of it after the initial acclimation.

Python you have to learn something arbitrary for each dunder method you want to define/override. + —> __add__, * —-> __mul__, etc

C++ it’s just one pattern to learn, x -> operatorx

Re: I'm switching to Python and actually liking it

#478
post #80

Just a small note on the code in the linked script: API_KEY = os.environ.get("YOUTUBE_API_KEY") CHANNEL_ID = os.environ.get("YOUTUBE_CHANNEL_ID") if not API_KEY or not CHANNEL_ID: print("Missing YOUTUBE_API_KEY or YOUTUBE_CHANNEL_ID.") exit(1) Presenting the user with "Missing X OR Y" when there's no reason that OR has to be there massively frustrates the user for the near zero benefit of having one fewer if statemen…

This is nitpicking, but this is a good usecase for the := operator: if not (API_KEY := os.getenv("API_KEY")): ... For internal tools I just let os.environ["API_KEY"] raise a KeyError. It's descriptive enough.

Why would you use it though? I always thought it a bad thing that legacy code (such as in C or C++) had these side effects inside of checks happening

Re: I'm switching to Python and actually liking it

#479
For me, python is the closest thing to writing pseudocode that functions. Every time I have the instinct to gloss over a thing when writing it down (because it feels obvious in my head), it turns out that python has an intuitive abstraction for it.

Coming from a mathy background I found it incredibly satisfying, although I’ve come around to other languages since.

Re: I'm switching to Python and actually liking it

#480

Earlier quoted context omitted.

For this example, don't just command line arguments. There's an API key there, you don't want an API key visible in your cmdline.

Then how would you SET the API key in the first place? :) The argument doesn't make any sense at all.

In some .profile or .envrc or what you'd call such a file, I suppose.
Post reply on HN