Martin
Martin
May 26, 2018 · 3 min read

Hi. Hello. Hola.

I have been busy with my work that I have not had time to write any technical posts. As a teaser for my next article, it will be about React Native and calling functions in a view layer. Their current suggested approach is setting and managing boolean values; this can lead to both potential errors and dirty code.

This could be us when we don’t write clean code

In the meantime, I thought I would give my thoughts and opinions on code quality. I would say one of the harder aspects of code quality is we all believe that our code is understandable to everyone because we can understand it. This is not always the case.


Clarity and XKCD

https://www.xkcd.com/1833/

I see clarity as an overarching core tenant of programming. Anyone that comes to the project, code reviews, or pair programs should be able to understand, with minimal effort, the logic that you have implemented. Here are a few markers that will help yourself and others:

Code should be maintainable and efficient
Code should be well documented
Code should be well tested in both happy and error paths

If you have other standards your team utilizes please share them in the comments below.


Organization

I like to think the easier you can find your way around the better off you will be. There isn’t one right answer to everything in this scenario² but make sure you converse with your peers and agree upon a set of standards to enforce. In doing this, you will save yourself a lot of headaches. This can include a variety


Linters

Imagine you’re Mr. Clean and the floor is your code

If I’m being honest this post is really about linters. It is one of the quickest and easiest ways to generate consistency across a project. A couple of examples for customization include:

+1 for trailing commas
I’m a fan of brackets on the same line

Swift

My personal linter of choice for this is SwiftLint.

The community is very active in support and making sure everyone has the tools they need in their workflow. I won’t go into detail on integrating this into your workflow as their README.md is very detailed. Here is the current set of rules that I utilize.

These are simple complements to the standard set of rules

Objective-C and React Native

In the last six months, I have been working on a React Native project. A different set of challenges and integrations come with this new working environment. I recently stumbled across a package that allows me to integrate clang-format¹ into the work. Let’s look at how we can incorporate this into your work.

  1. Prerequisites

2. Add .clang-format into your project root directory

It’s opinionated, I know.

3. Utilize husky for git hooks:

I like the split incase we want to add more commands in lint-staged

This process looks convoluted however once completed you will never have to think about it again. Pre-commit hooks are a great way to automate code quality while committing to your repo.

Other Languages

The two Objective-C and Swift examples are a starting point there are plenty of linters at everyone’s disposal. Take a look at this Github collection and find one you can integrate into your project.


Bonus

So let’s say you decided to add your linter late into the project and you don’t want to create a whitespace commit just to force your git hook actions. Here is a quick cli command you can run to lint every .m and .h file inside your current folder:


  1. https://clang.llvm.org/docs/ClangFormat.html
  2. Except for linting, always lint your code fam.

mrtnrst

Life as a developer all told by quips, longform, and gifs

Martin

Written by

Martin

Programmer. Designer. And pretty much anything else that floats my boat. -arista™

mrtnrst

mrtnrst

Life as a developer all told by quips, longform, and gifs

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade