DEV Community

Cover image for Matt's Tidbits #70 - Cleaner diffs!
Matthew Groves
Matthew Groves

Posted on

Matt's Tidbits #70 - Cleaner diffs!

Last time, I wrote about some neat Kotlin field tricks. This week, I wanted to share a tip for how to achieve cleaner code diffs!

A coworker recently submitted a PR with something that caught my eye:

fun foo(
  param1: String,
  param2: String,
) {
}
Enter fullscreen mode Exit fullscreen mode

Did you see it? Right here:

At first, I thought this might be some kind of error, but after researching a little, I found that trailing commas are an upcoming feature of Kotlin!
https://blog.jetbrains.com/kotlin/2019/12/what-to-expect-in-kotlin-1-4-and-beyond

Why is this helpful? Well, if you add or remove parameters to this method, the diff will look much cleaner!

Here's an example of adding a parameter without using trailing commas:

And here's what this same change looks like when using trailing commas:

It's a small change, but having trailing commas can really cut down on the clutter of seeing two lines changed, when in fact you had only changed one. That means fewer lines of code to review, which should reduce the amount of review time, and also make it less likely that a substantial change would slip past someone.

What other upcoming Kotlin features are you most excited about? Let me know in the comments below! And, please follow me on Medium if you're interested in being notified of future tidbits.

This tidbit was discovered on May 20, 2020.

Latest comments (0)