Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

28
  • 113
    Maybe you should add a counterexample: const char DELIMITER = ':' would be actually useful. Commented Jul 6, 2016 at 19:03
  • 116
    I would make several arguments that EMPTY_STRING is beneficial. (1) I can much more easily find all uses of EMPTY_STRING in a file than I can find all uses of "". (2) when I see EMPTY_STRING I know for darn sure that the developer intended that string to be empty, and that it is not a mis-edit or a placeholder for a string to be supplied later. Now, you claim that by me making this argument that you may qualify my knowledge, and safely ignore me forever. So, how do you qualify my knowledge? And are you planning on ignoring my advice forever? I have no issue either way. Commented Jul 6, 2016 at 22:32
  • 39
    @immibis: We can stop thinking about these things as useful in the context of managing change. They're constants. They don't change. Think of them as useful in the context of humans searching and comprehending the semantics of code. Knowing that something is a key-value-pair-delimiter is much more useful than knowing it is a colon; that is a fact about the semantic domain of the program's concern, not its syntax. Commented Jul 6, 2016 at 23:14
  • 15
    @EricLippert: I'm kinda seeing the point of others here who point out that the only guarantee that a const provides is that it won't change at runtime (after compilation), though I do agree with you that the semantic meaning of the constis far more important than its use as a change management tool. That said, I can certainly imagine a const EARLIEST_OS_SUPPORTED which is not only semantically consistent, but will also change over time as the program evolves and old cruft is removed. Commented Jul 6, 2016 at 23:23
  • 16
    @DanielJour: So this then is a third argument for EMPTY_STRING; that a well-designed IDE will surface tools that allow me to treat this entity symbolically, rather than syntactically. Generalize this to a fourth argument: that the library of code analysis tools that sits below the IDE may allow for advanced programmatic analysis of code correctness at the symbolic level. A developer who wishes to take advantage of tools more advanced than those written literally 40 years ago need only make small changes to their habits in order to reap the rewards of advanced tooling. Commented Jul 7, 2016 at 19:23