3 ms·
Yes, and it's a surprising good part about PHP (a language that otherwise has an enormous collection of warts, to put it mildly). I feel like the more dynamic
by DarkUranium 2mo ago
Yes, and it's a surprising good part about PHP (a language that otherwise has an enormous collection of warts, to put it mildly).
I feel like the more dynamic and/or weakly-typed the language is, the more important it is to have a separate concat operator.
The worst ones being weakly-typed and dynamic. Consider `'5' + '10'` in JavaScript vs `'5' - '10'`.
I also very much dislike Python's `+` for concat, but at least it's more strongly typed.
PHP, Lua, and Erlang are three examples of dynamically-typed languages with separate concat operators (`.`, `..`, `++`; respectively), and they all are better for it.
That said, even statically-typed languages benefit greatly from it. Maybe if C++ had a concat operator, it'd never end up abusing `<<` for writing to a stream (yes, there's no opposite for reading, but maybe they wouldn't end up doing that in this case).
For example, D uses `~` in infix for concat. Even UnrealScript, a 1990s game-engine-specific language (which tend to be a mess in general) did this right (it uses `$` or `@` --- with `a @ b` being equivalent to `a $ " " $ b`, IIRC).