-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Establish Symfony coding standards for private readonly properties and readonly classes #57602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sorry, but your issue description is filled with speculation about how "people" don't understand certain language concepts. I don't want to participate in those speculations, nor do I find them relevant for this project. I'd like to close this issue. |
@derrabus So you understand this language concept differently? Please elaborate. Also I would have thought twice before creating this issue if Nicolas hadn't added this comment I remember until today. Taking into account his authority I think there must be something to this topic. btw. I'm not surprised you voted "no" because I saw many private readonly properties in doctrine/dbal for example. |
No. |
So please delete your previous comment if you don't want to take a part in the discussion. P.S. I'm sorry to say that but from all the core team members that I respect and like, you are the one that I place in "not so kind" box. If I had to point one person from the core team that needs to work on personal skills I would point you. And I'm saying this based on watching your communication with community since you became a core team member. |
I will do no such thing. I think I made clear why I disapproved of your opening comment and that disapproval will stay for the record.
I don't know why you feel like you need to take this to the personal level here. Also, I don't think that your personal feelings towards me are relevant for the topic that you allegedly wanted to discuss. That being said, I do support the initiative toβ¦
I believe we need some kind of guidelines on when and how we want to use |
i like we cant reset/mutate services/deps.. whats wrong with that? |
What is the thing is a trade off. How many times in you life have you overwritten a private property that you haven't supposed to? I've been in PHP world for many years and I've never heard about such a mistake. Also haven't seen a single person asking for feature to protect against overriding private properties. Thus a question is whether we want having all the codebase with readonly keyword everywhere or it's an uncecessary noise that doesn't bring much value if any. For me marking private property as readonly is like setting a password on a password, where |
Take in mind that the Symfony Code of Conduct is in effect to GitHub issues. This is no place for (unconstructive) personal attacks to anybody, we're having a purely technical discussion. I personally don't feel the need for a strict standard here. Things like this can be decided on a case-by-case basis. I also can't remember Nicolas comment nor do I see a reference to it. What would the downsides of going with readonly properties? |
@wouterj I hope this note about Code of Conduct was directed to derrabus who first violated the CoC.
I don't think the readonly keyword next to the private property is case-by-case specific. This is a standard or not. I also don't think this is something that developers keep an eye on when doing code reviews so it will end up being a mess eventually.
I have finally found this comment and even second comment. Issue description updated.
I think I've explained this in issue description and in this comment #57602 (comment) |
The comments tell us that they don't add enough value to make it worth fighting merge conflicts for 2 years. So changing existing properties is probably something we don't want. However, I don't see any arguments for not adding this to new properties/code. Personally, I only see a personal attack from you in this issue. Alexander merely stated that he is against this issue and doesn't want to elaborate on that (which is in his full rights). |
To further support this, the first hit in the search result is a property introduced by Nicolas: https://github.com/symfony/symfony/pull/48642/files#diff-b24b2d134d203cc7851340a7155af5639befdbe019fcf3bcd8bcf270b1122254R26 So I think our general stance is yes for new properties, no for existing properties (which we may change once all support branches require PHP 8.1+). |
Yes, I have seen that. If you look at the code review in that PR you will find out why Nicolas added readonly and how he commented on that (the emoji is essential) #48642 (comment). |
I'm not comfortable with this issue at all. It makes things way too personal. My supposed authority is not an argument on its own. And derrabus just stated his opinion - then you made it personal. On the topic itself: I don't like readonly props because they are flawed by design (or at least too many think they provide immutability, while that's just false). But they do have merits, so in the end: I don't care. It would be just me, I wouldn't use them much. And also: it would be just me, Symfony wouldn't be as great. In short: I have other topics more important to care about and given the polemic nature of such topics (not to say the general tone of the discussion), I wouldn't like to enforce any rule on the specific issue of private readonly. |
I agree. Let's close here then. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Again, please follow through the CARE team if you think action is required. I'll lock down this issue to prevent any more deviation from the technical discussions that need to happen on GitHub. |
Description
AFAIR, when Symfony bumped the minimum PHP version to 8.1 and people started using
private readonly
properties in pull requests the response from the core team was negative. I even remember a comment from @nicolas-grekas who said that private readonly properties don't make sense.Now I can see that we have 257 occurences https://github.com/search?q=repo%3Asymfony%2Fsymfony+%22private+readonly%22&type=code.
I fully agree that private readonly properties do not make sense and only make visual noise. I think people don't understand why this keyword was introduced to the language (I bet 99% don't read RFCs, only New Features section π) and started using it everywhere when they expect a property to be set once, doesn't matter it's a private api, so this keyword became more like a validation/protection use case.
What's more, 99.9% of private readonly properties are dependencies. Have you ever override a property that holds a dependency?
The same goes for readonly classes. Readonly on the class indicates a class is, surprise, readonly. But it makes sense only for structures like DTOs, VO etc. For classes that do a job, i.e. so called services, the readonly keyword doesn't make sense. You don't read anything from this class because they are not designed for reading (by "reading" I mean reading properties, not methods that return some data).
I think having a standard would be nice at least for consistency, otherwise some code will have private readonly properties and some not.
Please add a comment if you vote π.
P.S. I bet the readonly keyword would have never been introduced to the PHP if we has asymmetric visibility already.
Reference:
NIcolas' feedback on private readonly properties:
#46674 (comment)
#53279 (comment)
The text was updated successfully, but these errors were encountered: