1

I am trying to find good references for widely agreed naming/code-style standards for PHP (Laravel), JS and MySQL. In particular, I am looking at variable names and table column names.

From what I can see, by reading some guides and people's opinions, and reading code, it is widely accepted that:

  • PHP Variables as camelCase
  • JS Variables as camelCase
  • MySQL column names as snake_case

This seems quite inefficient, since when writing applications making use of all the technologies (especially JS apps interacting with an API) there is a lot of mapping going on unnecessarily between the two (e.g. first_name -> firstName), whether that's in the backend or the frontend.

Is there any reason for this, are there any major drawbacks by using camelCase for MySQL column names?

Giedrius
  • 1,370
  • 3
  • 14
  • 37
  • 2
    No issues I know of, if it reduces development time then go ahead. Just note that MySQL column names are case sensitive on Linux and case insensitive on Windows [https://stackoverflow.com/a/23929312/4516316](https://stackoverflow.com/a/23929312/4516316) – Arun A S Jun 02 '20 at 04:12
  • Check [this](https://github.com/alexeymezenin/laravel-best-practices) article. Also, check [PHP PSR standards](https://www.php-fig.org/psr/). You will spot that it is more than black or white. You also have `['array_key' => $arrayValue]` in PHP used (for example). Other than following standards you can do what ever you want that can be parsed/compiled but it will take time to other developers that follow all standards and recommendations to keep up with code that is not well standardized. – Tpojka Jun 02 '20 at 10:22
  • @Tpojka That's one of my main concerns - I am happy to come up with my own style and use it, but it will be a pain for the next developer if it's not within the widely accepted standards. I'd hate to take over code like that so would not want to produce code that's hard to pick up for the fellow developer. Therefore, I am in search of somewhat recognized style/standard that would avoid all the pointless mappings etc. – Giedrius Jun 02 '20 at 17:19
  • 2
    Honestly, I don't think you need to worry about the camel/snake case that much. It won't create too much of an issue. You should be more concerned on writing meaningful names. As long as it's not some random style such as `cOluMn_NamE`, it won't affect too many developers to switch between `column_name` and `columnName`. – Arun A S Jun 02 '20 at 17:33
  • 1
    @Giedrius Also, it is not uncommon thing that company/group develop and use own coding style aside of industry standard. Or just something as addition to already known styles. However, I'd recommend to stick with PSRs in first row, then on top of that to add additional styles pulled out from concrete framework used. That way everybody wins and it is way to have least confusion between developers. – Tpojka Jun 03 '20 at 06:36

0 Answers0