2 ms·
I suppose that's something every Java programmer should know: How types are automatically converted during "arithmetic" operations. There are some subtleties (l
by struppi 9y ago
I suppose that's something every Java programmer should know: How types are automatically converted during "arithmetic" operations. There are some subtleties (like byte+short => int), but it's not too much to remember.
The deeper question is: Was it a wise choice to disallow operator overloading BUT use "+" as a string concatination operator AND convert all values to strings during string concatenation?
I think not, but it's a rather moot point, since that desing decision is not likely to change...
- nicwilson 9y agoThats why I'm glad D chose '~' as a binary concatenation operator so that there is never any confusion.
- cm2187 9y agoThere is something to be said about using all the special characters of the ASCII table in term of readability. Looking forward languages that will start making good use of Unicode! I am actually surprised Greek letters haven’t made it already. Lots of computer scientists are mathematicians that are used to math papers looking like an Ancient Greek tablet.
- cakoose 9y agoThe Fortress programming language was a research project at Sun that incorporated mathematical notation. See page 24 of http://www.oracle.com/technetwork/systems/ts-5206-159453.pdf http://www.oracle.com/technetwork/systems/ts-5206-159453.pdf They also had an ASCII-only representation for everything, so you could use a regular text editor if you wanted, kind of like Markdown.
- kelnos 9y agoEh, it's just a design decision. They could have required that people construct strings using printf-style formatting (which you can do, with String.format(), but isn't required), or have some sort of interpolation (like Scala does with s"This var is $foo"), but they just opted to let people concat with + instead. You could argue it any way, I suppose; there's no one right answer. The behavior in the OP's example is unsurprising for a language that defines + to be left-associative and has a well-defined order of operations.