“Code” or “source code” are terms used to describe the written words in a programming language that have meaning in the context of that language. What I’m writing here right now is not “code” even though to someone who only reads and speaks Latin or Greek, it would certainly look like a secret code that they need to decipher. When I write software, I “code”, “write code”, or “write software.” The text that’s been written is called “code” or “source code.”

I have changed my opinions about the style, or formatting, that should be used when writing code. I recently wrote some Java code for the server at work and once I was finished and this code was incorporated into a master copy of all of the server source code, the formatting had been changed. A line like this:

int x = function( alpha, beta, gamma, delta );

might have been turned into this:

int x = function( 
alpha,
beta,
gamma,
delta );

This isn’t exactly what happened. But it did happen when the lines were “too” long by someone’s standards. A lot of my code that was written as a single line was changed into multiple lines. I’ve been writing a lot of code lately that is one long line. Here’s another example of code that I would write and how automatic formatters and most other people might write:

if( x == y ) { continue; }

And theirs:

if( x == y ) {
continue;
}

I often write my code on a single line because, after 35 years, I find that using multiple lines for what appears to be a single action or operation, is not useful when trying to understand or debug the software.

When I debug software and I don’t know what the software is doing, I’ll read through the code and try to understand it. Usually, the first few words and symbols on a line are enough information to understand it. Sometimes, the first few parameters passed to a function (the stuff in the parentheses after the function name), are all that is needed for the purpose of grasping what’s going on. By the way, and for those out there that might read this someday, using single letter variable names line ‘i’ makes your code completely unreadable to someone like me who will not infer the meaning of your variable name just because of some tradition in the programming world that ‘i’ means “the index of something”. So stop using single letter variable names and spell out what you mean.

Back to the formatting…

When something as simple as a “continue” statement is on it’s own like along with one or both of the curly braces being on their own lines, it takes room on the screen away from more important information. Scrolling the screen to see more of the code is like walking through a door of your house where your mind naturally transitions to the new environment and what you were thinking about in the previous room is just wiped from your memory. At last some people have reported that experience walking through doors. I’ve certainly had it scrolling down a page in someone else’s source code.

I like the Swift programming language but they did one really weird thing that differs from other languages – they placed the return value type of a function on the right side of the function definition. With a function that takes more than a few parameters, this is often far off to the right of the screen or even out of view. But this is very important information, perhaps, and should be visible along with the name of the function. I get that they wanted something more human readable where you might say in English: “Function named ‘dave’ returns an integer value”. I am not sure if the return value type is really important since it’s the name of the function that should hold ALL of the meaning. A function named “sqrt” might mean “squirt” or “square root” and it really should be spelled out. Programmer need to stop the inane practice of making their code look like some sort of “code” that needs to be deciphered.

So these days, I write long lines when the part of those lines that is hidden off the right side of the window/screen is not important to understanding the overall functionality of the code. I don’t like to write a block of code after “if” when the block has a single statement. It doesn’t help anyone understand what the code is doing. I write my code so that someone can figure it out without spending 5% to 10% of their time scrolling and re-establishing their context after the scroll if finished.

I know that this is a bit of a rant. But it’s really just some thoughts I wanted to get in writing while taking a break from writing code and doing some of that all-on-one-line formatting I like to do.