ButterKnife or not

In one of the freelance networks where I work on Android apps, there have been an effort to standardize the code review to come to a mutual consensus on how every Android developer should write their code.

The effort was made to standardize coding practices because code quality is a subjective thing. And at this freelance network, there are code reviews done with scores given to determine whether the codebase is healthy enough for the team to move onto the next phase of the project or not. And since code quality is very subjective, there have been issues where certain codebases would get a wide range of scores, from downright terrible to excellent.

For Android development specifically, it was decided that libraries like Android’s own databinding or the popular ButterKnife had to be used to reduce boilerplate when it comes to assigning XML elements to variables was something that was required for every Android apps written. Specifically, I’m talking about removing the findViewById calls. For example…

The above is a vanilla Android example, where we declare a mButton variable of type Button, and then use the findViewById call to assign a button that’s laid out in the XML to the mButton variable. Let’s compare this to ButterKnife.

Now, I understand that beauty is in the eyes of the beholder, but I am still confused on why the Android community thinks that the ButterKnife example is less boilerplate and looks cleaner. All ButterKnife seems to do is shove all the bindings to the top of the Activity class. I guess the ExampleActivity has one less line of code (and that lines of code will start adding up), but the amount of reasoning I have to make in my head is more or less the same as the vanilla Android example.

I agree with the general consensus that reducing boilerplate is a good thing. But to me, reducing boilerplate means that things are abstracted to a point where I’m not even aware that the extra code exists somewhere. All what ButterKnife and DataBinding seem to do is simply shove the bindings away to some other parts of the codebase. And to me, that’s not reducing boilerplate. It’s just moving code to somewhere else.

About the Author Chris Jeon

Software developer currently focusing on Android development.