Sunday, February 9, 2014

If you write code, turn off your editor's scroll bars and line numbers now

I like using Gvim for writing code. These are my favorite settings:

set number! " Remove line numbers
set guioptions! " Remove scrollbar, tool bar, and menu bar

This results in an editor window without scrollbars and line numbers.

You don't need line numbers. This is why:

Line numbers are not future proof. If someone refactors a source file, the line number to code association you're brain subconsciously created is now irrelevant. What it the point in creating a line-number-to-code-association when it's going to become irrelevant information in the future?

Aren't line numbers useful for communicating between programmers? No. Function definitions should be smaller rather than large. You shouldn't need line numbers to orientate yourself within a function that is 10 lines long. If it's small, you should be able to get the gist of an entire function's purpose by glancing at it. Small functions make line number orientation irrelevant.

Aren't line numbers useful for jumping to compiler errors/stack traces/assertions? No. Use your editors/IDE's "Go To Line..." feature, or better yet use your editors/IDE's quickfix feature.

Have you tried editing a +10k source file? It looks intimidating:

You don't need scroll bars either:

Once you break the line-number-to-code-association, you'll end up jumping to functions rather than scrolling to line numbers.

The scrollbar doesn't help you get over how intimidating a +10k source file looks:

Parting thoughts

Think about it. If you've ever used an editors/IDE's default settings, you would have grown up with a code-to-line-number-association! Is this the right way to think about code?

Getting rid of this code-to-line-number-association mentality by removing line numbers and scrollbars will change your life in many ways, including:
  • It's more important to think of a source file as a collection of code rather than lines of code
  • Your brain won't be subconsciously remembering line numbers which become irrelevant
  • You don't get intimidated by large source files anymore
What do you like most: Code, scroll bars, and line numbers, or just code?

No comments:

Post a Comment