With a bit of fiddeling you can use every kind of bracket to basically make function calls in c++
Here are the links to the snippets, all compile and run
Rust: https://godbolt.org/z/bM3d7bG14
With a bit of fiddeling you can use every kind of bracket to basically make function calls in c++
Here are the links to the snippets, all compile and run
Rust: https://godbolt.org/z/bM3d7bG14
cpp and their operator overloads are also insane. It makes understanding cpp code impossible. A “+” could actually do something completely different or have insane side-effects. Truly superior language for spreading confusion.
When I was an intern, I was tasked with writing a file converter for 3D geometry files. There was an official cpp library to read the source files, so I was using that to read the data, restructure and transform it as needed, then write it to the output file format. Near the end, I was having a problem where I was SURE that my math was correct for the transform coordinates, but the resulting file would load in the viewer with all the correct looking pieces but all in the wrong locations. The senior guy there helped me debug it since I wasn’t super familiar with cpp at the time, and we found that the library I was using had overloaded the multiply (*) operator specifically for the objects I was using it on, and it was actually multiplying and saving the result directly to the first variable used in the multiplication. I assume it was done for memory efficiency or something, but I had no idea it would behave that way, so I was accidentally changing the values of variables I didn’t intend to.
Example: I was doing something a = b * c, which caused the value of b to be changed (to b * c). Which screwed things up when I needed the original value of b later.
This is the type of shit that haunts me. Imagine overloading “>>” for piping and hiding threading behind that. The idea was to create an async pipe, but nowhere are you aware of async or threading or whatever was chosen. You look at the code and think “of it’s like piping to stdout” or whatever, only to find out that the method immediately returns.
Tracking down what the hell is happening with code that has such hidden side effects is a nightmare.
Are you still in the C++ world?
That is WILD lol. No, after that, I did a bunch of backend server apps for a few years mostly in C#, and then I got put onto some web app stuff after that. For better or worse. I do enjoy it and appreciate the abstraction, and I have found that I do love frontend dev a lot, but I do sometimes miss the lower level languages haha.
I talked to a frontender recently who said they had less pleasure writing frontend, because AI could make it look as good as they wanted in a fraction of the time. Has AI changed anything for you?
I was “encouraged” to use AI at work for frontend and while it output functional stuff, lofting the hood om the how, terrified me. 😅
Operator overloads is something that sounds like a good idea until you experience them firsthand. Just properly name your functions for fuck’s sake.
Like all of the footguns in C++, it’s only a problem if the codebase uses it wrong. When used correctly (i.e. only when behaviours mimic built-in types, and without side effects), it helps makes code more readable
Don’t do what numpy does, which is to define * for two arrays. Without learning the library, you wouldn’t know whether this performs element-wise multiplication, matrix multiplication, dot product or cross product. Worse yet, it behaves differently to Python’s built-in * for lists (which is also bad), which concatenates N copies of the list
Clearly you’ve never had to read code like
entity.position = vector_algebra::vector2_add(entity.position, vector_algebra::vector2_scale(entity.velocity, dt));I prefer Java style:
entity.position = entity.position.add(entity.velocity.scale(dt));Not hard to read.
Every time I use a language that doesn’t have operator overloading I wish I was using C++. It’s absolutely maddening to have to read and write things like “end.subtract(start)”.
Operator overloading is awesome in a functional language. Haskell allows for a lot of creative stuff with operators, but since they can’t have side effects, must conform to predictable types, and have specific requirements they are somewhat understandable. Idris is also very ergonomic when it comes to operators.
C++ allowing a library to override the
+operator withsystem("rm -rf /")is a lot less awesome.As a computational physicist, I appreciate operator overloading IF used properly.
Example of a good use: + for matrix addition
Example of a bad use: left shift operator << as a pipe
I still don’t understand who’s in the C++ committee that they would choose this garbage over a function
Honestly, I’m glad to have them, it can make a number of things simpler. For instance, a program I wrote had a number of duration fields that had to be stored in XML files and updated every once in a while. It was something that had to occur very often in the code: add a value to the duration, set that value in the XML data, and save the XML file. So I created a class that stored the date/time value and a pointer the XML element (it could be assumed that nothing else would be changing the value in the XML file and if it did, then that change should be overwritten) and overloaded the
+=operator (among others), so then all I needed was to create theDurationFieldobject, and then I could godurationFieldX += time2 - time1for instance. I could abstract all the logic away and make it very clear and easy to write. Could I have made it so that I have to todurationFieldX.add(time2 - time1)? Of course I could have. But IMO that variant is less neat and less readable.I’ll jump on your unpopular side. With a decent IDE you should be able to point/click and decode what any operator is doing in any context. If I have two vectors, or quaternions, and I want to operate on them, why should I be forced to pass them to a standard function instead of clearly seeing what I’m doing. If you can’t be bothered to know the types of your variables in a strongly typed language… IDK.
Omg I have the best idea but I’m not writing any C++ so someone else will have to do it.
Overload + to work as - in either some super rare condition or randomly with a very low chance
Ship it
People have made
NULLto be a random number on a specific day. As a goodbye present :DYeah it’s like a knife, wildly superior to cut stuff up in the kitchen, but you can also like stick it in your eye (but why?).