Coding standards are communication tools

I’ve been writing a lot of C code over the past few months. It’s been fun and I’ve learned a good amount about writing solid, low-level, procedural code. While cranking out code I’ve also been developing a simple coding standard, mostly for my own use and based on on the K&R standard. I’m not working with a particularly large group (and probably won’t be anytime soon) so I won’t be asking anyone else to follow these standards anytime soon. They don’t follow the rest of the code 100% either. But even being essentially the lone hacker on the project, I’ve found sticking to a standard helpful.

C is a great language but often I want to say things as part of the program that I can’t put in the code. For example, there are often things about variables that aren’t captured by the type and even if they are, I don’t want to have to look up the type every time I see the variable to get that information. But by following simple rules about how my variables are named, I can pack in a lot of information. For example, a plural name is an array, a name prefixed with num_ indicates that it holds the number of something in the system, a name prefixed with rv_ means that it stores the return value from a function (probably for error handling). Outside of variables, function names are verbs, locally defined types meant to be private are CamelCased, exposed types have a _t suffix. Of course, these don’t apply in all cases and some amount of discretion is involved.

Following a standard like the above has a double benefit: first I can think less when it comes to naming things and it prevents casual naming conflicts. Secondly, as I hinted to above, it’s a communication aid. There’s a certain amount of information that is encoded into the language’s syntax and semantics. This layer is checked and enforced mechanically at compile time. But a coding standard allows for a secondary, optional layer that can convey more information without expanding the language standard (and allowing teams and individuals to develop their own, suited to the task at hand).

Note that I’ve mostly talked about naming conventions and I haven’t said anything about formatting. Personally I think formatting conventions are less important and helpful. It can be annoying to read code that is formatted differently across files (or in the same file), but I think the benefits to be gained from consistent formatting are less than that for consistent naming. In fact, I think that formatting issues should be eliminated by having a tool that will automatically reformat code to a single standard. I have the Go language’s gofmt tool in mind, but I’m sure there are others. (This is also one of the pet peeves I have with Haskell: it’s apparently really hard to write an auto-indentation tool for its syntax)

One caveat is that I have no personal experience as to what effect a coding standard has across a large group. I’ve found two articles arguing against coding standards on teams, but they’re both far too emotional and hand-wavy for me to take them seriously. Personally I would be wary of a developer who can’t adapt to a coding standard in a reasonable amount of time. That being said, there are definitely more important things than adhering to a standard (getting working code for one). However, I do think that coding standards fit into a larger culture and system of good coding practices. These include things like code review, appropriate use of version control and proper communication channels to talk about bugs and feature changes.

To conclude, a coding standard can be a great tool for personal uses. In some ways it frees up my limited mental RAM to think about more important things. It also allows me to pack more information into my code, outside of what the language syntax or semantics allow. I’m less certain of the benefits for large groups and as Emerson puts it, a foolish consistency is the hobgoblin of small minds. That being said, I’d like to believe that a good coding standard (with formatting mechanically enforced) along with practices like code review can lead to a higher code quality.

Sunday Selection 2012-12-09

Around the Web

A Funny Thing Happened on the Way to Academia

As my third semester as a PhD student draws to an end, I’m starting to think about what to do in the long term: what kind of a career I want to have, what kind of problems I want to focus on, etc. This piece is an interesting look at how research in computer science can coexist with making an impact in the real world today.

Trouble at Code School

I’ve been a Teaching Assistant for two semesters, but I haven’t really been on the front lines of teaching students. That being said, from what little experience I have introducing newcomers to programming that both teaching and learning beginning programming is no easy task. Luckily, with the growth of education-based startups and the resurgence in academic CS programs we’ll probably see interesting approaches in the near future.

GitHub vs Skyrim

Giles Bowkett manages to come up with interesting perspectives on a regular basis. This article talks about about GitHub and Skyrim and how the way they encourage team dynamics may lay the foundation for a new way of organizing companies and teams. Perhaps the most insightful idea is that the very definition of an office or workspace is not only changing, but gradually becoming irrelevant as work becomes increasingly distributed.

