Hacker News new | past | comments | ask | show | jobs | submit login

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 :(




Yes, but Object Pascal's syntax is way cleaner.


Python has had the property decorator since early in version 2.


In 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.


Nim has everything you need to do that.


Surprisingly (or maybe not), JavaScript has getters and setters: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


Most 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#.


Besides the sibling answers, properties were originally taken from Eiffel/Sather into Object Pascal.


Doesn’t C# have properties?




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

Search: