Enforcing Coding Standards via Compile Errors

By 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
-fi

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

  1. Go has a standard formatting mechanism that is separate from the compiler, but standard with the language, gofmt - http://golang.org/doc/effective_go.html#formatting

    I agree with you in theory, though I'd like to see how it turns out in practice. For instance having Python be white space sensitive is fine most of the time, and a giant pain the other small portion of the time.

Add a Comment