VK-GL-CTS icon indicating copy to clipboard operation
VK-GL-CTS copied to clipboard

Using tabs for alignment

Open krOoze opened this issue 5 years ago • 8 comments

I have seen code here which uses tabs for code alignment (not just indenting), e.g. https://github.com/KhronosGroup/VK-GL-CTS/blob/master/external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp

AFAIK that is the incorrect usage of tabs. It assumes tab is always 4 spaces and behaves consistently across editors. Tabs should be used only for indentation, never for code alignment.

Little tricky to fix, so probably nothing to be done, except clarify the styleguide and stop doing that in any new code. And perhaps sic clang-format at this code base at some point (though I hate that tool since it breaks other nice code).

krOoze avatar Jan 15 '20 14:01 krOoze

Yeah, the code base uses tabs incorrectly all over the place. vktBindingDescriptorSetRandomTests.cpp for example I was one I was just looking at. It looks horribly and is almost impossible to edit.

baryluk avatar Mar 06 '20 19:03 baryluk

Sometimes I feel people troll tabs on purpose. No wonder Rust rather goes with spaces like it is the 16th century... </righteous indignation>

krOoze avatar Mar 06 '20 20:03 krOoze

Sometimes I feel people troll tabs on purpose. No wonder Rust rather goes with spaces like it is the 16th century... </righteous indignation>

Totally irrelevant. You can use spaces or tabs, or both, or make a mess, even in Rust, your choice.

baryluk avatar Mar 06 '20 22:03 baryluk

@baryluk Do not try to nitpick. Point was I am happy this repo chooses to use tabs. And I am sad it gives them a bad name by using them in the wrongest way possible. Just let me have this "sigh" moment please, ok? It wasn't meant to be a conversation starter...

krOoze avatar Mar 06 '20 23:03 krOoze

The code style is outlined in framework/delibs/coding_guidelines/de-coding-guidelines.html. For tabs look at section 6. external/vulkancts follows that coding style which is owned by Google. Any complaints regarding the code style please direct to Google trackers. Bear in mind that reformatting the repo with a tool like clang-format will screw up commit history.

alegal-arm avatar Mar 08 '20 10:03 alegal-arm

@alegal-arm There's nothing that wrong with the code guide per-se, except people apparently do not read it, or they misunderstand it.

Anyway I cannot find more appropriate open tracker. The code guide is apparently not maintained, and you already modified it in this repo anyway.

Bear in mind that reformatting the repo with a tool like clang-format will screw up commit history.

So does fixing this manually. (Well, technically history is still alright. It only makes blame little bit harder.)

My main complaint against clang-format is it scrambles valid code constructs of people that already strive to make code nice and readable for others.

krOoze avatar Mar 08 '20 15:03 krOoze

The code style is outlined in framework/delibs/coding_guidelines/de-coding-guidelines.html. For tabs look at section 6. external/vulkancts follows that coding style which is owned by Google. Any complaints regarding the code style please direct to Google trackers. Bear in mind that reformatting the repo with a tool like clang-format will screw up commit history.

The problem is that the codebase in this repo is not actually following these coding guidelines. The guidelines looks good to me. The issue is the code is not conforming to them.

baryluk avatar Mar 18 '20 16:03 baryluk

I would go one step further and say the guidelines are as good as irrelevant. They are hidden in some weird deep directory. They are some custom guidelines inherited from some 3rd-party that nobody would ever bother to read (and Google has other C++ guidelines). They have not been updated in forever. They are full of TODOs. And if one would want to petition for a change to it, the original is in some closed-source repo and nobody needs the red tape (at least all my internet searches points me back to this repo).

So I would say this is practically a "just do what others are doing" repo. And this Issue just points to a violation of best practices of C++.

But if we are still talking about the guidelines, they say:

Code should be indented with tabs (instead of spaces) and a tab-width of 4 characters should be used.

The last sentence is nonsense. There's no reason to be prescriptive of tab size. It is just an editor setting, not something that is part of the source code. If tab is ever only used for indentation (as it should be), then tab-width is irrelevant.

Also all the examples in the guidelines are also wrong, because they use spaces for indentation.

krOoze avatar Mar 19 '20 12:03 krOoze