In the coding world, a holy wars battle that is still occasionally fought.
"Use 4 spaces per indentation level."
`
—Python PEP coding indentation standard
When writing code, programmers like to format their source code for a variety of reasons. Imagine reading the code listed below (taken from the Linux kernel source code). You will see, among other things, sections of code within curly braces {}, which respresent the limits of, say, an if statement or a function. You'll also notice that stuff listed after the opening brace is indented. In part this is for legibility, so the reader can more easily see the various divisions and sections in the code. Over time, various standards have been set as to how code is to be indented. Python PEP states four spaces, The Linux kernel standard specifies eight spaces, which is the same length as a standard tab. This can naturally result in the programmer using a tab key to represent these eight spaces (as many text editors will convert the tab keypress as a certain number of spaces, which i have done in my .vimrc Vim settings).
When coding, often some lines are indented to improve readability. Imagine all the thunks on the spacebar to produce this:
// SPDX-License-Identifier: GPL-2.0
#include <linux/context_tracking.h>
#include <linux/entry-common.h>
#include <linux/resume_user_mode.h>
#include <linux/highmem.h>
#include <linux/jump_label.h>
#include <linux/kmsan.h>
#include <linux/livepatch.h>
#include <linux/audit.h>
#include <linux/tick.h>
#include "common.h"
#define CREATE_TRACE_POINTS
#include
static inline void syscall_enter_audit(struct pt_regs *regs, long syscall)
{
if (unlikely(audit_context())) {
unsigned long args6;
syscall_get_arguments(current, regs, args);
audit_syscall_entry(syscall, args0, args1, args2, args3);
}
}
long syscall_trace_enter(struct pt_regs *regs, long syscall,
unsigned long work)
{
long ret = 0;
/*
* Handle Syscall User Dispatch. This must comes first, since
* the ABI here can be something that doesn't make sense for
* other syscall_work features.
*/
if (work & SYSCALL_WORK_SYSCALL_USER_DISPATCH) {
if (syscall_user_dispatch(regs))
return -1L;
}
All this said, many programmers, when actually writing code, would rather use a single tab rather than many spaces, simply because it means fewer keystrokes.
Many people feel very strongly about this for various reasons (keyboard noise, concerns about inefficiency or simply sitting on some absurdly idealistic standard). In the TV show Silicon Valley there's a scene in which the depth of feeling is aptly illustrated. See the Youtube video clip from the show
For my part, in my editor (Vim!) i have a setup that translates my tab keystroke to be saved in the file as four spaces. in my .vimrc, I have the lines:
:set tabstop=4
5 :set shiftwidth=4
6 :set expandtab
simply to mollify the gods. Other
editors and
IDEs may even know where indentation is required and perform it automagically.
$ xclip -o | wc -w
419