Cursed Linear Types in Rust
geo-ant.github.io
geo-ant.github.io
We need a way to define how to "use" the types we define. That definitional structure is going to bleed from creation of instances into how they live out their lifetimes. It appears that Rust's design addresses some aspects of this dimension, and it also appears to be a fairly major point of contention among y'all, or at least require a steepish learning curve. I don't know, as I prefer to work in ubiquitous environments that are already featureful on 5-10yo distros.
One usage pattern many of us have found useful in our software for years is the "set once and only once" (singleton-ish) , whether it's for a static class member or a static function var, or even a db table's row(s). I don't know of any programming environment that facilitates properly specifying calculating something even that basic in the init phase of running the system, but I don't explore new languages so much anymore, none of them being mature enough to rely upon. Zig's comptime stuff looks promising, but I'm not ready to jump onto that boat just yet. I am, however, open to suggestions.
The real solution will ultimately require a more "wholistic" (malapropism intended) approach to constraining all dimensions of our software systems while we are building them out.
Rust also has wrapper types like OnceCell that have `get_or_init()` which will init the thing only once, and then it's guaranteed to be immutable. Unlike singletons, these don't have to be globally accessible.
The JVM has well-defined class loading semantics, including class initialization, that allow limited initialization capabilities before main is even run. Of course it has other problems too (defining the order in which these fire can be frustrating) but it always struck me as straightforward to work with.
As above : so below :: the universe : our datablow integration systems. The challenge is to make ours perfectly clockwork, too.
I was asking about programming environments that facilitate certain kinds of clean init semantics.
Like a clock. Or something that is operationally clocklike, deterministic, like we should design and implement our software to be in terms of reliability.
[1] https://doc.rust-lang.org/beta/std/sync/struct.OnceLock.html
Virtually all software ever developed managed just fine to with that alone.
> I don't know of any programming environment that facilitates properly specifying calculating something even that basic in the init phase of running the system, (...)
I don't know what I'm missing, but it sounds like you're describing the constructor of a static object whose class only provides const/getter methods.
> or even a db table's row(s).
I don't think you're describing programming language constructs. This sounds like a framework feature that can be implemented with basic inversion of control.
C# has this: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
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.
Same applies to readonly instance fields.
Where does "syntax sugar" end and "true features" begin?
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.
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.
In .NET it’s just 'static readonly'.
Non-goals
It is not a goal to provide Java language support for declaring stable values.
HmmmPlus the new PHP 8.4 version actually has asymmetric visibility for properties so you can have public properties that can not be mutated from the outside but still allow controlled mutation on the inside. The feature was borrowed from swift. I am super excited about it.
[0] https://move-book.com/move-basics/abilities-introduction.htm...