Hacker News new | ask | show | jobs
by stronglikedan 4423 days ago
I like to prefix the element name with the entity name that will be written to. That way, if I have a form that will be writing to the attributes of multiple entities, I know exactly what each represents. If two entities share an attribute name, then the element names will be distinct. For instance, if I have a UI where the user can enter order details and add order lines, then the elements that represent order attributes are prefixed with "order-" and the others are prefixed with "orderLine-". It is tremendously helpful during maintenance.
1 comments

Yep, that too. "dm2_register_form_name_input" for example. You could probably mix upper/lowercase to format it better but for some reason I don't like to mix them, just personal preference.

I avoid dashes because the text editor I use doesn't select them as a whole word when I double click them.

Oops, I didn't mean to type "orderLine" in camel case. I usually use underscores in the entity and attribute names, and separate them with a dash, like "order_line-item_sku". That way, I can distinctly select the entity or attribute, or easily search for all attributes for a given entity, like "order_line-".