jinxdash / prettier-plugin-rust

Prettier Rust is an opinionated code formatter that autocorrects bad syntax.
MIT License
178 stars 7 forks source link

Opinionated and battle tested... on TypeScript #20

Closed ricardo-reis-1970 closed 1 year ago

ricardo-reis-1970 commented 1 year ago

Intro

I am starting with Rust, but I am no beginner. I started writing code 40 years ago, in middle school. Then I graduated Computer Science with deep knowledge of K&R C, in a day and age where linters were not whiny bitches forcing every polygonal peg into round holes that fit no one but give the less enlighted a comfortable sense of belonging.

Line breaking and indenting

One of the things I hate the most with linters is this Twitter-brain obsession with long lines and the constant urge to break them either at flat-out stupid places or with indentations that just make one want to vomit. Why?

In 1988, one of my first assignments in my freshman year at uni was to develop a text editor. In PASCAL! Well, believe it or not, after 2 weeks the whole thing worked, even justified text and, most of all, wrapped lines. Later that semester, we moved to UNIX and I found out VI, the still unchallenged superior editor. VS Code is not too bad, though.

Something common to both VI and VS Code is that shockingly they both wrap lines! Worse, still: both these break indented lines with the indentation of the first line! Can you imagine this? And all available for decades!

And still linters and so-called beautifiers insist on this crap! And, opinionated as they insist on being, there is no opting out. In fact, there is no configuration at all for this extension! This is the exact same taks as Pythons black, "The Uncompromising Code Formatter", promising a ton of garbage like speed if only you decide to relinquish control over your own formatting.

Do as I say, or } else {...

Another "battle tested" feature is the æternally disgusting decision that some avant garde visual artist took that else cannot be in a line of its own, but rather inline with if's closing }. As usual, the error is not one cretin putting this out, but rather millions of cretins following it and transforming it into Law. Thank God poor Dennis Ritchie did not live to see this, but Brian Kernighan is still around.

This is not a case where millions of people can't be wrong, because indeed they are. And if you need examples proving that the majority could be devastatingly wrong, here are a few:

Opinionated... in a foreign language

The cherry on top — or, in this case, the fly atop the turd — is that the formatting has been battle tested by millions of people... from TypeScript! So, we go and take a shitty set of rules from another language and we just bring it into Rust! Why??? In order to atratc people from the other side of the fence? Yes, that went just great when JavaScript got its first half of the name from Java because there was the hope to attract people fromthere.

Rust has a golden chance to be its own new thingm no strings attached. And it is! You guys are trying to drag it through the mud, though. TypeScript linters actually produce an ERROR if you don't leave a space between the function name and the argument opening parenthesis, in the function definition. And this is the well from where you pulled your buckets of inspiration.

But should it all be anarchy?

Hell NO! We certainly all benefit from some measure of consistency, and it is true that people that don't leave a space after a comma should be taken outside, unceremoniously shot in the head and left for the scavenger beasts. But none of this actually addresses things that don't compile-and-run but still matter!

For instance, I'd much prefer a linter that whined about lack of docstrings, or even one that added these in template form. Just like breaking long lines, docstrings don't run, but do they add value to the development process! And this is all still within the scope of static analysis.

The way you seem to be wired, I can see the next generation of this producing docstrings... and breaking long lines on them!

Finally

Go read a book! I always suggest Salman Rushdie, because it's wonderful and requires absolutely no endorsement. But in your case, I'd have to recommend William Faulkner. After the first few 2-page-long SENTENCES, you might actually develop some reading ability beyond Twitter and you might actually realise how incredibly STUPID it is to break "long" lines in code.

If you read this far, good on you! There is hope, after all.

seahindeniz commented 1 year ago

Hello @ricardo-reis-1970, thank you for sharing a glimpse of years of your experience. I do appreciate this sometimes.

I'm not a maintainer on any Prettier repositories, but I've been using Prettier for TS and JS for a long time and am accustomed to it. Furthermore, I even write code like how Prettier formats when I work on something that doesn't have a Prettier setup. Personally, it's just a matter of perspective, and to me, snake case is blasphemy, an unorthodox invention, but for the sake of getting to learn and use Rust, I get along.

I've come across with some alternative plugins you can use to format a Rust file. Maybe you can try one of those?