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 "bad practice". The comments seem to be suggesting the same thing. However, for some reason the standard allows this trickery so somebody must either found no harm in it or has a use-case for it.
Is not escaping tabulator characters widely accepted as "bad practice"?
While there is nothing inherently wrong with the use of string literals, there is room for improvement. String literals very often lead to stringly typed code, a play on strongly typed.
The behavior is undefined if a program attempts to modify any portion of a string literal. Modifying a string literal frequently results in an access violation because string literals are typically stored in read-only memory.
Character literals represents alphabets (both cases), numbers (0 to 9), special characters (@, ?, & etc.) and escape sequences like \n, \b etc. Whereas, the String literal represents objects of String class.
You can include predefined String values within your code as string literals. A string literal is a sequence of characters surrounded by double quotation marks ( " ).
Using tabs in litterals instead of escaping them ('\t'
,"\t") is a bad practice because :
I've never really thought about it, but I can't imagine finding literal tabspace characters a good idea because you cannot immediately distinguish them from standard whitespace. If you need a tabspace in your string literal for some specific reason, it's more clear and explicit to write \t
so that everybody knows precisely what you intended to do.
By the way, the notion that there must be a good use case just because the standard allows it … is somewhat broken. For example, the standard allows us to declare raw pointers, and to write new
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With