Powerletters for Rust
34 points by matklad
34 points by matklad
This adds nothing new and is optimizing the wrong thing. What you're optimizing is for writing, writing is not a bottleneck in programming.
You're compromising long term understanding by a broad amount of people with short term writing and understanding by a narrow amount of people with your own idiosyncratic abbreviations.
I'm writing not only for present me, I'm writing for me years in the future, for others that might wanna fork my project or fix a bug they ran into once. Saving 4 letters is not worth it.
The author specifically says they're optimizng for reading, not writing! They call out visual clutter specifically.
I quite like their "I" power letter, which is a type safety improvement by ensuring that you're ignoring a Result instead of dropping a future (a bug both the author and I have run into).
I disagree. Shorter names are easier to read, if used consistently. There's a reason humans invent jargon, rather than expanding full explanations at every use.
Or, to put it another way: a word or set of words by which a person, animal, place, or thing is known, addressed, or referred to that use a smaller number of symbols, glyphs, or other elements of visual identity take a smaller amount of effort or present less difficulty to interpret the meaning of, under the assumption of learned familiarity and under the condition of all instances being written out in a manner that does not change by the conditions of use. As a result, humans invent special words or expressions that are used by a particular profession or group in order to convey meaning in a shorter space, rather than using the full phrases or generic widely used meaning of words at every moment that a word of phrase is placed into a sentence.
Brevity enhances readability.
(That said, when I find myself writing rust, I don't find myself using these methods often enough that the brevity feels worth it.)
It depends what the program is ... People claim Rust is good for both high level code (apps) and low level code (managing the machine)
I think that's true to a degree -- it is impressive / hard from a language design standpoint
But this kind of post shows the limitation
I kinda love it and I kinda hate it.
I've not written enough Rust to really be annoyed - and as long as this does not go to the whole alphabet it's still only a couple things to keep in mind.
On the other hand I've bashed perl in the past for "more than one way to do it" and this is not really easily discoverable, but if it's in one crate you would probably notice it by being imported and it's not "search for P in the whole stdlib docs"
I feel like there is a missed opportunity for some more letters so you could COSIGN
I am more aligned with Ruby and writing variables and methods with full names than with reducing everything to one character. Though I also agree that rust can be quite verbose. Especially when you’re in a context where heap allocations are not a big deal.
It wasn't a good idea when the original Bourne shell was written in Bournegol and it's not a good idea now.
If you want this kind of thing, make it a property of the editor, not the codebase.
"Optimize for reading, not writing" is meant to refer to reading by everyone, not just the future self of the person who wrote it.
(Plus, making it a property of the editor means you can apply it to any codebase, not just your own... similar to how a codebase uses autoformatting is open to an analogue to git's autocrlf option, but which autoformats to your preferred style when checking out and to the repo style when committing.)
Thanks, I hate it.
How about D() for Default::default() ?
I really like bevy's solution of putting default into the prelude as an alias for Default::default https://docs.rs/bevy/latest/bevy/prelude/fn.default.html
I thought that was the plan for the actual prelude at one point. But all I can find now is https://github.com/rust-lang/rust/issues/73014 which is closed.
What bevy does is use a wrapper function because you can't currently do pub use std::Default::default (that is export a single function from a trait). The standard library is forever so there's a reluctance to do the workaround when it would rule out doing the better thing in the long run.
i've been doing this sort of thing in C, for things i want to de-emphasize
i have E, T, and L macros for error assertions, function tracing, and logging, respectively. i generally don't care about those when i'm reading code, but i want them to be there when i'm trying to figure out why it's broken
I really like the idea of this, but the examples don't gel with my brain in the intended way. The density is wildly different from conventional Rust, and my eyes sort of scan over the smaller Powerletter tokens when reading the others. I would probably get used to it. It'd be worth trying since vertical and horizontal space is super important for readability.
This makes me think that Chuck Moore had the right idea with colorForth. colorForth splits the semantics of tokens based on the color (actual visually displayed color) they are typed in. IIRC, words in red are being defined, green words are compiled, and words typed in yellow are interpreted.
When looking at the listed functions: C, O, and S are operations on how the data is laid out in memory, and I and X are instructions to the compiler (and reader) that "no we really know what we're doing here". Powerletters is re-inventing the sigils Rust used to have. If we were willing to ditch syntax highlighting, I can see C, O, and S being one color, and I and X being a different color. They become easy to either focus on, or ignore. It starts inching towards the APL density and the FORTH / ASM-with-macros conversation-with-compiler style.
This feels like it’s reducing the visibility of important operations, and even though the author says they are doing it for readability it doesn’t feel like that from the examples.
I think this sort of thing would work much better in a real editor if you can make these important single letter functions stand out well. To do that I feel like you want an editor plugin, and if I’m doing that anyway then maybe the actual implementations should have longer names?
I’m not entirely sure on that last suggestion though. I’ve bounced hard off coding fonts with ligatures because they can turn obvious and learnable character sequences into impenetrable glyphs that novices can’t even see how to type.
Honestly I think the fact this library doesn't address any of the genuinely noisy patterns that exist in Rust, instead focusing on saving between 4 and 7 characters, speaks on its own as far as whether this was written by the correct person.
Are you the correct person ?
English is not my main language so I might get your message wrong, but it seems way too harsh for just a guy showing a library he made and like to use.
I would think this makes your code horribly unreadable for a negligible amount of convenience/time saved, i feel like IDE autocomplete serves almost the same function but without any downsides, but you do you …
I wrote a similarly named & functioning crate powerbool, and I've never used it due to the ceremonial overhead & narrow usefulness. powerletters avoids the second problem, at least.
Also, X is unwrap, not expect. Bad name.