Is it “bad practice” to use tab characters in string literals?

后端 未结 2 703
执笔经年
执笔经年 2021-01-19 06:22

As a follow-up on Is it mandatory to escape tabulator characters in C and C++? (do note I\'m not the author of said question).

I\'ve learned such code is considered

2条回答
  •  走了就别回头了
    2021-01-19 07:15

    Using tabs in litterals instead of escaping them ('\t',"\t") is a bad practice because :

    • the reader is not immediately aware that there is a tab. Consequence: wrong assumptions about code, wrong changes (for example when allignemnt of code output needs to be adapted)
    • the tab expansion might be different depending on your editor. Consequence: hindering of teamwork and maintenance, as different people may see different layouts.
    • MOST OF ALL: some editors convert tabs to spaces when saving your source file (using the configured tab expansion settings) getting rid of such embedded tabs. Consequence: unnoticed/undesired change (f.ex: when a teammember uses such an editor and make a minor edit, not even in this string).

提交回复
热议问题