Humans First, Compilers Second
My Outreachy project for this summer involves using Coccinelle to clean up the Linux kernel. For the past three weeks, I was focused on removing unnecessary variables from the Linux kernel. I was so eager to begin, that I soon finished a slew of patches over and beyond the ambit of my first task (removing variables that are initialized but never used). As there are apparently not all that many variables in the Linux kernel that are never used, I soon zeroed in on return variables. Why, I reasoned, do we need return variables that last till the end of a function, when we could just return the value directly at the end of every if statement?
I was a few days further into this internship before I realized something had gone wrong: all my patches were being rejected. As kernel developers explained to me over and over, apparently-pointless return variables serve a very useful purpose: to make the code more readable for people. Sure, the compiler might appreciate the micro-optimization of one fewer variable name, but human developers reading the code often find the various moving parts easier to keep track of if the variables have names.
This is, of course, not something I could have known about in advance. It’s not something that I readily understood even when it was explained to me the first few times. It’s more a convention than an objective rule. And, as my mentor explained to me (although she was probably being too kind) this is one of the common consequences of working with a pre-existing organization. No matter where I go there will be rules that I will unknowingly break in the first few days, and that’s okay as long as I learn from my mistakes.
On a final note: I think I may finally have figured out what kind of variables are unnecessary. Which of course means I’ll try sending in some more patches now.