grails / grails-forge

This is Grails project creator. Grails projects may be created using the browser interface, Command Line, or via CURL.
Apache License 2.0
4 stars 11 forks source link

Created app should use groovy gradle styling #398

Open codeconsole opened 1 month ago

codeconsole commented 1 month ago

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.

dependencies {
    implementation("org.grails:grails-core")
    implementation("org.grails:grails-logging")
    implementation("org.grails:grails-plugin-databinding")
    implementation("org.grails:grails-plugin-i18n")
    implementation("org.grails:grails-plugin-interceptors")
    implementation("org.grails:grails-plugin-rest")
    implementation("org.grails:grails-plugin-services")
    implementation("org.grails:grails-plugin-url-mappings")
    implementation("org.grails:grails-web-boot")

Formatting should be the same as it always has been:

dependencies {
    developmentOnly "org.springframework.boot:spring-boot-devtools"
    compileOnly "io.micronaut:micronaut-inject-groovy"
    console "org.grails:grails-console"
    implementation "org.springframework.boot:spring-boot-starter-logging"
    implementation "org.springframework.boot:spring-boot-starter-validation"
    implementation "org.springframework.boot:spring-boot-autoconfigure"
    implementation "org.grails:grails-core"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-tomcat"

centralize dependency versions in gradle.properties so they are not repeated multiple times.

jeffscottbrown commented 3 weeks 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.

codeconsole commented 3 weeks 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.

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"
matrei commented 3 weeks ago

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.

codeconsole commented 3 weeks ago

@matrei I agree, but knowing now it always compiles to a String changed my perspective because

  1. The build file no longer has uniform formatting
  2. If you want to add a dynamic version, you have to edit both quotes as opposed to just add the version.
assert "Test" instanceof String 
assert "Test" instanceof GString  // <-- Fails
matrei commented 3 weeks ago

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.

jamesfredley commented 3 weeks ago

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"
codeconsole commented 2 weeks ago

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.

matrei commented 2 weeks ago

Sounds like the majority favors double quotes ☺️

codeconsole commented 2 weeks ago

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?