4 ms·
All languages have pitfalls. Including the author's beloved Java. For example: String x = "foo"; String y = "foo"; // Appears to work but compares ref
by 430gj9j 14y ago
All languages have pitfalls. Including the author's beloved Java. For example:
String x = "foo";
String y = "foo";
// Appears to work but compares references
System.out.println(x[0] == x[1]);
There's no substitute for knowing your tools well.
- deleted 14y ago[deleted]
- diek 14y agoI assume you meant to say: System.out.println(x == y);
- 430gj9j 14y agoYes. In a previous version I was trying to bypass string caching to make x==y return false.
- wonderzombie 14y agoThe difference is that languages can have more pitfalls, more severe pitfalls, pitfalls which are more difficult to detect, and so on. I don't love Java, not by any stretch, but it's difficult to argue that Java and C++ are anywhere near equivalent in this dimension. Effective C++ is littered with examples of gotchas which are highly peculiar to C++ and the C++ compiler. It's an incredibly complex language. Whether C++ worth these trade-offs for a particular team, project, or company is orthogonal.