Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@mr-user Turns out `std::vector<int> bullshit;` isn't the same as `std::vector<int> bullshit();`
The former works, the latter is a function prototype. Because that makes fucking sense and is at all consistent or intuitive
Man fuck this language -
You can't take a reference to temporary. It will be discarded at the compilers convenience and any reference to that object will be invalid. This is an object lifetime issue.
-
Parzi86635yi've had this exact issue i don't remember how many goddamn times and every time it makes me actually scream
-
@Parzi I always forget about it and then think "Hey, I like to be explicit so let me just put these empty parentheses here to really make it clear I want to call the default constructor"
-
@Ranchu That's what confused me. `std::vector<int>()` isn't some special default constructed type of std::vector nor is it even an std::vector. It's actually a function type without args that returns an std::vector
It does make sense in a way but it's still stupid -
std::vector<int> vtype = std::vector<int>();
std::vector<int>& vref = vtype; // works
std::vector<int>& vref2 = std::vector<int>(); // does not compile, trying to ref a temporary -
@Demolishun That makes sense, but what I was doing is this:
// Works, default constructed vector
std::vector<int> list;
// Doesn't work, function prototype declaration
std::vector<int> list();
// Works, vector with initial capacity
std::vector<int> list(10);
Now that's pretty dumb. It of course makes sense and I (now) know why it does it but that's still baaaaad design -
-
mr-user13495yI second his opinion @12bitfloat , try to use {} unless you are working with older C++ (which I think you shouldn't have any reason to work with it since it is backward compatible)
-
mr-user13495y@FrodoSwaggins
I don't know that C++ is not backward compatible. I thought that in C++ the older thing will still work when you upgrade to newer version.
Could you give me an example of what kind of thing are not backward compatible?
I heard that the C++ is having trouble since it cannot remove stuff since it need to maintain backward compatibility (at least that what I got from CppCon). -
mr-user13495y@FrodoSwaggins
That make sense that they kill it (even if it break the compatibility issue) -
@mr-user @Demolishun I completely forgot about aggregate initializers. Do note that they don't call constructors (as far as I know) so you still have the inconsistent syntax of `std::vector a{};` vs `std::vector b(10);`
-
@FrodoSwaggins
So in c++98 you could shoot your dick off.
In c++11 removed this ability, but probably added other parts that could be shot off. -
@FrodoSwaggins Yeah that's what I'm saying, aggregate initializers don't call direct constructors of the initialized object, they initialize the object and it's fields themselves. So you can't explicitely call the default constructor for a stack allocated object of a class because syntax ambiguity
-
I dunno man, C++ is a really complex language. I am always paranoid when I start studying it because I want to make sure that If I fuck up it is because of my own damn self. The language belongs to masters really and just like Javascript fucking shit up left and right having you learn all sorts of workarounds with quirks the same applies to C++, you REALLY need to know your shit to work with C++, yes, this includes keeping up with the standards present in the compilers.
-
@FrodoSwaggins precisely why I say that its a language for masters man, y'all keep on the craft of an already complex language and learn the new standards and its hard already as it is. I appreciate cpp becay it sorts of weeds out the good developers from the bad more than any other language.
-
@FrodoSwaggins No there actually is ambiguity. You would expect `std::vector<int> a();` to default construct a vector but it doesn't... because it's ambiguous
(Yes, I'm aware that it's not *technically* ambiguous, just inconsistent, but same same only different) -
@FrodoSwaggins If I had a hard time with minor syntax ambiguities I wouldn't be a programmer, trust me
What I can't get over is the seemingly arbitrary inconsistency. It's just bad language design. I guess that's all I'm trying to say -
Can recommend:
https://amazon.com/C-Programming-La...
Also, this quote is apt:
"Within C++, there is a much smaller and cleaner language struggling to get out."
A later clarification adds, "And no, that smaller and cleaner language is not Java or C#." -
@Demolishun Without a doubt C++ is a great -- and probably the most powerful ever -- language. It's just that as it grew over the last decades it now has so many warts and so many dumb syntactic/semantic idiosyncrasies that I don't see a way of cleaning it up other than throwing it away and starting from a clean state. And that's what Rust is to me: Reimagined C++
(Yeah you thought I wouldn't bring up Rust in a thread about systems languages, huh? :P) -
mr-user13495y
-
@Demolishun I have mad respect for anyone that successfully builds a career in what I consider the hardest language to master. I know only the side of web development and data analysis, but our tools in both areas are so far removed from the metal that for some of us the idea of manually dealing with memory, the most important resource you can manipulate in a computer, is just a far fetched idea. It doesn't help that most of us touched C or C++ in academia, for which we were definitely not expecting to fight the language so much in regards to not learning the inner models and syntax to be profficient. Me? I liked it, a fucking lot, but still went the web side and I don't use C++ for anything. I have been following the Cherno on youtube in an effort to use C++ in the game design side of things. Its hard, but I love it, eventually I want to transition to working in something with C++ full time.
Related Rants
-
rephiscorth38Everyone here ranting about a fucking missing semicolon. I can't remember the last time a missing semicolon wa...
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
CodesNotHot11-Laughed at Gitlab the other day -Accidentally dropped my db today. fuck karma
Fuck c++
Everytime I have to use this fucking language it spits up some other bullshit error
`cannot convert std::vector<int>() to std::vector<int>&`
WHY THE FUCK ARE STACK ALLOCATED VALUES EVEN THEIR OWN TYPES
AND WHY CANT I TAKE A GOD DAMN REFERENCE TO IT
JUST WHYYYYY
rant
fuck
c++