Bikeshedding: Placeholders in strings

Posted by dotancohen on Programmers See other posts from Programmers or by dotancohen
Published on 2013-06-27T15:55:08Z Indexed on 2013/06/27 16:28 UTC
Read the original article Hit count: 169

Filed under:

I find that I sometimes use placeholders in strings, like this:

$ cat example-apache
<VirtualHost *:80>
    ServerName ##DOMAIN_NAME##
    ServerAlias www.##DOMAIN_NAME##
    DocumentRoot /var/www/##DOMAIN_NAME##/public_html
</VirtualHost>

Now I am sure that it is a minor issue if the placeholder is ##DOMAIN_NAME##, !!DOMAIN_NAME!!, {{DOMAIN_NAME}}, or some other variant. However, I now need to standardize with other developers on a project, and we all have a vested interest in having our own placeholder format made standard in the organization. Are there any good reasons for choosing any of these, or others? I am trying to quantify these considerations:

  1. Aesthetics and usability. For example, __dict__ may be hard to read as we don't know how many underscores are in there.
  2. Compatibility. Will some language try to do something funny with {} syntax in a string (such as PHP does with "Welcome to {$siteName} today!")? Actually, I know that PHP and Python won't, but others? Will a C++ preprocessor choke on ## format? If I need to store the value in some SQL engine, will it not consider something a comment? Any other pitfalls to be wary of?
  3. Maintainability. Will the new guy mistake ##SOME_PLACEHOLDER## as a language construct?
  4. The unknown. Surely the wise folk here will think of other aspects of this decision that I have not thought of.

I might be bikeshedding this, but if there are real issues that might be lurking then I would certainly like to know about them before mandating that our developers adhere to a potentially-problematic convention.

© Programmers or respective owner

Related posts about coding-style