News for hackers. Stuff that matters.
Re:Was Rust Worth It? by throwaway914 on Wednesday October 25, 2023 @07:17PM (#38019584)
I feel like Rust finally broke the idea that programmers should be in complete control and completely conscious of everything the compiler is doing. It hasn't been that way in decades, compilers are freaking magic. But Rust undid a lot of that with borrowing. People became comfortable with the compiler knowing better than them. I just wish we could relax further: We should never be explicitly iterating forward over a collection unless we need this behavior for the algorithm. Things should be implicitly parallel. Etc. Give me rusty bash.
Re:Was Rust Worth It? by j-pb on Wednesday October 25, 2023 @07:39PM (#38019782)
As someone who does a lot of unsafe rust, including tagged pointer foo, I strongly disagree.

If anything I want more explicit control, alleviated with an even more expressive type system. Ideally rusts type system would just be a prolog variant imho.

Re:Was Rust Worth It? by charcircuit on Wednesday October 25, 2023 @08:20PM (#38020078)
No thanks. Rust compile times are already too slow.
Re:Was Rust Worth It? by throwaway914 on Thursday October 26, 2023 @01:51AM (#38022101)
Anyone that can reliably and off-the-cuff do all of these can have complete control back:

https://en.wikipedia.org/wiki/Category:Compiler_optimization...

Otherwise we should trust compilers to know better.

Re:Was Rust Worth It? by alpaca128 on Wednesday October 25, 2023 @07:28PM (#38019687)
> We should never be explicitly iterating forward over a collection unless we need this behavior for the algorithm. Things should be implicitly parallel

There is already a crate providing parallel iterators. You just rename the iter() call and that's it. I don't agree it should be implicit though.

Re:Was Rust Worth It? by ModernMech on Wednesday October 25, 2023 @07:57PM (#38019933)
It’s called Rayon for anyone who wants to know.
Re:Was Rust Worth It? by oconnor663 on Wednesday October 25, 2023 @07:33PM (#38019731)
I think "not in control of what the compiler is doing" is overstating things a little bit. In some ways, Rust gives the programmer more control that C does. For example, Rust has standardized support for inline assembly, but inline assembly in C relies on vendor-specific extensions.

But to your point, the _defaults_ are very different. Things like raw pointer casts require a lot of ceremony and careful thought in Rust, and they have to follow more rules than in C. In particular, Rust references are all effectively "restrict", and it's really easy to screw that up when you do unsafe cast from raw pointers to safe references, which is a big incentive not to write code that needs to do that if you have a choice.

Re:Was Rust Worth It? by jeremyjh on Wednesday October 25, 2023 @09:29PM (#38020632)
> but inline assembly in C relies on vendor-specific extensions.

Whereas Rust is a standard with multiple implementations?

Re:Was Rust Worth It? by oconnor663 on Wednesday October 25, 2023 @09:38PM (#38020688)
I should've said "stabilized" instead of "standardized" to avoid stepping on this conversational landmine. But an important practical difference is that Rust supports inline assembly on Windows. (Correct me if I'm wrong, but I think MSVC mostly does not support inline asm.)
Re:Was Rust Worth It? by trealira on Wednesday October 25, 2023 @10:14PM (#38020898)
It does support inline assembly [1]. However, it's different than the way GCC supports inline assembly. It seems nicer, TBH.

[1]: https://learn.microsoft.com/en-us/cpp/assembler/inline/inlin...

Re:Was Rust Worth It? by oconnor663 on Wednesday October 25, 2023 @10:21PM (#38020942)
From that source:

> Inline assembly is not supported on the ARM and x64 processors.

Re:Was Rust Worth It? by trealira on Wednesday October 25, 2023 @10:40PM (#38021070)
Oh, my bad. I should have read the source more closely. I hadn't realized only 32-bit x86 processors were supported.
Re:Was Rust Worth It? by jeremyjh on Wednesday October 25, 2023 @10:57PM (#38021163)
That's hilarious. Like, the compiler team had ONE GUY that believed in and developed this feature and retired in 1999.
Re:Was Rust Worth It? by trealira on Thursday October 26, 2023 @10:24AM (#38026014)
I can't remember where I heard this, so take it with a grain of salt.

IIRC, the MSVC C/C++ compilers don't output assembly and then assemble that with an assembler; they output machine code directly for efficiency. It could be that inline assembly would require an assembly language parser that would have to be merged into the compiler and complicate the architecture, and they have no reason to do that unless enough paying customers request it.

Re:Was Rust Worth It? by jjn2009 on Wednesday October 25, 2023 @07:26PM (#38019664)
Arguably memory managed languages are the same or are you speaking to some specific slice of the available programming languages?
Re:Was Rust Worth It? by HKH2 on Wednesday October 25, 2023 @08:53PM (#38020359)
> Give me rusty bash.

Bash with types (especially floats), fewer edge cases, functions with explicit parameters, simple command line flags...

Re:Was Rust Worth It? by AgentME on Wednesday October 25, 2023 @09:02PM (#38020429)
You're skipping the most needed improvement of all: fixing the issue where scripts with unquoted variables will seem to work until they contain a space. Almost every single bash script of more than a dozen lines I've seen outside of large open-source projects fails if a user puts a space in a file path, because the programmer didn't understand the insanity of variable quoting rules! I don't know of any programming language with a more common major footgun.
Re:Was Rust Worth It? by HKH2 on Wednesday October 25, 2023 @09:23PM (#38020592)
Shellcheck does cover that. I think the bigger problem is people programming without warnings (in any language).
Re:Was Rust Worth It? by fbdab103 on Wednesday October 25, 2023 @11:01PM (#38021177)
Now you have me curious - where do you see the need for floats in shell? You are more creative than myself, because I am struggling to come up with a situation where I would lean on this. A "path" type would be by far more useful to my work.
Re:Was Rust Worth It? by HKH2 on Thursday October 26, 2023 @02:45AM (#38022482)
I have a script which uses wmctrl to tile windows when I press a shortcut key (for when I'm using an editor and want the editor window to take up most of the screen).

I guess I could avoid floats using multiplication, but I would rather keep the code as simple as possible.

Re:Was Rust Worth It? by bbkane on Wednesday October 25, 2023 @11:31PM (#38021322)
Re:Was Rust Worth It? by rustshellscript on Thursday October 26, 2023 @03:10AM (#38022631)
Re:Was Rust Worth It? by Aerbil313 on Thursday October 26, 2023 @04:01AM (#38022978)
Check out nushell, the Rust of the shells.

I know it’s still not 1.0. Then just get fish. At least would save some keystrokes.

Re:Was Rust Worth It? by HKH2 on Thursday October 26, 2023 @12:43PM (#38028185)
Fish is an easy alternative. Thanks.
Re:Was Rust Worth It? by mike_hearn on Thursday October 26, 2023 @10:52AM (#38026372)
We use a Kotlin scripting variant for our own shell scripting needs at Hydraulic, it's pretty nice because we've joined it with a lot of internal APIs that make working with the filing system and network easy. It fits all those requirements and more (you can declare flags easily at the top level, it has built in progress tracking for slow operations etc).

It's not really a "product" per se but there's an old version for download and some lightweight docs here:

https://hshell.hydraulic.dev/

We've never worked out what to do with it. Ideas and feedback welcome. It's pretty nice to use, albeit you need to use IntelliJ to edit scripts if you want IDE features.

Re:Was Rust Worth It? by pornel on Wednesday October 25, 2023 @10:02PM (#38020815)
That seems entirely opposite to my Rust experience.

Rust is quite transparent in what it does, and is very conservative with compiler magic. The language doesn’t do heap allocations, doesn’t do reference counting, it doesn’t even have implicit numeric type conversion. It won’t implicitly copy types that did not ask to be implicitly copyable, and even that is only legal for types that can be copied with a simple shallow memcpy.

Rust uses zero-cost abstractions all over the place, which means it’s predictable what code they will compile to, and that will be typically something simple. Std types have well-known basic layout, so you know that e.g. iteration over a Vec is going to be a loop incrementing a pointer, and there’s no implicit parallelism.

Describing borrowing as “compiler knowing better than the programmer” is a weird way of looking at it. Borrowing is like type checking. You declare a type to be temporary, and try to use it as long-lived, you get an error. It’s the same as if you declare function to return struct Foo, but returned struct Bar instead. Yes, compiler “knows better than you”, because you just wrote a bug.

Borrowing still compiles to direct pointer usage without a GC (it’s literally guaranteed to be identical to a C pointer in C ABI structs and functions), and you can override lifetimes with unsafe if you think know better than the compiler.

Re:Was Rust Worth It? by bjourne on Wednesday October 25, 2023 @10:05PM (#38020841)
That's the approach Haskell took. Didn't work since they didn't realize that waiting for your program to respond is a pretty effing huge side effect.
Re:Was Rust Worth It? by trealira on Wednesday October 25, 2023 @10:20PM (#38020935)
It has unpredictable performance because of lazy evaluation. Other high-level functional programming languages like OCaml, Standard ML, and Scheme can be compiled and achieve fairly high performance.
Re:Was Rust Worth It? by rustshellscript on Thursday October 26, 2023 @03:06AM (#38022616)