3 ms·
One language feature from Delphi (or Pascal?) that I wish modern languages had is class properties No getter/setter bs. When creating a class you declared a fi
by skeletal88 6y ago
One language feature from Delphi (or Pascal?) that I wish modern languages had is class properties
No getter/setter bs. When creating a class you declared a field a property, it looked like this
type
private
FBar: Integer;
procedure SetBar(Value: Integer);
published
property Bar read FBar write SetBar
so you specified what method was to be called when assigning to the propery and when reading from it. You could start with both read and write accessing the field directly and then later make them use getters-setters while keeping the class interface the same. Somehow this knowledge got lost by designers of modern languages unfortunately :(
- m_mueller 6y agoIn python nowadays you use data classes for that. Essentially nice with the frozen attribute. Before that there were named tuples - still useful to subclass instead of frozen data classes, as long as you don't need inheritence or any of the advanced data class field attributes.
- beagle3 6y agoNim has everything you need to do that.
- facorreia 6y agoC# has that: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...
- brokenkebab 6y agoYes, but Object Pascal's syntax is way cleaner.
- pdonis 6y agoPython has had the property decorator since early in version 2.
- yawaramin 6y agoSurprisingly (or maybe not), JavaScript has getters and setters: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- wtetzner 6y agoDoesn’t C# have properties?
- pjmlp 6y agoBesides the sibling answers, properties were originally taken from Eiffel/Sather into Object Pascal.
- sglienke 6y agoMost modern languages have that while at the same time removing a lot of the unnecessary ceremony and adding features such as init only setters in C#.