Latest / DevQuestions with Tim Corey / 092 Which Is Better: Tabs or Spaces?
Transcript
- 0:00SPEAKER_00: Welcome to the Deaf Questions Podcast with Tim Corey.
- 0:03SPEAKER_00: Join us each episode as we tackle the questions you are asking about a career in software development, understanding the industry, and new technology.
- 0:12SPEAKER_00: If you're just starting out or you want to grow stronger as a developer, this is the place to get your questions answered.
- 0:19SPEAKER_00: Now, here's your host, expert developer and online educator, Tim Corey.
- 0:25SPEAKER_01: Which is better, tabs or spaces?
- 0:28SPEAKER_01: This is a question that Pierre asked over on the suggestion site, and I thought it'd be a great one to address in this episode of Dev Questions.
- 0:37SPEAKER_01: Now, before we get started, if you're watching this on YouTube as opposed to listening to it on the podcast, if you're watching on YouTube, you'll notice some major differences in how this setup looks.
- 0:49SPEAKER_01: In fact, this is the beta episode, the very first one, the one we're trying out and doing some tweaks on still of the new standing station in my new recording studio.
- 1:01SPEAKER_01: So we'll still do some tweaks before we kind of finalize into how you want to do this going forward.
- 1:07SPEAKER_01: But this is our first attempt at just to see where we're at as far as setup goes.
- 1:12SPEAKER_01: Like I said, you'll see some tweaks over the next few weeks as we change things and adjust things, but this is the new recording studio setup.
- 1:22SPEAKER_01: So hopefully you like it.
- 1:24SPEAKER_01: And once we get things kind of finalized, then we'll go through and give you a behind the scenes tour of where everything is, both stations, how they work, and how we're doing new videos.
- 1:36SPEAKER_01: In fact, this is going to be the start of some new things for my content.
- 1:43SPEAKER_01: One of the things that I am super excited about is the fact that this is actually not a green screen.
- 1:49SPEAKER_01: This is a touch screen monitor behind me.
- 1:52SPEAKER_01: So I can have an actual whiteboard I can draw on.
- 1:56SPEAKER_01: I miss my whiteboard.
- 1:57SPEAKER_01: That's what I love to teach.
- 1:58SPEAKER_01: So you'll see a lot more of that in the coming days.
- 2:00SPEAKER_01: Okay, let's get back to the episode that we're talking about right now, which is tabs versus spaces.
- 2:07SPEAKER_01: This has been a debate in the programming community for years.
- 2:11SPEAKER_01: And it's one that's often divisive and it has very strong opinions on both sides.
- 2:18SPEAKER_01: And a lot of times it comes down to just that opinion.
- 2:22SPEAKER_01: So let's talk through what's the difference between tabs and spaces in programming, and is there a clear winner?
- 2:31SPEAKER_01: Is there one that is more important than the other or better than the other?
- 2:35SPEAKER_01: I'm gonna give you a sneak preview of the end.
- 2:38SPEAKER_01: The answer is yes, I think there is.
- 2:41SPEAKER_01: So we're gonna get there, but let's make sure we are clear on what is opinion and what is fact.
- 2:50SPEAKER_01: So let's talk through uh spaces and taps.
- 2:54SPEAKER_01: Now, personally, I'll tell you what I like.
- 2:57SPEAKER_01: And that is I like spaces.
- 2:59SPEAKER_01: I've always used spaces.
- 3:00SPEAKER_01: And it and for me, it goes back to this is what I've always used.
- 3:05SPEAKER_01: So it's just a comfort thing for me.
- 3:07SPEAKER_01: But spaces I can choose.
- 3:10SPEAKER_01: I can say, okay, by default, Visual Studio has four spaces, and you can use the tab key to put those four spaces in.
- 3:19SPEAKER_01: But that way, if I decide later, hey, I want three spaces, we can change what the tab key does, and it gives me three spaces instead, and we can reformat all of my documents to fit that new spacing.
- 3:32SPEAKER_01: So spaces allow me to have very specific widths on things.
- 3:37SPEAKER_01: I say, okay, this is gonna be four spaces wide.
- 3:41SPEAKER_01: But then it gets even better when I have things wrapped the second and third and fourth line, where I can add a few more spaces if I want to align things to a certain ending or to a certain start.
- 3:55SPEAKER_01: So I can say, hey, I want to align to the opening parentheses.
- 4:00SPEAKER_01: Well then they it looks nicer, and maybe it's over 10 spaces instead of eight.
- 4:05SPEAKER_01: And that's okay if I want to have that nice look.
- 4:09SPEAKER_01: So that's the spacing side of things, and there's some benefits there to that.
- 4:14SPEAKER_01: And the other thing with spaces is if I say three spaces is a uh a standard width for one indent, well then I can enforce those rules using my editor, using uh editor config or other things to make sure that everyone conforms to that same styling.
- 4:37SPEAKER_01: So that's spaces.
- 4:39SPEAKER_01: Let's look at tabs.
- 4:41SPEAKER_01: Tabs are usually one tab per indent.
- 4:46SPEAKER_01: And then you you can say, okay, well, I want to have this many, this large of an indent, but that's one tab.
- 4:55SPEAKER_01: Well, if I decide to align things, they don't always align quite right because maybe if I'm trying to align to that parentheses or parenthesis, um, I have to move over a couple more spaces, and tabs don't do that.
- 5:10SPEAKER_01: So you have then tabs and spaces mixed, and it's just a little ugly.
- 5:14SPEAKER_01: So tabs, for me, going back to as far as I can remember in programming, I've always used spaces because of the fact that there's that precision where I can say this is how large I want this space to be.
- 5:27SPEAKER_01: So that's kind of the basics of the opinion side.
- 5:32SPEAKER_01: There is a little bit, if you want to get really specific, you could say, well, with spaces, you have to use one character per space you want.
- 5:43SPEAKER_01: So if you have a standard four spaces is one uh indent, well, then you're using four characters as opposed to one tab character.
- 5:53SPEAKER_01: So using, you know, an extra 75% more characters as opposed to tabs.
- 5:59SPEAKER_01: So if you have a lot of indents, then you're wasting a lot of space in your files.
- 6:05SPEAKER_01: That's not really an argument in my book just because of the fact that we don't have really tight margins when it comes to the amount of space we can use for our applications.
- 6:16SPEAKER_01: And that's only for source code, anyways, because once you compile it, that all goes away.
- 6:21SPEAKER_01: So, yes, you can save a little bit of space by using tabs, but that's not really, in my opinion, much more than a tiny argument.
- 6:32SPEAKER_01: It's it's not really a value.
- 6:34SPEAKER_01: It's it's something, but it's not really anything of importance.
- 6:39SPEAKER_01: But let's talk for a minute about why tabs are more important to use than spaces.
- 6:46SPEAKER_01: And yes, I have said my preference is spaces because that's what I've known, that's what I've grown up with, that's what I've used as a developer.
- 6:53SPEAKER_01: But tabs are probably the better choice when it comes to choosing tabs versus spaces.
- 7:02SPEAKER_01: And here's why it's about usability, accessibility.
- 7:07SPEAKER_01: It's about the idea that each person can choose what that tab width is on their machine.
- 7:15SPEAKER_01: So when I say four spaces, when it goes to your machine, you're gonna get four spaces.
- 7:21SPEAKER_01: That's it.
- 7:22SPEAKER_01: And if you conform to my my layouts, which you should, well then you've got just four spaces of width, which may be a ton of space or not much at all.
- 7:35SPEAKER_01: So let's talk about a few cases where having a tab instead would be beneficial.
- 7:43SPEAKER_01: The first one is what if I have not a lot of room on my screen?
- 7:49SPEAKER_01: And so I want to get as much usage out of the width as possible.
- 7:55SPEAKER_01: Well, I want to narrow my indents.
- 8:00SPEAKER_01: So the way to do that is if you're on spaces, is to reduce the number of spaces.
- 8:06SPEAKER_01: But that means I have to then apply that to all the files and tell you you have to do it as well, even if you have an ultra-wide screen monitor.
- 8:16SPEAKER_01: So that's not great.
- 8:18SPEAKER_01: Whereas with tabs, I can say a tab is the width of two characters.
- 8:25SPEAKER_01: It will not change the source file, but it will allow me to see and use more of my horizontal width without affecting you.
- 8:37SPEAKER_01: Conversely, if you're on an ultra-wide-screen monitor, having an indent of even four characters might not be the best because of the fact that you have more horizontal space to give.
- 8:50SPEAKER_01: You might want to have a larger indent.
- 8:54SPEAKER_01: Well, you can change your tabs over to say they take up eight spaces or eight characters of width instead of four.
- 9:02SPEAKER_01: Well, now you have more clear indents, and you haven't affected me who's on the narrow monitor.
- 9:11SPEAKER_01: So tabs allow you, allow each person to have an individualized choice on what the width might look like.
- 9:21SPEAKER_01: Tabs also allow you to use any editor.
- 9:27SPEAKER_01: If you open up a Visual Studio project, like a CS file in notepad, well, that's not, it has no features for text editing besides just it's text, you can change it.
- 9:41SPEAKER_01: So if you have an indent of four spaces and you have three indents deep, you need to add a line, you need to add 12 spaces at the beginning.
- 9:52SPEAKER_01: However, if you were using tabs, you just tab three times.
- 9:57SPEAKER_01: So there is a benefit there.
- 9:59SPEAKER_01: But then let's talk about the most important benefit, which is the accessibility of this.
- 10:06SPEAKER_01: If you have a person on the team, or if you are low visibility, you have a hard time reading things, you have to zoom in on things a lot.
- 10:17SPEAKER_01: Maybe when you're zooming in, one of the things you can do is reduce the size of your tabs so that even though the indents aren't very large, because the fact that text is zoomed in so much, it will be still clear as to what the indents are, and you can have more of your horizontal width to use for actual code.
- 10:40SPEAKER_01: The other side of it is maybe you need to have a much clearer indentation level, then you can go the other direction and have those tabs be wider.
- 10:52SPEAKER_01: So this allows more developers to more easily work with your code in a way that is accessible for them.
- 11:02SPEAKER_01: It's usable for them, it's more comfortable for them.
- 11:07SPEAKER_01: So while I prefer spaces and I like I'm comfortable with spaces, I've always worked with spaces.
- 11:18SPEAKER_01: Tabs provide a better option for a broader audience and allows me to use the same things I'm comfortable with.
- 11:27SPEAKER_01: I've always used a tab key, it just puts four spaces in.
- 11:30SPEAKER_01: Well, now the tab key can put one tab in and I can adjust how wide that spacing is for me.
- 11:38SPEAKER_01: I can still feel comfortable, but then when I give my code to you, you can also still feel now feel comfortable if I use tabs.
- 11:47SPEAKER_01: So while you can definitely have your own opinion, and you can even say, hey, you know what?
- 11:52SPEAKER_01: I still like to use spaces.
- 11:54SPEAKER_01: I still want to use what I'm comfortable with, and that can be your opinion, that's totally fine.
- 12:00SPEAKER_01: I think when it comes to which is objectively better, I think we can agree, and hopefully we can agree, that tabs do provide more options for us and allows for more flexibility than spaces do.
- 12:17SPEAKER_01: Spaces lock us into this is the width.
- 12:21SPEAKER_01: Whereas tabs allow us to adjust based upon each developer's needs.
- 12:26SPEAKER_01: So that's my take on the tabs versus spaces argument or issue.
- 12:32SPEAKER_01: Now, I do want to pause and say something though.
- 12:35SPEAKER_01: There are a lot of issues in our ecosystem when it comes to developers.
- 12:42SPEAKER_01: We are passionate about a lot of things.
- 12:44SPEAKER_01: You know, which language is the best, which type of uh friend versus backend is best, which desktop versus web, all these things, tabs versus spaces, these are all passionate arguments we can have back and forth.
- 13:01SPEAKER_01: That can be good if you are working towards learning more and growing and sharing what you think is best, what you like, that can be excellent because with that back and forth, you can grow and learn something new.
- 13:17SPEAKER_01: But be very careful with these not to turn it into a right versus wrong anger thing.
- 13:25SPEAKER_01: Now, like I said, I think there is a clear reason why tabs are objectively better because it's objective, not subjective.
- 13:34SPEAKER_01: But don't turn this into a right versus wrong.
- 13:38SPEAKER_01: Don't turn this into an anger thing.
- 13:41SPEAKER_01: Leave that alone.
- 13:42SPEAKER_01: Okay, step away from that.
- 13:44SPEAKER_01: Let's have a good discussion on this and not one that that leads to hurt feelings and isolation.
- 13:50SPEAKER_01: So just be careful of that.
- 13:52SPEAKER_01: I see a lot in the community, and really we shouldn't be trying to tear each other down.
- 13:57SPEAKER_01: We should be trying to build each other up in how we work together with these kinds of things.
- 14:00SPEAKER_01: Okay, so that's my thoughts on tabs versus spaces.
- 14:04SPEAKER_01: I'd love to hear your thoughts if there's any more benefits you can think of for spaces that you like, or are there any more benefits for tabs that you appreciate?
- 14:14SPEAKER_01: And going forward, are you going to change from spaces to tabs?
- 14:18SPEAKER_01: Are you gonna stay on tabs, or are you gonna stay on spaces?
- 14:22SPEAKER_01: So let me know down in the comments if you're watching on YouTube.
- 14:25SPEAKER_01: If you're watching the podcast, I'd love to have you come over to YouTube and leave a comment if you have some thoughts on that.
- 14:31SPEAKER_01: There's not a good place to leave comments on the podcast episode, but if you do have time to go to your favorite podcast um host and leave a leave a review, that'd be great.
- 14:43SPEAKER_01: I appreciate it.
- 14:44SPEAKER_01: Um, it's always good to hear your positive thoughts on how things are going.
- 14:48SPEAKER_01: If you have suggestions for future dev questions episodes, go to suggestions.imtimcorey.com and leave one there.
- 14:58SPEAKER_01: Upvote ones that you find there.
- 15:00SPEAKER_01: This is one from suggestions.imtimcorey.com.
- 15:03SPEAKER_01: Thanks, Pierre, for asking it.
- 15:06SPEAKER_01: And if you have your suggestion posted there, maybe you'll see that answered in a future episode.
- 15:12SPEAKER_01: All right, thanks for listening.
- 15:13SPEAKER_01: And as always, I am Tim Corey.
- 15:16SPEAKER_00: Thank you for joining us for this episode of Dev Questions.
- 15:19SPEAKER_00: Tim is committed to making it easier for you to become a developer.
- 15:22SPEAKER_00: If you would like to help make more content like this possible, please like, subscribe, rate, and share dev questions.
- 15:29SPEAKER_00: You can also send your questions to questions at imtimcorey.com.
- 15:34SPEAKER_00: Until next time, remember you are too smart and your time too valuable to waste up making all the mistakes attended.
- 15:42SPEAKER_00: When you're ready to learn to think and code like a professional developer, head over to imtimcorey.com and enroll in a course.