Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

281–290 of 718 posts

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

#281

Earlier quoted context omitted.

It's like the bright orange garments that hunters wear, the ugliness is sort of the point. It says "this is a different sort of thing."

> It's like the bright orange garments that hunters wear, the ugliness is sort of the point. Ugliness is not the point of hi-vis vests lol, the point is to not get shot by other hunters.

...by being as shockingly contrasting with their environment as possible. Maybe your aesthetics differ, but I find it quite ugly. If it wasn't, it wouldn't grab my attention so well. Wearing something shockingly ugly is a great way to not be mistaken for a deer.

By contrast, I find a well camouflaged deer quite beautiful--once I notice it at all. The beauty comes from the way that it is so clearly a thing of its surroundings. Nothing at all like a bright orange hat.

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

#282
post #5

> Python has done a good job of hiding its legacy ugliness (such as __init__, __new__, and similar aberrations), swettening its syntax to accomodate developers with good taste. What exactly is the problem with __init__ or __new__? @dataclass is very nice syntactic sugar, but are we arguing here that having access to initializer/allocator/constructor dunder methods is "legacy ugliness"? This is the core of pythonic bu…

Bizarre is that you don’t consider it ugly. Kotlin: constructor is either part of class definition or keyword constructor. Ruby: initialize JS: constructor Python: ______new______, _______init_______ Literally this meme: https://knowyourmeme.com/memes/three-headed-dragon

I mean, it's never been a problem for me in my 26 years of Python, but if it is such a big deal for you, maybe you should consider this: https://gist.github.com/josiahcarlson/39ed816e80108093d585df...

I wrote it in about an hour and a half. It seems to work in Python 3.6 and 3.12. Now you never need to write another double-underscore magic method again.

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

#283
post #79
post #71

Earlier quoted context omitted.

Can you elaborate bit what is the problem here? Is it shape of the characters or something else?

Amazing. If you need to ask this question I am guessing you have spent too long with Python . No other language uses this underscore madness for special methods or otherwise. Because it’s just , I don’t know a more appropriate word for it , stupid.

I mean, Python is dynamic. Here, have this: https://gist.github.com/josiahcarlson/39ed816e80108093d585df...

Now you don't need to write your double-underscore methods ever again, if you don't want to.

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

#284
post #5

> Python has done a good job of hiding its legacy ugliness (such as __init__, __new__, and similar aberrations), swettening its syntax to accomodate developers with good taste. What exactly is the problem with __init__ or __new__? @dataclass is very nice syntactic sugar, but are we arguing here that having access to initializer/allocator/constructor dunder methods is "legacy ugliness"? This is the core of pythonic bu…

Probably the system of giving special meaning to what are otherwise ordinary identifiers. __ isn't a reserved keyword in Python or anything. But there's a set of conventions you're supposed to follow when naming methods and attributes, and they're visibly artificial. It would be cleaner to make the features that are a special part of the language definition also a special part of the language syntax instead of runnin…

Not when this can be done: https://gist.github.com/josiahcarlson/39ed816e80108093d585df...

Take a deep breath.

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

#285
post #246

Earlier quoted context omitted.

I think for a lot of us, it was very frustrating when it was being pushed with no real analog for the practices we had in other languages. Poetry used to be pushed as how to do dependency management, but it was not obvious that it was not necessarily your build manager, as well. Even today, I'm not entirely clear what the standard approach is for how to manage a project. :(

If I were to try again I'd go with uv, it seems way way better

I have been sticking with poetry for a while, now. What would make me want/need to move to uv?

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

#286
post #172

Earlier quoted context omitted.

I write a decent amount of Python, but find the walrus operator unintuitive. It's a little funky that API_KEY is available outside of the `if`, perhaps because I had first seen the walrus operator in golang, which restricts the scope to the block.

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.

Maybe Python will get a let one day

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

#287
> I would like to have a tool that generates the project structure for me, but I haven’t found one that fits me yet.

I recommend cookiecutter for this. I have a few templates I've built with that which I use frequently:

python-lib: https://github.com/simonw/python-lib

click-app: https://github.com/simonw/click-app

datasette-plugin: https://github.com/simonw/datasette-plugin

llm-plugin: https://github.com/simonw/llm-plugin

You can run them like this:

  uvx cookiecutter gh:simonw/python-lib

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

#288

Out of curiosity, why would I use Dataclass vs a Pydantic Basemodel. If we did not have a PyDantic dependency I could imagine wanting to use Dataclass. But if I have it, why not use everywhere?

To help answer your question, here's a detailed comparison from the attrs project:

https://www.attrs.org/en/stable/why.html

There's some obvious potential for bias there, but I thought most of the arguments were well reasoned.

Edit: found another that I thought was helpful: https://threeofwands.com/why-i-use-attrs-instead-of-pydantic...

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

#289

Earlier quoted context omitted.

why would you want a lambda to span multiple lines? How would that be any better than a function?

Because sometimes I want to have logic that spans multiple lines and I don't want to assign it a name. An easy example might be something with a `map` or a filter. For example, in JavaScript [1,2,3,4].filter(x => { let z = x * 2; let y = x * 3; let a = x / 2; return (z + x * a) % 27 == 2; }); Obviously I know I could name this function and feed it in, but for one-off logic like this I feel a lambda is descriptive eno…

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 a function to a function and you just want it to be concise. I could imagine using something like that off the top of my head, but then pulling it apart and giving it a name the moment I had to troubleshoot it. Which is how I currently use nested comprehensions, just blurt them out in the moment but refactor at the first sign of trouble.

I think maybe I just have trouble seeing some of the braces and stuff, and it's easier for me to reason about if it's named. I guess that's why we have 32 flavors.

Thanks for answering me honestly I really do appreciate it, even if my tone came off as dismissive. Sometimes I don't realize how I sound until after I read it back.

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

#290
I make projects following almost identical patterns. It's a little uncanny. Maybe the people in the python developer ecosystem are converging on a pretty uniform way to do most things? I though some of my choices were maybe "my own", it seeing such consistency makes me question my own free will.

It's like when people pick a "unique" name for their baby along with almost everyone else. What you thought was a unique name is the #2 most popular name.

Post reply on HN