tab vs spaces

if you watch silicon valley HBO then you’d know the tab vs spaces arguments that took place there. it is said that tab save you 4 spaces and give your code smaller sizes. while you may agree with this, you should know that when you code in python it is very important to have indentation in your code or else the interpreter would throw a syntax error.

maybe you’re used to code in javascript or php that don’t really care whether you use tab or spaces but in python indentation matters very much.

I also prefer tabs because:

  • They’re a character specifically meant for indentation
  • They allow developers with different preferences in indentation size to change how it’s the code looks without changing the code (separation of data and presentation)
  • It’s impossible to half-indent something with tabs. So when you copy code from some website that used 3 spaces into your 4-space indented file, you don’t have to deal with misalignment

Use spaces if you’re lining up characters within a line, so they always line up regardless of tab size.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s