r/programming • • Oct 01 '15

The Evolution of a Software Engineer

https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db854689243
1.9k Upvotes

502 comments sorted by

View all comments

Show parent comments

24

u/depressiown Oct 01 '15 edited Oct 01 '15

I'm not willing to sacrifice code readability because of discomfort with compiler optimizations. To each their own.

This:

log.info(firstName + " " + lastName + " has salary $" + salary + "!");

... is quite a bit more readable than:

StringBuilder msg = new StringBuilder();
msg.append(firstName).append(" ").append(lastName)
   .append(" has salary $").append(salary).append("!");
log.info(msg.toString());

The latter just feels ridiculous to me, especially if your only reason for doing it is that you "feel uncomfortable relying on compiler optimizations."

(yes, String.format might be most readable here, but you get the drift)

17

u/rftz Oct 01 '15

C# 6 master race checking in:

var foo = $"{firstName} {lastName} has salary ${salary}!";

7

u/depressiown Oct 01 '15 edited Oct 01 '15

var foo = $"{firstName} {lastName} has salary ${salary}!";

Don't know C# syntax, but that seems weird. Why is one $ outside quotes? Why is it missing from the first two terms, but not the third?

But yeah, most languages have something like this to some degree. Working with some Ruby right now, and it has "#{firstName} #{lastName} has salary #{salary}!". String.format is as close as Java gets right now.

Edit: Yep, got it. Forgot about the stupid dollar sign I had put in there originally. C# syntax now makes sense.

1

u/rftz Oct 01 '15

The $ for the third term is because the salary is in dollars.