100% agree, it’s really ugly, but… let’s place var
keyword on the rhs of :
, right before a type and let’s use other keyword for “introducing” data description, let it be let
, then everything becomes “homogeneous” and super-consistent:
data (variables and constants)
let name: const T; // immutable data
let name: var T; // mutable data
let ptr: const * const T; // immutable pointer to immutable data
let ptr: const * var T; // immutable pointer to mutable data
let ptr: var * const T; // mutable pointer to immutable data
let ptr: var * var T; // mutable pointer to mutable data
Just look, it reads exactly as it’s written (in English, of course):
const * var T;
immutable pointer-to mutable data-(of-this-type)
function arguments
just a copy-past of :
rhs above:
fn func(arg: const T) R {}
fn func(arg: var T) R {}
fn func(arg: const * const T) R {}
fn func(arg: const * var T) R {}
fn func(arg: var * const T) R {}
fn func(arg: var * var T) R {}
types (structs) and theirs fields:
let Struct: const type = struct { // : var type?!? what would that mean?
// struct-global stuff
let a: const u32 = 3;
let instances: var u32 = 0;
f1: const T, // assign once?
f2: var T,
f3: const * const T,
f4: const * var T,
f5: var * const T,
f6: var * var T,
};
Language designers, don’t just walk past, grab the idea!
Why not. My favorite (semi-humorous) definition of “philosophy” is - “Philosophy is a science about proper usage of words”. In respect to PL syntax the usage of Pascal style var/const
words is a bit improper in the sense that they are used for two different purposes:
- introducing data description
- indicating whether that data may be changed or not
Rust with it’s let
and let mut
is a little bit more closer to what I’m trying to say, but…
let’s place mutability keyword on the :
rhs anyway.
Too many const/var
, ok, let’s make everything immutable by default, then const
keyword is not needed at all, just let
and var/mut
will do (if really needed):
let name: T; // immutable data
let name: var T; // mutable data
let ptr: * T; // immutable pointer to immutable data
let ptr: * var T; // immutable pointer to mutable data
let ptr: var * T; // mutable pointer to immutable data
let ptr: var * var T; // mutable pointer to mutable data