DEV Community

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

Posted on

1 1

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay