unifystockx / code_compete

Coding Competition with TDD and TypeScript
MIT License
0 stars 2 forks source link

Narcissistic numbers printer implementation #16

Closed krajasekhar-unify closed 3 years ago

krajasekhar-unify commented 4 years ago

This is the solution for the assignment - Narcissistic numbers.

krajasekhar-unify commented 4 years ago

I agree to rename my test file to narcissisticNumber.test.js but why shall I not keep my main logic (the function which I am responding to out of the folder) in index.ts? Why to make an extra file with keeping only export & import in the index file? Any reason behind this? I agree if there are multiple functions need to be exported from a single folder where we keep each function in a different file and we need an index file to group them and export together. Shall we still do it if I am exporting one function for my folder? By keeping the logic in index.ts at the scenario of one function to export, When I am navigating (Ctrl + p), I can directly land to my logic by typing folder name. Thoughts? Screenshot from 2020-09-12 12-40-57

nirajunify commented 4 years ago

why shall I not keep my main logic (the function which I am responding to out of the folder) in index.ts? Why to make an extra file with keeping only export & import in the index file? Any reason behind this?

Yes. This is a best practice. The idea is that outsiders, developers who use our package, should not meddle with its internal structure, search for files inside our package folder. We export only what’s necessary in auth/index.js and keep the rest hidden from prying eyes.

Shall we still do it if I am exporting one function for my folder?

You should be mindful about best practices even when you think your code is very little. It's about getiing into the habit

zulqer-nain commented 4 years ago

I think if there is more than one context and more than one function of every context then we should maintain files of functions and maintain index file to import/export all the function . In case Narcissistic problem . best directory structure should be :

index ts - code_compete - Visual Studio Code 14-09-2020 10_01_44 (2)

krajasekhar-unify commented 4 years ago

Yes. It is good to move the tests to a different folder as it separates the test code from parent logic. But for the test file in __tests__ folder, we don't the require the name as index.test.js since we are not importing it anywhere and the tests are auto picked. Also it will be bit difficult to navigate to it from search/Ctrl+P by typing filename. So I advice to still keep the test file name as narcissistic.test.js.

krajasekhar-unify commented 4 years ago

@nirajunify mentioned there shall be index.ts in every folder whose job shall be just to do grouping of functions from other files in the folder. Any thoughts? @zulqer-nain