News for hackers. Stuff that matters.
Re:Baidu File System – A distributed file system for real-ti... by GoToRO on Tuesday October 25, 2016 @07:16AM (#12786893)
It's not about initialization, it's more about specifying clearly what happens in all cases.

Anyway the reason for which it would no pass review is that today you use one compiler, tomorrow you have to use another and then you have to review all these little details again. It's about saving money more than anything and you do that by not relying on compiler behavior.

Re:Baidu File System – A distributed file system for real-ti... by bn-usd-mistake on Tuesday October 25, 2016 @07:59AM (#12787126)
It is specified clearly though. The behavior is not compiler dependent, it's specified in the C++ Language standard. See http://en.cppreference.com/w/cpp/language/default_initializa... and http://www.cplusplus.com/reference/string/string/string/

If a different compiler breaks this behavior, it's not standard compliant and thus could do all sorts of stuff in every possible line, including in:

    std::string pad = "";
Re:Baidu File System – A distributed file system for real-ti... by GoToRO on Tuesday October 25, 2016 @08:11AM (#12787186)
Standards change. Don't they?
Re:Baidu File System – A distributed file system for real-ti... by knorker on Tuesday October 25, 2016 @12:31PM (#12789308)
So how can you use operator= or copy constructor of string?

The '= ""' won't help you.

Re:Baidu File System – A distributed file system for real-ti... by consz on Tuesday October 25, 2016 @08:18AM (#12787221)
Do you think that's any more likely than the constructor of std::string changing?
Re:Baidu File System – A distributed file system for real-ti... by knorker on Tuesday October 25, 2016 @08:03AM (#12787147)
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)

Re:Baidu File System – A distributed file system for real-ti... by rbadaro on Tuesday October 25, 2016 @08:25AM (#12787268)
In Java the default value for a String (or any object) is null, not an empty string.
Re:Baidu File System – A distributed file system for real-ti... by knorker on Tuesday October 25, 2016 @12:22PM (#12789216)
Did you not read my whole comment? Please read the whole thing before replying.
Re:Baidu File System – A distributed file system for real-ti... by rbadaro on Saturday October 29, 2016 @09:54AM (#12823935)
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?".
Re:Baidu File System – A distributed file system for real-ti... by knorker on Monday October 31, 2016 @12:48PM (#12838538)
You specifically mentioned Java, and I specifically mentioned reference-based languages, with Java being the most obvious example.
Re:Baidu File System – A distributed file system for real-ti... by knorker on Tuesday October 25, 2016 @06:53PM (#12792490)
Looks like I can't edit, so I'll create another comment.

I ran into this article that puts quite nicely why the problem isn't the "else", but the "if" itself:

https://medium.com/@bartobri/applying-the-linus-tarvolds-goo...

This is what I meant in the other comment by preferring the non-branching.

Re:Baidu File System – A distributed file system for real-ti... by pritambaral on Tuesday October 25, 2016 @07:57AM (#12787111)
> the reason for which it would no pass review is that today you use one compiler, tomorrow you have to use another

Good thing then that it's mandated by the language reference, and not up to the compiler to decide. According to C++11, §21.4.2/1, an uninitialized std::string should be an object of class std::basic_string with non-null data and a size of 0.