php-oop icon indicating copy to clipboard operation
php-oop copied to clipboard

Cheatsheets organization

Open yarimadam opened this issue 5 years ago • 7 comments

As far as i can see, cheatsheets are both containing implementation and test code. It's better to separate them. We may think to use phpunit to test cheatsheets.

The world "cheatsheets" doesn't sound right to me. I already made a pull request regarding the composer autoloader, so lets put these files under "src" and it's own directory. I can make one example and we can discuss it further.

yarimadam avatar Jun 16 '20 13:06 yarimadam

Yah you are right, I've changed cheatsheets to src now, but I'm not sure how to go about sepatating test code from cheatsheet. please make an example

20jam avatar Jun 16 '20 13:06 20jam

I'll make an example and open a pull request. do you want to try phpunit? i can utilize that too. examples can be run systematically. you may search about it can give feedback to me.

yarimadam avatar Jun 17 '20 06:06 yarimadam

I think PhpUnit is great framework for testing, but to keep matters simples it is best to leave it out. for now.

I saw how some repos separate the code from implementation/simulation, which also yields unnecessary complexity.

20jam avatar Jun 17 '20 12:06 20jam

I propose the following directory structure. Please inspect and give feedback so i can organize the implementation.

src/ConcernName/ExampleName

example1: src/StrategyPattern/FileUploader example2: src/StrategyPattern/CacheManager

So, with this pattern we can have multiple example under same concern.

We can put test folder and readme file inside the example. (we can consider it after some time.)

yarimadam avatar Jun 18 '20 07:06 yarimadam

Nah, directory based navigation and extra setup will make this more complex. I’m actually working on creating a reference for design patterns and am doing exactly what you’ve proposing here.

Since the examples are small in size and the scope is (doing oop in php) we can have multiple examples in one file. The namespacing and autoloading might be an example where we split the code into multiple files. The good thing of having the implementation and simulation in the same file is only needing to open one file when needing a reference for doing something.

We need two dirs inside src (examples and challenges). In challenges dir we can have a set of challenges written in readme for people to solve, and the solution in a numbered php file 01.php with the same dir “challenges”.

I’m excited for having challenges, it will put will we learn under testing.

20jam avatar Jun 18 '20 11:06 20jam

Since the examples are small in size and the scope is (doing oop in php) we can have multiple examples in one file. The namespacing and autoloading might be an example where we split the code into multiple files. The good thing of having the implementation and simulation in the same file is only needing to open one file when needing a reference for doing something.

Putting implementation and test code in to a file violates PSR-1, and it's bad generally considered as bad practise because they are different concerns.

Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both.

https://www.php-fig.org/psr/psr-1/#1-overview

Challenges should be located outside of "src" as they are not part of the library/source.

"Examples" is irrelevant as a vendor/library name. We can think "src" directory as library folder (which it is) so anything irrelevant must located or non-exist in this directory.

yarimadam avatar Jun 18 '20 12:06 yarimadam

Thanks for pointing this out, it actually make sense. I must get used to some standard after all. I agree challenges might be best be outside the src. Please open a PR request for the needed changes.

20jam avatar Jun 18 '20 14:06 20jam