Похожие чаты

Why can't you have resource handles on the stack without

RAII?

13 ответов

12 просмотров

Cause that will mean manual disposal of the resource. RAII makes it automatic and guaranteed.

Thomas- Автор вопроса
Thomas
Manual is fine by me

By you. Not for the greater number of C++ developers, and not for the multitude of most developers in other programming languages, seeing that few of the major programming languages permit manual resource disposal.

Kenshin Himura
By you. Not for the greater number of C++ develope...

In Java, Perl, PHP and Python you have to close file handles manually if you do not want to run out of them. May other languages have automatism for that.

Sebastian Dicke
In Java, Perl, PHP and Python you have to close fi...

And I maintain that none can match RAII cause, as I explained above, RAII does not force you to think about resource disposal routines at the call site, ensuring cleaner code.

Thomas- Автор вопроса
Kenshin Himura
And I maintain that none can match RAII cause, as ...

I don't it's cleaner when I can't see what's happening, in most cases I want to know everything about all the code

Sebastian Dicke
In Java, Perl, PHP and Python you have to close fi...

Python has context managers that do that for you when the handle goes out of scope

Thomas
I don't it's cleaner when I can't see what's happe...

Clean code should have a separation between the logic of the function and resource management. Why should a function to process account balances also have memory management code? Why should code to calculate coordinates also have socket management code? https://www.fluentcpp.com/2016/12/15/respect-levels-of-abstraction/

Thomas- Автор вопроса
Kenshin Himura
Clean code should have a separation between the lo...

I thoroughly disagree with this, if logic should be separated from resource management, it should be actually separated, not just hidden, but mixed

harꭑony5 (⊙ ◡ ⦿︎) ↺
Python has context managers that do that for you w...

Yes, and it operates similar to RAII in C++; resource acquisition at beginning of context, then cleanup at end of context (scope). However, with Python, in order for you or users of your own classes to take advantage of this, you must implement the context management protocol. With C++, you just need a constructor, destructor, and any interface you or your users will need to access the internal resource. There is no protocol that you have to adhere to.

Thomas- Автор вопроса
Thomas
https://youtu.be/LKKmPAQFNgE

I wonder what happens if you do stuff with the orphaned vector. Probably UAF eventually.

Thomas- Автор вопроса

Похожие вопросы

Обсуждают сегодня

я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Ребят такой вопрос я хочу пранк сделать в колледже и убрать все права установить 000 рекурсивно у домашней директории юзера, установить переменную окружения PATH в "" и сделат...
Super Sigma
21
Всем привет! Массив вводится с клавиатуры, кол-во элементов неизвестно, поэтому я указал arr db 100 dup(?) С нахождением максимума проблем нет, а вот минимум почему-то всегд...
En Vind Av Sorg
11
hi, just reinstalled komodo wallet, and can't find ARRR on there? tried to search ARRR and pirate and nothing came up... is arrr still supported on komodo wallet. it's been ...
Pilner
10
в сях есть множество как в питоне? для удаление дубликатов
Linus
25
Hi everyone, long time no see! 🐼 recently i want to update our Ergo Eco-System map, can everyone help to find out, which to delete and other new to add in? list it, that i can...
HEROKOO
14
55. Hi, how's everything with you?TG大会員2U|82. How's life?TG会員2U|83. Hi, how's everything been treating you?飞机会員2U|84. How's your day been so far?電报会員2U|85. Hey, how's everythi...
Allice Grace
2
читать файл максимально быстро? странный вопрос))
zamtmn
53
I will wait, no problem, I invested in other project also, but with my 8 years experience I can see when something is not good enough. Last bull market everyone was so excited...
jeronim jurakovic
1
If arrr gets implemented on cake wallet. Would that mean arrr/xmr swaps possible in cake wallet like atomic swaps on komodowallet ?
Keks Meister 🏴‍☠️
22
Карта сайта