paint-brush
Git-aware code stylingby@blipinsk
2,764 reads
2,764 reads

Git-aware code styling

by Bartek LipinskiJune 28th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

There are patterns within your <a href="https://hackernoon.com/tagged/code" target="_blank">code</a> style you can use to simplify the way you’re interacting with <a href="https://hackernoon.com/tagged/git" target="_blank">GIT</a>. Or any other Version Control System for that matter…

Company Mentioned

Mention Thumbnail
featured image - Git-aware code styling
Bartek Lipinski HackerNoon profile picture

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.