Uh oh!
There was an error while loading. Please reload this page.
Add a StatementRank class - #562
Conversation
JonasKress
commented
Oct 8, 2015
+1 |
JeroenDeDauw
commented
Oct 8, 2015
Did you consider having an actual Rank object, and if so, what made you go with the static approach? |
There was a problem hiding this comment.
This is just a suggestion for a possible enhancement. You can use these alternative constants in a context where it is critical to know that ranks are integers.
There was a problem hiding this comment.
In those cases just use 0 instead of Rank::RANK_0 as you hardcode the zero anyways.
There was a problem hiding this comment.
No, what? What is "hardcoded anyway"? I'm not sure you get the point of all this. Constants are for easy tracking and refactoring. A rank should never be expresses via an integer constant.
Benestar
commented
Oct 9, 2015
Thanks for sharing your proposal, we definitely need an improvement how we handle ranks in our data model. However, I think we could avoid introducing so many methods by just relying on the fact that the constant integers of the rank values replicate the order of the ranks (which is in fact what the class does). What I think would be more appropriate would be a static method |
JeroenDeDauw
commented
Oct 9, 2015
Can you elaborate on what you currently find inadequate? The same goes for Thiemos proposal here. It's a lot easier to comment on this if its clear what the goal is. |
thiemowmde
commented
Oct 9, 2015
Yes, and I find the idea of an object wrapping nothing but an integer pointless and scary. It also doesn't help solving the issue I want to solve here: The semantics of how ranks are compared is currently duplicated across our code base. This would only be solved if we ditch the idea of ranks being integers completely, across all components. This would be a major breaking change that's not worth it, in my opinion. Therefore: Ranks stay integers and a helper class with some comparison methods is good enough.
That's exactly the issue we have: This knowledge is not in a single place but duplicated across the code base. This caused heavy confusion yesterday, but nobody was able to point to that single place that says "ranks are always, now and in the future, guaranteed to be in increasing order from least to most preferred".
Yes, it does create an explicit place for this knowledge. That's the point.
That's a possible enhancement, but doesn't solve any issue.
As said above, yes, it could, but no, it shouldn't. |
JeroenDeDauw
commented
Oct 9, 2015
That is somewhat surprising to me. Ranks are parts of statements. So if there is no Rank enum, then that is where I'd first look. And if that is too unclear, I'd just add a Rank enum. |
thiemowmde
commented
Oct 9, 2015
How would you do that? There are no enums in PHP. |
JeroenDeDauw
commented
Oct 9, 2015
I meant having a Dedicated class to hold the constants rather than putting them into Statement. |
JeroenDeDauw
commented
Oct 9, 2015
Thinking about it, if we create a dedicated class for ranks, regardless of what we put in there, Rank(s) seems like a bad name. The concept here is not disjoint from statements, so the name ought to reflect that, by being like StatementRank(s). |
thiemowmde
commented
Oct 9, 2015
|
Benestar
commented
Oct 9, 2015
I wasn't part of that discussion or meeting when this arised so could you summarize what happened? The rank to integer mapping seems to be quite clear to me as there is only one place where the integer values are defined (inside Statement). The only thing that is missing imo is a static place where one can get the list of all available ranks, which can easily be solved by adding a method to Statement. That should btw also answer Jeroen's question.
We have several places where we hardcode |
thiemowmde
commented
Oct 12, 2015
What I just explained: There is no single place that encodes the knowledge what "best" means, when a rank is "better" and so on.
I'm not sure how often I should repeat myself. Please read #562 (comment) again. |
thiemowmde
commented
Oct 12, 2015
I can not find this array anywhere outside the Statement class. Some tests use arrays of ranks in data providers, but I do not understand how this is a mistake. Tests should be independent from implementations they are not testing. |
8f22d3c to
fbc9bcfCompare| * | ||
| * @return int|null Best rank in the array or list of arguments, or null if none given. | ||
| */ | ||
| public static function findBestRank( $ranks = array() /*...*/ ) { |
There was a problem hiding this comment.
I'm afraid a method with this signature is of not much use. How would you call it when you have a StatementList?
JeroenDeDauw
commented
Aug 8, 2018
No changes since 2015. Please reopen if needed for current goals |
JeroenDeDauw
commented
Sep 17, 2018
Please rebase and find reviewers if this is change relevant to your goals. The PR just sitting here with merge conflicts and no one looking at it for years is not helpful. |
JeroenDeDauw
left a comment
There was a problem hiding this comment.
I like how this provides one place where rank comparisons are defined, though do not think global functions are a good approach. Instead we could encapsulate the primitive, something like
class StatementRank {
publicfunctionisPrefferedOver( self$rank ): bool {}
}That gets rid of the global functions and follows the primitive encapsulation practice.
JeroenDeDauw
commented
Sep 17, 2018
Also beware that the @SInCE tags need updating |
No description provided.