Tabs or Spaces? (Soundcheck Question) - Computerphile

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2019
  • / computerphile
    / computer_phile
    This video was filmed and edited by Sean Riley.
    Computer Science at the University of Nottingham: bit.ly/nottscomputer
    Computerphile is a sister project to Brady Haran's Numberphile. More at www.bradyharan.com

ความคิดเห็น • 2.1K

  • @slotharmstronk1348
    @slotharmstronk1348 4 ปีที่แล้ว +3532

    Next question should be curly brackets on same line of function vs next line

    • @TheGameAffinity
      @TheGameAffinity 4 ปีที่แล้ว +26

      Sloth Armstronk was about to make a comment about this lol

    • @SJohnTrombley
      @SJohnTrombley 4 ปีที่แล้ว +46

      K&R style

    • @slitbodmod5555
      @slitbodmod5555 4 ปีที่แล้ว +217

      define function{
      content;
      }
      I know it's silly but I will die on this hill

    • @lohphat
      @lohphat 4 ปีที่แล้ว +54

      Simple. Next line.
      Why? So you can add another statement by just inserting a line, you don’t need to edit the last line to move the closing brace.

    • @marklonergan3898
      @marklonergan3898 4 ปีที่แล้ว +133

      Has to be next line.
      Function a()
      {
      // Code
      }
      I know im in the minority but the other style bugs me. If i have to take charge of a new script that was written by someone else, this is the first thing i have to change with it. Its not being petty, i really find it makes it a lot easier to see what blocks belong to each other, especially when other coders dont care much about indentation.

  • @bhabyadeeprai2242
    @bhabyadeeprai2242 4 ปีที่แล้ว +854

    Tabs or Spaces?
    Others: Tabs
    Prof. Brailsford: Ohhh I didn't expect that question... Ohhh oh Lord no...

    • @Thalario
      @Thalario 4 ปีที่แล้ว +78

      And he actually gave a sensible answer. Tabs are designed for moving to a tab stop, but you might not trust whatever’s operating over the text to deal with them correctly.
      It’s the only reason not fully negated by the fact that nowadays we all tend to use decent editors.

    • @FrankHarwald
      @FrankHarwald 4 ปีที่แล้ว +85

      "Ohhh oh Lord no" is in fact, the only correct answer to that question.

    • @kankawabata3398
      @kankawabata3398 4 ปีที่แล้ว +3

      Frank Harwald no tabs is

    • @DanielFSmith
      @DanielFSmith 4 ปีที่แล้ว +2

      He's a professor, so he doesn't program any more. ;-)

    • @666Tomato666
      @666Tomato666 4 ปีที่แล้ว +7

      @@Thalario while we have decent editors, you still have to watch out not to save a file that uses _both_ on the same line - therein lies madness

  • @TheHaters112
    @TheHaters112 4 ปีที่แล้ว +686

    Every other developer: Doesn't matter
    Python developer: THIS IS A LIFE AND DEATH QUESTION!

    • @DominikMarczuk
      @DominikMarczuk 4 ปีที่แล้ว +29

      I've worked with at least 4 different programming languages (discounting HTML, CSS and its preprocessors as "programming languages") where the code style violations would actually make the build fail. So not just Python.

    • @TheHaters112
      @TheHaters112 4 ปีที่แล้ว +29

      @@DominikMarczuk Style doesn't break the program on many of the popular SE used languages. Python uses a style as a syntax, I *personally* believe that shouldn't happen. Style varies from Organisation to organisation sometimes it's even departmental.
      Where I work we outsourced a project and the company wrote code who's style and naming convention doesn't match our department's standards. Yh, we weren't happy about it but the software did it's job and did it well. Will we use them again? Depends on how desperate we are.
      Don't get me wrong I don't hate Python I just have a complicated relationship with it. Honestly I can't truly hate it because it's what got me invested in programming.

    • @DominikMarczuk
      @DominikMarczuk 4 ปีที่แล้ว +3

      @@TheHaters112 I do understand that languages such as Python and Ruby, or maybe CoffeeScript and SASS on the frontend side, use indentation to denote nested code blocks. But does that mean that using true tabs will actually break the syntax? (it's a question; I guenuinely don't know)

    • @kevinbee4617
      @kevinbee4617 4 ปีที่แล้ว +9

      @@DominikMarczuk I tested it in the python interpreter. Eight spaces are apparently equivalent to one tabulator - even when my terminal shows one tab four characters wide.
      To be clear: You can actually use tabs, but you shouldn't mix tabs and spaces, because it looks weird when tabs aren't eight characters long. Also, pep-8 recommends to use four (true) spaces.

    • @CakeBossan
      @CakeBossan 4 ปีที่แล้ว +5

      @@kevinbee4617 pep-8 is my master

  • @globalincident694
    @globalincident694 4 ปีที่แล้ว +321

    So the answers are:
    Tabs, -spaces- tabs, tabs, tabs, tabs, tabs, tabs, tabs, "I just press the tab button and hope for the best", tabs, tabs, tabs, "it depends on the tabbing mechanism", tabs

    • @paulk.8681
      @paulk.8681 4 ปีที่แล้ว +37

      Except I am willing to bet that most of them use spaces, but don't know it. The people who said that they use tabs because "it's faster than mashing the spacebar over and over" particularly.

    • @fatehaliyev2017
      @fatehaliyev2017 4 ปีที่แล้ว

      Yeah, sometimes it indents too much.

    • @oliverlemke465
      @oliverlemke465 4 ปีที่แล้ว +3

      @@paulk.8681 Yeah, but I think the question isn't what is actually written in the code, it's what they use for writing it.

    • @SylvainBrunerie
      @SylvainBrunerie 3 ปีที่แล้ว +2

      @@oliverlemke465 I really really hope no one thinks preferring spaces over tabs actually means preferring hitting the space bar over hitting the tab key… Text editors have been able to insert spaces on a Tab key hit since, what, 20 years?

    • @encycl07pedia-
      @encycl07pedia- 2 ปีที่แล้ว

      @Nico Braun Most editors CAN (not will) substitute tabs with spaces. If that's the default behavior of an editor out of the box, it's a bug.
      Using spaces over tabs is idiotic regardless of what key you're pressing to insert them. Tabs are far more flexible and efficient.

  • @noahhastings6145
    @noahhastings6145 4 ปีที่แล้ว +221

    "Tabs or spaces?"
    Prof Brailsford: "Give me a week and I'll have the thesis in your inbox."

  • @TheThriven
    @TheThriven 4 ปีที่แล้ว +698

    I love when a video can tell me which computerphile personalities I can no longer trust.

    • @sentjojo
      @sentjojo 4 ปีที่แล้ว +64

      I think too many of them have only worked in academics

    • @caynebyron
      @caynebyron 4 ปีที่แล้ว +10

      @@sentjojo yeeeup

    • @scowell
      @scowell 4 ปีที่แล้ว +30

      Glad to see Moriarty prefers tabs... I prefer his politics too! Trump is a spaces guy I can tell.

    • @danielrdrigues
      @danielrdrigues 4 ปีที่แล้ว +17

      Spaces its to mentally disabled programmers, never had trouble with compatibility with spaces, what IDE these people is using? vanilla notepad?

    • @EgoShredder
      @EgoShredder 4 ปีที่แล้ว +8

      @@scowell Make Academia Great Again! ;-)

  • @bbdnuh1028
    @bbdnuh1028 4 ปีที่แล้ว +1282

    Real question is:
    for () {
    }
    Or for ()
    {
    }

    • @viswow
      @viswow 4 ปีที่แล้ว +137

      the latter

    • @Sierra410
      @Sierra410 4 ปีที่แล้ว +608

      First one.

    • @Ethernet3
      @Ethernet3 4 ปีที่แล้ว +46

      type the first because its fastest, have autoformat convert into w/e they want at work/uni

    • @91Wasu
      @91Wasu 4 ปีที่แล้ว +88

      for :
      😅

    • @4AneR
      @4AneR 4 ปีที่แล้ว +44

      The first for control flow like if while for, the second for blocking like namespace, class, function

  • @cre8ive65
    @cre8ive65 4 ปีที่แล้ว +307

    "Do you use Tabs or Spa-"
    "I USE ARCH LINUX"

    • @mido3ds
      @mido3ds 4 ปีที่แล้ว +36

      btw

    • @markkeilys
      @markkeilys 4 ปีที่แล้ว +4

      huh, now i want there to be a (meta)distro called "Tabs or Spaces," I wonder what the gimmick would be..

    • @Acorn_Anomaly
      @Acorn_Anomaly 4 ปีที่แล้ว +3

      @@markkeilys it randomly picks an indentation style and size for you(tabs vs spaces, width of tab/number of spaces), and forces that value on you by hardcoding it into every piece of editing software while building your system.

    • @c0smo709
      @c0smo709 4 ปีที่แล้ว +2

      I'm vegan

    • @benlyman115
      @benlyman115 4 ปีที่แล้ว +4

      @@c0smo709 Found the vegan

  • @kedarshinde4216
    @kedarshinde4216 4 ปีที่แล้ว +952

    Next is vim or emacs

    • @SuperTux20
      @SuperTux20 4 ปีที่แล้ว +58

      Or nano
      (Tbh I prefer vim)

    •  4 ปีที่แล้ว +39

      ...and while you're at it, ask the emacs users, if they happen to keep a stash of 'space cadetes keyboards', had the fundamental structure of their hands surgically altered, or how else they do it!?

    • @ayeyefookinw0tm859
      @ayeyefookinw0tm859 4 ปีที่แล้ว +26

      nano

    • @merone351
      @merone351 4 ปีที่แล้ว +18

      I prefer nano because I never read any documentation but I heard vim is nicer if you're used to it

    • @TWX1138
      @TWX1138 4 ปีที่แล้ว +8

      @@SuperTux20 pico/nano doesn't have the same global file manipulation capabilities as vi. I regularly use vi to take exported data from one application to reformat it for another, and sometimes those files are tens of thousands of lines long.
      vi is a huge pain to learn but once learned it's a lot more powerful to use.

  • @Freddan0
    @Freddan0 4 ปีที่แล้ว +216

    I press tabs 4 times

  • @iammaxhailme
    @iammaxhailme 4 ปีที่แล้ว +595

    I press the tab key, which makes four spaces.
    I originally used tab = tab until my boss complained and said I should use spaces. I didn't really care one way or the other so I just set my editor to do four spaces for a tab.

    • @zacksargent
      @zacksargent 4 ปีที่แล้ว +18

      +

    • @brnddi
      @brnddi 4 ปีที่แล้ว +179

      It surprised me how many people in the video thought that using spaces involves manually pressing the spacebar. The reason people use spaces is so that the indendation is consistent for everyone working on the project, so that eg. hanging function parameter lists are aligned correctly.
      Modern editors naturally make this easy on both fronts, allowing you to change whether pressing tab produces spaces or tabs, and to customize the tab width (anything except 4 is heresy).

    • @thomasclark2892
      @thomasclark2892 4 ปีที่แล้ว +21

      I also set my editor to do 4 spaces for a tab. I appreciate the consistency it creates across my projects, and anyone who collaborates with me tends to follow the same convention so it's nice.

    • @billigerfusel
      @billigerfusel 4 ปีที่แล้ว +19

      @@brnddi agreed. Wtf is wrong with them

    • @rinat2160
      @rinat2160 4 ปีที่แล้ว +22

      @@brnddi
      > anything except 4 is heresy
      And this is why choosing tabs invites another holywar. One can prefer tab size 4, others use 8. Somebody can indent with tabs align with spaces, others use tabs for alignment too. Latter cause formatting issues if their preferred tab size is 3 or some other number.
      In teams it's easier to force everyone to use spaces. Then code looks the same to everyone.

  • @saeedbaig4249
    @saeedbaig4249 4 ปีที่แล้ว +88

    1:29 - He sums up the advantages of tabs pretty well:
    a) Tabs allows everyone to view the code at their own preferred indentation-width. Some people prefer 4-character-long indents, some prefer 8-long, some 3-long, etc. Using tabs for indentation, everyone can set tab to look however long they want in their editor and see the indentation-width they prefer without having to change the code.
    b) Smaller file sizes. A single tab character is less bytes than 2 or more space characters.
    That said, I prefer mixed (tabs for indentation, spaces for alignment).

    • @happygimp0
      @happygimp0 4 ปีที่แล้ว +17

      a) Breaks aligment.
      b) Nobody, i mean really nobody cares about a few bytes more.

    • @himpta
      @himpta 4 ปีที่แล้ว +11

      Can you explain how it breaks alignment?

    • @azmah1999
      @azmah1999 4 ปีที่แล้ว +7

      @@himpta if you're using both tabs and spaces changing the tab width will brake alignment

    • @humm535
      @humm535 4 ปีที่แล้ว +13

      @@azmah1999 It will not. You use tabs for indenting and spaces to the right of the indentation for alignment.

    • @lobovutare
      @lobovutare 3 ปีที่แล้ว +1

      @@humm535 It will when you will want to align to what's on the last or next line. Convert them tabs to spaces.

  • @Syphdias
    @Syphdias 4 ปีที่แล้ว +181

    I feel like a lot of answers did miss the point. It is not about pressing a key once or multiple times, that's just something your editor should take care of.
    It is about you want the tab character or multiple spaces. So I'd say:
    1. Use the thing that is recommended in Style Guides or Best Practices (e.g. PEP-8 says 4 spaces are preferred)
    2. But use the thing that is already used
    3. Be consistent about it and make sure other contributers know how to configure their editors and provide a modeline (vim, and emacs probably can use it, too)

    • @Casanova646
      @Casanova646 4 ปีที่แล้ว +12

      PEP-8 states 4 spaces, not 4 tabs.

    • @Syphdias
      @Syphdias 4 ปีที่แล้ว +1

      @@Casanova646 Arg, sorry, for that. Ofc it's spaces!

    • @lost4468yt
      @lost4468yt 4 ปีที่แล้ว +21

      @@Syphdias You weren't wrong, 4 tabs is just hardcore mode. Gives you the negatives of both, and on top of that you editor probably won't like it.

    • @paulchapin7874
      @paulchapin7874 4 ปีที่แล้ว +2

      ​@@lost4468yt He was wrong. In his original statement he claimed that PEP-8, the Python Style Guide, called for the use of 4 tabs (that was of course a perfectly acceptable mix-up, but whatever). And while I'm being nitpicky: 4 tabs isn't just hardcore mode, it's totally unnecessary, and I'd go so far as to say it's bad style, because the tab is a character intended for indentation. Using 4 tabs would just mean you were on the fourth level of indentation. And most, if not all, editors are totally fine with that. (At least Vim is, and you should use vim, because it is the only acceptable editor). Ah, by the way, did I mention I use VIM?
      Edit:
      I totally agree with Syphdias, just to be clear.

    • @malporveresto
      @malporveresto 4 ปีที่แล้ว +7

      In summary: use a .editorconfig file.

  • @Alex2Buzz
    @Alex2Buzz 4 ปีที่แล้ว +313

    Dammit, spaces people aren't hammering the spacebar eight times to indent! Editors have bindings on the tab key to put the appropriate number of spaces.

    • @volundrfrey896
      @volundrfrey896 4 ปีที่แล้ว +20

      The thing is that back in the olden days it was just tha, the tab meant tab and if you wanted spaces you hammered space. And a lot of the computer scientists who work at eg. universities doing research are still using the tools from those days. Because it works great for those use-cases, less so for us who produce software at larger scales.

    • @electronicwoe
      @electronicwoe 4 ปีที่แล้ว +62

      Seriously have these people never used an editor?

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว +3

      How many spaces is appropriate?

    • @kaustubhmurumkar2670
      @kaustubhmurumkar2670 4 ปีที่แล้ว +35

      So, basically, Tabs...

    • @Alex2Buzz
      @Alex2Buzz 4 ปีที่แล้ว +13

      @@kaustubhmurumkar2670 I'm not saying the other arguments in favor of tabs are wrong. I'm just saying that this particular one is not grounded in reality.

  • @BleuSquid
    @BleuSquid 4 ปีที่แล้ว +55

    To be fair, I completely understand Professor Brailsford's opinion, because it also matters if you're just talking about indentation, or also alignment: Tabs are great for indenting code, but you would want to use spaces for comments after the code. Spaces are for fine-granularity alignment.

    • @IceMetalPunk
      @IceMetalPunk 4 ปีที่แล้ว +7

      Man, I miss comments... my workplace explicitly bans all comments, with the ideology that code should be self-explanatory and if you need comments, then your code isn't clear enough. I get what they mean, but... I miss comments :(

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 4 ปีที่แล้ว +22

      @@IceMetalPunk Code can only do what it does. Comments that describe what the code does are obviously superfluous, but ones that explain _why_ it is doing what it is doing should be essential. How could code ever be “self-explanatory” in that way? It cannot.

    • @IceMetalPunk
      @IceMetalPunk 4 ปีที่แล้ว +2

      @@lawrencedoliveiro9104 I mean, I agree with you in many cases. But there's also many cases where following the logic of the code is enough to understand why it's doing what it's doing. It depends on what the code is implementing and how.

    • @qwertyuiopzxcfgh
      @qwertyuiopzxcfgh 4 ปีที่แล้ว +16

      @@IceMetalPunk I never understood that kind of people. I'm a maintenance programmer myself and let my tell you: no matter how amazing and self-documenting your code is, comments make my job a lot easier.

    • @Spongman
      @Spongman 4 ปีที่แล้ว +4

      Professor Brailsford's answer is wrong in every respect. tabs should _only_ be used for indentation. using tabs for post-indentation alignment is always an error.

  • @__-cx6lg
    @__-cx6lg 4 ปีที่แล้ว +17

    I understand the argument that the whole point of tabs is that they indicate indentation as well as allowing editors to display them differently depending on style. I'm sympathetic to it in principle. But in some languages, including all of my favorites, you need to use spaces to get your formatting right.
    E.g., Haskell. In the standard way to style Haskell, there are tons of times when you two lines that need to be lined up with each other, to the exact character. This is called alignment, and since tab sizes vary depending on the editor, you need spaces for it.
    This doesn't mean you can't use tabs too-in principle, you could use tabs for indentation and spaces for alignment (so each line would begin with however many tabs you need to determine the context and scope, followed by however many spaces you need to make it visually align with the previous line).
    But the mixed style has an issue too. Whitespace in Haskell is semantically significant; indentation determines the program's structure (unless you use the optional braces/semicolons style, which I have never once seen outside of a Haskell manual, where it's usually relegated to a footnote). This means to answer questions like "what is the scope of this variable", you need an unambiguous interpretation of when one line is further right than another. If you arbitrarily mix tabs and spaces, this is undefined.
    Hence, the best way to code Haskell is to use spaces for everything. That's why plenty of Haskell editors don't even have an _option_ for tabs, instead automatically inserting spaces when you hit . In fact, there's even a compiler option to warn or error if there are any tabs in your source code.
    So yeah, if a language involves neither semantically significant whitespace nor stylistic alignment, then I guess I have a weak preference for tabs. But in some languages (again, including all of my personal favorites), spaces dominate.

  • @RandomUser311
    @RandomUser311 4 ปีที่แล้ว +18

    They are answering 2 different questions: Tabs or spaces in the file vs. press tab or spam space bar.

  • @RobertFisher1969
    @RobertFisher1969 4 ปีที่แล้ว +105

    My personal preference is tabs for indention & spaces for aligning (past the first graphic character on a line). This way, code automatically adjusts to the indention preference each person has set in their editor without messing up alignment. Unfortunately, the vast majority of people I’ve worked with are against using tabs at all because of the issues of using them with alignment, so I’ve adapted to using spaces for indention. And my editor is configured to insert spaces when I hit tab.
    Even better are flexible tabs where a smart editor lines up things aligned with tabs whatever the indention size is set to. But too few editors support that.

    • @NicosLeben
      @NicosLeben 4 ปีที่แล้ว +7

      That's also my personal preference. It also makes the most sense to me. I use tabs for indention and then spaces when there are multiline commands, for example multiple parameters for a function call spread over multiple lines. I then align the parameters using spaces.

    • @cjk32cam
      @cjk32cam 4 ปีที่แล้ว +3

      This approach has always seemed the ideal solution, but I’ve never got around to configure an editor to do this automatically when hitting the tab key.

    • @platinummyrr
      @platinummyrr 4 ปีที่แล้ว +5

      @@cjk32cam The problem is that someone else who doesn't have an editor configured right will inevitably screw it up again later :(

    • @europeansovietunion7372
      @europeansovietunion7372 4 ปีที่แล้ว +5

      @@platinummyrr The same applies to spaces as well.

    • @SickThought
      @SickThought 4 ปีที่แล้ว +2

      @@cjk32cam Emacs has a plugin for it (obiviously) called smart-tabs-mode

  • @astroblurf2513
    @astroblurf2513 4 ปีที่แล้ว +15

    I’m disappointed no one mentioned accessibility. Resizable tabs are important for devs with bad vision or tiny monitors. It also makes the “how many spaces to indent” question mostly subjective as long as your style guide accounts for it.

  • @freezybird
    @freezybird 4 ปีที่แล้ว +96

    The video we all actually wanted.

  • @fsmoura
    @fsmoura 4 ปีที่แล้ว +33

    Tabs for indentation that signifies structure, spaces for alignment.

  • @alxmorais
    @alxmorais 4 ปีที่แล้ว +43

    Physicist: How does matter interact? Where do we come from?
    Computer scientist: Tabs or spaces?

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว +5

      Physics: Finding order in chaos.
      Computer science: Rigorously defined chaos.

    • @LKRaider
      @LKRaider 4 ปีที่แล้ว

      Yevhenii Diomidov I like your answers

  • @brainplot
    @brainplot 4 ปีที่แล้ว +54

    The strange thing is that there's clearly a general preference for tabs but most coding standards and guidelines use spaces.

    • @GerardoOscarJT
      @GerardoOscarJT 4 ปีที่แล้ว +3

      "Most coding standards and guidelines are using spaces" wat?

    • @keithkaranu4258
      @keithkaranu4258 4 ปีที่แล้ว +4

      Probably because you can emulate tabs with spaces but not the other way around.

    • @GerardoOscarJT
      @GerardoOscarJT 4 ปีที่แล้ว +10

      @@keithkaranu4258 that is like designing only for 800x600 screens :D

    • @Lightn0x
      @Lightn0x 4 ปีที่แล้ว

      @@GerardoOscarJT You seem pretty uninformed. Look up some stuff and then come back and comment :P

    • @whossname4399
      @whossname4399 4 ปีที่แล้ว +9

      @@GerardoOscarJT the python pip is spaces, ruby is two spaces, the air bnb styleguide (seems to be the defacto JS style guide) is spaces. These are the ones I can think of without research.

  • @richardlaager4615
    @richardlaager4615 4 ปีที่แล้ว +12

    In theory: Tabs for indentation, spaces for alignment. As noted in the video, tabs semantically mean indentation and allow for per-user (viewing) customization. In practice: spaces for both, because people (especially those who are less experienced?) seem to screw up tabs in copy-and-paste, etc. How many spaces? I use 4 to keep things from being too wide, except in HTML where I use 2 because it has so many levels of indentation. When using spaces for indentation, your editor should be configured so the tab key inserts spaces, of course.

    • @thedavidd
      @thedavidd 4 ปีที่แล้ว

      100% agree.

    • @humm535
      @humm535 4 ปีที่แล้ว

      Except I don’t care about people messing up enough to ditch my tabs. Tabs, viewed 8 characters wide, for indentation, of course!

    • @encycl07pedia-
      @encycl07pedia- 2 ปีที่แล้ว +1

      If they can't handle copy/pasting, they shouldn't be employed as coders.
      If they use spaces over tabs, they shouldn't be employed as coders.

    • @marcs9451
      @marcs9451 ปีที่แล้ว

      Ruining your code style just because some moron can't copy paste properly is unacceptable

  • @chaal_upaa
    @chaal_upaa 4 ปีที่แล้ว +165

    Why do so many people think that you actually press the space bar when using spaces?

    • @TimGautier
      @TimGautier 4 ปีที่แล้ว +33

      Because academics have an academic understanding of coding not a practical one.

    • @jspiro
      @jspiro 4 ปีที่แล้ว +14

      Yeah wth is this nonsense. I’ve never manually added spaces. Tabs are idempotent with spaces and otherwise chaotic without.

    • @cplusplussizeddick1430
      @cplusplussizeddick1430 4 ปีที่แล้ว +16

      I'm totally confused by this question, the fact that 33 people have liked it, and the fact that 2 people have responding showing that they comprhended it... All I read is "why do so many people think you actually press the pedal when driving a car". How on Earth does that make any sense...

    • @-dubu
      @-dubu 4 ปีที่แล้ว +4

      He's not asking how you want your tab key to respond, because like multiple people mentioned it's pretty irrelevant. Some very proficient coders do use space to indent their code, and refuse to use the tab key.

    • @chaal_upaa
      @chaal_upaa 4 ปีที่แล้ว +10

      @@-dubu if you watch the video, multiple people answer saying they dont like spaces because you'd have to press space bar multiple times, while you might be right, I don't think your comment actually makes much sense in this context.

  • @RossBamford
    @RossBamford 4 ปีที่แล้ว +30

    In over twenty years of professional software development I don’t think I’ve ever been on a team where the standard was anything other than four spaces, no hard tabs. Obviously I hit the tab key, and the editor quietly converts it to the requisite number of spaces, no-one complains at code review, and life goes on.
    (I am now wondering if I subconsciously selected jobs where people do the right thing though 😉)

    • @filker0
      @filker0 4 ปีที่แล้ว +3

      In the nearly 40 years that I've been using C in professional software development, I've had to follow several conventions:
      * indent aligned on 4 columns
      * indent aligned on 2 columns
      * indent aligned on 3 columns
      * indent aligned on column 4, 8, 12, 16, 20, 22, 24, ....
      As for '\t' vs. spaces, the editor takes care of it. In many cases, the rules allowed hard tabs only between the end of the code and the beginning of the comments. The reason for this was to make printing the code more consistent. If you change the tab stops from the original formatting, the alignment of the text indented with tabs is lost.
      An amazing amount of coding style guidelines go back to when we used punch cards and serial terminals that had tab stop settings that could be changed over the serial line. For punched cards, there were no tab characters, however serial terminals could handle horizontal tab as a single control character.
      The horizontal tab control character was used to minimize the number of characters sent over the serial line at 300, 1200, or if you were really lucky, 9600 characters per second. The terminal driver could be set to pass HT through or to emulate HT; when emulating HT, the tab stops were set in the driver itself so it could expand HT into the right number of spaces. This requires the driver to know the position of the cursor on the current line and expand tabs appropriately; it's a pain. "stty -tabs" in a Unix environment will tell the driver to interpret HT characters rather than sending them to the terminal. On at least one system I've worked on, the lp (line printer) driver allowed setting the individual tab-stops that it would emulate. though I don't recall how many columns it allowed you to specify before it used a default interval for anything after that.

  • @Robin_Nixon
    @Robin_Nixon 4 ปีที่แล้ว +72

    Of course Professor Brailsford saw it from many directions.

    • @ghfsd786fa
      @ghfsd786fa 4 ปีที่แล้ว

      and with criteria, and giving a full explanation and comprehending the question; some of them actually thought when asked that developers hit the space bar literally for spaces

  • @alpheusmadsen8485
    @alpheusmadsen8485 4 ปีที่แล้ว +52

    I'm a tiny bit surprised that no one said "both": tabs for indentation, and spaces for formatting. If you have a while statement four levels in, but had multiple conditions that needed to be put in one line, you tab for levels in, then fill in the rest with spaces, to get to the parentheses. That way, the tabs show how things are indented, but the remaining spaces maintain the association that the conditions have with the while statement.

    • @darthmonks
      @darthmonks 4 ปีที่แล้ว +2

      Then you run into the problem of tabs being a different length in different editors. You might have a very fun time with four levels of indent and it looks very lovely in your favourite editor. But then somebody else want to read it, and they have eight levels of indent. All of a sudden your spaces don't match up at all.

    • @YourMJK
      @YourMJK 4 ปีที่แล้ว +18

      darthmonks No, that's wrong. That's the whole point of using both, to avoid this issue.
      If you use tabs only for indentation and spaces only for formatting/alignment, it will work for everyone, regardless of their current tab width.
      Consider this pseudo-code (substitute "-> " for tab and "•" for a space):
      int func() {
      -> int a = 0;
      ->
      -> for (int i = 0; i < 10; i++) {
      -> -> if (a > 0 &&
      -> -> ••••b != 9 &&
      -> -> ••••isTrue()) {
      -> -> -> doSomething();
      -> -> }
      -> }
      ->
      -> return 2;
      }

    • @bennylofgren3208
      @bennylofgren3208 4 ปีที่แล้ว

      The best standard I have come across is one (8-position) tab for the first indentation level, then indentations every four characters. Fill up with tabs as required, then if needed pad last level with four spaces. It is easy to read, easy to find functions, easy to see indentation levels and conserves line width fairly well. And it’s beautiful. 😊

    • @YourMJK
      @YourMJK 4 ปีที่แล้ว +6

      Benny Löfgren That's awful imo. Indentation should be consistent, don't mix tabs and spaces in indentation.
      If you really want this style, just get an IDE that lets you configure the width of the first indentation level.

    • @user-lt2rw5nr9s
      @user-lt2rw5nr9s 4 ปีที่แล้ว +3

      4:06

  • @psychoh13
    @psychoh13 4 ปีที่แล้ว +15

    I use the tab key to indent my code and the editor inserts spaces everywhere, and to be more precise tab formats my code rather than merely inserting spaces because it might remove indentation levels or add several of them with one key press. I don't have to hit the space key several times. I also prefer tabs because often time the indentation I need is based on the length of the functions written on the line above and it may not align with the 4 space indentation of tabs.

  • @lierdakil
    @lierdakil 4 ปีที่แล้ว +11

    After giving it a watch, I'm very surprised that the majority said "tabs". And by the number of people who seemingly don't realize that pressing the "tab" key does not necessarily mean inserting a "tab" character. For personal code, it's perfectly fine to use whatever, unless the language is indentation-sensitive (f.ex. Haskell, Python). But for collaborative code, if _that one guy_ uses tabs, it messes up everything for everyone else. And yes, one could enforce using either tabs or spaces with git hooks and style guides and whatnot. But then again, spaces are way more consistent across all the different editors and other software, like diffing tools, version control systems, etc.

  • @ianrob1201
    @ianrob1201 4 ปีที่แล้ว +25

    I would be interested to know if more industry focused people would tend to say spaces. I prefer it because it's easier to work over multiple IDEs, merge tools, etc. Also variable tab sizes fails in situations like aligning comments at the end of a line. To be fair, I'd always press tab and then rely on the IDE to fix it for me.

    • @offensivearch
      @offensivearch ปีที่แล้ว +1

      Just use tabs for indentation and spaces if you want to align within the line. That way you can change the tabstop without modifying your parameter alignment.

  • @antonm_
    @antonm_ 4 ปีที่แล้ว +12

    With the intelligence that IDEs now have, the question can be misinterpreted... are we talking about the actual unicode/ascii character or the keyboard key being pressed? Nowadays, 99% of developers press the tab key, and what gets written is dependent on what is the default for the IDE, or what is idiomatic of the programming language. Devs who work in teams use project-wide configurations, so even if half of the devs want tabs but the config uses spaces, then spaces are written.

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว +1

      The ASCII character.
      Vim automatically converts the tab key to spaces anyway if you configure it wrong.

    • @scowell
      @scowell 4 ปีที่แล้ว

      I hate that when my precious tabs require four backspaces to delete. Almost as bad as programming in proportional fonts.

    • @antonm_
      @antonm_ 4 ปีที่แล้ว

      @@scowell Most IDEs use the "Shift + Tab" shortcut to remove an indent; especially useful for when spaces are used for indents. I prefer spaces, so this comes really handy.

  • @feha92
    @feha92 4 ปีที่แล้ว +6

    disclaimer: I prefer spaces, so I might seem biased, but...
    Almost everyone in the video that said they prefer tabs claimed it was less button-presses, but that's false. It takes exactly as many presses on the tab-key, no matter what you set it to input.
    One said that its nice to ppl reading later on, but editors nowadays can easily format to users specification with spaces too (although usually needs to be done with a manual command), and there are edge-cases where if tabs were used and another user displays them differently, stuff stops lining up correctly.
    The only real difference is probably that tabbing with spaces can let you force the indent to 'weird' intervals when needed (though you might need to edit your editor to allow for it, as some make backspace equal to shift+tab by default instead). ie. when you continue a prior line and decide to indent it 1.5 times, to signify that it isn't a control-flow indent but rather continues the expression from prior line.
    Except I am fairly sure I have seen one ide that knew the language that would be used for it, and identified such continuations of prior lines, letting the user to tab like normal but have it displayed differently to achieve the same result.
    And even if your ide doesnt, there is nothing stopping you (well.. python does) from using both: tabs for indentation and spaces for alignment. Rather, many ppl argue that "Both" is the desired answer to this question.
    tl;dr the guy that said it doesn't really matter with modern editors is the one who seems to actually know what he is talking about.
    ps: the reason I use spaces is mostly because I remember horrible stuff happening when using languages with significant whitespaces back when I used tabs. They.. did not like tabs (was either haskell or python, dont remember which. maybe both). Also because I don't like the aesthetics of seeing a line followed by dots, as seems to be how most ides like displaying whitespaces (tabs and spaces respectively).

  • @angeldude101
    @angeldude101 4 ปีที่แล้ว +128

    Unless there's a global standard and something like gofmt or rustfmt, then tabs, for one main reason: I like 4 spaces, but I know not everyone else does. If you don't like 4-spaces, change your editor config so your tabs aren't 4 spaces! Your spacing preference isn't my problem and my spacing preference isn't yours!

    • @europeansovietunion7372
      @europeansovietunion7372 4 ปีที่แล้ว +13

      Project managers usually prefer spaces in order to assert their dominance.

    • @killerbee.13
      @killerbee.13 4 ปีที่แล้ว +37

      I'm a weirdo that prefers a tabstop of 3, which literally nobody would accept if I used spaces. But if I use tabs, you can't even tell that I use a tabstop of 3, because your editor's setting of 2 or 4 is just applied to the text. There's no trace of my editor preferences in the file. It's great! I have no idea why anyone does anything else.

    • @Yorick257
      @Yorick257 4 ปีที่แล้ว +2

      @@killerbee.13 yep, 3 is a golden number. 2 is too tight, 4 is too wide.

    • @TheNewton
      @TheNewton 4 ปีที่แล้ว +2

      Project managers usually prefer spaces to insure a successful project

    • @AloisMahdal
      @AloisMahdal 4 ปีที่แล้ว

      Your "main reason" does not actually speak for spaces OR tabs, you could rewrite it: "I like tabs, but I know not everyone else does."

  • @Gengh13
    @Gengh13 4 ปีที่แล้ว

    Soundcheck questions are awesome. It's really entertaining hearing all the different opinions.

  • @NeinStein
    @NeinStein 4 ปีที่แล้ว +2

    The most alienating message of this video to me is, how people seem to use editors, which force them to type either spaces OR tabs multiple times in succession by hand!?

  • @HansPeter-qg2vc
    @HansPeter-qg2vc 4 ปีที่แล้ว +5

    Haha, I really like that almost all of them are in team tabs and that even the spaces guy in the end changed his opinion. Also: It's great that he uses Emacs.

  • @josephs.7960
    @josephs.7960 4 ปีที่แล้ว +146

    My tab button is just a macro for 4 spaces

    • @bardes18
      @bardes18 4 ปีที่แล้ว +22

      You monster.

    • @black_platypus
      @black_platypus 4 ปีที่แล้ว +10

      I hope that's just within your editor and not system wide?

    • @kurodashinkei
      @kurodashinkei 4 ปีที่แล้ว +7

      Indeed - when the editor is set to insert spaces when you press tab, you can get other intelligent behaviour like "I highlighted text, I want the tab key to increase the indent of the highlighted lines". If it's a system-wide macro, it's "I highlighted text, I want the tab key to replace it entirely with 4 space characters"

    • @TimeTravelingFetus
      @TimeTravelingFetus 2 ปีที่แล้ว

      Why? Just... why? Joke or not, I know some people actually do this. What's the point?

  • @SRG-Learn
    @SRG-Learn 4 ปีที่แล้ว

    I just discover this format, really clever. You get a nice natural soundcheck and at the same time get a survey, i'm gonna remember that if anytime I make a series.

  • @zyighzag4050
    @zyighzag4050 4 ปีที่แล้ว +5

    I've read an interesting thread on twitter a few time ago :
    Someone was saying he would prefer spaces for no particular reason. Then he realized that someone of his team was visually deficient, and everytime he pulled from git repo, he had to convert every spaces to tab, set tabs aspect to 1 space and zoom as f to have something he could read. Then he would convert to spaces before he pushed to git.
    Main reason why to use tabs, it's easier for people with visual deficiency to use the code :)

    • @kevinorr54
      @kevinorr54 4 ปีที่แล้ว

      Not sure I'm following. He converts every space to a tab, and then sets tab width to 1? How does this change anything visually?

    • @zyighzag4050
      @zyighzag4050 4 ปีที่แล้ว

      @@kevinorr54 if you zoom and have 4 white spaces on the left, the way he had to zoom make it a huge space on the left. Having tabs allowed him to make it the same blank space as one space, which was more comfortable to read.
      In a way, i don't really care as i read 4 spaces the same as one tab on my computer. Just hearing of a visually deficient prefering tabs over spaces for his own comfort was the only time i've heard a valid argument in the war spaces against tabs, and i just felt like sharing :)

    • @kevinorr54
      @kevinorr54 4 ปีที่แล้ว

      @@zyighzag4050 Oh! I see. He effectively makes it so that n spaces take the width of 1 space. I guess that's an argument in favor of the tabs+spaces style (I can't believe I'm saying this)

  • @hansb1337
    @hansb1337 4 ปีที่แล้ว +45

    set tab size to 1 and press 4 time

    • @TheNewton
      @TheNewton 4 ปีที่แล้ว +1

      😈hahaha there's a prank in there somewhere

    • @Baekstrom
      @Baekstrom 4 ปีที่แล้ว +4

      Congratulations. You managed to find the solution that makes both camps unhappy.

    • @hansb1337
      @hansb1337 4 ปีที่แล้ว

      @@Baekstrom my intention exactly ;)

    • @markkeilys
      @markkeilys 4 ปีที่แล้ว

      use > indention

  • @teof99
    @teof99 4 ปีที่แล้ว +228

    The real question is: which tab size? #team4

    • @SuperTux20
      @SuperTux20 4 ปีที่แล้ว +54

      Always 4 :)
      Psychopaths use 3 or 5
      VIM users use 8

    • @galier2
      @galier2 4 ปีที่แล้ว +22

      and that is axactly the problem with tab

    • @Egzvorg
      @Egzvorg 4 ปีที่แล้ว +36

      @@galier2 how is this a problem?

    • @glenmatthes8839
      @glenmatthes8839 4 ปีที่แล้ว +72

      @@galier2 I would argue that's the benefit of tab. If you like 4 and I like 2 then I set my editor for 2, you set yours for 4, and everyone is happy. But if we use spaces, then my 2 is too tight for you, and your 4 is too spread out for me. From there, battle lines are drawn, armies of software developers choose sides, and we take out the entire internet as we battle whether 2 or 4 spaces is appropriate.
      Moral of the story: use tabs - save the internet.
      P.S. Tux Penguin is right - only psychopaths use 3 or 5

    • @DanielMonteiroNit
      @DanielMonteiroNit 4 ปีที่แล้ว

      Yes

  • @zeikjt
    @zeikjt 4 ปีที่แล้ว +3

    When I have a choice, tabs. The fact that most great text editors let you choose the indentation size is a great mechanism so that people with different expectations can get what they want.

  • @Rickety3263
    @Rickety3263 4 ปีที่แล้ว +5

    Bash scripting HATES too many tabs. Spaces are always safe

    • @Verrisin
      @Verrisin 4 ปีที่แล้ว +2

      agreed. *Spaces are always safe.*
      Tabs bring chaos.

  • @biehdc
    @biehdc 4 ปีที่แล้ว +5

    just set your editor to interpret 4 spaces as a tab and everyone can be happy and use whatever they want :)

  • @RPGillespie
    @RPGillespie 4 ปีที่แล้ว +139

    What's up with all these presumably computer literate people thinking that the people who prefer spaces mash the space bar?

    • @AnttiBrax
      @AnttiBrax 4 ปีที่แล้ว +21

      Because you end up doing it. You like to pretend that the editor takes care of everything but if you observe your coding critically you'll notice the amount of indentation tinkering you do.

    • @RPGillespie
      @RPGillespie 4 ปีที่แล้ว +19

      @@AnttiBrax Wrong, with vscode I use tab and shift+tab exclusively for indentation. Most of the time vscode auto-indents based on if I just pressed enter after a curly brace

    • @spronkey
      @spronkey 4 ปีที่แล้ว +10

      @@RPGillespie What about the times you accidentally hit your cursor 1 character before the start of your line? Or you select a couple of your indenting spaces? I'm 100% sure you've encountered this at least once.

    • @RPGillespie
      @RPGillespie 4 ปีที่แล้ว +7

      @@spronkey VSCode auto-intents so I rarely need to physically press tab or shift-tab. But when I do, it's usually block-level operations (highlighting a block of code and intenting or unindenting the entire block). Also, how is accidentally highlighting a few leading spaces any different from accidentally highlighting a leading tab?

    • @Gloubichou
      @Gloubichou 4 ปีที่แล้ว +2

      ​@@spronkey Not if you use your editor properly. Don't use the mouse to move the cursor: use the key that brings you to the beginning of the line.

  • @turpialito
    @turpialito 4 ปีที่แล้ว

    Fascinating topic. Well done, guys. Cheers!

  • @markusr3259
    @markusr3259 4 ปีที่แล้ว +144

    holywar.exe

    • @ayeyefookinw0tm859
      @ayeyefookinw0tm859 4 ปีที่แล้ว

      Mark Randall
      > mfw the world ends because people think tabs < spaces

    • @user-vn7ce5ig1z
      @user-vn7ce5ig1z 4 ปีที่แล้ว +4

      If only all conflicts were as benign as nerd conflicts. :-\

    • @alurma
      @alurma 4 ปีที่แล้ว +6

      holywar.sh

    • @patrik5123
      @patrik5123 4 ปีที่แล้ว +3

      holywar.py

    • @LividImp
      @LividImp 4 ปีที่แล้ว +3

      There is no holy war here. There are only those that are right (TABS), and those that will soon fertilize the fields (spaces).

  • @floomp4657
    @floomp4657 4 ปีที่แล้ว +90

    I am freaking out about the guy who said 1 tab = 3 spaces. What kind of tabs is he using?!?

    • @DonovanDMC
      @DonovanDMC 4 ปีที่แล้ว +14

      You can change the tab size, some people have 2/3, but I believe the normal is 4 spaces per tab

    • @RymdTeknisten
      @RymdTeknisten 4 ปีที่แล้ว +3

      Some editors have soft tabs (actually spaces) and you can set the amount of spaces

    • @gentoobr
      @gentoobr 4 ปีที่แล้ว +1

      I know, right?!

    • @alexanderhuliakov6012
      @alexanderhuliakov6012 4 ปีที่แล้ว +1

      I have 1 tab = 3 space at VS Code.

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว +1

      Obviously tabs should be measured in points, or ex, not in spaces.
      Is that quad spaces?

  • @slap_my_hand
    @slap_my_hand 4 ปีที่แล้ว +20

    [holy war mode activated]
    Tabs make so much more sense. Their width can be customized, you can skip through indentation levels with a single key press and there is no confusion between 3 and 4 spaces.
    Also, the curly brace goes on a new line.

    • @mavoc3094
      @mavoc3094 4 ปีที่แล้ว

      The issue becomes, what if you are trying to align things at the end of the line(like comments) and the beginnings have different layers of indention. With customizable tab lengths, the alignment will be off, so forcing a fixed tab width becomes important for a project. Which is why hitting the tab to place x number of spaces is generally best on large teams as the IDE will auto add spaces to the next tab layer.
      You do realize that the curly brace means different things in different languages right?

    • @user-zz6fk8bc8u
      @user-zz6fk8bc8u 4 ปีที่แล้ว

      @@mavoc3094 Elastic tabstops (how tab should really work) fixes all those issues

    • @mavoc3094
      @mavoc3094 4 ปีที่แล้ว

      @@user-zz6fk8bc8u Elastic tabstops does not solve the issue when lines of code with various levels of leading indentation need to have parts of their code be lined up.
      some code //lined up comments
      more code //lined up comments
      more code //lined up comments
      etc

  • @ITR
    @ITR 4 ปีที่แล้ว +1

    Tabs for indentation, spaces for alignment. Though obv use whatever standard the project you're working on uses.
    My problem with spaces is that if I press left next to an indent, I get sent one character left rather than to the previous indent. Most editors probably have a setting or plugin to change this, but it's almost never default

  • @ryansteffer
    @ryansteffer 4 ปีที่แล้ว

    You can tell how long someone has been writing code by how quickly and fiercely they answer this question.

  • @Gokuroro
    @Gokuroro 4 ปีที่แล้ว +8

    Firstly, most of people who answered don't really know that using tabs in most programming focused text editors will actually transform tabs into a pre-configured number of spaces. So almost half of the answers don't even make sense. Secondly, although I personally use spaces (through pressing the TAB button), tabs are more semantically correct to be used, since you have 1 indentation character per indentation level, and you can leave the actual interpretation of "how many spaces does an indentation level take" to the person reading/creating the code.

  • @tenseikenzx-3559
    @tenseikenzx-3559 4 ปีที่แล้ว +7

    I use the physical tabs button to insert 4 spaces for my code through the editor. But I would use spaces to align it further for something like one liner getters and setters. It gives me a lot of precision to organise my code to however I want.

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 4 ปีที่แล้ว

    I used to use the tab key, but only in editors where you could customize it to go in steps of four columns. This still caused problems looking at the text in other programs which did not have such an option.
    So I switched to spaces. Now I know my formatting will look the same regardless of what program is displaying it.
    For backward compatibility, I still have Emacs configured to sniff the file on opening; if it detects tabs, then the tab key generates tabs in that buffer, otherwise pressing tab inserts spaces.

  • @Nerdsown
    @Nerdsown 4 ปีที่แล้ว +19

    This issue concerns software engineering far more than computer science so you will get more passionate answers from software engineers.
    The answer is to have the editor convert pressing the tab key to spaces and ban tab characters from the code. Code is often viewed using a variety of tools on different people's machines where tab may be represented as a different number of spaces. By using spaces the code is always formatted correctly no matter how its viewed. This avoids incorrectly flagging formatting errors in QA and when devs work with someone else's code it wont look like garbage on their editor.
    Computer scientists don't need to concern themselves with high quality code because very few people read it or maintain it.

    • @hielke2332
      @hielke2332 4 ปีที่แล้ว +3

      I also remember a stackoverflow survey that correlated preference for spaces with more open source contributions, and higher salary.

    • @platinummyrr
      @platinummyrr 4 ปีที่แล้ว

      @@hielke2332 which is a bit funny considering Linux style forces tabs and treating tab as 8 spaces.

    • @icesentry
      @icesentry 4 ปีที่แล้ว +1

      There's an argument to be made that for blind programmers tabs are much better than space for screen readers. Also people consider the configurability of the tab length to be a feature not an issue.

    • @gloverelaxis
      @gloverelaxis 4 ปีที่แล้ว +1

      @@bosstowndynamics5488 No, they can't, because spaces are also used for alignment. Web developers understood the importance of separating a document's *meaning* from its context-specific *presentation* decades ago, and the rest of you still haven't grokked this incredibly simple and vital concept.

  • @ashimkarki9652
    @ashimkarki9652 4 ปีที่แล้ว +22

    The consequence of TAB VS SPACE is shown in silicon valley very nicely

    • @BrieoRobino
      @BrieoRobino 4 ปีที่แล้ว +14

      Not really, no one presses space 8 times.

    • @BrieoRobino
      @BrieoRobino 4 ปีที่แล้ว

      @NEON SONIC ALPHA yes

  •  4 ปีที่แล้ว +27

    Spaces, because they look consistent across all viewers and editors. Almost nobody presses 4 spaces, editors do that for you.

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว

      No, they don't.
      The spaces in Noto have a different width than the spaces in Fira.

    •  4 ปีที่แล้ว

      @@davidwuhrer6704 this seems like a troll, but I will feed it: I meant consistent relatively to other characters in the same program, whereas tabs are sometimes set to take place of 2, 4, or even 8 characters depending on the program, or command line tool (like 'git diff').

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว

      @ Tabs don't have a size as such, they align along vertical lines.
      If you mean indentation: That should be measured in points, not characters.
      `git diff` pipes output through `less` (unless configured otherwise), and you can set tabwidth in `less` with an environment variable. You can also set tabstops in most terminals using the `cols` command, but `less` ignores that.

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว

      @M. de k. Fonts don't do aligning.

    •  4 ปีที่แล้ว +1

      @@davidwuhrer6704 yeah I am aware that you could possibly configure it in every single tool that you use. But then there still is going to be some gitlab, github, or bitbucket service, which will again do it differently, and at that point I say, I'll just use spaces.

  • @dexterrik
    @dexterrik 4 ปีที่แล้ว +3

    Can you make a video about indentation styles, coding standards and the history and uses of some of them? That would be amazing!

  • @sacredgeometry
    @sacredgeometry 4 ปีที่แล้ว

    Also: "I just press the tab button and hope for the best ... sometimes it works"
    Is so perfectly British!

  • @MrGeekGamer
    @MrGeekGamer 4 ปีที่แล้ว +9

    I'm a tabs man, but as Prof. Brailsford points out, there are often times when it just doesn't work properly between editors. Spaces always seem to be handled consistently.

    • @bborkzilla
      @bborkzilla 4 ปีที่แล้ว

      Try maintaining code that's been around for more than a year or two and that has been modified by several people, all of whom have different ideas about spacing. And no, "Just Refactor It" doesn't solve the problem either - because new bugs, expense, et. al.

  • @calvin7330
    @calvin7330 4 ปีที่แล้ว +34

    NOBODY actually presses space each time they want to indent, they just set the editor to insert the spaces when the tab key is pressed.

    • @kevinbee4617
      @kevinbee4617 4 ปีที่แล้ว +3

      Yes, and some editors automatically indent after you type "{" or ":

    • @fghsgh
      @fghsgh 4 ปีที่แล้ว

      ...unless you use 2 spaces and reaching over to the tab key is not worth it.

    • @briansonof
      @briansonof 4 ปีที่แล้ว +2

      So.... Tabs?

    • @fghsgh
      @fghsgh 4 ปีที่แล้ว

      @@briansonof No. A tab is the TAB character \011, space is \040. This is stored in a completely different way. When you bind the tab key to a number of spaces, those spaces are stored, not the tab character.

  • @LMFinney
    @LMFinney 4 ปีที่แล้ว +1

    It seems that people answered two different questions here:
    1. What keyboard key do you use for indentation?
    2. What character do you use to represent indentation in the files?
    Depending on the editor, the answers aren't necessarily coupled.

  • @mikefochtman7164
    @mikefochtman7164 4 ปีที่แล้ว

    Tab key, with the editor setup to recognize the language and map the tab key to the proper auto-indent macro (I use emacs, but I'm sure other editors can do this as well). And the auto-indent macro inserts the correct number of spaces, so when others open the file in their editor, it still appears similarly.

  • @leofreitasa9933
    @leofreitasa9933 4 ปีที่แล้ว +33

    Tabs

    • @jdmnissan
      @jdmnissan 4 ปีที่แล้ว +3

      Space

    • @Monk-E
      @Monk-E 4 ปีที่แล้ว

      @@jdmnissan taba

    • @europeansovietunion7372
      @europeansovietunion7372 4 ปีที่แล้ว +3

      Says the dude with a profile picture of SPACE! xD

    • @charmdoesart9272
      @charmdoesart9272 4 ปีที่แล้ว

      tabs and spaces, depending on mood

    • @leofreitasa9933
      @leofreitasa9933 4 ปีที่แล้ว

      @@europeansovietunion7372 ;(

  • @kb3dow
    @kb3dow 4 ปีที่แล้ว +4

    Spaces. Makes the appearance consistent across different user desktops and user settings regardless of the individuals settings.

    • @humm535
      @humm535 4 ปีที่แล้ว

      That defies the reason, individual settings exist. Tabs!

  • @bobthecannibal1
    @bobthecannibal1 4 ปีที่แล้ว

    The horizontal tab is ASCII character 9, and Unicode U+0009.
    Setting your tab stop to whatever width works for you, once, means I'm not forcing my indentation preference on you or anyone else, and by using tabs instead of spaces you aren't forcing yours on me.
    Set your tab stop and use tabs; it's more polite.

  • @locust76
    @locust76 4 ปีที่แล้ว

    Tabs 4 Ever.
    1) customizable indentation in an editor
    2) special characters that can be searched for and used for things, such as delineating columns in a CSV-file
    3) perfect text alignment in word processing applications
    4) faster than using multiple spaces

  • @stolz_ar
    @stolz_ar 4 ปีที่แล้ว +4

    0:28 has the best answer I've ever heard in my life. I've been using spaces for a long time, just because most people in my career history used spaces. Never got a real answer, but for consistency's sake I've stuck with spaces. Semantically we all should be using tabs and, as he said, you can later adjust tab sizes for your personal preference, but with spaces you can't really do that. I've been converted!

  • @martinkamarabrunson
    @martinkamarabrunson 4 ปีที่แล้ว +50

    Soft tabs! I would never press the space button multiple times, but I prefer to have spaces because then you can move the cursor in straight lines. As opposed to tabs where the cursor aligns with the beginning of the tab.

    • @RymdTeknisten
      @RymdTeknisten 4 ปีที่แล้ว

      So agree

    • @ElijsDima
      @ElijsDima 4 ปีที่แล้ว

      I just press down spacebar and hold it long enough to insert 4 characters. Single button press ftw.

    • @GerardoOscarJT
      @GerardoOscarJT 4 ปีที่แล้ว +1

      How does your editor when the cursor down to an empty line and then go up again? Magic!?!? Decent editors store the column when cursor is moving horizontally and do not modify It when cursor is moving vertically.

  • @IceMetalPunk
    @IceMetalPunk 4 ปีที่แล้ว +1

    I was self-taught as a programmer until uni, and at first I used Windows Notepad and never indented. Years later, when I started writing code for other people to learn from, I realized no one else could easily read my code, so I started indenting with spaces, because Notepad's tabs are all kinds of way too wide. When I switched to Notepad++, I still used spaces out of habit. It wasn't until I got my first professional job in the industry, and started using VSCode, that I switched to using tabs all the time. So, yeah, it definitely depends on (a) who you're writing code for, (b) what language you're using, and (c) what IDE you're using.

  • @SteinGauslaaStrindhaug
    @SteinGauslaaStrindhaug 4 ปีที่แล้ว

    I just press tab and the editor will insert 2 or 4 spaces depending on the language and/or some linter will keep the styling consistent. In Go that turns out to be actual tab characters because that's the convention there, everywhere else it's usually spaces.

  • @deterligegyldigt
    @deterligegyldigt 4 ปีที่แล้ว +4

    tabs for indentation, spaces for alignment.
    so use spaces for aligning parameters split over multiple lines, tabs for the standard indentation.
    Argument: you can have your own personal tab size, but alignment has to be exactly the right place.

  • @TetraluxOnPC
    @TetraluxOnPC 4 ปีที่แล้ว +56

    Wait - do people that prefer tabs assume that people who use spaces have to press space three extra times to indent their code? That can't be right, surely.

    • @jordanzimmerman7590
      @jordanzimmerman7590 4 ปีที่แล้ว +7

      I get the feeling there are a surprising number of people who've never seen an IDE

    • @modernkennnern
      @modernkennnern 4 ปีที่แล้ว +4

      I've never really understood the question; Does it mean they have the 'tab indentation' in the code, or that they use the tab key to indent?
      I don't know any code editor I've used in the last many years that actually have the tab indentation anymore, like how Microsoft Word and similar does indentation

    • @jordanzimmerman7590
      @jordanzimmerman7590 4 ปีที่แล้ว +6

      @@modernkennnern Another comment here got it right. I'll bet most people who think they're using TABs are actually using spaces courtesy of their editor.

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว

      @@modernkennnern How do you write your makefiles?

    • @TetraluxOnPC
      @TetraluxOnPC 4 ปีที่แล้ว +2

      @@jordanzimmerman7590 Not even an IDE - just a text editor that you press TAB in :grin:

  • @k1ngjulien_
    @k1ngjulien_ 4 ปีที่แล้ว

    the button but its converted to 4 spaces when saved to disk. that way you don't have issues with mixing the two.

  • @44r0n-9
    @44r0n-9 4 ปีที่แล้ว

    At TU Graz we learn to use spaces, and in some courses it's also graded.
    To me it's clearly spaces, because you can just set your editor to make 4 (or any number you want) spaces by pressing tab, and it will look the same on every editor.

  • @playerguy2
    @playerguy2 4 ปีที่แล้ว +3

    Big proponent of "tabs for indentation, spaces for alignment"
    often you need to align something and spaces will reliably do it, but this way it also gives you all the bonuses of tabs.

  • @henlofrens
    @henlofrens 4 ปีที่แล้ว +3

    Haskell: what are tabs? They just make my compiler explode

  • @xybersurfer
    @xybersurfer 4 ปีที่แล้ว

    tabs for indentation and spaces for aligning is best. but it's hard to check if if you did it right (especially if the editor also formats automatically), so i uses spaces for both. my tab key inserts multiple spaces

  • @CesarScur
    @CesarScur 4 ปีที่แล้ว +2

    It amazes me that no one explained why this debate is a thing and why the char to be saved is preferably the space. Since I started, almost 20 years ago, any coding software would convert tabs for spaces to maintain visual coherence between different systems. Different coding softwares could render the tab differently prompting a second dev to change indentation only to be changed again by the original dev. To avoid this back and forward, a standard space was used.

    • @drunkenmonkey1457
      @drunkenmonkey1457 4 ปีที่แล้ว +1

      So you're saying people should set their tab width properly? :)

  • @alcesmir
    @alcesmir 4 ปีที่แล้ว +6

    With a decent editor it literally doesn't matter. I prefer spaces because it makes sure that the display of code is consistent everywhere, but with my editor the editor experience is no different. The tab key indents to the next tab stop and removes until the previous tab stop. I don't mind if you use tabs for indentation, just don't mix them. (Tabs for indentation and spaces for alignment is perfectly fine though.)

  • @BTrain-is8ch
    @BTrain-is8ch 4 ปีที่แล้ว +29

    I bet a bunch of the tabs people are using spaces and don't even realize it.

    • @sentjojo
      @sentjojo 4 ปีที่แล้ว +9

      It's like they were answering tab key vs space key instead of tab chars vs space chars

    • @TheAudioCGMan
      @TheAudioCGMan 4 ปีที่แล้ว +2

      I really hate to find out that I used spaces accidentally.

  • @Corsairtux
    @Corsairtux 4 ปีที่แล้ว +2

    In my experience spaces are preferred in professional world. Probably the reason being that code is more often shared between multiple Devs. (I'm assuming that this might not be the same in the academic world) Not to mention that often linters are used to maintain a shared style. Probably in the academic world they just don't bother about it. The point of having to hit many time the space bar is silly because pretty much all editors are configured so that you can hit tab and X spaces are inserted.

  • @martineyles
    @martineyles 4 ปีที่แล้ว

    I would answer with a question: Proportional or fixed character width font?
    Use tabs with proportional fonts in text documents and use spaces (inserted with the tab key) with fixed character width fonts in code. When quoting code in documents, use the coding standard for code blocks.

  • @canyon_online
    @canyon_online 4 ปีที่แล้ว +20

    absolutely in awe they think that using spaces means pressing the space bar n times. people who use spaces just press tab

  • @menachemsalomon
    @menachemsalomon 4 ปีที่แล้ว +20

    Next question needs to be: "How wide are the tab stops?" or "How many spaces?"

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว +6

      How wide are the tab stops? Whatever you want them to be. They are tabs.
      How many spaces? Let the flame wars begin.

    • @nooneyouknow4312
      @nooneyouknow4312 4 ปีที่แล้ว +2

      4 for code, but 2 for xml-ish

    • @humm535
      @humm535 4 ปีที่แล้ว

      8

  • @andy.robinson
    @andy.robinson 4 ปีที่แล้ว

    I generally stick to PSR-2 so I'm a spacer. But the misconception here is that people DO NOT press 4 times! Hit once and the editor gives 4 spaces and auto-aligns.

  • @DaVince21
    @DaVince21 4 ปีที่แล้ว

    I code using the tab key to quickly indent and deindent. It's nice that it also works on block selections of code. But I let the IDE deduce (or decide) whether it should actually put spaces or not, because different languages and projects usually have a different convention in this.

  • @Tinfoilpain
    @Tinfoilpain 4 ปีที่แล้ว +3

    People answering "It takes more presses" don't realize that nobody uses the spacebar to indent, just maps the tab key to insert N spaces. It then is formatted correctly throughout.

    • @markkeilys
      @markkeilys 4 ปีที่แล้ว

      what I'm hearing with this is everyone should use tabs with their editor set to display N spaces.

  • @JoshuaKisb
    @JoshuaKisb 4 ปีที่แล้ว +136

    the real criminals are IDE creators who dont auto convert and Python creators

    • @Mtaalas
      @Mtaalas 4 ปีที่แล้ว +34

      White space for syntax is evil

    • @nathanrcoe1132
      @nathanrcoe1132 4 ปีที่แล้ว +7

      There is also the estoteric whitespace language that also makes whitespace characters meaningful semantically in programs

    • @josephs.7960
      @josephs.7960 4 ปีที่แล้ว +1

      Use a curly brace lib

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 4 ปีที่แล้ว +5

      @@Mtaalas Luckily, Python’s use of whitespace is pretty much consistent with my formatting conventions anyway.
      I do still put in “#end” comment lines. If nothing else, it gives Emacs something to jump to, so I can quickly move between the beginning and ending of a block just by looking for lines with the same indentation level.

    • @GodBreathed77
      @GodBreathed77 4 ปีที่แล้ว +4

      So glad for white space indentation. No arguments about where brackets go, and I don’t have to spend forever making sure my brackets are all closed properly. Not that I can’t work my way through it, but damn was that always annoying when editing existing code. I get to spend my time being productive rather than dealing with formalities. Even if I don’t agree with the way things look it’s nice to know that you can’t have idiots not indenting their code and getting away with it.

  • @mattlm64
    @mattlm64 4 ปีที่แล้ว

    There's a difference between the spacebar and tab keys, and the tab and space characters, hence the confusion. I have vim setup to insert spaces when I hit the tab key.
    The number of people answering tabs is odd to me as I seem to come across spaces more often in codebases. The reason I switched to spaces was because of the large number of codebases I found with spaces instead of tabs. Maybe a lot of people were thinking about the tab key vs the spacebar key, in which case the tab key is always the most sensible option.

  • @pev_
    @pev_ ปีที่แล้ว

    I prefer tabs, but I use a tab width of two because the default (four or was it even eight early on) is usually too much, two spaces are enough to clearly identify indentation and not making lines unnecessarily long with multiple indentations. AND I mention it in the documents that the code is originally formatted with a two-space tab indentation.

  • @ninadsachania3652
    @ninadsachania3652 4 ปีที่แล้ว +17

    Next Q&A should be what editor they use.

    • @sentjojo
      @sentjojo 4 ปีที่แล้ว

      That would be very revealing

    • @jordanzimmerman7590
      @jordanzimmerman7590 4 ปีที่แล้ว +4

      I sense it's Notepad :D

    • @ElijsDima
      @ElijsDima 4 ปีที่แล้ว +1

      Some has got to say *nano*

    • @TheHaters112
      @TheHaters112 4 ปีที่แล้ว +1

      I'm gonna get hate but atom or VS

    • @GerardoOscarJT
      @GerardoOscarJT 4 ปีที่แล้ว

      The edit command from MsDOS

  • @kevinfontanari
    @kevinfontanari 4 ปีที่แล้ว +6

    I use the tabs button, but I set all my editors to convert those automatically to spaces so it's just one button press and it's more consistent across editors and systems.

    • @koga7349
      @koga7349 4 ปีที่แล้ว +1

      Until you backspace and have to delete individual spaces instead of a single tab character

    • @davidwuhrer6704
      @davidwuhrer6704 4 ปีที่แล้ว

      How many spaces?

    • @trefmanic
      @trefmanic 4 ปีที่แล้ว

      @@koga7349 But why would you use backspace? All sane editors allow to change indentation level, like Shift-Tab in SublimeText.

    • @koga7349
      @koga7349 4 ปีที่แล้ว

      @@trefmanic I know you can shift + tab but you should be able to use backspace also. You can with tabs. One less thing you can do with spaces

  • @mrlithium69
    @mrlithium69 4 ปีที่แล้ว

    Nobody besides Bagley and Brailsford mentioned anything about the history of alignment differences. Only mono-spaced / fixed-width terminal fonts (like Courier) would not be affected by this. In the context of a word processor we usually use proportional fonts, so 4 spaces in 1 font would align differently than in another font, but Tab means fixed-width Indentation (regardless of font) - something entirely different than X number of spaces. BTW one Tab in hex is 0x09, and one Space is 0x20. The conversion is up to the program/settings. Also if you had bandwidth/space concerns, but uncompressed Ascii encoding was required, one 0x09 tab is more efficient than multiple spaces (0x20 0x20 0x20 0x20).

  • @threeMetreJim
    @threeMetreJim 4 ปีที่แล้ว +2

    I like tabs but when you open in a different editor it can look odd if the tab spacing settings are different. Sometimes with spaces, depending on the font (if it isn't a monospace type) the indentation can be all over the place.

  • @fsmoura
    @fsmoura 4 ปีที่แล้ว +23

    all the plebs saying _"tabs because I don't want to press space a bunch of times"_ should go on strike until the sweatshop owner that employs them buys a real editor and they can stop indenting their code manually

    • @falconne
      @falconne 4 ปีที่แล้ว +5

      Yeah I also don't get how people still use that argument. Are they writing code in Notepad? Also, auto-indentation and auto-formatting have been in programming editors since the advent of vim (and probably much earlier) so you rarely even need to press tab.

    • @IceMetalPunk
      @IceMetalPunk 4 ปีที่แล้ว +2

      To be fair, even the best editors can screw up indentation at times while you're in the process of deleting and editing code, and then you need to manually fix it. (Or trigger an auto-format of the document, but then it might reformat other parts of the code and bloat your diffs.)

    • @Verrisin
      @Verrisin 4 ปีที่แล้ว

      all free editors (that do not come bundled with windows) are already sane.

  • @gabrielketzer7084
    @gabrielketzer7084 4 ปีที่แล้ว +6

    These are the real questions we should be asking.

  • @mikaelhenriksson1796
    @mikaelhenriksson1796 4 ปีที่แล้ว

    You should totally ask these geniuses for their favourite text editor. I would love to know!

  • @DoctorX17
    @DoctorX17 4 ปีที่แล้ว

    Yes
    If I open someone else's code, I'll use whatever they used. If I'm in the Arduino IDE, it's spaces [always 2 spaces]. If I'm in Visual Studio, it's usually tabs if I'm starting from scratch. Otherwise it depends on my mood. But I try to be consistent within one file/project