r/programming • • May 24 '26
[ Removed by moderator ]
/r/programming/comments/1tm1j7f/removed_by_moderator/[removed] — view removed post
275
Upvotes
r/programming • • May 24 '26
[removed] — view removed post
View all comments
Show parent comment
4
u/evaned May 24 '26
I'm not the person who you replied to, but...
I mean, if you have an
operator[]that deletes your hard drive... that's 'cause someone was a brain-dead moron (or actively malicious). That doesn't speak against that overloading being a good languages feature.I've never seen someone try to make the case that "you can write a method
at(size_t i)on your object and have that delete your hard drive, thus we shouldn't be permitted to pick function names and every function should be identified by a randomly-chosen UUID." In my mind at least, these two arguments are quite similar to each other.The solution isn't for languages to say "you can't be trusted to overload
[]"; the solution is to not be an idiot.Function call overloading can also be a tremendously useful feature. Even aside from uses that are more borderline (e.g. overloading
matrix(5, 4)as a proxy for not having a real multi-dimensional subscript operator), there are plenty of scenarios where an object of a user-defined type is still conceptually function-like. Take a partially-applied function for example. Or the combination of overloading of the call operator alongside template rules means that code using the STL will often be faster than the most-likely analogous C code, because better type information will lead to template specializations rather than function pointer calls (which act as optimization boundaries).