Comments (10)
@theofidry So just like @Swader you suggest to keep the get
prefix, but there is no issue to introduce the conversion prefixes?
from central.
2 persons external from the Hoa project with a good influence in the PHP world telling me to not drop the get
prefix is enough for me —so far— to change my mind.
Thank you for your feedback!
from central.
Since we choose to don't remove the get
prefix, do you think there is something important to do here ? I looked at some Hoa libraries and haven't found methods with invalid convention.
Maybe writing a guide about the naming convention on https://hoa-project.net/ can be nice (or just an article ?). if you agree, I can work on that content 😄.
from central.
First proposal is to remove the get prefix for all getters.
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.
Let's $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).
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.
from central.
@Swader Why removing the get
prefix. Why not. In many languages I tried recently, this prefix has been drop/is not present, and I didn't feel any blockers. So from my point of the view, it becomes useless. And this is more “data-centric”/“data-oriented”. A class is a structure, we ask data on it, no need for a get
prefix. We might have “conflicts” with action methods, like map
, which is not a getter. But it works in collaboration with RFC #56. For instance:
$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 with the current approach?
What's wrong: It's heavy, and not necessary. The get
prefix is not mandatory to understand the code.
Now, about the toString()
: This is an example. The to
prefix indicates an expensive conversions, not the form of the results. It warns the user that (i) this is a conversion, (ii) it is costly, (iii) then it might cache the results (i.e. avoid calling it in a loop for instance if possible), (iv) the result is a string. The suffix is not necessarily a type name, toXmlRpcMessage
is still valid. The important part is to
. So in your case, toJson
will provide more information than toString
, even if we don't know what JSON representations we are using (strings, objects?). Maybe toJsonString
is better. Note, having a real generic serializer in this case is even better 😉.
The goal is to define a naming convention to indicate the cost of conversions, and the abstraction changes. I think this is useful.
from central.
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 ?
from central.
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.
from central.
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.
from central.
Your example about map()
conflicting is something I didn't even think of - that's another reason not to drop it, definitely. But yes, the prefixes for conversions sound good.
from central.
👍 go!
from central.
Related Issues (20)
- steps for next version - bc break HOT 7
- Drop PHP 5.x HOT 15
- Drop Hoa\Log HOT 6
- Configure mirror on Gitlab HOT 7
- no more gitter? HOT 7
- Configure Mirror on Pikacode HOT 9
- create repository for atoum-option-extension HOT 3
- Configure bors-ng for all projects HOT 2
- Move PR from Ruler to Central HOT 1
- Add rexfordkelly to contributors and contributors.md
- Remove synchronizing gitlab on bhoat HOT 1
- Dependency errors when installed with prefer-lowest HOT 1
- Add rodion-k to contributors and contributors.md
- Deprecate unused libraries HOT 20
- Removing Rush Release
- Add dependabot on libraries
- Add @jwage and @SilverFire as a new contributor HOT 1
- Add atefBB as contributor HOT 1
- Add @taylorotwell as a contributor
- Add @mikeshatch as a contributor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from central.