Git-aware code styling

There are patterns within your code style you can use to simplify the way you’re interacting with GIT. Or any other Version Control System for that matter…

To give you a rough idea of what you should be looking for, think of when need to list a whole bunch of arguments for a function.

TLDR:

This does not give the full picture, so I suggest you keep on reading…

Here why:

1. Keeping arguments in one line will make the change less visible:

2. Putting every argument in a new line will result in simpler GIT diffs:

(more on the last argument in the next point)

3. Adding a trailing comma & moving the closing brackets to a new line, will result in simpler git diffs when reordering.

This is language-specific. Not all programming languages allow trailing commas. Unfortunately none of the languages I’m using on a daily basis (Java & Kotlin) allow them. Let’s look at Python:

(if you didn’t know what I was talking about)

Unfortunately for languages without trailing commas this has no positive effect, but you can still use this pattern as a way of learning good habits. After all, Kotlin might get this feature in the future.

https://medium.com/media/57f66f640115e58b2db15a0dacfe4fe3/href


Git-aware code styling was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.