Controller Naming Conventions

1 view
Skip to first unread message

Tony Nelson

unread,
Feb 10, 2011, 9:19:55 PM2/10/11
to ColdMVC
All,

I've been going back and forth on some framework naming conventions
and wanted some feedback.

Typically speaking, ColdFusion reads better when components and
methods are written using camelcase. For example, something like
emailService.sendEmail() reads better than email_service.send_email()
or emailService.send_email().

However, I have always felt that folders and URLs look horrible when
written in camelcase, and instead I prefer to use underscores. For
example, if I were to list out all of the product categories that an
ecommerce application might have, a URL might look like
http://www.myapp.com/product_categories/list and the view might be
located at /views/product_category/list.cfm, while the request would
still be routed through a ProductCategoryController. Does this make
sense? I believe this is similar to conventions used in Rails, but
Ruby's naming conventions tend to be a lot stronger than ColdFusion's.

Also, what happens if your action isn't just a single word, like if
you were adding a subscription. Your URL might look like
http://www.myapp.com/account/add_subscription, which would invoke the
AccountController. In this case, what should the method be? I think it
would feel more natural to ColdFusion if the method was written using
camelcase and not using underscores, but does that make sense to
everyone else? So that /account/add_subscription invoked
accountController.addSubscription() rather than
accountController.add_subscription().

Honestly I'm not sure how the framework currently handles such a
situation, but I'd like to make a decision and go with it in order to
move forward with unit tests and documentation. I'm leaning towards
having the controllers and actions referenced using underscores, while
having the actual methods being written in camelcase, but I'd like to
get your ideas before making a final decision.

Granted nobody ever responds to these threads, but I figured I'd at
least give people a chance to speak their mind if they cared...

Thanks,
Tony

Dan Vega

unread,
Feb 10, 2011, 9:29:57 PM2/10/11
to ColdMVC
I would agree with a lot of this.

emailService.sendEmail() reads better than emailService.send_email();

but I think for url puproses I like /account/add_subscription.

The question I have is why does the framework need to worry about
this. This could easily be accomplished by a rewrite rule. I think the
framework should do only what it needs to and let other systems od
what they need to do.

just my $0.02c




On Feb 10, 9:19 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
> All,
>
> I've been going back and forth on some framework naming conventions
> and wanted some feedback.
>
> Typically speaking, ColdFusion reads better when components and
> methods are written using camelcase. For example, something like
> emailService.sendEmail() reads better than email_service.send_email()
> or emailService.send_email().
>
> However, I have always felt that folders and URLs look horrible when
> written in camelcase, and instead I prefer to use underscores. For
> example, if I were to list out all of the product categories that an
> ecommerce application might have, a URL might look likehttp://www.myapp.com/product_categories/listand the view might be
> located at /views/product_category/list.cfm, while the request would
> still be routed through a ProductCategoryController. Does this make
> sense? I believe this is similar to conventions used in Rails, but
> Ruby's naming conventions tend to be a lot stronger than ColdFusion's.
>
> Also, what happens if your action isn't just a single word, like if
> you were adding a subscription. Your URL might look likehttp://www.myapp.com/account/add_subscription, which would invoke the

Tony Nelson

unread,
Feb 10, 2011, 10:00:37 PM2/10/11
to ColdMVC
But wouldn't you rather have the framework handle the 90% rule for
you? It's one less thing to worry about.

Tony

On Feb 10, 8:29 pm, Dan Vega <danv...@gmail.com> wrote:
> I would agree with a lot of this.
>
> emailService.sendEmail() reads better than emailService.send_email();
>
> but I think for url puproses I like  /account/add_subscription.
>
> The question I have is why does the framework need to worry about
> this. This could easily be accomplished by a rewrite rule. I think the
> framework should do only what it needs to and let other systems od
> what they need to do.
>
> just my $0.02c
>
> On Feb 10, 9:19 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
>
> > All,
>
> > I've been going back and forth on some framework naming conventions
> > and wanted some feedback.
>
> > Typically speaking, ColdFusion reads better when components and
> > methods are written using camelcase. For example, something like
> > emailService.sendEmail() reads better than email_service.send_email()
> > or emailService.send_email().
>
> > However, I have always felt that folders and URLs look horrible when
> > written in camelcase, and instead I prefer to use underscores. For
> > example, if I were to list out all of the product categories that an
> > ecommerce application might have, a URL might look likehttp://www.myapp.com/product_categories/listandthe view might be

Dan Vega

unread,
Feb 10, 2011, 10:02:09 PM2/10/11
to col...@googlegroups.com
Yes but eventually your going to start asking yourself that for every question. You need to find a middle ground for features / performance.

Joe

unread,
Feb 10, 2011, 10:05:06 PM2/10/11
to ColdMVC
I'd agree with it.

I am not a fan of rewrite rules and it would be nice to have a setting
in the config.ini that would define a naming convention for actions.
Example: ActionConvention={url:"underscore",action:"camelcase"}.

