3 ms·
And yet, I interviewed 10 people easily where I was using new and delete in the example code and only one person asked "hey - can we use unique_ptr?".
by vlovich123 9mo ago
And yet, I interviewed 10 people easily where I was using new and delete in the example code and only one person asked "hey - can we use unique_ptr?".
- deleted 9mo ago[deleted]
- oxag3n 9mo agoOwnership problems with pointer/references don't end with allocation. A codebase can use only std::make_unique() to allocate heap, and still pass around raw pointers to that memory (std::unique_ptr::get()). The real problem is data model relying on manual lifetime synchronization, e.g. pass raw pointer to my unique_ptr to another thread, because this thread joins that thread before existing and killing the unique_ptr.
- vlovich123 9mo agoI don’t disagree. That’s why I don’t write C++ anymore. It’s a masochistic language and trying to do it in a team environment with people who do understand how to do it properly is a mess let alone adding in people who don’t know.
- mackeye 9mo agomany schools (like mine) don't teach unique pointers in the pure "programming" class sequence, but offer a primer in advanced classes where c++ happens to be used, with the intent to teach manual memory management for a clearer transition to e.g. upper-levels which use c.
- johannes1234321 9mo agoWell in interviews this is tricky. Sometimes the interviewer wants to see I can new/delete properly, sometimes this tells me "well, if that's the style they are using I better go elsewhere" If it's done as part of a "here is legacy code, suggest ways to improve it" question one should point it out, though.
- vlovich123 9mo agoDon’t worry. The question was super basic and almost every candidate still failed to mention that you need to delete in the destructor, that copying requires a new allocation or that you also need to define the move constructor. It made me sad about the state of C++ developers and thankful that Rust makes such mistakes impossible.