From the Bookshelf

Surely You’re Joking Mr. Feynman

I first read this book years ago in school and it was probably the first book to show me that you can fill a life with equal parts work and fun. This book probably played an important, though subconscious part in my decision to stay in academia for the time being. Even if you’re not a scientist or and academic, this book is worth reading and learning from. Life is supposed to be fun.

Sunday Selection 2012-10-21

Good afternoon everyone. It’s fall in my part of the world, the leaves are changing color, the weather is getting colder and the days are getting shorter. Things are moving and shaking in the tech world (as usual) and today’s Selection takes a look at Microsoft, Linux, Firefox and the intersection of technology and life.

Around the Web

The Story of the New Microsoft.com

Microsoft has a new website. No matter what you might think of the company and its products, I think you’d be hard pressed to say that the website wasn’t a job well done. It’s clean, effective and very modern.

UX Principles Behind Firefox for Windows 8

I’ve always had a soft spot for Firefox. Even though I mostly use Chrome nowadays, I keep coming back to Firefox. It was the first non-IE browser I used and I think the Mozilla team has done a lot to make the web a better place. It’s good see Firefox evolving and developing to stay in tune with the rest of modern technology.

Linus Torvalds Answers Your Questions

Linus isn’t the most public of technology superstars, but he doesn’t pull any punches either. In this recent Slashdot interview he talks about kernel development, what he might have done differently, patents and more.

Video

Creative Mornings with Jonathan Harris

CreativeMornings is a monthly breakfast lecture series for creative types. Each event is free of charge, and includes a 20 minute talk. This one is by Jonathan Harris creator of We Feel Fine and Cowbird (among others). It talks about his journey exploring technology, life and storytelling. If you’re looking for examples of a remarkable life well lived, this one’s a keeper.

Rules for Computing Happiness Revisited

About a year and half ago I wrote down some Rules for Computing Happiness. I based the list off of a similar list by Alex Payne. But in the year and half since then a lot has changed in my life. I graduated from college and finished a year as a graduate student at Cornell University’s computer science running experiments. I’ve also finally joined the world of smartphone users. I spend the greater part of the day writing programs and scripts and spend an increasing amount of time on remote machines. In the light of all those changes I think it’s a good idea for me to revisit the rules I laid down and see how much they’ve changed (or stayed the same). Here goes:

1. Use as few physical machines as possible

This one’s a keeper. I now use only two physical machines: my personal Macbook Air and my powerful Linux desktop at work. I use a combination of Git, Dropbox and Chrome tied to my Google account to keep things in sync between them. In reality the work I do on each doesn’t much overlap so there isn’t a pressing need to keep them in sync.

2. Keep work and play separate

Another keeper. I don’t have any social media apps on my work machine, I generally keep IM closed and I’m busy and in the flow enough that I don’t feel the need to randomly open up Reddit or Hacker News. I should be honest and say that this isn’t a purely (or even mostly) technical thing – in fact it probably has more to do with my shifting perspectives on what’s important. I have my phone near me if anyone really needs to get in touch with me. Since I’m a grad student I have a lot on my plate that is important but little that is urgent so my phone rarely gets used.

3. Get a Linux machine for programming. Use multiple monitors and a tiling window manager

I’m a bit less sure of this one and I’m partly afraid that I’m just plain biased. I do most of my programming on my Linux machine, but I do a decent amount on my Macbook Air too (especially experimental web stuff). I mostly use the UNIX in each so I’ve become fairly agnostic to what skin I’m running on top. I’ve never programmed on Windows so I don’t have anything to add on that matter.

However, I do use two monitors on a regular basis and going back to one can be annoying. I tried using Unity for a while and while it’s not bad, I keep going back to XMonad. It’s clean separation of physical monitors and virtual desktops makes using multiple monitors very flexible and efficient and I always find myself missing it when I’m on a different environment. By contrast, the way OS X does it is complete rubbish, especially if one of your windows is in fullscreen mode.

