Open codeconsole opened 1 month ago
or bonus points if you use Strings instead of GStrings
FYI... I think the examples you cited are indeed Strings. I don't think Groovy creates GStrings for something like "org.grails:grails-console". I think the compiler knows that is a String.
or bonus points if you use Strings instead of GStrings
FYI... I think the examples you cited are indeed Strings. I don't think Groovy creates GStrings for something like "org.grails:grails-console". I think the compiler knows that is a String.
Thanks for clarifying @jeffscottbrown I tested and confirmed the compiler is smart enough to compile into a String so I now prefer double quotes, but obviously without the braces.
implementation "org.springframework.boot:spring-boot-starter-logging"
It's obviously a personal preference, but for what it's worth, I prefer single quotes as it helps my brain distinguish between String and GString without having to check. Also, again my opinion, single quotes take up less space, which makes the code easier to read.
@matrei I agree, but knowing now it always compiles to a String changed my perspective because
assert "Test" instanceof String
assert "Test" instanceof GString // <-- Fails
The build file no longer has uniform formatting
That's part of the feature, I don't have to actively check if there is a variable in the string when reading/scanning the code.
If you want to add a dynamic version, you have to edit both quotes as opposed to just add the version.
This is the drawback, but with Alt+Enter+Enter
in Intellij you can toggle between GStrings and String syntax easily.
Are we optimizing for reading or writing? I think every little thing that brings clarity and simplifies reading helps out.
You need double quotes for versions from gradle.properties
.
If we want them to match, double quotes would be the way to go. With the grails-bom expansion, these are rarer, but there will be a few in a normal Grails apps.
Some examples from one of my projects:
implementation "io.awspring.cloud:spring-cloud-starter-aws:$springCloudStarterAWSVersion"
implementation "io.awspring.cloud:spring-cloud-starter-aws-parameter-store-config:$springCloudStarterAWSVersion"
implementation "com.sendgrid:sendgrid-java:$sendGridVersion"
implementation "com.google.api-client:google-api-client:$googleApiClientVersion"
implementation "com.google.auth:google-auth-library-oauth2-http:$googleOauth2Version"
implementation "com.google.maps:google-maps-services:$googleMapsServicesVersion"
I've spent a lot of time thinking about this and I now advocate for double quotes.
My rational is for consistency across the entire file and still accomodate situations that need GStrings. It is also from the perspective of clarity for people that are not fluid in the Groovy language.
Previously I adopted the Groovy purist perspective where '' was always used for Strings, but considering the fact Groovy has lost a lot of popularity and has tried in several ways to be more like Java over the past 5 years, I think it is better to preference Java like constructs when the Groovy equivalent does not provide any gains. This is more to eliminate any confusion to someone new to the Groovy language.
Sounds like the majority favors double quotes ☺️
lol, I still like single quotes, but if Groovy isn't going to have a purist mentality when it compiles double quotes into Strings, why should I?
Current app looks like Kotlin and adds a bunch of unnecessary characters.
Not sure why this happened, but if we are going to keep this route we should also add semi-colons to every line.
Formatting should be the same as it always has been:
centralize dependency versions in
gradle.properties
so they are not repeated multiple times.