4

A long time ago when starting learning programming I remember a teacher saying that compiler do not care about whitespace and they are useful to make code readable for human beings. It made perfect sense back then, but I only knew some Pascal and C++.

Many years later, after diving in many other languages I began wondering what is the rational of having programming languages that rely on indentation / white space, as there are quite a few disadvantages:

  1. Stange errors like this one (unindent does not match any oute indentation level)
  2. Minifying still requires extra whitespace - example
  3. Many other reasons as indicated in this Quora post:

    • lack of white space indentation across operating systems / text editors
    • whitespace might be introduced while doing code merge
    • possible errors while copy-pasting
    • all modern IDEs automatically indent code

Question: Why do we still have programming languages that rely on indentation / white space?

Alexei
  • 452

3 Answers3

20

What do you mean, "still"? Whitespace-delimiting is an advanced feature.

Lisp, Algol, Pascal, C etc. etc. were delimited by BEGIN..END or by bracket characters. The focus in early programming languages was to get the computer to do what we wanted at all. It mattered little if the formatting looked clunky.

But then programming became a huge success story, and programs, modules, and entire systems became huge and unwieldy. Eventually we realized that making the code look good for human readers was just as important as making it understandable for computers, because no one would be able to maintain old code otherwise. Mirroring logical structure (nesting) with indentation turned out to be a very good way of achieving this. Proper indenting became a standard rule of clean code.

Eventually people realised that the indentation could be used to inform both programmers and computers: with proper indenting - which every style guide already said you should be using anyway - you could in fact omit Pascal's BEGIN..END, or Lisp's wastelands of parentheses, or C/Java's brackets, and readability would be even better. This last point is controversial, but historically, whitespace delimitation is the endpoint of a development, not a remnant.

Glorfindel
  • 3,167
Kilian Foth
  • 110,899
6

Because some crazy people think its an "advanced feature"!!

Honestly it drives me mad. Not only do they remove the nice printable end of line and closure indicator characters ; { } THAT YOU CAN ACTUALLY SEE WITH YOUR EYES! But they don't even use tab for indentation!!! Apparently pressing space twice is better than a century of using the key SPECIFICALLY DESIGNED FOR THAT PURPOSE.

Fotunately most IDEs allow you to turn on 'show whitespace' so you can see the EOL character and all important multiples of space space that follow them.

I think they should all be forced to program in Fortran 77 untill they see reason

Ewan
  • 83,178
0

You are right about the possible errors. It is inevitable, though, as is the case with many other peculiarities of any language. Forget one curly brace in any C language, or Java, and you'll have to go through hell and back at times just to figure out WHICH curly is missing - especially true when you are using an environment that auto-indents as you go (tabs will give you the illusion that curlies line up when they do not). Languages such as Python (super hot right now) will make full use of indentation, and while cross operating system files are interpreted differently sometimes, I have never run into the problem of white-space misinterpretation with .py (python) files. That being said, I am a regular user of MacOS, Ubuntu and Windows 10. My guess is that they have formatting configured in such a way that would not mess up python files?

Adam S.
  • 17
  • 3