Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Guaranteed destructors is probably the most complex features ever added to C++, more than templates or move semantics.


The combination of exceptions and non-trivial {copy constructor, assignment operator, destructor} are what combine to make C++ a somewhat broken language when you try to use all the features. And also responsible for poisoning the well for exceptions as an error handling mechanism for native code.

Delphi did native exceptions much better IMO.


How do native exceptions work in Delphi?


Very similar to Windows Structured Exception Handling, which the Win32 implementation used, and also looks similar to Java, but without checked exceptions. try/except/end and try/finally/end blocks.

The major differences with C++:

    * objects are references not values, cutting out all the copy constructor,
      assignment operator, destruction on out of scope etc.
    * objects are zero-initialized after allocation and before constructors run
    * constructors are run from most derived to least derived
    * calling Free method checks if Self is nil
    * this + zero init means that you can call '.Free' on all the objects you 
      reference in the destructor without checking if they're nil first, 
      handling partial construction
It's not a memory safe language, but it does give you a bunch of idioms that, if you stick to them, you don't feel nearly as much pain as C++.


Not all objects are references, because Delphi still supports the Turbo Pascal object model for compatibility, regardless of how many years they are deprecated now.

Agree with the rest, I always loved how Borland picked Object Pascal extensions from Apple, merged them with what was going on with Modula languages and C++ during the 1990's, while coming out with something saner.

While at the same time keeping C++ around, as market value when buying the whole package.

What everyone is going crazy regarding Zig, Odin, Jai, C3, whatever improvements over C and C++, where already available in Delphi, Modula-2, Ada and co, with Delphi being the most affordable option until Borland decided to pivot to big corp.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: