Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

371–380 of 718 posts

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

#371

When did Python go out of fashion? This is the second article I've seen talking about it as if it's some kind abomination. I get that it's not the shiny new thing, but I don't understand people hating on it. Is this just junior devs who never learned it, or is there some new language out that I missed? (And please don't tell me Javascript....)

A decade ago, Python was pretty rough around the edges in production. Of course you could make it work, but you had to sacrifice a lot in terms of: - Environment / dependency management - Type safety - Performance As the author points out, these have largely been addressed now by uv, type hints, pydantic, FastAPI, etc.

>A decade ago, Python was pretty rough around the edges in production.

Not really.

Environment/dependency management is/was never an actual problem. People act like you update a version and stuff breaks. Even then, venv existed for this reason, and you could specify version in the setup.py or requirements.txt.

Type safety should in theory be covered by unit tests. If you assign a variable to another one in a dynamic setting accidentally, like a string to a dict, then your functionality breaks. In reality though, its really not that hard to use different variable names. In my experience, the only time things start getting confusing is if you start using Java concepts with things like Factories and a lot of OOP and inheritance in Python. None of that stuff is really necessary, you can get by with dicts for like 90% of the data transfer. And in very type safe languages, you spend a lot of time designing the actual type system instead of just writing code that does stuff.

Performance is still slow, but language performance doesn't really matter - you can launch natively compiled code easily from Python. Numpy was built around this concept and is also 10 years old. You will never beat C (with explicit processor instructions for things like vector math) or CUDA code, but most of your code doesn't require this level of performance.

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

#372
post #238

Earlier quoted context omitted.

The most insane python feature is that for loops keep their intermediate variable. for x in [1,2,3]: print(x) x sticks around! So you'll always have these random variables floating around, and hope you don't use the wrong one. And to add insult to insult to injury, if you're using mypy for type checking you'll get a nice error if you try to reuse x with a different type: for x in ['a', 'b', 'c']: print(x) And the typ…

Comments like this basically should say "I want as much handholding as possible" Lucky for you, LLMs are pretty good at that these days. >And the types I can never trust. I've used all the tooling and you still get type errors in runtime. It's also ridiculously slow. IDE integrated mypy checking does this in the background as you type. As for errors, it all has to do with how much typing you actually use. You can set…

[deleted]

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

#373
post #319

Earlier quoted context omitted.

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)?

exceptions being the exception is funny somehow

very recursive

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

#374
post #45

From what I was told, Python was originally seen as a Swiss Army knife for sysadmins. It started gaining more traction when Canonical adopted it as the main language for Ubuntu 4.10 in 2004. Then, in 2005, Guido van Rossum was hired by Google to work on Google Cloud. That opened the door for wider adoption in academia, since Python had strong math libraries and integrated well with tools researchers were already usin…

This aligns with what I remember and Guido going to Google explains things. Mid 2000's was all about PHP (Cake/Symphony/CodeIgniter/etc) vs Ruby (Rails) in the open source world. I remember hearing about Python only in sysadmin work and Plone. Then, suddenly were suddenly a lot of articles from Google about just about everything, all in Python.

I remember saying to a coworker, "Google is single-handedly keeping Python alive."

Then bam. It was everywhere. Mid 2010's, I took a cybersec job and they told me to learn Python in the two weeks between accepting and starting. "Python is all over cybersec," I was told. It was then I realized Python took over academia, which positioned it perfectly for ML. It's features made it easy to start, but it also benefited from right place, right time.

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

#375

Earlier quoted context omitted.

can you give at least one example? You are probably just expecting too much. No manual checkout/install process is easy as installing an application.

What about Go? "go install github.com/org/repo/x"

`pip install git+https://github.com/org/repo/x`

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

#376
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)?

Also true of JavaScript pre-ES5, another language that on first glance seems to only have function scope: it actually does have block scope, but only for variables introduced in `catch` blocks. AFAIU that was the standard way for a dumb transpiler to emulate `let`.

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

#377
post #9

It's funny, I'm the opposite: LLMs have made it easy to draft something in Python, then translate to a more appropriate language for the target problem-domain, for example Go.

Is go the language that doesn't include a module to do mmap and doesn't include a module to place binary data into a struct?

If you want to read binary files, you can use C or python, but not go (unless you use segfault prone 3rd party libraries of very dubious quality, of course).

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

#378
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…

I feel like use case and audience matters when making these decisions. In this case, the user is probably someone interacting with a python script they're running in a console (I assume by print), then I really don't think it matters - the user will check that both things are set. Should you also give them some documentation about setting env vars? Should you customize that documentation to the OS they're running? etc.

If the user is a typical consumer using a typical consumer interface, then yes you want to handhold them a bit more.

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

#380

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.

dang the backend is leaking old comments from 2007
Post reply on HN