Naming convention

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

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Naming convention

Post by shiznatix »

Ok I know there is the Model, View, and controller classes and whatnot but I don't like that kinda naming. It's too long and they don't show up in order on a alphabatized list. I want the View to be on top, then controller, then model as this makes sence. Is there another naming convention that would do that? What other ways to call them do you use?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Functional naming is what I stick to :)

Only 'difference' I have is prefixing with the 'project' name/acronym.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Input, Processing, Output.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Naming convention

Post by Christopher »

shiznatix wrote:It's too long and they don't show up in order on a alphabatized list. I want the View to be on top, then controller, then model as this makes sence. Is there another naming convention that would do that?
This is the kind of kooky, personal requirement that just makes things harder for you down the road. I would suggest looking a something like the Zend Frameworks and follow that. Otherwise you end up with 1View, 2Controller, 3Model or some such nonsense. I don't particularly like PEAR style naming -- but I use it without complaint because it is a standard and works pretty well.
(#10850)
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

lol, i use a mix of my naming convention and C++ naming conventions MINUS hungarian. that smurf blows smurf. also i split up all my files in the correct areas but the M/C stays in one area and the V's go in a completely different area.

why don't you name them functionally anyways? like forum.model.php, forum.controller.php?

i'm gussing that you've got all your files in one folder then right?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I think... you ought to try namespacing.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

MrPotatoes wrote:why don't you name them functionally anyways? like forum.model.php, forum.controller.php?
I do. Like if i make a page to lets say, add or edit email addresses for a client. I make a folder and name it like 'EmailAddresses' then I make my 3 files and name them like 'EmailAddresses.View.class.php', 'EmailAddresses.Controller.class.php', and so on. Really the biggest problem is that when I go to open them, I cant just highlight them all and click open. I have to open them one at a time so they will be in order in my tabs thing (i use editplus).

Ya it's such a silly thing but it annoys the crap out of me.
Ambush Commander wrote:I think... you ought to try namespacing.
I havn't really grasped what namespacing is yet. Care to elaborate?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Namespaces are not yet available in PHP (I heard they are to be available in PHP6? When I say hear, I mean literally.. didn't read an article, a friend mentioned it.. so don't shoot me if I am wrong :p,) but in other languages are most useful.

Java for example.. java.lang.String

String is the class, of the namespace lang, of the namespace java.

Think of them as virtual directories.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ohhh. ok ya i did that stuff in java but never knew they where called namespaces. thanks
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

With PHP, you emulate namespacing by doing the Namespace_ClassName() convention. I agree: real namespaces would be dead useful. However, now that I see some examples, that's largely irrelevant.

Regarding your troubles, you're very much in "Transaction Script" mode. If you find yourself needing to edit all the model classes at once, you may want to consider refactoring to a more Model based layout.

Or you could create a batch script that scans the directory and opens them all. ;-)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I've seen others use directories as kind of pseudo namespaces, granted it doesn't help too much when your 'in app' but they say it's dead handy for this type of scenario.. all model classes are in the /model dir, view class in the /view dir.. controller classes in the (you guessed it) /controller dir etc.
Post Reply