An override in the annotations of the component or a function would be
handy too.Example:

/**
*@actionConvention {url:"underscore",action:"camelcase"}
*/
function test(){

}

The setting would need another name then "actionConvention", but I am
just trying to get the concept across.

In truth there could be many different naming conventions used, but I
think underscore and camelcase are the most popular in my opinion.

On Feb 10, 8:29 pm, Dan Vega <danv...@gmail.com> wrote:
> I would agree with a lot of this.
>
> emailService.sendEmail() reads better than emailService.send_email();
>
> but I think for url puproses I like  /account/add_subscription.
>
> The question I have is why does the framework need to worry about
> this. This could easily be accomplished by a rewrite rule. I think the
> framework should do only what it needs to and let other systems od
> what they need to do.
>
> just my $0.02c
>
> On Feb 10, 9:19 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
>
> > All,
>
> > I've been going back and forth on some framework naming conventions
> > and wanted some feedback.
>
> > Typically speaking, ColdFusion reads better when components and
> > methods are written using camelcase. For example, something like
> > emailService.sendEmail() reads better than email_service.send_email()
> > or emailService.send_email().
>
> > However, I have always felt that folders and URLs look horrible when
> > written in camelcase, and instead I prefer to use underscores. For
> > example, if I were to list out all of the product categories that an
> > ecommerce application might have, a URL might look likehttp://www.myapp.com/product_categories/listandthe view might be

Tony Nelson

unread,
Feb 10, 2011, 10:25:37 PM2/10/11
to col...@googlegroups.com
I would prefer to choose one or the other as the standard in order to allow plugins to work across the board without having to worry about configuration too much.

I agree though allowing an annotation to specify how the action is configured is nice. So then your methods could be named whatever you wanted and still have actions map to them correctly.

component {

    /**
     * @action foo
     */
    function doFoo() {

    }

}


-Tony

Tony Nelson

unread,
Mar 29, 2011, 1:06:14 PM3/29/11
to ColdMVC
Quick update.

The latest of ColdMVC will follow new conventions. A request made to /
account/add_subscription will invoke
AccountController.addSubscription() and will render a view located at /
views/account/add_subscription.cfm.

I hope this doesn't cause too many problems.

-Tony

Tony Nelson

unread,
Mar 29, 2011, 1:10:20 PM3/29/11
to ColdMVC
Random thought: Would people prefer to use hyphens instead of
underscores in actions and view paths? Zend Framework (PHP) uses
hyphens, along with other frameworks (I assume). Plus, CSS (background-
color) and HTML5 (data-foo) both use hyphens to separate words.
Thoughts?

-Tony
> > >www.myapp.com/product_categories/listandtheviewmight be

Joe

unread,
Mar 30, 2011, 8:06:19 AM3/30/11
to ColdMVC
I'd rather use underscores in case my view has a hyphen in the name
for some silly reason.

On Mar 29, 12:10 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
> Random thought: Would people prefer to use hyphens instead of
> underscores in actions and view paths? Zend Framework (PHP) uses
> hyphens, along with other frameworks (I assume). Plus, CSS (background-
> color) and HTML5 (data-foo) both use hyphens to separate words.
> Thoughts?
>
> -Tony
>
> On Mar 29, 12:06 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
>
> > Quick update.
>
> > The latest ofColdMVCwill follow newconventions. A request made to /
> > account/add_subscription will invoke
> > AccountController.addSubscription() and will render a view located at /
> > views/account/add_subscription.cfm.
>
> > I hope this doesn't cause too many problems.
>
> > -Tony
>
> > On Feb 10, 10:25 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
>
> > > I would prefer to choose one or the other as the standard in order to allow
> > > plugins to work across the board without having to worry about configuration
> > > too much.
>
> > > I agree though allowing an annotation to specify how the action is
> > > configured is nice. So then your methods could be named whatever you wanted
> > > and still have actions map to them correctly.
>
> > > component {
>
> > >     /**
> > >      * @action foo
> > >      */
> > >     function doFoo() {
>
> > >     }
>
> > > }
>
> > > -Tony
>
> > > On Thu, Feb 10, 2011 at 9:05 PM, Joe <jban...@gmail.com> wrote:
> > > > I'd agree with it.
>
> > > > I am not a fan of rewrite rules and it would be nice to have a setting
> > > > in the config.ini that would define anamingconvention for actions.
> > > > Example: ActionConvention={url:"underscore",action:"camelcase"}.
>
> > > > An override in the annotations of the component or a function would be
> > > > handy too.Example:
>
> > > > /**
> > > > *@actionConvention {url:"underscore",action:"camelcase"}
> > > > */
> > > > function test(){
>
> > > > }
>
> > > > The setting would need another name then "actionConvention", but I am
> > > > just trying to get the concept across.
>
> > > > In truth there could be many differentnamingconventionsused, but I
> > > > > > Ruby'snamingconventionstend to be a lot stronger than ColdFusion's.
Reply all
Reply to author
Forward
0 new messages