Death to the Space Infidels!

Clean, well formatted code is essential. I think we can all agree to that. :slight_smile:

I work on a system that uses an old VBScript 4.0 implementation for scripting things the software can’t perform and to do data validation in particular instances. This system, due to its architecture, is limited to 60k characters per script with the ability to include other scripts.

To keep simpler scripts to one file we settled on keeping blank lines to a minimum, using comments sparingly once the script was applied, and tabs instead of spaces to keep the file size down.

I too have been guilty of cleaning up code I had to maintain just to make it easier to work with.

Formatting, down to the the type of characters used for whitespace formatting, is important and will vary by the environment.

Something cool about tab idents is that you can make your code breath as you want according to your screen size. Eg: If you have a wide screen, it will be easier to read code with tabs set at 8 chars width. With normal screen you could prefer 4 chars, or 2 chars on a small screen or terminal. All recent editors allows you to change the tab width.

Personally I like to choose the font I use for coding, why couldn’t I also decide the width of the code identation ?

One other issue that combines with this one is: do you have a maximum line length?

It’s been established that when text is below a certain width, your eyes can take in the entire text of a line without moving horizontally; conversely, if the text exceeds that width, your eyes have to track horizontally to get the entire content of the line. This horizontal tracking slows reading considerably. The exact width varies from person to person, but is greater than 80 characters for most people.

This can impinge on tabs-v-spaces arguments. If you think that a line should be no more than 80 characters wide, the representation of a tab becomes important, because line with a 3-character tab might not exceed the 80-character limit while a 4-character tab will.

An alternative is to consider only the non-tab space for the purposes of determining maximum width. (Your eye is still taking in the entire line at once so long as the width from the end of indentation to the end of the line is not exceeding the limit.) The problem then is quickly determining when you’ve exceeded the 80-character limit. (This is easily done when not ignoring text by simply making sure your editor opens with an 80-character width.)

As my friend Matt is fond of pointing out, if we were to store source files tokenized rather than as text files, then this entire debate would disappear. You could then display source files according to your preferences, and I could display them according to mine. But alas, 60 years of accumulated history has weighed us down with the notion that code must be stored in text files. Why? Historical reasons!

By the way, a good working defintion for any process that is done for Historical Reasons (synonym: Tradition) is that no one remembers why it is done that way; it has just always been that way.

Thus we, the most intelligent people on the planet, are fighting over how to format our language, even though it has long been in our power to make the issue irrelevant.

Excuse me while I go reformat my coworkers code…

@those arguing that code is easier to read - given a wide enough screen - with tabs that are 8 spaces wide, you must use Java.

Having to scroll your eyes horizontally to read code that’s across different lines doesn’t make it easier to read. Not all code has really long lines…

That said, I learned a long time ago that 3 spaces is an amazing in-between for the conciseness of 2 spaces and the verboseness of 4 spaces. I have VIM configured to insert 1, 2, or 3 spaces to reach the tabwidth of 3.

I used 2 space characters, no tab (well, tab = 2 space characters).

Tabs are like hidden bombs, they’re not predictable. If I press backspace one time will I jump back one character or number of characters per tab characters? There’s no telling, unless you turn on some kind of UI helper, which is distracting. It’s like playing minesweeper with your code :slight_smile:

If I press backspace one time will I jump back one character or number of characters per tab characters?

Complain that the shovel handle is broken, not that the ground is so far away that you have to bend halfway down to scoop it up.

Python solves this by not allowing either the semi-colon or tab issue affect developers. Python code is some of the cleanest, minimal, and correctly formatted code that is all the same. Refreshing…

I indent my code with spaces, but I’m lazy so I wrote a macro that automatically inserts spaces when I press the TAB key.

guys, guys guys,

look at the title of this post. then look at how he closes.
this is clearly a guy who is at conflict with himself and
only posting flame-bait :slight_smile: thanks @jeff.

there was a time when jeff actually educated you or was insightful
(as opposed to inciteful)now, lately, he just writes cleverly
worded stuff to provoke debate.


insert picture of self with pinky to chin pose
or any other graphic that shows you for your true
evil genius


insert picture of self with pinky to chin pose
or any other graphic that shows you for your true
evil genius


insert picture of self with pinky to chin pose
or any other graphic that shows you for your true
evil genius

Back in college I worked with one guy who insisted on using Hungarian Notation for variable names, even though no one else on the team had heard of it except me. We almost got into a fistfight over it… and the ensuing rift hurt our grade too because we hadn’t properly managed to work together. :frowning:

Still better than using Hungarian Notation though. :wink:

Really though, arguments or not you should use whatever is standardized by the company. (Our school’s coding standards were NOT to use Hungarian Notation, of course.)

I actually don’t understand the reason for using spaces. One of the points of contention between different programmers is how far they want to indent their code. Some programmers prefer large indents, some programmers prefer small indents. Using spaces, nobody will end up happy, but using tabs, everyone can set their own indent size. And for the places where you want to use spaces because you’re not indenting scopes but characters, you still can.

What is the reason for wanting to use spaces? Can anyone explain?
Coding style and formatting are pretty arbitrary, but a project is much easier to follow if everyone uses the same style. Individuals may not agree with every aspect of the formatting rules, and some of the rules may take some getting used to, but it is important that all project contributors follow the style rules so that they can all read and understand everyone’s code easily.

Tab in Emacs indents the current line depending upon the language settings you’ve set up, always has. It’s one of the things you need to understand when you start using it. You can choose tabs or spaces. Ruby uses 2 spaces by convention so that’s what I use. I think I’d prefer tabs sometimes so I could see how far something’s indented but that’s not the standard.

If you’re running one of the code completion engines and are at the end of a line then it will do that instead.

Emacs also has an indent-region command that applies the conventions of the language you’re using to a selected region. These conventions are entirely user-configurable.

I’m curious: why are people pressing the tab key at all? If you’ve got auto indent on it will indent when it detects a block being opened, not just Emacs but nearly every decent editor (including Vim). Also, as many others have said, just run a code beautifier on it as part of the check-in process (not hard).

I was amused by the idea of editing some kind of artefact instead of code - how would you version control it? Text works and is really easy.

NB not prettifying is one of the things you should do in OSS, because it makes the check-ins huge and hides the real changes you made.

The other good thing about spaces is that it means 3 to 7 extra keystrokes so you look that bit busier…

The office where I work uses Visual Studio 2005 which has its own ideas about coding conventions. I worked with someone (who has now left) who didn’t believe in them. I think he spent more time reformatting code than actually writing it.

I have a huge suspicion that almost all of the above preachers have a random mix of indent tabs and sections of indent spaces plus the occasional evil non-indent tab thrown in too, in their code. To be absolutely consistent, you have turn on whitespace visibility in your editor. If you’re a tab guy, you have to actually look at your code at different tab sizes (both very big and very small) to make sure you don’t get magic tab size syndrome (where your code is only readable at the magic undocumented tab size). Space guys need to a run a tab detection program over their source every now and then.

It’s really easy to get bits of contrary formatted code into your source, just a copy and paste from the net or some editing on a new editor.

Both sides suck. Tab guys need to know a huge amount of theory about how tabs fall apart. Space guys need find a sophisticated editor that does backspace unindents and they have to dig into the preferences to set it to spaces on every new install (as tabs are normally the default); it should also have a tab char alarm bell and a convert between different sized indent amounts (but you won’t find these functions anywhere).

I think nano/pico have always done elastic tabs, a feature I like a lot.