4. Get a Macbook for non-programming tasks

I’ve had my Macbook Air for over a year now and I love it. It’s the best laptop I’ve owned and probably the best computer ever. I only use a handful of userspace apps but they’re high quality ones like Reeder and OmniFocus. Homebrew is definitely the missing package manager for OS X and makes any programming I do a lot easier.

5. Keep a backup server, either physical or virtual

I’m still running a small Linode VPS that serves my personal website and acts as the syncpoint for my Git repos. I haven’t had any destructive crashes in the past year so I haven’t really felt the need for a backup, but it does offer peace of mind.

6. Learn and customize your tools

Yes, but do realize that it’s not the point.

7. Use public computers as little as you need to

Since I have both a great portable machine and a great workstation I haven’t had to use public computers at all. My desire to work in coffee shops and libraries has also been decresing steadily and I now prefer to work in a private office or a quiet shared workspace.

8. Pay for good software if you need it, but only after you’ve tried it out for a while

I’ve bought software like OmniFocus and Reeder and by and large I don’t regret it. I’m currently considering getting iA Writer. It’s cheap enough that I rarely think twice about gettting something that would make my job easier. However they “trying out” part is harder. My biggest gripe about the Mac App Store is no way to try out apps for a period of time (or stop using them and get a refund).

9. Keep information in open formats, preferably plain text

Yep. The only non-plain text format I interact with regularly is PDFs, only because that’s how most academic papers are distributed. I hold out hope that one day the academic community will move to publishing in hypertext.

10. Use version control on all projects

All my source code, my research data, my configs, my public and private writing are in version control. It not only makes it easy to go back and get something I may have overwritten, it also makes backup easier.

Process and Product

Yesterday I came across a post entitled “default behavior” by Ben Augarten about how important it is to put your products out in the world. It starts with him talking about how the code he’s writing is for an internal tool and hence will never see the light of day. Few people will use it and he’ll lose ownership of it once his internship ends. He implores programmers to release their code as products into the world and seems more than a little disdainful of programmers who don’t release their own products. He seems to be under the impression that if you’re not working on your very product that you’re dead inside.

He’s wrong.

It’s great to love to your product. It’s great to build something, to show it to the world, to have people use it, get feedback and make it better. If that’s what motivates you and makes you happy then by all means go ahead and release products. Life is too short to be unhappy (though people are working on that). What it doesn’t mean is that not releasing products makes you unhappy.

There’s a distinction to be made between process and product. Product is the fruit of your labor, process is the labor itself. In the rush to create startups, launch products, have dozens of repos on your Github account, we tend to lose sight of the process itself.

While I certainly understand (and have felt) the allure of releasing a product, there’s a lot of joy to be gained in the process itself. While many of us got into computers and programming because of the things we could create, many of us (including myself) got into it because of the joy of coding itself. I love learning new technologies, working through problems, crafting solutions. I love the mental strain of thinking my way to answer, I love the physical feel of my fingers on a keyboard and the seeing the characters of the screen. I love the process of seeing something being created as much I like the feeling of having created something. The same goes for writing or drawing or cooking – how you make something is just as important as what you make.

I suspect that this joy for the process itself is why so many incredibly talented and hardworking people are happy working for closed source companies (financial and material renumeration aside). If you are fulfilled by the labor itself then you care less about the fruits of your labor. This isn’t particularly new thinking – it predates open source, computers, software, even modern science and technology. As far as I know, the earliest well-known expression of such a notion is from the Bhagavad Gita where the god Krishna tells Prince Arjun:

“To action alone hast thou a right and never at all to its fruits; let not the fruits of action be thy motive; neither let there be in thee any attachment to inaction”

I don’t entirely agree with this: I do believe in property rights and I think that as a creator you deserve some say in how your creation is used. However I do agree with the underlying idea that you can find motivation in the actions themselves and not just their results. Getting too invested in the result can detract from joy you recieve from the process (and vice-versa). I’m not going to claim that process is better or more meaningful than product. Humans and their motivations and emotions are far more complex than such simple comparisons. But I am going to claim that finding fulfillment in the process itself is a perfectly valid way of living your life.

