UP | HOME

Rust

A meme language, which is OK

It has essentially the same social momentum like Perl and then PHP had, except much larger. Unlike Javascript, it is still a niche language, so more like a popular cult to be identified with.

This is not a joke. The social dynamic is very common – to be identified on public with something fancy (fashionable).

Over-excited amateur community

One has to be an amateur to be excited about anything. Well, except high quality art and true craftsmanship in general.

It must be noted that the language feels very rough, compared to much refined, mostly-functional language of the SML family (notably Scala 3), which is the direct consequence of having a large amateur community.

When I say amateur I mean that none of them have been studied programming languages as a major subject and qualified as language designers.

It must be admitted that it is way better language than the well known “fractal of bad design” (also result of a similar community process), because the team at Mozilla has at least done a lot of (C++) programming beforehand.

Pragmatic

Being reasonably high-level, with meaningful high-level syntactic forms (like ?) it is a pragmatic language, indeed.

It is a principle-guided imperative language, by restricting and formalizing (via model) what can be done.

It is in principle imperative, so the order of statements matter (even mode due to changing of ownerships). Also one has Enums instead of proper sum-types.

Free community docs

Books

There are a few recent books on some specifics, so all the information is available.

Principles

The mind tends to abstract away (and out) and ignore the details, so should our high-level languages do.

When we have to write down explicitly every single detail we will end up with another Java-like degeneracy.

This is may be ok at the implementation side, but it is ridiculous at use site. So use high-level DSLs or macros to hide all the ugliness.

The right thing to do is to have well-crafted defaults, and the clean syntax (like Scala 3) and allowing to explicitly override any default property (a universal principle).

C++

Programs must be read like arithmetic, not some anintimplementedaswithsignalsoverflowinthisway.staticmethodinvokedbyaconstantreference+(aninstanceofanintegerimplementedas….)

With all possible symbols thrown in.

Ideas

By the way, always having an implicit context (as in Scala) is a universal notion (not just of a human language, but even animal’s stress calls), and it should be added as a “semantic closure” – a captured meaning (which won’t change).

Because it is so fundamental, it should have very minimal syntax, like . for accessing the slots.

A context is just a frame of an environment, an alist, so we can reuse all the familiar notions.

Semantic environment is not different. We capture meaning (into language) with properly generalized abstractions.

A context is by definition shadowing of symbols (just like a closure).

Something like a#b (like in CLU) instead of a.b

Disclaimer

Even if I rant about Rust a lot, it is only because I do know “any better” - Scheme, Common Lisp, SML, Elang, Ocaml, Haskell, Scala3, F#. It is important, however, to strongly emphasize that Rust is vastly superior and way better designed language that C++.

It is similar in the spirit to what Scheme was back then to all the previous Lisp dialects - principle-guided reduction to the essence (it was build from the ground up - from the Lambda Calculus foundation, like every other decent language) with a minimal set of required features, and almost everything has been done just right. Rust is relatively small language, compared to C++ or even Scala 3 (which is an principle-guided absolute masterpiece, with careful attention to details, that Rust lacks).

This is just a “natural” result of the over-enthusiastic but grossly under-qualified large amateur community, similar to the one which gave us fucking PHP “ecosystem”.

All the wrinkles, however, will eventually go if the core team will be willing to do tedious work to streamline the concepts with mathematics and terminology with the SML tradition and unify and refine the syntactic forms in new “editions” of the language without being ashamed of borrowing from Scala 3 or Ocaml (better module) or even Erlang (uniform pattern-matching).

We can’t bury C++, it is already “crossed the threshold of immortality”, but at least we could push it to the retirement home, together with Cobol and Java.

The rant

I came up with some enlightened and precise definition of why some languages feel so crappy, like PHP, which is, as we know, the fractal of bad design.

I have been reading a definitive Rust book, full of supposedly idiomatic, well-chosen examples, and I regularly cringe intuitively without being able to articulate exactly why. It just feels crappy at some examples. Now I can articulate why.

The language “designers” and community contributors are math-illiterate. This and only this. It feels exactly as if some PHP coders are designing a better SML for systems programming, without understanding why SML or Ocaml are the way they are.

Here is an example:

pub fn notify<T: Summary + Display>(item: &T);

This is the syntax for constraining an abstract type with multiple “trait bounds” as they call it.

The operation they are trying to denote is not a Set Union of individual methods, but a Product of distinct traits (named sets of type-signatures). A star * (for a product) would be appropriate. The + is mathematically a fundamentally different operation. This particular choice makes one cringe.

+ is associated with concatenation, so it says a concatenation of methods, while in fact two distinct Sets of methods are required to be implemented.

Even more so is the where clause (borrowed from math or Haskell), which by itself is the right choice, and then you see that + (a sum) for what is really a product.

The math experts who have designed SML have used * for product types.

Here, in Rust, this is NOT a product type, but it is a product of two traits. The precise meaning is a product of two named Sets of type-signatures. Not a sum.

Another cringe is that they use push and pop on collections, as if they are stacks, but this is OK because the idiots were those who designed the C++ collections.

There are a few more, mostly in naming of the methods, which I think is an intention, to make everything look familiar to C++ developers, but my generalization is obviously adequate and correct.

Scala feels so much better because the designers came from the right SML tradition, and are math experts. Odersky is the Giga Chad, you know.

Also the lack of a uniform pattern-matching everywhere, like in SML, Ocaml or F# is a cringe too. As if they just thrown away the most important thing because they did not get it, again, by being math-illiterate. They could, at least, have a look at Erlang, which is a high-level system language.

By comparing Rust with Scala we could see how and why a principle-guided /attention do details really matters. Rust feels PHP’sque.

It is worth knowing that guys at AT&T Bell Labs, who have designed the Basis library (an stdlib) have explored the possibility of using SML/NJ for system programming, and there were no problem with the syntax and semantics of the SML.

Author: <schiptsov@gmail.com>

Email: lngnmn2@yahoo.com

Created: 2023-08-08 Tue 18:39

Emacs 29.1.50 (Org mode 9.7-pre)