Skip to content
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

fromJSON should be from fromObject #1

Open
m7vicente opened this issue Mar 20, 2020 · 10 comments
Open

fromJSON should be from fromObject #1

m7vicente opened this issue Mar 20, 2020 · 10 comments
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed severity-minor Item is not urgent

Comments

@m7vicente
Copy link
Contributor

The serialization method 'fromJSON' is capable to parse in entity not only json strings, but entire objects, so, it should be called 'fromObject'.

@dalssoft
Copy link
Member

Agree. I think a better name would be build or buildFrom
What do you think?

@m7vicente
Copy link
Contributor Author

The most intuitive is buildFrom , but i think the best way to create a entity from a object is from constructor parameters , like new User(obj).

@dalssoft
Copy link
Member

dalssoft commented Jul 7, 2020

what about `newFrom'?

const user = new User.newFrom({ ...input });

or just from

const user = new User.from({ ...input });

still open to suggestions

@endersoncosta
Copy link
Contributor

I believe that .build or .create should be better than .from ... Because it already is used in other libs like own javascript...

@dalssoft
Copy link
Member

dalssoft commented Jul 7, 2020

just to add to this discussion...

There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton

there are two approaches towards naming:

  1. capture the intention of the method:

const user = new User.create({ ...input });

  1. prioritize code readability:

const user = new User.from({ ...input });

in (1) create captures the intetion of the method, but doesn't look that nice when reading the code

in (2) it is a attempt to capture the intention "create a new User from this data" in code and make it more readable

@m7vicente
Copy link
Contributor Author

In most cases we use of this method to create an entity instance-based from any object, it can be from a database or a simple post request, in some ways, the object has been constructed previously, so User.from(obj), make more sense, because it's not a literal new object.

@endersoncosta
Copy link
Contributor

Ohh, got it! This really make sense. Now new User.createFrom( param ) seems to be an option...

dalssoft pushed a commit that referenced this issue Jul 8, 2020
Add super lint checker on pull request
@dalssoft
Copy link
Member

dalssoft commented Jul 9, 2020

createFrom seems to mix both ideas. I'm not sure it's the way to go...

@m7vicente
Copy link
Contributor Author

lets use just User.from(param), this way, in the future we can create other constructors like User.FromXml(xmlParam)`, and we let the users create customized constructors methods for an entity using the same pattern.

@jhomarolo jhomarolo added help wanted Extra attention is needed severity-minor Item is not urgent labels Dec 24, 2021
@italojs
Copy link
Member

italojs commented Apr 14, 2022

I think it's related with issue #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed severity-minor Item is not urgent
Projects
None yet
Development

No branches or pull requests

6 participants