News for hackers. Stuff that matters.
Re:Cursed Linear Types in Rust by logicchains on Sunday December 01, 2024 @02:27PM (#42290136)
>One usage pattern many of us have found useful in our software for years is the "set once and only once" (singleton-ish)

C# has this: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Re:Cursed Linear Types in Rust by MrMcCall on Sunday December 01, 2024 @03:40PM (#42290585)
That's new since I've been tramping around VS.NET (F# 2 or 3 & C# from 10ya).

My immediate purposes require that I avoid depending on unique programming language/environment constructions, but it helps to learn, so thanks for levelling me up.

Re:Cursed Linear Types in Rust by cempaka on Sunday December 01, 2024 @03:20PM (#42290470)
And Java will soon have StableValue: https://openjdk.org/jeps/8312611
Re:Cursed Linear Types in Rust by neonsunset on Sunday December 01, 2024 @04:29PM (#42290860)
Reading the JEP, isn’t StableValue about JIT constants?

In .NET it’s just 'static readonly'.

Re:Cursed Linear Types in Rust by cempaka on Sunday December 01, 2024 @06:28PM (#42291568)
The basic feature set is at-most-once thread-safe initialization of values, which can then enjoy the same constant folding and other JIT optimizations one would get from `static final`, but can be initialized at any point during the program's run.
Re:Cursed Linear Types in Rust by mrkeen on Sunday December 01, 2024 @04:47PM (#42290968)

  Non-goals
  It is not a goal to provide Java language support for declaring stable values.
Hmmm
Re:Cursed Linear Types in Rust by jcrites on Sunday December 01, 2024 @05:13PM (#42291108)
From context, I would infer that this means they are not changing the Java language itself. It’s a feature expressed through the existing language, like as a library feature. I could be wrong though.
Re:Cursed Linear Types in Rust by cempaka on Sunday December 01, 2024 @06:29PM (#42291575)
Yes you're correct, the idea is that they're not adding any keywords or bytecodes, just some new standard lib APIs that will get some special treatment by the JVM.
Re:Cursed Linear Types in Rust by chipdart on Sunday December 01, 2024 @05:32PM (#42291213)
> C# has this:

This is only syntactic sugar to allow using object initializers to initialize specific member varabiles of a class instance instead of simply using a constructor and/or setting member variables in follow-up statements. It's hardly the feature OP was describing.

Re:Cursed Linear Types in Rust by neonsunset on Sunday December 01, 2024 @05:55PM (#42291359)
While mutation of init-only properties is sometimes done by e.g. serializers through private reflection or unsafe accessors, it otherwise can lead to unsound behavior if class implementation does not expect this. You cannot bypass this through normal language means.

Same applies to readonly instance fields.

Where does "syntax sugar" end and "true features" begin?

Re:Cursed Linear Types in Rust by bee_rider on Sunday December 01, 2024 @06:11PM (#42291445)
Anyway, trying to actually prevent a program from modifying its own memory is really hopeless, right? So any promises beyond “syntactic sugar” would be resting on a poor foundation, perhaps even dangerously misleading.
Re:Cursed Linear Types in Rust by neonsunset on Sunday December 01, 2024 @06:19PM (#42291509)
You can always mmap a memory range, place a struct there, then mprotect it. And on the language side you cannot overwrite readonly structs observed by readonly refs (aside from unsafe, which will trigger segfault in this case).

There are ways to do it. What matters is the user ergonomics, otherwise, by this logic, most higher-level languages would have even less of a claim to immutability, and yet somehow it's not an issue?

If there are exotic requirements - there are exotic tools for it. FWIW static readonlys are blocked from modification even through reflection and modifying their memory with unsafe is huge UB.