Cleaner Code? Learn to Lint.

Vladilen Napuri
4 min readSep 11, 2020

Messy Code Stinks

The longer I spend learning, practicing and reading about code. The more I have come to realize just what a burden messy code can be.

At first we all started with 5, 10, 15, 50! lines of code. Things were all within sight and even then we were easy prey to the tangled code we were attempting to write.

Now with hundreds, if not thousands of lines of code. Not writing and maintaining clean and organized code will surely lead to roadblocks in your progress to Kevin Mitnick levels of notoriety.

Luckily for us, Stephen Johnson had major issues debugging his code written in C. When trying to upgrade to a 32-bit version UNIX , he realized he was better of creating a piece of software that would analyze his code and take the responsibility of checking for errors and bugs that the compiler should not be handling.

“the general notion of having two programs is a good one” because they concentrated on different things, thereby allowing the programmer to “concentrate at one stage of the programming process solely on the algorithms, data structures, and correctness of the program, and then later retrofit, with the aid of lint, the desirable properties of universality and portability”

Since 1979 when the first Linter was used outside of Bell Laboratories, we have had a consortium, of developers, companies, and groups develop Linters for various programs. Although the dominant language using Linters is C++, it is incredibly useful for languages that lack a compiler, such as Python and JavaScript.

Can “I” use a Lint program

More than likely many of you have seen the “Lint” like extensions that are available on the VSCode extension store. I would say that getting comfortable with some of these extensions for the language you are coding is the smoothest way to get some experience and knowledge with Linter software.

What is SonarQube

As I did my reasearch on these incredibly useful pieces of software I learned about SonarQube. SonarQube is a tool to detect errors, bugs, vulnerabilities, and code smells by reviewing your code before compiling. It can work on a variety of languages, including:

ABAP, Apex, C, C#, C++, CSS, COBOL, Flex, Go, HTML, Java, JavaScript, Kotlin, Objective-C, PHP, PLI, PL/SQL, Python, Ruby, Scala, Swift, TSQL, TypeScript, VB.net, Visual Basic 6, XML

As far as the languages I am working with this Linter covers it. There are literally dozens of publicly available linters, so please search for that fits your exact use case. Make sure to leave feedback with the developers and help the process of cleaning up everybody’s code.

How do I use SonarQube?

As far as installing SonarQube, it really couldn’t get easier. On their website are very explicit steps on how to install. Step 1 is to download the zip file and Step 2 is to run the executable to install. All done!

In or to get a piece of software analyzed, there are 5 easy steps:

Click the Create new project button.

When asked How do you want to create your project, select Manually.

Give your project a Project key and a Display name and click the Set Up button.

Under Provide a token, select Generate a token. Give your token a name, click the Generate button, and click Continue.

Select your project’s main language under Run analysis on your project, and follow the instructions to analyze your project. Here you’ll download and execute a Scanner on your code

Always Strive for cleaner code

People have made amazing strides when it comes to software that makes our jobs easier. Yes, we do love coding but no matter how much joy or excitement you get when everything functions correctly. It is not worth the pain and suffering we all will have to go through when we have to traverse through the jungle maze that is your DOM.

In all seriousness.

Time, Money, Effort, and other Invaluable resources are spent in trying to achieve our goals as Software Engineers. Loads of self sacrifice, wether it’s late nights or early mornings working. The least we could do is keep it clean.

SOURCES

https://en.wikipedia.org/wiki/Static_program_analysis

--

--