Is your feature request related to a problem? Please describe.
I cannot use tabs for indentation. This seems extremely counter intuitive for a whitespace sensitive language.
Describe the solution you'd like
I would like to be able to use tabs for indentation. I find they are far better to work with in any language and especially in languages that are whitespace sensitive. Tabs make it far harder to miss an extra or missing space causing an indentation related error.
Describe alternatives you've considered
I can enable #indent "off" but that is obviously not a solution because it simply removes all whitespace sensitivity
This has previously been decided in F# and is a design decision. This will not change.
I understand that it has been set this way allready.Could you perhapse give a justification beyond: "it is that way because it is already that way"?
Tabs are variably-sized. Spaces are not. Tabs result in different indentation for different computers.
Again I am aware of this. Infact in my opinion that is a positive of tabs. What is not an opinion however is the fact that tabs, a character specifically designed for indentation -that for me at least, is far better- Is not supported for indentation.
Now my opinion on the tabs Vs spaces debate. Which I don't believe is really relevant here.
I don't see the argument that tabs can be different as a very good one.For most people they are standard at 4 spaces and for the few people that want to change it, they can. For example people with visual impairments who would like a much larger gap, or people on small screens who might want a smaller one.
There's a general policy that if there's been a discussion before and it was declined, that it stays that way (there are exceptions to that rule, esp wrt c# interop, but it's quite rare). In the F# suggestions page, there's a guide line about this. Obviously, we can't expect everyone to know the whole history, so imo it's perfectly fine to ask, but sometimes that's the answer: won't do for reasons that have been discussed at length in the past (in this case, F# 1.0, prior to moving to github).
More info on the argument here: https://github.com/fsharp/fslang-suggestions/issues/104
@Happypig375, haha, posting at the same time ;)
Actually half a minute before ya, just GitHub updates previous comments when you comment :wink:
@faldor20, you can see the notes on the design process here: https://github.com/fsharp/fslang-suggestions/blob/master/README.md
Note that the primary reason for not allowing tabs is that they're contextual, and that different editors will have different spacing settings. And since writing code without spaces is not possible, it becomes non deterministic whether a visually aligned (or malaligned) block should belong together.
Personally, I just set every editor I have to "convert tabs to spaces" and sharing code (also with other languages) is never a problem. When I receive code (a friend of mine sticks to 3 spaces per tab and mixes spaces and tabs in code and xml), I first have to normalize it to make it readable. I'm very happy that that will never happen with F#.
Okay thankyou for clear that up. I did a search of the hit issues but couldn't find anything and so assumed it was uncontested.
I am disappointed but I understand.
I still probably have around 2-3 annoying indentation moments caused by subtly different indentation or trying to move one indent in or out ever time I sit down to code f#. That's why I felt like I really needed a good explanation.
Thanks again, sorry for wasting your time. :)
Visual Studio has:
So indentation is not as hard as it seems.
I understand tabs can be different from one person to another. However I don't see how that can ever change relative alignment. You shouldn't be able to misalign a piece of code by making all tabs smaller or larger
Think about when spaces and tabs are mixed together
Oh I see your point about mixing, but that seems like a non issue. Don't mix them. Protecting people from themselves is silly.
Even with that you could add is a linting rule to show warnings when mixing.
```fs
// tab
// spaces
let a = 1 // all spaces
let a = 1 // all tabs
Sorry what?? No one thinks we should get rid of spaces. I just ment for indentation. Obviously right?
I'm most some kind of crazy space hating tab evangelist.
Don't mix them. Protecting people from themselves is silly.
It's not possible not to mix. How else will you use the undentation rule? Remember that it's allowed to undent by one or two spaces to better align parens, curlies, sq brackets. There's no such thing as a tab that's one space less than other tabs. Ergo, you'll always end up mixing.
Besides, people sometimes vertically align equal signs, pipes, or single line comments for readability. Do that with tabs, and they'll look different in each and every editor.
And another thing: ever tried pasting code to the web or another editor that has tabs? Each time I do that with C# code, I have to replace tabs with spaces (on SO there are many code examples where the poster doesn't do that, leading to hard to read code).
I hear and understand all you arguments. I get that mixing them can be problematic if done thoughtlessly. I see all that and still think if I want to use tabs I should be able to.
However all that said, I do understand that it has been ordained and I can't change it.
"Suck it up or use Haskell"
And that's fine.
It'll likely always be a contentious issue, look how vehemently the pros and cons are defended in this discussion for python (it allows both, but official guidelines strongly favor spaces, but that doesn't deter many users to use tabs regardless): https://stackoverflow.com/q/119562
In short, I'm glad that there's no real discussion for F#, because the rule to use spaces is enforced. That may sometimes be unfortunate, but I prefer there's clarity to the matter.
Btw, I don't know what editor you use, but in VS it's best to turn smart indentation on. It'll allow you to use the tab key, and backspace key, and it'll introduce enough spaces to align your tab size, or delete enough until the previous indent.
Same works with alt-select, and normal select,in which case shift-tab undents the line.
On Haskell: as far as I know, one tab is given the same weight as a single space. If any user ever mixed tabs and spaces, that'll wreak havoc to readability. From what I gather from a quick search, spaces are the way to go in Haskell too, though it'll take another century before that's fully settled ;).
(in languages where white space is irrelevant, I prefer tabs, like in C#, but only at the start of the line. And most companies I worked with enforced that).
I use vscode and the damn smart indentation is broken for f#. I probably wouldn't have ever been annoyed enough to even post this if that worked flawlessly. But it doesn't even work at all and the extensions meant to replace it are a bit buggy.
@faldor20, then we should fix it. On my system, only smart paste is buggy, I don't use it. Smart indent works.
Please, submit a bug report, as these things need to be fixed so that you and others can work more easily with it.
That's what I was going after with this :) thought I'd try the root problem. However that will be my next step.
Closing due to acceptance but not satisfaction ;)
@faldor20 if you have a good repro of smart indent throwing you off in VSCode, please file an issue over here: https://github.com/ionide/ionide-vscode-fsharp/issues
@faldor20, I feel your pain, we've all been there at some point in time. As an aside, you may want to have a look at the coding guidelines wrt to whitespace. They are just that, guidelines, but most of what's in that document is applied in many open source F# projects, and it never hurts to have a guide that promotes consistency in coding practices (or in case you need to convince a coworker to stop using 3 spaces ;).
Haha well I think we can all agree that tabs Vs spaces must be put aside to fight the true evil that is 3 space indentation. ;)
I'll tell my coworker exactly that! (it's true, he swears by 3 spaces)
Seems I forgot to give the link to the guidelines I was referring to: https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#general-rules-for-indentation
Most helpful comment
It's not possible not to mix. How else will you use the undentation rule? Remember that it's allowed to undent by one or two spaces to better align parens, curlies, sq brackets. There's no such thing as a tab that's one space less than other tabs. Ergo, you'll always end up mixing.
Besides, people sometimes vertically align equal signs, pipes, or single line comments for readability. Do that with tabs, and they'll look different in each and every editor.
And another thing: ever tried pasting code to the web or another editor that has tabs? Each time I do that with C# code, I have to replace tabs with spaces (on SO there are many code examples where the poster doesn't do that, leading to hard to read code).