littleredbutton / bigbluebutton-api-php

Unofficial (but better) PHP API for @BigBlueButton
GNU Lesser General Public License v3.0
25 stars 12 forks source link

Add trait to lazy load properties #110

Closed SamuelWei closed 2 years ago

SamuelWei commented 2 years ago

See #109 @sualko This would allow to load other properties the same way, by implementing a lazyResolvePropertyName method

This is just an idea, maybe you can come up with a more elegant solution.

sualko commented 2 years ago

I was today years old when i learned about traits :smile:

Looks great and should simplify the code further. What is @FelixJacobi thinking about traits?

FelixJacobi commented 2 years ago

Looks great and should simplify the code further. What is @FelixJacobi thinking about traits?

Not quite easy to say. There is no definitive yes or no. It strictly depends on the situation. Traits are introducing coupling of classes, e.g. you cannot change the trait code to fit the requirement of one class if this clashes with the requirements of another class also using the trait.

I am not really sure if this it worth it, it introduces kind of really black magic here. Currently it doesn't really save any lines of code. The loading logic is still required, the only lines saved, are the ones, which are checking if the property is initalized.

On the other side, in my opinion, it makes it harder to read the code as the really logic is hidden behind paths of magic codes which are hard to unterstand if you have no prior knowledge of the code. This could harden contributing for other here or debug the library behaviour for consumers.

Generic code fragments also prevents to make code more strictly typed (one of the best savers from bugs) for obvious reasons - their must deal with any data type.

I would not introduce the trait - this allow us, to offer a well designed typed interface for the library consumers which the little duplication of code is worth it, in my opinion.

SamuelWei commented 2 years ago

I'll close this for now.