-
Notifications
You must be signed in to change notification settings - Fork 8
Simplify getter naming, introduce data conversion naming #54
Comments
get*
, introduce as*
, to*
and into*
Okay, but why exactly? What's wrong with the current approach? I think it's more consistent, predictable, and fits in well with the setter naming.
How does this work with multi dimensional arrays? Would this conversion be predictable / clear / standardized? The method name does not accurately convey the nature of the conversion - I wouldn't be sure what to expect in the final string. |
@Swader Why removing the $product->collection()->isSome() is strictly equivalent to: $production->hasCollection() The former is more readable from my point of view. The API is unified more importantly. To answer:
What's wrong: It's heavy, and not necessary. The Now, about the The goal is to define a naming convention to indicate the cost of conversions, and the abstraction changes. I think this is useful. |
Helping developers knowing the cost of an operation by convention naming is a very nice idea 👍. Also the collaboration with RFC #56 and getter naming simplification make the code simpler to read for me. But what about existing code ? Once implemented this will introduce a BC break for most of the getter methods... Do you think the code must be compatible for some time ? |
Nop. Since we are thinking to drop PHP 5.5, we will introduce a big BC, like everytime we drop a PHP version. The goal is then to take this opportunity to rewrite the API. |
I can understand where this is coming from, but IMO it's too alien to most PHP developers and the BC break introduced by it is not worth it. It only hurts the adoption of Hoa projects. |
@theofidry So just like @Swader you suggest to keep the |
Your example about |
2 persons external from the Hoa project with a good influence in the PHP world telling me to not drop the Thank you for your feedback! |
Since we choose to don't remove the |
👍 go! |
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
This article explain what was discussed in the RFC : hoaproject/Central#54
Hello fellow @hoaproject/hoackers and users!
In this RFC, I would like to simplify and standardize the API to get data.
Introduction
So far, we use this formalism:
getFoo()
to name a method that returns the valuefoo
. This can be a direct attribute, or a computation. To get this data within another form, i.e. to convert this data into another type, we don't have any formalism yet. For instance, iffoo
is an array, and we would like to get it as a string, we will probably name a method likegetFooAsString()
but this is not deterministic.Shorten getter methods
First proposal is to remove the
get
prefix for all getters. SogetFoo()
will be renamed likefoo()
. Real example:instead of:
The meaning is strictly the same, but I think the former is easier and shorter to read.
However, the
setFoo()
formalism for setters will remain. I would like to seeset_foo()
but it does not respect PSR, so let's not start a war 😉.Conversions
I would like to introduce 3 method prefixes:
as
to
into
Example:
$x
be a float.asInteger()
will be (almost) free.$x
be an array.toString()
will be expensive because we have to iterate over the array, to allocate a string, and to convert every pairs in the array as a string (like a serializer).$x
be an object.intoArray()
will not be that expensive, it might reference all attributes into an array, so that's just one allocation.Conversions prefixed
as
andinto
typically decrease abstraction, either exposing a view into the underlying representation (as
) or deconstructing data into its underlying representation (into
). Conversions prefixedto
, on the other hand, typically stay at the same level of abstraction but do some work to change one representation into another.Outro
This is not something we will use often, but it is important to have a strict naming here. Based on this naming, the user will be able to choose if the resulting data must be cached or not (for instance, all
to
conversions are likely to be cached because they might be expensive).Thoughts?
The text was updated successfully, but these errors were encountered: