The Dangers of C++ Operator Overloading ? #programming #coding #lowcode

preview_player
Показать описание

Curious about C++ operator overloading? 📚🚀 #Cplusplus #CodingTips #OperatorOverloading #MatrixMultiplication #CodeTricks

🔥🔥🔥 SOCIALS 🔥🔥🔥
Рекомендации по теме
Комментарии
Автор

In many huge projects c++ just feels like a completely different language

sweaderlol
Автор

Sometimes it's good to be explicit. For example overloading the multiply operator on a mathematical vector would not be a good idea. Half the people would assume it's doing the dot product, the other half would assume it's doing the vector product.

embeddedbastler
Автор

operator overloading is like the one thing about C++ C programmers complain the most about but is the least important. No actual project uses it to create terrible code and the few cases it's used are intuitive and make sense (ranges, standard streams). Complain about something like template metaprogramming and you'd have a point.

noxtenebris
Автор

So the lesson is: you, the dev, don't do naughty stuff and bad design.

Yupppi
Автор

C also gives you the ability to write unintuitive inefficient garbage code that C++ has an optimized library for

justsomebeanz
Автор

This is the main complaint I hear from rust and pure C / embedded developers - it's always: "yeah you have absolute freedom to do anything, but, then people can do dumb shit"

Yeah, so don't do dumb shit.

PixelThorn
Автор

C++ is the most expressive and flexible programming language ever built. Note that I didn't say the best, but in term of expressiveness, there is nothing like C++.

biomorphic
Автор

c++ is basically lisp if you understand templating. the black magic you can do with that is scary 💀

kenneth_romero
Автор

The best example is the << crap you use in cout.

Simon-yffo
Автор

I really don’t like the argument that just because a language gives you the power to write unintuitive/unsafe code that makes the language bad or even less preferred. If you’re worried about that, just don’t write your code that way. To borrow from Twain on censorship, it’s “telling a man he can’t have a steak because a child will choke on it”

siamesestormtrooper
Автор

Modern C++ is extremely easy to read, which isn't necessarily the same as reason about [and I think it was you that pointed that out] but if I see two objects with an * in between them, I know that that's calling the binary * operator... [Which would colloquially be called multiplying them]

skeleton_craftGaming
Автор

Not being able to use good features because they can be abused is a terrible trade off. If you're coding alone, then make it as freaky as you want. Otherwise, linting tools and code review exist to prevent doing stupid and terrible things.

elmstfreddie
Автор

I very rarely use operator overloading, but when I do its almost always for an extremely primitive type like matrix as mentioned. the only other time I tend to use it is to overload the dereference operator on a class that essentially just wraps a pointer so I can continue treating it as a pointer in most cases.

zami
Автор

You can apply this argument to not writing functions since they're basically the same thing. If bad functions can make your code unreadable by being bloated and side-effect-y, why have functions?

sp.n
Автор

Assignment operator overloading is also useful when setting a pin as 1 or 0

JTordur
Автор

Incredible, and yet I still find ways to make intuitive, overloaded bulk in JavaScript

DeusGladiorum
Автор

I don't see how operator overloading is that much different in concept than being able to define any kind of function. You can write really unintuitive in a function called Multiply just as much as you can do it with an overloaded multiplication operator.

BibendiYT
Автор

In c++ string addition is also awesome use of operator overload

zakhapiell
Автор

In Unity, objects can mysteriously == null even though you never set them as such.

horsethif
Автор

In every language you have the power to write obscure code. Writing intuitive code (and clear comments and documentation) is an attitude that a programmer should have as a person and as a professional, it's not a problem of C++ (or of any other language).
It's like saying that English is a bad language because some people use harsh language in English.

robertoprestigiacomo