Tabs or spaces? #188939
Replies: 5 comments
-
|
My opinion, It doesn't really matter which one we pick, as long as we pick one and stay consistent Or just setting up a .editorconfig or a Prettier/Linter rule and forgetting about it forever. Let the machine handle the formatting so we can focus on actually shipping features. Life’s too short to manually count dots or arrows, right? |
Beta Was this translation helpful? Give feedback.
-
|
Tabs. Because it’s simpler.
Examples with different tab widths Tab width = 2 function processUsers(users) {
if (!users) {
return [];
}
return users.map(user => {
return {
id: user.id,
name: user.name
};
});
}Tab width = 4 def calculate_total(items):
if not items:
return 0
total = 0
for item in items:
if item.available:
total += item.price
return totalTab width = 8 int process_device(struct device *dev)
{
if (!dev)
return -EINVAL;
if (dev->status == DEVICE_READY) {
start_device(dev);
}
return 0;
}In practice, a common setup is tabs with a display width of 4. The only real exception is Makefiles, which require actual tab characters. |
Beta Was this translation helpful? Give feedback.
-
|
tabs cause u can config it. add we are already beating the living hell out of the space bar. |
Beta Was this translation helpful? Give feedback.
-
|
Use Tabs if you prioritize accessibility and want users to select their own visual indentation width. Use Spaces (specifically 4) if you want the code to look identical across all platforms and tools. |
Beta Was this translation helpful? Give feedback.
-
|
The practical answer is: Use whatever your project's linter/formatter enforces. Whether tabs or spaces doesn't matter much technically—what matters is consistency. Modern teams solve this with tools like Prettier, ESLint, or EditorConfig that enforce a standard automatically, so no developer needs to think about it. If you're starting fresh without constraints, spaces (4 or 2) are more widely compatible across tools and platforms, while tabs are slightly more accessible (users can adjust width to preference). But honestly, the best indentation choice is the one that lets you stop debating indentation and focus on writing good code. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
And why?
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions