Enforcing Coding Standards via Compile Errors

By Deane Barker on November 1, 2013

Slash is a new programming language that promises to marry the simplicity of PHP (embed a bunch of code in a file and call it directly), but with the elegance of Ruby or Python.

Regardless of that, I found this code snippet from their compiler interesting:

-if git ls-files | grep -v Makefile$ | xargs grep -n '\t'; then
- echo "There are hard tab characters in the following source files:"
- echo
- git ls-files | grep -v Makefile$ | xargs grep -n '\t'
- echo
- echo "Failing build."
- exit 1

They are enforcing coding standards in the compiler — if you have tabs in your file, the build simply fails.  (The commit was titled “fuck it,” if that gives you any insight on it.)

Ken Arnold talked about this exact same thing in “The Best Software Writing“:

For almost any mature language (C, Java, C++, Python, Lisp, Ada, FORTRAN, Python, Smalltalk, sh, javascript, …) coding style is an essentially solved problem, and we ought to stop worrying about it. And to stop worrying about it will require worrying about it a lot first, because the only way to get from where we are to a place where we stop worrying about style is to enforce it as part of the language.
I totally agree with this approach.  Simply take this debate out of the conversation by making the compiler the bad guy.  When it’s non-negotiable, most developer will just stop arguing about it.



Comments are closed. If you have something you really want to say, email editors@gadgetopia.com and we‘ll get it added for you.