On my previous article a talked about the Kotlin compiler and I showed it’s basic command line usage. I just want to briefly extend on that article to remind of a feature that Kotlin compiler has that it’s quite useful but often forgotten.
A code base that throws a lot of warnings is a code base that contains risk. It’s just matter of time until one of those warnings will cause an issue. Maybe we are using a deprecated library, or maybe we forgot to use a parameter, etc … As Agile developers we should always strive to make our code maintainable, readable, simple and risk free; hence treating warnings as errors is considered a good Agile practice.
Let’s look at an example. I am going to compile a Kotlin class that has a function with some unused parameters. By default this will compile and generate the .jar file but the console will print some warnings.
As shown in the sequence of screenshots above the .jar file was created in the place where we executed the compilation command. Ignoring those warnings could potentially cause a bug. In order to make sure we are treating them as errors, we need to use the -Werror option that Kotlin compiler gives us.