Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

641–650 of 718 posts

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

#641
post #585

Earlier quoted context omitted.

> `for i in range(5): ...` will leave `i` bound to 4 after the loop. reply This "feature" was responsible for one of the worst security issues I've seen in my career. I love Python, but the scope leakage is a mess. (And yes, I know it's common in other languages, but that shouldn't excuse it.)

I would love to hear about the security issue if you're able to talk about it

I don't remember the exact details, but it basically involved something along the lines of:

1) Loop through a list of permissions in a for list

2) After the loop block, check if the user had a certain permission. The line of code performing the check was improperly indented and should have failed, but instead succeeded because the last permission from the previous loop was still in scope.

Fortunately there was no real impact because it only affected users within the same company, but it was still pretty bad.

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

#643
post #482

Earlier quoted context omitted.

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.

no one uses walrus

I use it fairly often

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

#644

Earlier quoted context omitted.

[flagged]

Glad I'm not working with you if you consider that kind of PR comment to be worthy of a negative comment.

Funny how statements like these get upvoted and not flagged, but my "Lmao" did. I should be more toxic it seems. Which I thought is worse than an "Lmao" but hey, HN knows best.

("Lmao" is useless, but definitely not worse than some other responses.)

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

#645

Earlier quoted context omitted.

Glad I'm not working with you if you consider that kind of PR comment to be worthy of a negative comment.

I would have just replied with "Oops, something went wrong." If it hadn't already been flagged, that is.

Which is unfortunately very commonplace.

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

#646
I get the “actually liking it part.”

I have been enjoying Lisp languages since the late 1970s, and today it makes me happy using Common Lisp and Racket in the same way as when I stood in a forest very early this morning drinking coffee makes me happy.

But, Python is also a fun language and phrases like “good enough” and “actually liking it” are valid.

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

#647

Earlier quoted context omitted.

I find it incredibly intuitive and useful that it does that. sometimes it drives me nuts that it doesn't do it for comprehensions but I can see why. But if something fails in a loop running in the repl or jupyter I already have access to the variables. If I want to do something with a loop of data that is roughly the same shape, I already have access to one of the the items at the end. Short circuiting/breaking out o…

Python 2 actually did let comprehension variables leak out into the surrounding scope. They changed it for Python 3, presumably because it was too surprising to overwrite an existing variable with a comprehension variable.

Oh wow, maybe that's why I expect it to work that way! I can't believe it's been long enough since I used 2 that I'm forgetting it's quirks.

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

#648
post #470

Earlier quoted context omitted.

- Performance: uv is so much faster that some operations become transparent. poetry's dependency resolver is notoriously slow. uv being a native binary also means it has a faster startup time. - Interpreter version management: uv can handle separate python versions per project automatically. No need for pyenv/asdf/mise. - Bootstrapping: you only need the uv binary, and it can handle any python installation, so you do…

I'll pay attention to poetry soon. As is, I don't recall my builds ever going slow because of poetry. I don't think I've noticed it have any impact on speed, at all. I did just update the dependencies of some of my projects. I could see how that could be faster. I don't do that often enough for me to care about it, though. `poetry run pytest` is the slowest thing I have, and I'm confident most of that slowness is in…

uv supports the standardised lock file format. This means that you're not tied to uv for anything, as most project settings it uses (eg metadata, dependencies, extras, etc.) are based on PEPs. poetry has its own format for many things.

https://peps.python.org/pep-0751/

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

#649

Earlier quoted context omitted.

Honestly, I don't really see the appeal of unnamed functions in general. I so rarely use lambdas that I wouldn't really miss them if they were gone. Just occasionally as a sort key, or in a comprehension. I have seen people do this in JavaScript quite often, but I always assumed there was some kind of underlying performance benefit that I didn't know about. As I think about it I guess it makes sense if you're passing…

Obviously it's totally fine to have a difference of opinion for something like this. > I have seen people do this in JavaScript quite often, but I always assumed there was some kind of underlying performance benefit that I didn't know about. I don't think so, at least I haven't heard of it if there is. I tend to have a rule of thumb of "if it's more than 6-7 lines, give it a name". That's not a strict rule, but it's…

And I think that's where the reasoning behind only allowing one line lambdas came from. I believe I read a thread a long time ago where GVR didn't even want to include lambdas at all, if I have time I might look for it and edit in a link.

At it's core, I think it's fair to say Python is about forcing the user into formatting their code in a readable way. It's gotten away from it over the years for practicality reasons, and to increase adoption by people who disagree on which ways are more readable.

Sometimes I wish they would take nested comprehensions away from me, I am too lazy to avoid them in the heat of the moment, and I get a thrill out of making it work, even though I know they're disgusting.

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

#650

Earlier quoted context omitted.

First, I grok make. I'm saying this from a position of familiarity, not of ignorance and fear. Make is great at compiling code in languages that don't have bespoke build systems. If you want to compile a bunch of C, awesome. For building a Rust or JavaScript project, no way. Those have better tooling of their own. So for the last 15 years or so, I've used make as a task runner (like "make test" shelling out to "cargo…

I don't really like Make as a build system, especially since today every language I've worked with has a much better one - cargo, uv, cmake, bazel, others. My thing is that it's ubiquitous and if you stay simple, the syntax is perfectly readable; if you're doing anything complicated, I'll argue you don't want your logic in a Makefile anyway, you want it in a shell script or a Python script. I get that if you want to…

That’s the thing: just is a lot simpler and cleaner for the simple things, too. Like not requiring .PHONY, for instance. And if you already have to install cargo/uv/cmake, add just to that list of dependencies.

The argument stuff is nice when you realize you’re no longer constrained by not having easy access to it. I used just to build my blog, and added a target to create a template entry whenever I updated to a new release of certain software. I could write “just newversion 1.2.3” to publish an announcement using the same mechanisms that did everything else. Without that feature, I could have scripted something up to do the same. With it, I didn’t have to. I wouldn’t have tried that with make.

Post reply on HN