-
Notifications
You must be signed in to change notification settings - Fork 53
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
Define some basic naming conventions. #17
Comments
I agree. This is something I've struggled with as well and I seem to change my mind constantly. I like both the explicitness of a |
+1 for getters :) |
total agreement that the only really wrong answer is mixing the two. fwiw, i'm more inlined in the direction of not using totally just my 2c. |
I agree that mixing them is a bad idea; semantically I would say that |
+1 on |
👍 for |
I'm leaning more towards omitting the |
also, perhaps methods could be normalized for better integration with other interfaces, for those who want to implement multiple interfaces (as php arrays) in the same class. For example... interface Queue interface Stack interface Deque extends Stack, Queue maybe this is conceptually wrong? |
|
not that is impossible now. talking about using a different naming. addLast() and getFirst() rather than enqueue() and dequeue() |
Why not follow the convention of the SPL here? Once it's not working, you can start with prefixes (get, is, has), most likely for reserved keywords (IIRC that's the first case of "not working"). Because once you start with prefixes you can't stop. But getters is more for field-access and here are mostly interfaces or abstract classes. Whether or not it will represent a field is an implementation detail and most likely not necessary to know for the interface. And the counter-argument: getters signal state. data-structures normally represent state. sure those are bulky and we do the mistakes of Java however in SPL we have I know that w/o Perhaps keep the "core" methods from Conclusion: I personally prefer the non-getter style, but I know I run into problems with that time-to-time and getters is often accepted but also the lazy decision. Type less, do more, so if you can keep getters out (as long as possible), the interface is less bulky and more precise. It could also allow concrete classes implementing an interface to add getters as they wish. So yes, I'm leaning towards to not introduce In the spirit of good code, keep waste out as much as possible. |
I'd keep SPL interfaces' methods aliases of the properly-named ones. SPL is not very consistent. Also, "has" and "is" aren't good prefix either. getIsEmpty() i know this doesn't exist, but explains why one should have get/set also for booleans you can't take java as example because java supports method overloading, while php doesn't - and really hope it will never do prefixes should be
suffixes should be All, None, or maybe
no prefix at all would be confusing. what does ->empty() do? does it clear the collection or tells if the collection is empty? HTH |
It's also worth mentioning that the problem with reserved words in classes is being limited in PHP7 (not removed entirely, as some words like public, protected and private have to be reserved, but fewer words will cause conflicts). See this RFC. |
I am still not sure what to do here. Leaving open. |
I'd like to
For what it's worth, I would suggest:
With regards to some of the other issues addressed:
Hope these ramblings help. TL;DR: I suggest not to use
|
I can't do |
I don't think queues and stacks should be implemented within a single structure because they have kinda conflicting definitions:
If you wish to merge them "nicely", you'd be forced to consider @WesNetmo's solution; however, I'm not too fond of this because the With regards again to |
Currently we have names like
first
andlast
but also have names likegetLeft
andgetHeight
. I'm not sure which convention I'd like to use just yet, but having both rubs me the wrong way.The text was updated successfully, but these errors were encountered: