Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sure, I would have preferred a non-branching:

std::string pad = descriptive_name_here(path);

with the added bonus of being able to add "const" to that, for the benefit of the reader.

This is not relying on compiler implementation! Can you name one language that has strings that initialise to anything but a valid object containing an empty string?

This is not an obscure side-effect. This is like assuming "std::vector<int> v;" creates an empty vector, not a undefined-state vector container.

(I don't want someone coding C++ as if all objects are references. Coding in one language as if it were another is a well-known antipattern)



In Java the default value for a String (or any object) is null, not an empty string.


Did you not read my whole comment? Please read the whole thing before replying.


Read the whole comment. Still don't see nothing that invalidates my answer to "Can you name one language that has strings that initialise to anything but a valid object containing an empty string?".


You specifically mentioned Java, and I specifically mentioned reference-based languages, with Java being the most obvious example.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: