bgrins / ExpandingTextareas

jQuery plugin for elegant expanding textareas
http://bgrins.github.com/ExpandingTextareas/
MIT License
260 stars 73 forks source link

Suggestion: improve naming conventions #36

Closed domchristie closed 10 years ago

domchristie commented 10 years ago

There are currently a few different ways to name various parts of the plugin:

Project name:                ExpandingTextareas
Source filename:             expanding.js
jQuery method name:          expandingTextarea()
Container class name:        expandingText
Initial selector class name: expanding
Init class name:             expanding-init
Clone class name:            textareaClone
Event namespace:             expanding

May I suggest the following to improve consistency?:

Project name:                ExpandingTextareas (unchanged)
Source filename:             expanding.js (unchanged)
jQuery method name:          expanding()
Container class name:        expanding
Initial selector class name: expanding__textarea
Init class name:             expanding__textarea--init
Clone class name:            expanding__clone
Event namespace:             expanding (unchanged)

(CSS class names based on BEM)

Thoughts?

bgrins commented 10 years ago

I'm all for cleaning up the naming and making it more consistent. A few thoughts:

Initial selector class name: expanding__textarea - I'm not sure about this one, since this is the class that people will add on their in HTML elements, and it seems less guessable / 'rememberable' than either expanding or expandingTextarea.

jQuery method name: expanding(): It is less specific (though I'm not seeing any existing plugins using that name), but it does match the file name which is a good convention to follow. Alternatively, we could rename the file to expandingTextarea.js to match the $.fn name. I think expanding is a little less ugly FWIW, especially as we move forward into the CSS selectors used (which should be consistent with the method name).

Other CSS names - I think unifying all of these under the plugin name is a good idea. If I was to come up with names based on conventions from other plugins I've done I would use:

Container class name:        expanding-container
Initial selector class name: expanding
Init class name:             expanding-init
Clone class name:            expanding-clone

Either your suggestions or these would be better than what is in use now, since they are at least more consistent. Anyway, these are just some thoughts, what do you think?

domchristie commented 10 years ago

Re: class names: I like those. Whilst the BEM style is nice, it’s probably overkill and harder to understand.

Re: jQuery method name: yes, the name expanding is quite broad, but given that the plugin has used it for its event namespace (for couple years, without any conflicts AFAIK), it’s probably safe to go ahead.

It does read pretty nicely:

$('textarea').expanding();
domchristie commented 10 years ago

Minor point, what about .expanding-wrapper?

I tend to think of containers having some kind of constraints (like height or width), whereas wrappers just enclose their contents.

domchristie commented 10 years ago

Closed with #38