[fpc-devel] Language semantic suggesion regarding static methods
J. Gareth Moreton
gareth at moreton-family.com
Tue Oct 22 01:19:51 CEST 2019
This is a very low-level semantic issue, but I'm not particularly keen
on how static methods are defined in classes.
*class function *StaticMethod: Integer; *static;*
What's wrong with it? Well, it's an issue of consistency that gets me,
plus 'static' is only valid as part of a class method declaration,
making it a very restrictive directive. I'm not sure how best to
explain it, but there are three levels of 'connectivity' that a method
can have with an object:
*function *RegularMethod: Integer; // Self points to the calling object
*class function *ClassMethod: Integer; // Self points to the calling class
*class function *StaticMethod: Integer; *static;* // Self unavailable -
effectively a regular subroutine tied to the class.
To draw attention to the inconsistency, I doubt anyone would support
syntax like this (or maybe they would... I don't know!):
*function *ClassMethod: Integer; *class;*
For one thing, it doesn't immediately jump out that the method is a
class method, especially if there are a lot of parameters and it scrolls
off the edge of the UI. For language consistency, surely a more logical
syntax would be the following:
*static function *StaticMethod: Integer;
For backward compatibility, I would suggest keeping the 'static'
directive for class methods so existing code doesn't break, but maybe
mark it as deprecated.
Granted I can live with it if it isn't going to be changed, but it's
something that always bugged me!
Gareth aka. Kit
P.S. If I've missed something obvious as to why static methods are
implemented using a directive, please educate me!
This email has been checked for viruses by Avast antivirus software.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel