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

tiny world pre-OOP #618

Merged
merged 12 commits into from
Sep 27, 2022
Merged

tiny world pre-OOP #618

merged 12 commits into from
Sep 27, 2022

Conversation

YuraZagor
Copy link
Contributor

@YuraZagor YuraZagor commented Sep 19, 2022

tiny world pre-OOP

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@github-actions
Copy link

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 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. 😒

Please, make sure that your code follows the requirements based on the most common mistakes as well as basic requirements from the original task.

Universal recommendations:

  • Make sure your code follows General Requirements
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.
  • Pay more attention to code style - descriptive variable names, indentations, empty spaces, etc. Code should look good :)

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

Sincerely yours,
Submissions Kottachecker 😺

@A-Ostrovnyy
Copy link
Collaborator

@YuraZagor please provide the link on the demo page in the first message.

@YuraZagor
Copy link
Contributor Author

Done. I already did the OOP version of this in old repo, so had to create a new repo for this one

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.

@YuraZagor double-check yoursefl against all requirements linked in the bot's message.
Also make sure to do whatever bot asks to do.

@YuraZagor
Copy link
Contributor Author

self-check done, code changed

@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.

@YuraZagor the code is not DRY enough.
See the item 3 on the list posted by bot.

@YuraZagor
Copy link
Contributor Author

Simplified readability of the printing message with destructuring, although not sure was it what was needed. Also, had to change from forEach to simple for ... in

@OleksiyRudenko
Copy link
Member

Please copy the entire item 3 from the requirements here.
Ask questions if anything is not clear.
Fix code accordingly.
Please do not expect mentors to check code against checkslists for you and to red-pen every single issue.

@YuraZagor
Copy link
Contributor Author

Code is DRY, which means that whenever you see a pattern in your code it should be optimized. Examples:
print(dog); print(cat); etc ... should be refactored employing Array.forEach as the least.
${obj.legs}; ${obj.name}; etc... (yes, strings are also code) must be refactored employing appropriate Array methods

@OleksiyRudenko
Copy link
Member

So the repeating part in your long string is "; ".
How could we reduce repetition by using Array#join?

Comment on lines 52 to 53
const printArr = [species, name, gender, legs ? legs : paws, hands ? hands : tail, saying, friend]

Copy link
Member

Choose a reason for hiding this comment

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

Why not .join in this line? (not a rhetoric question)

Copy link
Member

Choose a reason for hiding this comment

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

Also textToPrint and printArr are quite generic.
What would you call concepts this variables represent in the real world?

E.g. inhabitants are technically objects, but we still give variables that represent them names that are connected with the business domain.

Copy link
Contributor Author

@YuraZagor YuraZagor Sep 21, 2022

Choose a reason for hiding this comment

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

not .join() because we have conditions (ternary) and they would not be processed if stringified

As per the namings... inhabitantRepresentation and inhabitantRepresentationArr could be less generic I believe

Copy link
Member

@OleksiyRudenko OleksiyRudenko Sep 21, 2022

Choose a reason for hiding this comment

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

inhabitantRepresentation sounds just right for a string data type.
If its content is a list of something then it would be probably inhabitantProperties. Note the "-s" at the end, this way we denote that a variable contains multiple things.

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 see this logic, thanks

let textToPrint = `${species}; ${name}; ${gender}; ${legs ? legs : paws}; ${hands ? hands : tail}; ${saying}; ${friend}`;
const printArr = [species, name, gender, legs ? legs : paws, hands ? hands : tail, saying, friend]

print(printArr.join('; '),'div')
Copy link
Member

Choose a reason for hiding this comment

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

re naming: imagine this line of code is 1000's lines of code away from the fragment where it's been formed, probably, even in a different file.
As a human peer developer I want to read what exactly this variable represents.

Code is written for other people. Computers are OK with low-level assembly codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, thanks

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.

@YuraZagor please test the code and fix bugs

@YuraZagor
Copy link
Contributor Author

Sorry for wasting your time with broken code, re-wrote the erased ending. Now it seems running ok

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.

@YuraZagor great job!
For the OOP Exercise task, note that OOP helps to avoid "workarounds" like legs ? legs : paws, hands ? hands : tail by designing classes so that every class handles its own properties without much care about what other classes do.

@OleksiyRudenko OleksiyRudenko merged commit fbd9c5b 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants