I don't see the modernity point, either. Object Pascal has modern features.
I don't see the modernity point, either. Object Pascal has modern features.
For example, this tutorial (from 2017) recommends doing "try .. finally: f.Release" block. https://www.thoughtco.com/communicating-between-forms-409254...
This tutorial, which is also from 2017, says that that you need to either explicitly add each member to an owned list, or to explicitly free every class member in destructor: http://newpascal.org/assets/modern_pascal_introduction.html#...
Is this a recommended best practice? I hope not -- most (all?) of the modern languages either have GC, or offer automatic refcounted pointers, and Object Pascal claims to be modern.
The good thing about managing your memory is you don't have memory bloat and you don't have jitters when the GC decides to fire.
In the class definition:
std::shared_ptr<BigStruct> big_struct;
In the constructor (or anywhere else in the program): big_struct = std:::make_shared<BigStruct>(arg1, arg2)
and that's it. When there are no more users of the pointer (for example, when the container object disappears), it will get destroyed automatically. There is no magic -- this is a simple reference counting pointer, and the compiler will automatically add the release call to the object destructor, on function exits, or in any other place when the variable is no longer accessible.I found these things extremely helpful in the modern languages without GC. They are obviously not perfect -- if you have a complex structure with a loop it will never get destroyed -- but they eliminate 99% of all possible memory leaks with a very little effort. And the good news, they have almost no overhead. They are also fully thread-safe, so they become extremely helpful if you have a multi-threaded application and you want to pass the data between the threads.
This is the simplest of things that modern non-GC languages, and this is one of the big reasons why I no longer do C, just C++. There are more advanced features, of course, but I don't think you can call a language "modern" if it does not even have the smart pointers.
As a Delphi application developer, you will most likely not be manually allocating/freeing memory a lot. Delphi's visual component library has a component ownership model. For example, any components/controls that you drop on a form are automatically "owned" by the form and are created/destroyed for you.
Object Pascal may have modern features, but that doesn't mean it is a modern language - nobody is going to start learning it now. Only people that have known it for years already will use it.
Re: modern languages: a language having modern features isn't a modern language, rather how popular it is at this moment is the most important aspect ? How did that work out for Python ? And where does PHP land using this criteria ? Is PHP better than Object Pascal because more people write PHP code ?