20jam / php-oop

Overview and Examples for object oriented programming with php
23 stars 12 forks source link

Cheatsheets organization #2

Open yarimadam opened 4 years ago

yarimadam commented 4 years ago

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.

20jam commented 4 years ago

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

yarimadam commented 4 years ago

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.

20jam commented 4 years ago

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.

yarimadam commented 4 years ago

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

20jam commented 4 years ago

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.

yarimadam commented 4 years ago

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.

20jam commented 4 years ago

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.