Readable code

C#, Development, PHP

Earlier I have tend to do string concatenation when building strings in PHP and also c#. But with sprintf (PHP) and string.format (C#) I see that my code, or at least the string building, is becoming easier to read.
What I am talking about is this:
PHP:
Less readable:
$string = “Hello “.$name.”, how are you today”;

More readable:
$string = sprintf(“Hello %s, how are you today”, $name);

or even more readable:
$tring = “Hello {$name}, how are you today”;

c#
Less readable:
var name = “John Doe”;
var someString = “Hello” + name + “, how are you today”;

More readable:
var name = “John Doe”;
var someString = string.format(“Hello {0}, how are you today”, name);

What do you think?

Leave a Reply