Home  >  Article  >  Backend Development  >  Tabs vs Spaces - Makefiles in C

Tabs vs Spaces - Makefiles in C

Linda Hamilton
Linda HamiltonOriginal
2024-10-25 05:02:29266browse

Tabs vs Spaces - Makefiles in C

Silicon Valley S3 - Ep6

The tabs vs spaces debate among developers revolves around the preferred method for indentation in code. 'Tabs' advocates argue that tabs are semantically correct for indentation, customizable, and more accessible, especially for those with visual impairments. They suggest using tabs for indentation and spaces for alignment. 'Spaces' advocates emphasize consistency, as spaces ensure that code formatting appears the same across different editors and platforms, avoiding issues with variable tab sizes. This approach is often preferred in team environments to maintain uniform code appearance.

But if you are programming in the C language and need to use Makefiles, there is no choice - you must use 'Tabs'.

The requirement for tabs in Makefiles originates from Stuart Feldman, Unix developer and the creator of the 'make' utility. Feldman chose tabs to help in distinguishing between commands and other text in the Makefile. Specifically, the Lex parser used in the early implementation of 'make' had difficulties distinguishing between tabs and spaces, leading to the mandate for tabs. Although Feldman has acknowledged this as a suboptimal decision, the convention has persisted.

Tabs vs Spaces - Makefiles in C

The above screenshot, shows a Makefile. This example is using the 'show symbol' feature in notepad - with it you are able to clearly distinguish between tabs and spaces - the arrows indicate that tabs are used on lines 8, 12 and 16. If you indent those lines using spaces instead of tabs, the program will not run - you'll receive an error:

Makefile:line_number: *** missing separator. Stop.

So, whether you prefer tabs or spaces when you program is up to you. But if you're working with Makefiles in C, Stuart has left you no choice.

If you haven't seen the Silicon Valley episode above (S3 Ep6) - give it a watch, as with the entire series, it's a lot of fun.

Ben Santora - October

The above is the detailed content of Tabs vs Spaces - Makefiles in C. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn