[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: stroustrup.jpg (53 KB, 314x314)
53 KB
53 KB JPG
C++'s greatest insight was that resource acquisition is initialization (RAII)
>>
>>103220377
Not every basic programming insight needs to be turned into an exploitable buzzword you piece of shit.
>>
>>103220377
its a horrible acronym for a simple concept

> creating objects should initialize them
> objects going out of scope should destroy properly them via their destructor

wow, 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.
>>
>>103220416
If 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
>>
>>103220416
You'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.
>>
>>103220476
it wasnt obvious until GUIs. programs were very procedural until then
>>
File: 1731839701005327.png (389 KB, 603x379)
389 KB
389 KB PNG
>>103220377
https://www.youtube.com/watch?v=xt1KNDmOYqA
Nice, but you should be using ZII
>>
>>103220542
that dude is a retard
>>
>>103220548
You mean, italian?
>>
>>103220542
that dude is a genius
>>
>>103220586
you're a retard
>>
>>103220489
how am I retarded, I never said RAII precludes anything you just said. Ignorant hussy alert.

>>103220476
because I wasn't born yet to invent it
>>
>>103220671
you're a genius
>>
File: 1730388121211429.png (363 KB, 828x683)
363 KB
363 KB PNG
>>103220694
everything 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
>>
>>103220377
No, 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 errors
It's shit.
>>
It's too tiresome.
https://en.cppreference.com/w/cpp/language/rule_of_three
>>
>>103224345
Such an impressively bad designed language.
>>
>>103220416
>> creating objects should initialize them
this is good OOP design

>> objects going out of scope should destroy properly them via their destructor
this 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 release
Enjoy your leaks.
>>
>>103224256
return for results
throw for errors

you can't return error code from stack overflow. you still need to handle exception.
>>
>>103224499
RAII 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.
>>
>>103224256
you can use factory methods on a class that initialize an object and use std::expected<T,E> to initialize it

If 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 interface
No, C# has garbage collection. Imagine if it didn't and you had to use IDisposable for everything.
>>
>>103220476
RAII does not, and it does not even intend to, solve the problem that GC are meant to solve
>>
>>103224551
An 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 server
Fortunately not all programmers have your low standards.
>>
>>103227188
You should check a connection is available before acquiring a resource that requires such connection, you barely evolved chimpanzee
>>
>>103227251
Am I talking to a true idiot?
>>
>>103227307
No, but sufficiently high intelligence is indistinguishable from stupidity for a sufficiently stupid person
>>
>>103227820
Oh, 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.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.