Hacker News new | ask | show | jobs
by tadfisher 3826 days ago
> Why can't our source control software take code indented any way, any how, and convert it to your personal preference when you pull the repo? It's not like we enforce what color syntax highlighting you use or what font.

Because the mapping from one whitespace style to another is not a bijection. Moreover, our source control tools rely on things like content hashes which change when even a single bit of the source has changed, and sometimes even our language parsers depend on whitespace format.

Frustrating, I know, but you will not see a resolution to this problem with automated tools alone. You will, however, when the Tab key is removed from keyboards altogether :)

3 comments

Wouldn't this feature be similar to how Git converts line endings?

https://help.github.com/articles/dealing-with-line-endings/

It would probably have to be configured per repo so that it doesn't mess with tab delimited files etc.

Auto CrLf is a terrible thing that can change the meaning of programs. Source control shouldn't be changing the contents of files (though a hook to format wouldn't be bad necessarily).
Auto CRLF is awesome for languages I use. Which ones can it change meaning in?
Any language that allows string literals to wrap lines without normalizing it. Like C# or F#. Anything with HERE docs might do it, but Ruby and Python seem to normalize.
But I have seen a solution to this problem, back in subversion days. With help from perl-tidy and php-tidy.

Pre commit hooks, combined with an appropriate *-tidy program for your language. Code is formatted according to the repo tidy config with a pre-commit hook and formatted according to the developers preference on checkout.

I'm missing why whitespace style mapping is not a bijection, you do have to accept some limits to code style in terms of completely rigid indentation rules, and it is obviously language specific. But it seems to be a bijection to me, what am I missing?

I believe mapping is 1:1 when only the initial indentation is used with tab/space, and further indentation is done with spaces.