It’s great that Ben and so many other programmers and entrepreneurs want to create products and see them in action. We need that. They don’t have to become process-oriented. But they do have to understand that not all people will value products as much as they do and they have to respect that. Sometimes the journey is more important than the destination.

Sunday Selection 2012-07-01

Around the Web

Hackers and Fighters

When it comes to the debate between computer science and programming I’m of the opinion that knowing some computer science will make you a better programmer. Being a regular programmer will give you a better appreciation of the problems scientists need to solve. I’d love to see a proper scientific test of this hypothesis rather the jumble of anecdote and posturing that exists on the web today. This article is one of the more balanced ones and gives a worthwhile metaphorical veiw of the matter.

How One Hacker Quit the Programming Life for Bluer Skies

As much as I love writing code for my day job and wouldn’t be doing anything else, I don’t think that need be true for everyone. For a lot of programmers, writing code is just a day job and that’s ok. I find the notion that “real programmers” program day-in-day-night to be rather silly. You should do what makes you happy. Peer pressure that makes you produce more is still peer pressure. How good you are as programmer is determined by the quality of your code – not the hours you put in and not the number of open-source projects you maintain. And when you decide that you’ve had enough, don’t be afraid to go do something more interesting.

A much higher education

These are interesting times for academia and education in general. While I’m all for free (both as in beer and in freedom) digital distribution and decentralized, on-demand self-education, you can pry my expensive liberal arts education from my cold dead hands. I don’t think the higher-education system is unsustainable, I think there’s increasing pressure to commercialize and corporatize it and we’re unwilling to explore other options. Education is the foundation of a free society. Academic freedom is one of the pillars of modern science and technology. It’s about time we took that seriously.

Video

Jon Moore on Hypermedia APIs

Programming for the web is still one of my blind spots. That being said, I find the idea of programmatic exploration of APIs very interesting. I don’t fully understand all the implications and applications and I don’t think I will until I write a hypermedia application. But if you’re interested in knowing what programming for the modern web is like, I think this is a good start.

My Emacs Config

I’ve released parts of my emacs configuration on Github. Fork away! I first started really getting into Emacs after reading Steve Yegge’s blog posts on the matter. Since then I’ve pretty much fallen in love with Emacs, waxed eloquently (or maybe not so eloquently) about why it’s a power tool and despite all the cool modern editors and IDEs you can pry my Emacs from my cold dead hands.

I add to my Emacs configuration every time I embark on a project in a new language or using a new toolset. Currently I have a good 15MB worth of Elisp code for programming in C, Python, JavaScript and Ruby, dealing with XML and Git, blogging with WordPress etc. etc. All that stuff is not in the repository (though the names of some of the packages are if you want them). What is on Github are my general Emacs configurations, custom keybindings and custom Elisp functions for moving around the buffer and relocating files.

A note on keybindings

Most of my keybindings are different from the standard Emacs ones. I rebound them to be easier for me to remember, especially the movement keybindings. The mnenomic I use is:

  • `f` key moves forward
  • `b` key moves backward
  • `d` key kills (deletes) forwards
  • `w` key kills (deletes) backwards

I use the Ctrl and Alt modifiers to make these actions work on words or individual letters. The Ctrl key makes each of the above operate by word and the Alt or Meta modifier makes them work by letter. The Ctrl-m combination is a prefix key for various functions to reposition the current open buffer in the window. The functions are defined in `functions.el`.

A note on tools

I’m a great believer in customizing and shaping your tools to fit your work and your workflow. However, I believe more strongly that the code is not the point and that your tools are definitely not the point. In keeping with that I rarely tinker with my Emacs setup nowadays: I’ve found a configuration that works for me and is acceptably efficient. If I move to new tools and language (Haskell and Go are on the horizon) then I might make more additions.