flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Heap > Tabs vs. Spaces

Author
Thread Post new topic Reply to topic
VEG



Joined: 06 Feb 2013
Posts: 70
Location: Minsk, Belarus
Tabs vs. Spaces
First of all, a short and funny movie about the subject: https://www.youtube.com/watch?v=SsoOG6ZeyUI =)

I've noticed that sources of FASMG use both spaces and tabs:
Image
Actually, I always use visible tabs and spaces (most editors allow you to display tabs and spaces), so I always notice such inconsistency. What's wrong with it? It just means that when tab size is different from the size in the author's editor, the formatting of the source code will look a bit broken, like on my previous screenshot. I suppose that the author uses 8 as the tab size, and it has to look like this:
Image

The solution is easy. Just always use tabs for indentation and spaces for alignment. Such code will look nicely in every editor independently on tab size, and it is still will be possible to choose preferable tab size (for example, I prefer tab size = 4).

So, we are using tabs here (for indentation):
Image

And we are using spaces here (for alignment inside lines):
Image

For example, Notepad++ has a plugin (the TabIndentSpaceAlign plugin) which automatically chooses between tabs and spaces in different situations. So, it always uses tabs in beginning of any line, and spaces when any other symbols than tabs are on the left of the current line.

Description of the plugin:

Quote:
Support using tabs for indent and spaces for alignment. It does a couple things. First, when you insert a new line it will exactly copy the preceding indent, instead of turning tabs to spaces or vice-versa. Second, if you insert a tab anywhere in the indentation part of a line (which is considered to be from the beginning of the line to the first non-tab) it will insert a tab, otherwise it will insert spaces.


Some other editors may name such behavior as “Smart Tabs”, and it can be enabled in settings. And yes, you can always do it without any plugins, but automatic solution is better, of course Smile

Example. Before:
Image

After (tab size = 4):
Image

Tab size = 8:
Image

Tab size = 2:
Image

So, any tab size can be used and the source will look ok.
Post 22 May 2017, 14:54
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6676
Location: Kraków, Poland
The schemes in my sources are made by the "Optimal fill on saving" option of "flat editor" (the editor core used in FASMW and FASMD). This option is inherited from the DOS Navigator's editor which "flat editor" tries to mimic in many features. The editor by itself does not use tabs at all, it just has a freely navigable whitespace. With this option turned on it automatically converts any area of whitespace into a sequence of DOS-sized tabs and spaces that makes the smallest file. Turning this option off makes the editor fill all the whitespace with spaces only, which preserves it better for other editors.
Post 22 May 2017, 16:04
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
I think the point was that "Optimal fill on saving" is only optimal is the user also sets their tab size to 8. Any other value make the "Optimal fill on saving" not so optimal.
Post 25 May 2017, 16:31
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6676
Location: Kraków, Poland

revolution wrote:
I think the point was that "Optimal fill on saving" is only optimal is the user also sets their tab size to 8. Any other value make the "Optimal fill on saving" not so optimal.

Yes, of course. This is a legacy of the DOS days when there was only one tab size for everyone. Wink (And the "optimal fill" phrase is also a legacy, it was named this way in DOS Navigator.) If we allow variable tab size, the only way to preserve the exact whitespace structure is to not use tabs (only spaces) and this is what "flat editor" does when that option is turned off. Perhaps I should make FASMW have the "optimal fill" turned off by default, I don't know.
Post 25 May 2017, 16:59
View user's profile Send private message Visit poster's website Reply with quote
VEG



Joined: 06 Feb 2013
Posts: 70
Location: Minsk, Belarus

Quote:
the only way to preserve the exact whitespace structure is to not use tabs (only spaces)

It is better to use tabs for indentation and spaces for alignment. It is more flexible.
Post 25 May 2017, 18:16
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6676
Location: Kraków, Poland

VEG wrote:
It is better to use tabs for indentation and spaces for alignment. It is more flexible.

In case of assembly language this distinction is not well-defined. It is usual to have at least a label column, instruction mnemonic column and operands column, and each needs to be aligned properly even when the previous one is missing. You can have label on the same line as instruction, sometimes you might even want to put an instruction prefix before the mnemonic column so that the main instruction is aligned with the other mnemonics (and not operands). Or you may split longer operand lists into multiple lines with "\" (and have a line that starts right at the operand column). Thus for a pure assembly language it just an alignment everywhere (note that the "smart tabs" feature, another one inherited from DOS Navigator, nicely fits into this). Though, of course, indentation shows up in case of macros and nested block directives.

Therefore the only real solution to the problem of "portability" of source text between editors with different tab sizes is to fill everything with spaces, preserving the exact measurement for every indentation and column alignment. And this is what "flat editor" does by default (but FASMW overrides it by turning the "optimal fill" option when initializing a new configuration).
Post 25 May 2017, 19:26
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
Hehe:

https://arstechnica.com/information-technology/2017/06/according-to-statistics-programming-with-spaces-instead-of-tabs-makes-you-rich/

Quote:
"But what about those enlightened souls who use tabs for indentation, spaces for alignment?" you may ask. Sadly, they are indistinguishable from the other tab users.

So If you want to make more money use spaces!

Also related: http://www.tylervigen.com/spurious-correlations Very Happy
Post 19 Jun 2017, 23:21
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 891
Nah, that part is true. Indenting with spaces is better since the best indentation is 2 spaces, anything more is a waste. Plus, with tabs you can "customize" the indentation, even though no tab width is 2 spaces by default (so it sucks).

Customization is bad. People should be forced to read code indented with 2 spaces, whether they like it or not. Because it's smarter. Clearly my opinion is law. Wink

That said, the article is pure bullshit, I mean really it said PHP and Perl? That's kind of ridiculous typo for Java and Python...
Post 20 Jun 2017, 11:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
There seems to be an accepted wisdom that indentation is the "proper" thing to do, and that only the amount of spacing is in question.

But what if there is a better way? Instead of having indentation, as thus no arguments over how much indentation to apply, maybe something else entirely? Perhaps some sort of colouring scheme? A different font size? Or a different lead character that isn't whitespace, perhaps a bracketing layout? Maybe some combination of these?

Furs wrote:
That said, the article is pure bullshit ...

Of course it is, see the final link I posted. Razz
Post 20 Jun 2017, 12:14
View user's profile Send private message Visit poster's website Reply with quote
nyrtzi



Joined: 08 Jul 2006
Posts: 187
Location: Off the scale in the third direction

revolution wrote:
But what if there is a better way? Instead of having indentation, as thus no arguments over how much indentation to apply, maybe something else entirely?



I've gotten so old and tired of the whole issue that I've just switched to using automated formatting tools whenever I can so that I don't have to waste time fine-tuning missing or extraneous whitespace. I much rather just select the block of text that needs reformatting, press a key combination and be done with it. Or tell the tool to reformat a bunch of files in place. After all why bother doing it manually if the machine can do it for you better and faster than you ever could? Just install the tool and tweak the default config file it dumps until things look the way you want. Unless you're doing something weird you don't need to tweak it more than once.

If all relevant tools would also understand and support automated formatting properly for both input and output then would people even need to be having this discussion for anything other than two people with different preferences viewing code on a shared screen?
Post 05 Aug 2017, 20:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.