I don't want to camelCase my directive names

339 views
Skip to first unread message

Nick Retallack

unread,
Apr 9, 2014, 5:17:13 PM4/9/14
to ang...@googlegroups.com
Today I tried to dynamically create and use some directives at runtime.  Then I realized I have to spell them differently when I create them from when I use them.  This is silly.  Now I have to procedurally translate them between camelCase and snake-case myself.

One of my previous co-workers also thought this was stupid.  He was looking at my angular templates and then trying to grep the source code for where those attributes are used.  If I were using jQuery, those attributes would have shown up in the source code in selectors.  But since it's angular, they were camelCased, and thus un-greppable.

Being able to grep your source code for identifiers is one of those unspoken rules of software development, isn't it?

Since a directive's name is just a string, why can't we just write it the way it is going to appear, in snake-case?  I've heard the argument that it needs to be a valid JavaScript identifier, but when is it ever interpreted in JavaScript?  Angular is moving toward Polymer anyway, and in Polymer you have to name tags with dashes in them in the first place.

Alesei N

unread,
Apr 10, 2014, 8:54:08 AM4/10/14
to ang...@googlegroups.com
what do you mean by dynamically creating directives? please elaborate.

Alesei N

unread,
Apr 10, 2014, 8:54:16 AM4/10/14
to ang...@googlegroups.com
what do you mean by dynamically creating directives? please elaborate.

On Wednesday, April 9, 2014 4:17:13 PM UTC-5, Nick Retallack wrote:

Nick Retallack

unread,
Apr 10, 2014, 3:38:20 PM4/10/14
to ang...@googlegroups.com
Well I suppose you can't not create directives dynamically, but what I mean is, I'm creating several of them in a loop, the same way it is done in several places the angular source code.  Then I'm creating another directive that contains a switch statement between the dynamically created ones.  To embed the directives into the switch statement, I had to copy the camelCase/snake_case functions from the angular source code, since they aren't accessible.  I realize I could have just made this be one directive with a single massive template.  Anyway, that is all irrelevant to my point.

I'm just trying to say it's silly to have to name directives in camelCase when you have to use them in snake-case.  Why don't we just use snake-case all along?  This could be supported without dropping backward compatibility.  If the name is already in snake case, don't change it.  Convert it to camelCase internally if you need to.

Alesei N

unread,
Apr 10, 2014, 4:59:23 PM4/10/14
to ang...@googlegroups.com
i am sorry, i am still lost in terms what you are trying to describe. Code sample would be me more descriptive.

I am not sure how is this a problem, i am yet to find camelCase in directive's angular('module').directive('camelCase',[function(){}]) introducing any issues for me to write it as <div camel-case></div> or <camel-case></camel-case>. I agree it is a bit offsetting in begging. But beyond this initial getting to know angular, i have not had any issues with this.










--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/CMBzQc9-GUk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages