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

Added index.js file to rewiev #385

Merged
merged 5 commits into from
Sep 27, 2022

Conversation

chernetskyi8704
Copy link
Contributor

@chernetskyi8704 chernetskyi8704 commented Sep 1, 2022

OOP exercise

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@github-actions
Copy link

github-actions bot commented Sep 2, 2022

Hey!

Congratulations on your PR! 😎😎😎

Let's do some self-checks to fix most common issues and to make some improvements to the code before reviewers put their hands on the code.

Go through the requirements/most common mistakes listed/linked below and fix the code as appropriate.

If you have any questions to requirements/common mistakes feel free asking them here or in Students' chat.

When you genuinely believe you are done put a comment stating that you have completed self-checks and fixed code accordingly.

Also, be aware, that if you would silently ignore this recommendation, a mentor can think that you are still working on fixes. And your PR will not be reviewed. 😒

A Tiny JS World -- OOP exercise check list

Relates to A Tiny JS World OOP exercise.

Check-list - definition of done

Minimal requirements to meet:

  • Implement a base class to inherit from
  • Employ default parameters
  • Each species is represented with its own class
  • No need to specify species at instantiation
  • Classes for species that do not have hands by natural design, do not consequently have hands or any equivalent property and do not inherit such properties from any base classes
  • All inhabitants are stored in a container (array or object)
  • JS native features are intensively employed (const, let, Array.map|join|forEach|..., etc)
  • Object methods like keys, values, entries as well as for...in shouldn't be used as these do not guarantee any particular order of keys/values
  • Properties used to form an object presentation string must be explicitly listed/specified; Use Array.map and Array.join to build a presentation string from the list.
  • A parent class shouldn't know anything about its children's props. Child classes must have good reasons to assign or refer to any parent's props. There are no such reasons in this task. Method overloading is to the rescue when building an inhabitant's presentation string.
  • OOP, SOLID and DRY principles are intensively employed

Optional level up (not required to implement):

  • Friends list is a list of objects refs rather than names (strings)
  • Cat-woman class is built employing composition rather than inheritance only

Bonus:

  • toString magic method; when implemented print(inhabitant) does the job as .toString is called implicitly
  • this.constructor.name; when used for output then no need to store species property

Helpful resources:

Universal recommendations:

  • Give variables and functions meaningful names. Avoid generic names like item, element, key, object, array or their variations. Exception: helper functions that are specifically and intentionally designed to be multipurpose.
  • Function names should start with a verb as they denote actions; variables are normally nouns; boolean variables/functions start with is, does, has etc; variable containing multiple entities and functions returning lists contain entity name in plural form.
  • Have consistent code style and formatting. Employ Prettier to do all dirty work for you.
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.

Also take a note of the requirements above and follow them in all your future projects.

By the way, you may proceed to the next task before this one is reviewed and merged.

Sincerely yours,
Submissions Kottachecker 😺

@chernetskyi8704
Copy link
Contributor Author

chernetskyi8704 commented Sep 3, 2022

Has completed self-checks

@chernetskyi8704
Copy link
Contributor Author

Comment for activity.

@OleksiyRudenko OleksiyRudenko added the self-check-done Student confirmed that self-checks against requirements/common-mistakes are done label Sep 20, 2022
Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chernetskyi8704 quite a decent job!
A couple of improvements are still needed.


displayData() {
return ["species", "name", "gender", "saying"]
.map((data) => this[data])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data is a generic term. What exactly map works with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take into account in the future, not to use a generic term in situations like that. Thanks a lot.

}

displayData() {
return `${super.displayData()}; ${this.hands}; ${this.legs};`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this (and other similar fragments in subclasses) DRYer with Array#join.
Do not use strings representing propety names. KISS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. Now really code looks better.

Comment on lines 53 to 56
const man = new Man("Man", "Dimitrij", "male", "Nice to meet you!", 2, 2);
const woman = new Woman("Woman", "Kate", "male", "Have a good day!", 2, 2);
const dog = new Dog("Dog", "Molly", "female", "WOOF-WOOF!", 4, 1);
const cat = new Cat("Cat", "Whiskey", "female", "Meow!", 4, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the checklist:

No need to specify species at instantiation

There is at least two ways to achieve this. One you already use for a different property. Another one is hinted in the checklist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think now i made it correctly.

// ======== OUTPUT ========
const allInhabitants = [man, woman, dog, cat];

allInhabitants.map((inhabitan) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check English spelling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that one, it was obvious.

@OleksiyRudenko OleksiyRudenko self-assigned this Sep 20, 2022
@OleksiyRudenko
Copy link
Member

OleksiyRudenko commented Sep 20, 2022

I just noticed there are two submissions for TJSW OOP from you.

What tasks exactly implements each of #385 and #575?

Minimal requirements and hence review flow is different for pre-OOP and post-OOP.

@chernetskyi8704
Copy link
Contributor Author

In #385 I perhaps make more than it requires in 'Building a Tiny JS World (pre-OOP) - practice'. First, it was written like this - chernetskyi8704/a-tiny-JS-world@dcab8f6. But then I asked in the chat if it ok and replied that I needed to be made some changes. My bad that I incorrectly read the requirements.

@chernetskyi8704
Copy link
Contributor Author

Should I replace this code with the code that in the commit that I send above or just make improvements wich you pointed on?

@OleksiyRudenko
Copy link
Member

Hold on. I will suggest the approach so that we do not discard what's been done so far in terms of both code and review.

@chernetskyi8704
Copy link
Contributor Author

Is there something requier to do from me?

@OleksiyRudenko
Copy link
Member

@chernetskyi8704 let's keep this PR for OOP version and #575 for pre-OOP version.

@chernetskyi8704
Copy link
Contributor Author

@OleksiyRudenko I hope I understood you correctly.

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chernetskyi8704 nearly there

Comment on lines 80 to 86
super("Man🤵", Name, Gender, Saying);
}
}

class Woman extends Human {
constructor(Name, Gender, Saying) {
super("Woman👩", Name, Gender, Saying);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Men and women belong to the same species. I just cannot let heresy pass through :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was a stupid one.

Comment on lines +118 to +119
this.Paws = "4";
this.Tail = "1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not critical here, as we do not really do math operations with paws and tails.
Just wondering, why strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings because of using string methods.
Should i fix it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily. For example, telephone numbers do not actually make sense as numbers in mathematial sense, as we do not math operations over them. From the other hand we may want to count total number of legs in a herd.

Probably a missing part in your puzzle was that numbers coerce to strings automagically in string context.
Check what 4 + "" results in and why [1, 31, 3, 5, 11].sort() doesn't work as expected. This is an important part of understanding JS internals and peculiarities.

You may skip fixing this. Make sure to take some learnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type conversion it's really a great thing in JS but I'm not thought about this in the border of this task. In the future will ask my self more often 'What about if...'. Thank you so much for the review.

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chernetskyi8704 great job!

@OleksiyRudenko OleksiyRudenko merged commit 8a31c15 into kottans:main Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
self-check-done Student confirmed that self-checks against requirements/common-mistakes are done task-TJSW-OOP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants