News for hackers. Stuff that matters.
Re:Rust for the small things? but what about Python? by daft_pink on Monday September 09, 2024 @11:22AM (#41489389)
To me, a clear benefit of rust over python, and I love python is that once you write something in rust, you have an executable that you can give to someone that doesn’t know how to program.

Python is great for something I will use myself, but not so great for when I want someone else to use my code.

Re:Rust for the small things? but what about Python? by Levitating on Monday September 09, 2024 @11:29AM (#41489503)
I don't agree with this.

If I give somebody a binary, I have to compile this binary for their operating system and architecture. If they don't know how to program they'll be confused as to why they cannot share this program with others.

If I share somebody a python script, they can still execute it as a program as long as a shebang is set. They can use this script on any operating system and can open it with at text editor to view it's inner workings.

This makes scripting languages like Python much more accessible for single-file scripts.

Re:Rust for the small things? but what about Python? by NoboruWataya on Monday September 09, 2024 @11:36AM (#41489598)
> If I share somebody a python script, they can still execute it as a program as long as a shebang is set.

As long as they have the right version of Python and all of your program's dependencies installed, which they most likely won't.

> They can use this script on any operating system and can open it with at text editor to view it's inner workings.

Someone who doesn't know how to program most likely isn't going to be using multiple operating systems and isn't going to want to open the script in a text editor to view its inner workings.

I agree with the parent comment that distributing binaries is way more seamless when your users are not very technical.

Re:Rust for the small things? but what about Python? by wrenky on Monday September 09, 2024 @02:07PM (#41491503)
AND holy shit I have to install another venv to run special-snowflake-3 script I will literally lose it. I literally have a folder of all the venvs I need to run one-off shit people pass me. I get the lack of wanting to compile things but thats not a problem with modern build systems like Rust/Go have- Beyond trivial.
Re:Rust for the small things? but what about Python? by awesomebytes on Tuesday September 10, 2024 @06:00AM (#41499145)
I have recently started to use uv, and you can just do "uvx tool" and it executes the tool (https://docs.astral.sh/uv/guides/tools/). Sure, the tool needs to do something to be able to be executed like that, but it seems pretty easy. And there's also a way to embed the dependencies with a comment at the top of a python script: https://docs.astral.sh/uv/guides/scripts/#running-a-script-w...

The venv created for this is ephemereal (it can not be if you want), so you don't need to keep in mind cleaning up stuff and so. Also uv is really fast in creating the venv and installing whatever is needed. Coming from using plain pip and venvs (and having pain setting up different python version interpreters for projects), and poetry just after that, I am pretty happy with the improvements.

Re:Rust for the small things? but what about Python? by blackfawn on Tuesday September 10, 2024 @06:17PM (#41506181)
Yeah, really... Python tries to hide some of the insanity behind venvs, conda, etc. but it often ends up some dependency nightmare that's barely holding together. Everyone that tells me "oh Python is so great, it just works" is either only using it for the absolute most basic tasks or kidding themselves. I'd often get a blank stare when I respond to that with "then why am I helping you fix this virtual environment with gigs of cruft for a 'simple task' that has suddenly and inexplicably stopped working for you?"

The equivalent things in Go, Rust, etc are a breath of fresh air for sure

Re:Rust for the small things? but what about Python? by pizza234 on Monday September 09, 2024 @11:38AM (#41489611)
> If I share somebody a python script, they can still execute it as a program as long as a shebang is set.

I'm not familiar with Python, but I presume its similar to Ruby, where besides trivial scripts, this is false - as soon as there are libraries required, you need to find a way to handle them, which in some cases may include handling multiple envs (I write and distributes such scripts).

Compiling for multiple environments in a controlled environment is by far much more convenient than debugging scripts failing on end users' systems.

Re:Rust for the small things? but what about Python? by pid-1 on Monday September 09, 2024 @11:57AM (#41489838)
IMO it's far worse than Ruby. Since Python is meant to be a glue language, scripts can have every type of esoteric dependency, including binaries, os libs, java programs, etc...
Re:Rust for the small things? but what about Python? by Levitating on Tuesday September 10, 2024 @05:11AM (#41498805)
Ruby isn't any different
Re:Rust for the small things? but what about Python? by stonemetal12 on Monday September 09, 2024 @11:39AM (#41489626)
>If I share somebody a python script, they can still execute it as a program as long as a shebang is set.

Since when has windows come with python installed and worked with a shebang?

Mac OS doesn't come with python installed and clicking it won't run it.

So anyone " confused as to why they cannot share this program with others." isn't going to be able to use your python script.

Re:Rust for the small things? but what about Python? by ayhanfuat on Monday September 09, 2024 @11:49AM (#41489740)
This would work in a language with better and more modern packaging (like Julia) but giving people Python files and expecting them to run them in correct versions might just be a bigger ask then asking them to compile C code.
Re:Rust for the small things? but what about Python? by greener_grass on Monday September 09, 2024 @11:36AM (#41489597)
> they can still execute it as a program as long as a shebang is set

Not if you use any libraries.

Re:Rust for the small things? but what about Python? by faangguyindia on Monday September 09, 2024 @01:08PM (#41490747)
Unlikely, you need to install virtualenv.

As they may not have same python version, may have different python libraries (version)

It's not simple to run a python script specially one which uses libraries (let's be honest how often your core is not using those popular libraries)

Re:Rust for the small things? but what about Python? by keybored on Monday September 09, 2024 @11:48AM (#41489725)
The Rust implementation is on the heavy compiled end. The Python implementations are on the more interpreted end.

Considering how widespread Python is it seems like solving the one-executable problem for Python should be easier than solving Rust’s problem (heavy compilation). Like with a wrapper or something.

Re:Rust for the small things? but what about Python? by xyst on Monday September 09, 2024 @12:02PM (#41489891)
Python is so “widespread”, that I have seen (non-technical) users with 4-5 different versions of python on their machine. And default/system python in path is 2.7 :dead:
Re:Rust for the small things? but what about Python? by jasomill on Monday September 09, 2024 @10:57PM (#41496756)
Re:Rust for the small things? but what about Python? by judge2020 on Monday September 09, 2024 @11:45AM (#41489691)
There are a host of Python to Executable tools that either compile the code to c or include the interpreter and run the code dynamically.
Re:Rust for the small things? but what about Python? by anonymoushn on Monday September 09, 2024 @11:33AM (#41489550)
Re:Rust for the small things? but what about Python? by globular-toast on Monday September 09, 2024 @11:41AM (#41489643)
This is what pyinstaller is for. It's not quite as good as a binary executable, although are you really sending ad hoc binaries to people? Seems like a nightmare for version control etc. The pyinstaller manual is much easier than learning rust!
Re:Rust for the small things? but what about Python? by judge2020 on Monday September 09, 2024 @11:46AM (#41489705)
PyInstaller does have --onefile but that's kind of cheating since it creates and extracts the files to a temp folder.
Re:Rust for the small things? but what about Python? by relaxing on Monday September 09, 2024 @02:02PM (#41491440)
It’s not cheating at all. It’s an inelegant solution, but it works.
Re:Rust for the small things? but what about Python? by zie on Monday September 09, 2024 @01:04PM (#41490677)
You can totally make binaries with Python, there are even many, many ways to do so. None really come out of the box, and some assembly is usually required, but if you want to do it, you can.

That someone is too lazy to do so is not Python's problem, that's their problem.

Re:Rust for the small things? but what about Python? by faangguyindia on Monday September 09, 2024 @01:07PM (#41490724)
That's what I use Go for.

It's much simple to write scripts in Go.

Here's an example; https://github.com/zerocorebeta/bashlike