-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The '%w' and '%i' syntax for arrays is just a bad idea #908
Comments
You must be referring to the
with the following examples: # bad
STATES = ['draft', 'open', 'closed']
# good
STATES = %w[draft open closed] Do you have some counterexamples in mind? As the style guide strives to follow the community usage of the Ruby language,
would you like to harvest |
Thanks for the reply. The example that keeps occurring for me is the process of adding another token to a %w-ified list. As array elements in nearly all languages have commas between them, silently automatically adding the comma into the token just causes pain. The other one is long lines:
Is there a way to harvest real-world usage from before the recommendation was added to the style guide? It has an undue influence for better or worse, as it gets rolled into tooling (especially IntelliJ/RubyMine in my case). |
The guideline non-ambiguously tells to "strings without ... special characters in them", where a comma is a special character. Such usage would be detected by a corresponding cop and would save you from the pain:
Are there other real daily usage examples that are problematic for you?
Things are as they are now. We don't doubt much about the effectiveness of boolean logic vs tri-state logic, using null, or byte length, even though, as an after-thought, those might not have been the best design decisions. I'm just stating that the guide reflects modern real-life usage, even though early iterations of the guide might have affected real-world usage. |
Agreed. We generally try to avoid affecting real-world usage, but rather reflect it in the guide. Btw, I'm not a big fan of |
Re the "corresponding cop" suggestion I'm pretty dubious that fixing issues exacerbated by tooling with more tooling is a virtuous cycle. I think that the guide has a degree of influence it's wrong to minimise. If a practice is poor, is popularity enough to make it a recommendation? |
Are you confident enough to state that a certain practice is poor, basing on just your personal experience? If you look at this
I understand what you mean. Yes. As Bozhidar mentions above about his personal preference to avoid |
The argument for this is reduced git churn for multiline lists, as only one line will be touched when re-ordering, preserving git blame, etc. To that end, the argument of problems with commas apply equally to the "normal" form, as it has happened quite frequently at work that someone re-ordered an array literal and forgot to move the comma. 😅 To me the strongest argument against using this style is that it can't be consistently applied. I prefer rules that aren't applied conditionally, like this one is as it requires the qualifier "non-empty strings without spaces and special characters in them". Personally I'm on the fence about which one is "better". There's clearly a case to be made for either. But as it's a community style guide, I think we need to tolerate that the community might not always share our personal preferences. |
@pirj I'm interested in this issue as well. Is there a guide for harvesting? |
@JohnCoates something like:
there was a tool that would save you on steps 2-5 that just goes through a directory and prints all matched usages https://jonatas.github.io/fast/, but I have never used it. |
I believe there is or should be a cop that would catch punctuation inside percent literals, as they certainly are unintentional in most cases if not always. |
@Drenmi IMO that's not a great argument, ideally you'd be using git-blame-ignore-revs which has been available since 2019. That being said, it sounds like the OP doesn't believe in linters (which have been in use since 1978) and I feel that's the root cause of the OP's problem, not the style guide (which as others pointed out, also addresses the scenario). Linters are the only realistic way to ensure a consistent application of a style guide. By definition, if you aren't using them, you're not applying the style guide. The OP's admission that not all the rules are being followed is proof of that. So I feel this issue is moot. |
Why are these forms favoured? They're harder to read than the original syntax and easily lead to errors with commas. I've personally lost hours chasing non-existent bugs thanks to this "feature" because the eye naturally skips over commas in lists.
I get that people seem to love new shiny things, but this is just a poor decision IMHO.
The text was updated successfully, but these errors were encountered: