Abstraction Class Interfaces: DB, Template, etc.

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

My 2 pence: yes, it's can be a pain to use different APIs when using PHP libraries. How nice would a standard interface be! But take a moment to consider: where does PHP come from? Open Source - which lives from being diverse. In fact, diversity is the air OS breathes. You will get accepted best practises (as, for example, mentioned and partially explained Chapter 1 in Georg Schlossnagl's "Advanced PHP"), but none of them will be what everyone uses.
Solution: live with it, learn about it, accept it and you will grow to like it.

I have not seen any authorative guidelines on how to program PHP - the debate about procedural vs. OOP is still going on, while PHP itself is clearly moving into the OOP direction. Once you've got the fundamentals of OOP under the belt, you will have learned about standards and, as in my case, are quite keen to explore more. One of the best sources, I find, is http://www.phppatterns.com/
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I know; I have searched them. But I am not interested in formatting, capitalization, underscores, whitespace, etc. I am interested in standards for the words used. An example, is that there seems to be agreement that when setting and getting vars from a class you do: set_varname() or getVarname() or some other variation of caps and underscores.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

I really don't think it's that big of an issue. If you get paid to do this, I'm sure you can read the manual for each CMS to find out what does what. If not, then just keep using the one you already know.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I've noticed that arborint has been repeating his statement over and over with no result in sight.

If programmers should change all of their vocabulary set in their work and parallel it to all other programmers, how could there be more than one or two different libraries out? I, myself, use my custom made DBI's and Template systems for most of my customers and I'm happy with it. The simplest thing you can do is learn and work. Don't sit there and cry about the choice of wording in a program.

My two cents.
Image Image
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

If programmers should change all of their vocabulary set in their work and parallel it to all other programmers, how could there be more than one or two different libraries out?
My point exactly. And that would be a bad thing?
I, myself, use my custom made DBI's and Template systems for most of my customers and I'm happy with it. The simplest thing you can do is learn and work.
You freely admin that you rewrite simple code that has been written hundreds of times. If instead you got together with other programmers who write a DBI or Template system in the style you like, you would have a library that performed better, had fewer bugs, had a test suite written for it, and documentation.
I really don't think it's that big of an issue. If you get paid to do this, I'm sure you can read the manual for each CMS to find out what does what. If not, then just keep using the one you already know.
I do get paid to do this and do read the manuals. I think people who get paid to do this are the ones who would benefit the most. The more time you spend coding and supporting standard libraries, the less time you are spending adding value to you clients/company's projects. You can either charge more or make less profit.

I'm not saying that we should become like Sun or Microsoft or IBM in dictating a single total solution, but a few guidelines would give us some of the benefits that those very successful communities have.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

arborint wrote:
If programmers should change all of their vocabulary set in their work and parallel it to all other programmers, how could there be more than one or two different libraries out?
My point exactly. And that would be a bad thing?
sorry, more choice = good.
less choice = bad.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Naming is very important. In good code names help explain what's going on; in bad code they're a barrier to understanding, forcing you to spend time working it out.

Different conventions make it much harder to learn to program. What does person A mean by "command" - is it the same thing that personB means by "action"? Is A's command an "application command" (eg the "viewtopic" you can see in the address bar right now) and is person B using action in the same context or are they referring to the of list of tasks undertaken in response to an "application command" (input validation/filtering, serve client page, send email, write logs, etc). The more you learn the better you get at working it out from context but this sort of thing can be very confusing.

It's not just about a common vocabulary for common APIs: sometimes there isn't even a standard API. There are for example the eclipse iterators and Harry Fueck's idea for a SimpleIterator. Other people will have their own variations. I like to add an extra "seek" method to eclipse.

The most important thing however is creativity. Rules are good if they help us to communicate ideas but at the point where they start to hinder new ideas they've got to be dropped or redefined.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

sorry, more choice = good.
less choice = bad.
100 libraries that all do the same thing but use slightly different names for a couple of the functions and vars is not really freedom. I'll take the freedom of interoperability.
... Other people will have their own variations. I like to add an extra "seek" method to eclipse.
The most important thing however is creativity. Rules are good if they help us to communicate ideas but at the point where they start to hinder new ideas they've got to be dropped or redefined.
I agree competely. I'm really not looking for full interfaces, just the minimum set of functions for each library/pattern. I am also all for there being several standard interfaces if there are several way to solve the same problem. If you like to add seek() that's fine. And others who don't need seek() can still use your code because you use: connect, query, etc... I also agree that specifying too much hinders new ideas.
Post Reply