Naming ID, Class, Componentes, database

Hey!

I would like to work the best way in the organization of the code. I know the naming is important.

When I follow tutorials or I read forums. People name ID and Class differently. And with Wappler every person does it differently.

When I tried to learn JS the only thing I remember is that variables are named “thisIsExample”.

When I follow tutorials about MySQL(MariaDB), some people name the tables “user_data” others “userData”.

I saw that the CLASS is always “user-data”.

What would be the best practice for Wappler?

Is recommended that always name ID?

If there’s any good tutorial or course about this. I will appreciate it if you share it with me.

Cheers

this is not a standard case and you can use whichever is best for you. However, as you said, choosing common usage patterns will create a more understandable code layout.

I will pur resources that I find.


Source: https://courses.cs.washington.edu/courses/cse154/17au/styleguide/html-css/naming-conventions-html.html#class-id-names

I thought about this for ages… I wanted a system that was simple and consistent across all the languages (html, css, php/server actions, MySQL).

I chose:

All word separators are underscore, e.g first_name.

All characters lower case.

Start with what you have and then describe it, eg amount_invoiced rather than invoiced_amount, (amount_sales_tax, amount_deposit)

Make id values start with a letter. Eg c_amount_invoiced for a column.

Don’t get hung up about giving everything an id. With Wappler you can just select things graphically.

Hope that helps!

Antony.

1 Like

Given the same terms may appear in various contexts, I find it helpful to add prefixes so I can identify the right type of thing when searching a page, or a whole project. Eg I’ll prefix a serverconnect component with sc_ and a repeat with rpt_ etc.

This is particularly useful if you decide to change the terms you’ve chosen, as different terms seem to make more sense as you’re developing. I expect if you plan everything very carefully in advance, this wouldn’t be necessary, but I never seem to manage that.

The same approach applies to tables, column names etc.

1 Like