11

Oh boy I have to interact with some C++ library code again, please kill me now

Comments
  • 2
    You are already using Rust. There is nothing worse than that fate. ;-)
  • 4
    @Demolishun Not sure I can agree :D
  • 3
    C++ devs can get creative with their responsibility patterns. My personal favourite so far (found in a friend's project) is the "weak referent" pattern which is an object that refers to some other objects passively but strongly, meaning that it can not affect them in any way but it also must be finalized before them. The result is a twisted backwards logic on the external interface such that the weak referent's lifetime ends when any of its referents' lifetimes end.

    Weak referents don't give out weak references to themselves. A weak referent is an object in memory that will be freed when any of some other objects are freed. The referrer is responsible for keeping track of each of those lifetimes. After that point, they're holding an invalid object which generally doesn't have a validity flag.
  • 3
    This is actually the same as a struct with a reference field in Rust, but without the borrow checker it's the biggest footgun programmer has ever written.
  • 2
  • 1
    I hope that its interface is "C-like"

    Otherwise... well good luck
  • 1
    Most "creative" solutions in C++ are bad solutions, alas, that's the power you command when the language doesn't try to restrict you.

    What your friend tried to do is solved with correct use of shared_ptr and weak_ptr (or their boost versions if dealing with c++03).
  • 1
    @LotsOfCaffeine It's some weird windows UWP C#/C++ library built on top of idl description files 🙃
  • 1
    @12bitfloat

    Ugh, hope you are not talking about that abomination that is C++/CLR.

    If so, my condolences.
  • 1
Add Comment