[eluser]jedd[/eluser]
Going back a step (and then I'll get to my take on the design approach)
[quote author="TheFuzzy0ne" date="1236710590"]
Indeed. I just want to avoid repeated code as much as possible. For getting a rows by ID or by Email, or by username for example, the code in each function would be virtually identical, apart from the WHERE condition.
[/quote]
Yes, but each function is then
insulated from any changes you may make to that function in the future. Sure, you
probably won't, but that's not the point with coding for tomorrow, is it?
As you say, these are perhaps three lines of code - two of which are rough validation and a return() - but there's still the possibility that you'll make this more complex in the future, perhaps as your schema changes.
(Random example - consider what happens if you properly normalised the average 'user' table. For most programmer-designed systems this would mean that you'd then be looking up a different table for a user's name, f.e. - and if you're doing AR this means a different model. If you've got specific get_by_XYZ() functions, this is relatively easy to migrate to. If you don't, you can fake it but you'll be doing some ugly stuff to make it happen.)
As to how far you take this - it's obviously a matter of degree. I like the idea of sticking to multiple simple clearly labelled function calls - but that's because a) I won't have an onerous amount of them, b) they don't take up much space (and are bundled neatly together in one section of my model), c) there'll be no chance of them being a measurable performance problem, and d) I'm not a terribly proficient or experienced coder so I like the added reassurance that it'll make my code easier to read in the proverbial 'six months from now'.
It's also safe to say that making these
more abstract later on will be easy, as I can search for each specifically named function call and migrate it to any new generic call, if I ever feel the need. Going the other way will be less easy, as I'll be searching for a generic function call with any number (and named) parameters.
So, no, I don't think this approach engenders consequent problems down the road - I actually think it'll insulate you from some.
Quote:Personally, I think that would complicate things as you may not know for sure if you're accessing the right "version" of a particular function.
I kind of like the idea of function overloading, when I read about it a while back in an OO theory book, and was then a tad disappointed that PHP (incl. v6) doesn't offer it. I can see the benefits of the feature, but OTOH I also feel safer knowing exactly what I'm passing and what I'm expecting at the other end. I suspect a lot of that is attributable to (d) above though.
To the question of designing a forum .. xwero's approach is far more formalised than what I do (I have a very
jedd hoc approach to design - much like you described your approach). If I was trying to be a bit more disciplined I'd probably approach it from a data dictionary / ERM angle to start with, and then work back up to some very basic models. If you're committed to AR then you're committed (IIRC) to a single Model per DB Table, anyway. Things like your search function would probably get designed after (and here I'm echoing xwero) you've come up with some mock-ups of screens. So in that sense I suppose I'd be designing from both ends - the stuff under the hood that I just know will have to be there, the basic infrastructure stuff I suppose. And the other side - the UI side - either based on 'competitor analysis' or user requirements. This falls down when the user is your own imagination though!