C++'s greatest insight was that resource acquisition is initialization (RAII)
>>103220377Not every basic programming insight needs to be turned into an exploitable buzzword you piece of shit.
>>103220377its a horrible acronym for a simple concept> creating objects should initialize them> objects going out of scope should destroy properly them via their destructorwow, I guess its novel when you're used to calling free all the time
That's an innovation, not an insight. An insight would imply this was something that was learned. But Resource Acquisition Is Initialization is not true in many other languages. It's a rule that was implemented in C++, and later copied in some other languages like Rust.
>>103220416If it's so simple how come it took until the mid-80s for it to be invented.Lisp, APL, ML, all kinds of advanced theoretical languages have been around forever along with C, but none of them introduced this simple idea instead of either manual management or slow-ass GC
>>103220416You're fucking retarded. RAII is not about memory, everyone (except C++, I guess) already knows how to manage it.RAII is about any shared resource: websocket, file handler, DB connection. RAII ensures that you always have access to this resource as long as you have a valid object associated with it. And if you closed it manually through this object the internal state will change and prevent you from breaking the resource.
>>103220476it wasnt obvious until GUIs. programs were very procedural until then
>>103220377https://www.youtube.com/watch?v=xt1KNDmOYqANice, but you should be using ZII
>>103220542that dude is a retard
>>103220548You mean, italian?
>>103220542that dude is a genius
>>103220586you're a retard
>>103220489how am I retarded, I never said RAII precludes anything you just said. Ignorant hussy alert.>>103220476because I wasn't born yet to invent it
>>103220671you're a genius
>>103220694everything in computing science was invented by the end of the 50s and mostly perfected by the end of the 60s. now we tweak to fit better into hardware because the software guys are knuckledraggers
>>103220377No, not really. It's a very simple and stupid concept.
I use RAII in C, except it's a lot more powerful because I define what is meaningful resource acquisition and what must be cleaned up by compiler inserting autoclean logic, thank you for betatesting this compiler feature in C++!
>>103220377>can't return errors on resource allocation (a common case)>needs to use exceptions as a roundabout way to return anything from constructors>a honest C++ program should have try/catch all over the place to actually handle errorsIt's shit.
It's too tiresome.https://en.cppreference.com/w/cpp/language/rule_of_three
>>103224345Such an impressively bad designed language.
>>103220416>> creating objects should initialize themthis is good OOP design>> objects going out of scope should destroy properly them via their destructorthis is bad and has led to many design problems with c++c# has explicit resource release via IDisposable interface and nobody ever though it's bad or confusing, on the contrary it leads to easier, better, more clear design.
>>103224451>explicit resource releaseEnjoy your leaks.
>>103224256return for resultsthrow for errorsyou can't return error code from stack overflow. you still need to handle exception.
>>103224499RAII makes resource allocation the same as constructing an object. Where do you pit the error? An error when opening a file or creating a network connection isn't exceptional. It's something you have to expect.
rust is just RAII taken to the extreme
>>103224256>>can't return errors on resource allocation (a common case)it literally isnt common, actually its very uncommon. and for the vast majority of programs out there, theres no point in doing anything other than terminating if an allocation failure occurs, which is the default behaviour of dereferencing null pointers.
>>103224256you can use factory methods on a class that initialize an object and use std::expected<T,E> to initialize itIf you get a `T` then the destructor will run, if you can't initialize a T, then you get an E and can handle it. I use this pattern all the time for error handling without exceptions and we can still take advantage of RAII
>>103224451>c# has explicit resource release via IDisposable interfaceNo, C# has garbage collection. Imagine if it didn't and you had to use IDisposable for everything.
>>103220476RAII does not, and it does not even intend to, solve the problem that GC are meant to solve
>>103224551An error when opening a file is exceptional, and so is a failure to connect to the internet if your program requires it. Don’t blindly try to open a file without making sure it exists and isn’t locked by some resource. If the file exists and is free, a failure to open the file is an exception The problem with C++ is that most people using the language are just not good programmers at all and have the IQ of a slightly dumber than average chimpanzee
It takes 2 minutes with an electric shaver to get all that hair off and leave a buzz cut and you do that once every 20 days.At this point a haircut like that is intentionally bad.
>>103226634>I want all of my programs to crash when they fail to connect to the serverFortunately not all programmers have your low standards.
>>103227188You should check a connection is available before acquiring a resource that requires such connection, you barely evolved chimpanzee
>>103227251Am I talking to a true idiot?
>>103227307No, but sufficiently high intelligence is indistinguishable from stupidity for a sufficiently stupid person
>>103227820Oh, is that why you called me a chimpanzee?Anyway, to connect connectivity, you have to attempt creating a connection. That's basic TCP/IP knowledge. Which confirms my argument, because you make a connection and failure is one of the expected results. Separating making a connection and checking for availability doesn't make sense.