this post was submitted on 16 May 2025
491 points (95.5% liked)
memes
14801 readers
4051 users here now
Community rules
1. Be civil
No trolling, bigotry or other insulting / annoying behaviour
2. No politics
This is non-politics community. For political memes please go to !politicalmemes@lemmy.world
3. No recent reposts
Check for reposts when posting a meme, you can only repost after 1 month
4. No bots
No bots without the express approval of the mods or the admins
5. No Spam/Ads
No advertisements or spam. This is an instance rule and the only way to live.
A collection of some classic Lemmy memes for your enjoyment
Sister communities
- !tenforward@lemmy.world : Star Trek memes, chat and shitposts
- !lemmyshitpost@lemmy.world : Lemmy Shitposts, anything and everything goes.
- !linuxmemes@lemmy.world : Linux themed memes
- !comicstrips@lemmy.world : for those who love comic stories.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Meanwhile JavaScript: 1+"2" = "12"
Just had fun with that yesterday
I'm assuming "" makes 2 a string... Would expect 12 as well.
@phoenixz @Deceptichum Engineer: The half of glass is wasted.
You can wind up in the same trap in VB/VBA as well. It baffles me that in this current century there are still languages where text concatenation symbols and mathematical operators are the same character.
It's even worse in the case of VB because you can also use & explicitly to concatenate strings, whereas + can be either a mathematical operator or a string concatenator depending on context and the types of variables you've put it between, which VB may or may not decide to cast into strings depending on an arcane set of conditions that nobody understands or remembers. So the solution was right there all along, i.e. just make & the only concatenator and reserve + for math only. But that would be too much like right.
There's nothing wrong with overloading an operator for other classes; the problem is the unexpected typecasting.
Python, for example, will allow you to "add" strings to concatenate, but will throw a type error if you attempt to add a string to an integer.
PHP uses . which works perfectly fine, I've never encountered this nonsense before
Yes, and PHP can even implicitly (or explicitly!) cast variables between different types. Dot (.) is for strings and + is for math. It's one of the few things about PHP that makes sense.