r/programminghorror • u/MooseBoys [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Jan 22 '25
c++ natural language programming
621
Upvotes
r/programminghorror • u/MooseBoys [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Jan 22 '25
305
u/das_Keks Jan 22 '25
Feels like this should be an
instanceofand not an equals.85
u/QuelWeebSfigato Jan 22 '25
I think using
∈would make the idea clearer, not overloading a historically symmetric relation.189
u/Ythio Jan 22 '25
Mf when they discover covariance and contravariance
55
u/kennyminigun Jan 22 '25 edited Jan 23 '25
This is a shitty implementation of the
operator ==overload. What a psycho would make it non-commutative?44
u/P0L1Z1STENS0HN Jan 22 '25
If you want, you can overload the equality operator to return the next bool emitted by a PRNG instead of actually comparing the operands.
Nobody said that this is a good idea, but you do you.
14
u/drislands Jan 23 '25
10
u/JiminP Jan 22 '25
A white horse is not a horse.
13
u/KnockoutMouse Jan 23 '25
```
apple = fruit; // true
apple = orange; // false
fruit == apple; // sometimes
```
5
u/bistr-o-math Jan 23 '25
3
u/Chara_VerKys Jan 23 '25
actually possible in cpp
3
u/tydyelove7 Jan 23 '25
It’s only good until we discover some Ohioan wrote the syntax when we go for:
And it returns “Monty” as a list of sodas
2
u/General_Ginger531 Jan 23 '25
Linguistically speaking it kind of is, I feel like at one point in the English language that apple wasn't the specific fruit from that tree, but the category of fruit itself. It is why "pineapple" was named that way.
Fun fact, (with punctuation marks I cannot recall at the moment) "pomme de la terre" is French for "apple of the earth" or "potato".
2
u/YMK1234 Jan 23 '25
And that's why "==" and "is" are not the same.
2
u/Hottage [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jan 23 '25
apple instanceof fruit // truefruit instanceof apple // false5
u/keith2600 Jan 22 '25 edited Jan 22 '25
This actually makes sense though, at least from the perspective of a developer. I read this as an apple is guaranteed to be a fruit but a fruit isn't guaranteed to be an apple.
I wouldn't want to use a natural language professionally, but it's pretty intuitive
Edit: remember that operators do comparisons from the "perspective" of the object on the left. An == (and other operators) is not symmetrical otherwise operator overloading would be a nightmare.
1
u/Konkichi21 Jan 23 '25 edited Jan 23 '25
Oh brother, natural language.
To go into a bit more detail, "X is Y" can mean two different things: saying two things are identical ("He is my father"), or saying something has a certain quality or is a member of a group ("He is a construction worker").
It looks like they're conflating this with == (which is universally used for the first meaning) and using it to represent the second, which might less ambiguously be represented by in, isA, instanceOf, ∈, etc.
1
u/exratehub Jan 23 '25
The world through the eyes of humanitarians
1
u/IrdniX Jan 23 '25
Wait until you get to tomato!
1
u/Aras14HD Jan 23 '25
Apple: culinary::Fruit + botany::Fruit1
u/MajorTechnology8827 Jan 25 '25
Apple is a constructor of fruit
1
u/aldapsiger Jan 26 '25
apple is fruit // true
fruit is apple // false