Skip to content
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

Add configuration for quote style: either prefer single quote or double quote #647

Open
okainov opened this issue Sep 30, 2021 · 3 comments

Comments

@okainov
Copy link

okainov commented Sep 30, 2021

Would be great to have a rule for quote style, for example for teams where the agreement was to use double quotes always

Initial request nvuillam/npm-groovy-lint#177

@nre-ableton
Copy link
Contributor

I somewhat disagree with this feature request. Groovy isn't like Python, where the quoting style is a matter of personal taste. Single and double-quoted strings behave differently in Groovy.The CodeNarc rule has a good rationale: single-quoted strings are java.lang.Strings that cannot be interpolated, are immutable, and therefore much more performant. Double-quoted strings are groovy.lang.GStrings which are more convenient but use more resources. That's why CodeNarc recommends using single-quoted strings when interpolation isn't necessary.

If you disagree with this, you can always suppress that ruleset.

Also, I realize that you are basically forwarding a feature request from the npm-groovy-lint wrapper project. 😄 So you could always implement the feature in your wrapper and turn off those rules relating to single/double-quoted strings.

@CliveUnger
Copy link

CliveUnger commented Oct 13, 2023

Hi, @nre-ableton could you point me to some resources or benchmarks to better understand the performance difference between single quoted strings (java.lang.String) and double quoted strings (groovy.lang.GString)?

It's stated that single-quoted strings are more performanced but by how much? And why?

I could only find this SO thread on the matter: https://stackoverflow.com/questions/9775672/string-vs-gstring-performance

@nre-ableton
Copy link
Contributor

nre-ableton commented Oct 17, 2023

@CliveUnger I think that your SO link is probably the best benchmark I've seen on the subject. The performance gains will be quite small (at best), but it's not so much about the performance gain as the best practice (immutability vs. mutability).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants