Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

671–680 of 718 posts

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

#671
post #173
post #163

Earlier quoted context omitted.

Yes, I'd say Python's crown as the go-to lightweight scripting and web development language was mostly ceded to JS. It's still reigning champion of data science, and of course it has a huge number of uses and users still around, but it's not really cool or in vogue outside of those circles.

Do people really turn to JS (instead of Python) for lightweight scripting? Are we talking about the "better Bash" use case?

I use "tsx script.ts" often and it's very nice good due to gradual typing you can use (plus I know lang well)

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

#672

I really don't find the Python language elegant at all. I prefer the Ruby syntax. But Python's tooling, particularly with what Astral is doing (uv, ruff, ty), is so good, I'm always using Python and virtually never using Ruby. And yeah, the rich libraries, too.

Jupyter is also great thing in python ecosystem + colab etc.

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

#673
post #656

Earlier quoted context omitted.

Assertions are disabled via `python -O` so they probably shouldn't be used like this.

On the other hand, presumably the program will just crash anyway with some terse permission/request error later on if these values aren't set

Doesn't matter. Assertions should be used for things that are always true (barring bugs in the program). That isn't the case here.

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

#674

Earlier quoted context omitted.

Neophytes take notice. Attention to details like this is what separates truly great programmers from merely good ones. That said, for scripts reusable by others you should use command line arguments . Environment variables in lieu of command line arguments is a huge code smell.

Typer has a great feature that lets you optionally accept argument and flag values from environment variables by providing the environment variable name: https://typer.tiangolo.com/tutorial/arguments/envvar/ It's especially nice for secrets. Best of both worlds :)

No, that's an anti-feature. :) Sibling comments here claim that command line arguments "leak" whereas environment variables does not. It's plain wrong. An attacker with access to arbitrary processes' cmdline surely also has access to their environ. Store secrets in files, not in the environment. Now you can easily change secret by pointing the --secret-file parameter to a different file. The only reason people use BLABLA_API_KEY variables is because Heroku or something did it back in the day and everyone cargo-culted this terrible pattern.

One could write a huge treatise on everything that is wrong with environment variables. Avoid them like the plague. They are a huge usability PITA.

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

#675
post #392

Earlier quoted context omitted.

I have a bunch of zero dependency projects. You can get a lot done with the standard library and single file projects which you can run on most systems without needing to do anything except curl it down and run it since Python is available. For example here's a ~2k line Python project which is a command line finance income and expense tracker: https://github.com/nickjj/plutus/blob/main/src/plutus It uses about a doze…

Argparse is part of my problem with Python! I can never remember the weird ways it wants to collect all these attributes and features, so I'm always leafing through manual pages or googling for examples. Same for if I'm modifying existing Argparse code, I have no idea how to make it do what I want. It can do a lot for you, but it's a pain in the ass to use. It's so much easier to write a simple usage() function that…

Arguments can get pretty complicated.

One nice thing about argparse is it comes with a helper function for mutually exclusive groups that can be optional or required. For example you can have --hello OR --world but not both together.

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

#676

Earlier quoted context omitted.

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.

And you expect someone will be able to read your bash_history, but not your .profile?

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

#677
post #73

Earlier quoted context omitted.

Python's success is entirely due to entry-level programming courses. They all switched to Python, because you have to explain less. I don't think I heard about web servers in Python before 2012. I suppose a 2005 computer wouldn't be able to serve a Python backend smoothly. PHP's popularity isn't really from 2005-2006. It was popular at the end of the 90s, and it looks like JS as much as it looks like a potato.

1. Python was pretty popular well before entry-level programming courses adopted it. I think they adopted Python because it was a good general purpose scripting language, multiplatform, easy to install and get going, that taught programming concepts in a more approachable way for beginners. 2. Python on web servers was a thing long before 2012. You had Zope in 1998 or so, and it was pretty popular for a while, and hu…

I always loved the huge standard library that PHP offered, that and the comment section per function on the php docs pages

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

#678

Earlier quoted context omitted.

> making it harder for yourself Looking at just the first link, looks way more complicated than venv. And I'm a C++ developer, imagine someone who less experienced, or even who just isn't familiar with C toolchains.

The first link is a sudo apt install command that you copy paste into terminal. in what world is that more complicated than venv? Here it is for clarity sudo apt-get install build-essential gdb lcov pkg-config \ libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \ libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \ lzma lzma-dev tk-dev uuid-dev zlib1g-dev libmpdec-dev libzstd-dev

Even what you just pasted is wrong. And it would give a confusing error if you used it. Try "sudo apt install vim \ make" to see.

It's the kinda thing an experienced engineer wouldn't have that much trouble with, but you should be able to recognize how much experiential knowledge is required to compile a complex C code base and what kinda dumb stuff can go wrong.

You probably don't need to do much of the stuff on that page to build, but "What is dnf?", "Is the pre-commit hook important?", "Do I need cpython?", "What's an ABI dump?" are questions many people will the wrestling with while reading.

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

#679

Earlier quoted context omitted.

Millions of people put it into Docker, or they just deal with it and you see the results with tons of Stackoverflow questions

> Millions of people put it into Docker, or they just deal with it and you see the results with tons of Stackoverflow questions Arrogantly wrong. I've coded in Python for almost 20 years. Many of those years I've had it as my primary language at work. 2024 was the first year I actually needed a virtualenv. Before that, I'd happily use pip to install whatever I want, and never had a version conflict that caused proble…

>2024 was the first year I actually needed a virtualenv. Before that, I'd happily use pip to install whatever I want, and never had a version conflict that caused problems.

Okay I'll bite: how did you deal with situations where you needed to work on two different projects that required different versions of the same dependency?

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

#680
post #470

Earlier quoted context omitted.

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/

Ah, I see that this is a newer format than the projects I've been using poetry for. Are there advantages to move to it?
Post reply on HN