Standard Ruby 1.0
blog.testdouble.com
blog.testdouble.com
> Obnoxious: come up with a set of style preferences, write some post-hoc justification, and then name it in a way that implies anyone who has different preferences is doing something wrong
> Doublespeak is language that deliberately obscures, disguises, distorts, or reverses the meaning of words. Doublespeak may take the form of euphemisms (e.g., "downsizing" for layoffs and "servicing the target" for bombing),[1] in which case it is primarily meant to make the truth sound more palatable. […]
I like linters, and having a good default config out of the box is a good idea. But the idea that you need an entire language community to agree to only ever do anything one specific way is just kind of silly IMO.
What projects like these say to me is that there are too many teams with poor leadership who spend far too much time bickering over things like which linter rules to use, and thus feel that invoking a higher power (the “standard,” in this case), is the only thing that will save them.
Now that this problem is “solved,” what new crisis caused by a lack of leadership will present itself?
Thing is, I _want_ my team members to argue over coding styles and patterns. I _want_ people to present different techniques and approaches, and for everyone to weigh in with what they like and they don't like. I _want_ people to be pushed to consider new things and and perspectives, and to challenge their accepted notions on how to code.
The true root cause, I think, is that many people know how to argue, but very few people now how to argue constructively. Where the goal isn't for one person to win, but for everyone to discuss ideas while tracing back our shared interests until the proper solution presents itself. I wish more people took the time to develop such a skill.
[1] https://www.quora.com/What-are-the-key-lessons-from-the-Touc...
To me the formatting does matter. It is a major factor in how comprehensible a code-base is, and often having freedom to deviate from the expected rules to line things up in certain ways helps to convey patterns and similarity that matters.
The big benefit to me would be as a maintainer of an open source project. I can use this, & I never have to consider whether or not someone’s suggestion to change a linter rule is worth listening to or not.
# .rubocop.yml
inherit_from:
- https://raw.githubusercontent.com/testdouble/standard/master/config/base.yml
Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma
Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma
# add further tweaks as needed
and just use rubocop’s CLIWhy do have people have to name their preferences 'standard' and promote them around?
Such initiatives simply add heat, noise and confusion to a perfectly fine and diverse community that can sport a palpable history of giving extreme power to its hackers.
Good way to avoid developer preference arguments.
Let's look at a mentioned example:
> Increase consistency around things that don’t matter. For example, Standard requires all string literals be double-quoted. Single-quotes don’t support interpolation but aren’t any more performant, so mixing single & double quoted strings adds a bit of cognitive overhead with zero discernible benefit.
But there are discernable benefits. Single-quotes are great for indicating "there is no interpolation here" and for strings that embed double-quotes.
Rubocop is great, though, and highly recommended if you do Ruby things.
I used to think that too. But it doesn’t really help that much, because interpolation is fairly obvious with syntax highlighting. I changed my mind and I prefer consistency, and have every string the same. Also, if you need to add or remove interpolation then you don’t have to change the type of quotes.
At the end of the day, let the tools enforce this nonsense, but I'm still a performance wonk at some level and it drives me crazy seeing interpolatable strings without interpolations.
I was told about a ruby project years ago where they gained a measurable performance boost by converting all the strings without interpolation to single quotes.
That's a vague anecdote so should be taken with a pinch of salt. Even if it was once the case VM often improve to fix these edge cases.
So I was just wondering if there was anything more formal to prove this so that I can avoid this preconception I've been carrying around for years based on nothing more than someone's now dated Lightning Talk.
That seems like a good enough reason to always use double " for consistency to me.
As you say, a configurable tool with reasonable defaults to encourage people to only change the things they actually have strong feelings about, fine.
The same with Node. I dislike the output of the (also named 'standard') eslint formatting rules I usually end up using, but by activating the auto-format as above the whole issue is redundant.
In other words, I dislike the format but as long as the code is readable I don't care - though as a writer the aesthetics of the formatted code disappoint me, so I can see both sides.
PS. As an aside the mention of prettier elsewhere makes me shudder. I, too, find that a threshold is reached whereby instead of small localised formatting 'fixes' it decides to change a fair amount more than expected which, as mentioned, makes for unnecessarily convoluted commits.
It really seems like a bunch of arbitrary linting rules that this company likes to use, and they are trying to push it on the masses as "Standard", which the uninformed won't understand the nuance of.
I think the name is really predatory.
Single quotes, double quotes, who cares? Oh no, you might have to change some extra characters. Such big cognitive overload, very hard...
All this 'standardization' is stripping the individuality and artistry from writing code. Sometimes I feel like the only person in the world who likes being able to look at code and know who wrote it by the style that they use.
In Ruby, especially, where expressiveness and being a little weird feature so prominently in our cultural heritage. If I wanted to be a conformist I'd write Javascript for a living!
(this isnt a criticism or anything, just my observation)
In particular, if the goal is to have clear (and therefore somewhat more likely to be robust) code, you're going to see things like the use of single quotes to indicate "this will never be interpolated" or the use of explicit return statements even when "unnecessary" - both of which run afoul of these sorts of highly-opinionated and unconfigurable style enforcers.
As long as a project I'm working on is being consistent about them, I'm good.
This project tries to go much farther.
I find this so strange. I also loathe nitpicking about syntax which is precisely why I think this would be a great tool!
I work in JS now on a large team and one of my least favorite activities is trying to find consensus on which linting rules we should/shouldn’t adopt. It’s such a waste of time!
(Linting is slightly different -- just use some sane eslint defaults and call it a day)
I find the argument that it will stop discussion of style bizarre, because it only shuts down discussions about style if you already have the power to tell people what the accepted style for your organisation is. In that case you don't need a tool that refuses to let you pick and choose, you just need the confidence to tell people you're not going to change things.
In other words: It's not Prettier that stops you from having discussions about style again, it's whether or not you signal to people that you're not willing to discuss it. To me, in that respect, a tool like this is a passive aggressive way of signalling that you're unwilling to discuss the subject without being willing to just say that you're not.
The antidote to nitpicking isn't to force something where nitpicking isn't possible/already resolved, it's staying open-minded and flexible enough to not let the nitpicked things bother you. "There are many roads to Rome" and all that.
If it's configurable then I'm going to end up wasting time talking about style rather than focusing on functionality. It's the exact reason I've set up my team's code with standard (and Prettier)
It's boring having different Rubocop settings and having people argue over new rules. I have preferences too, but I'd rather get on with my life. I can just write code, and have Standard make it standard and consistent across all projects.
It would be nicer if Ruby did this itself (Crystal does, and that's fantastic) but this is the next best thing. Having one attempted standard is better than no standards at all.
(My only quibble is the name makes it sound related to the Standard JS project when it doesn't).
It makes such a big difference when you just set it and forget it. It’s not my ideal preference, but holy hell it’s a million times better then what we had before.
But it's typical for naming projects like this that they try to convey a fake sense of authority.
It's pretentious naming at its worst, IMHO.
And yes, some people might have been looking for language standard and be mislead by this.
In the JS version they ultimately had to add some configuration because like it or not, there are different cases. Sometimes really strong opinions prevail, and if you are forced to throw the baby out with the bath water because the temperature on the tub is not configurable, you get to a sub optimal outcome.
I'll be using this though. Thanks for hard work!
The discernible benefit is the reduction of cognitive overhead in understanding if there is any interpolation in the string. At a glance you know whether there are any variables or escape codes to consider.
I will keep writing Ruby how I like it with 3 spaces indentation and double line breaks between methods/classes (yes, I will put multiple classes in one file).
What?
You inevitably end up having to shotgun edit a bunch of files (that could have been one file) to re-architect stuff when it changes.
I'm not a fan of single-class-per-file as a rigid rule, but it's not my effect that it has any effect on architecture. Adding a file with a new class isn't substantially greater overhead than adding a class in an existing file, and moving stuff between smaller files is, if anything, easier than moving it around within a single monster file.
Whilst I can see the benefit of having an AST format code for you, e.g. if can you use it to fix language version changes like positional arguments and keyword arguments in Ruby 3,.0 I worry about how good/bad RuboCop is at formatting.
Last time I tried it, it was indenting in a different way to the std-lib.
At the time I found that prettier-ruby[1] did a much better job. Hopefully that's improved since.
Wrong!
> Single quotes are 2x faster than double quotes because you don’t have to hit shift when typing them. Half the keystrokes, double the speed
> Single-quotes don’t support interpolation but aren’t any more performant, so mixing single & double quoted strings adds a bit of cognitive overhead with zero discernible benefit
“I can express things that would be interpreted as interpolation in a double-quoted string without escaping” is a discernable benefit.
“I can use literal double-quotes without escaping” is also a discernable benefit.
(Incidentally, this is a case where the justification also makes it unclear whether they've misdescribed the piece they are justifying: the say it requires string literals to be double-quoted but the justification refers only to single- and double-quoted strings. So, does it only ban single-quoted strings, or does it also ban Ruby’s other 6 forms of literals that resolve to strings?)
Also being a go developer I really appreciate gofmt and the way go code only has one formatted representation.
I am super happy about the leading dots on multi-line method chains which I also voted for. It was a long time in the making, but it gave the project time to consider all the little nuances.
Great work!