PHP/MySQL命名约定:camelCase vs under_score? [英] PHP/MySQL naming conventions: camelCase vs under_score?

查看:115
本文介绍了PHP/MySQL命名约定:camelCase vs under_score?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在PHP模型代码中(至少在我自己的此类代码中)直接引用MySQL表和字段名,并且由于MySQL标识符在大多数情况下不区分大小写,因此我通常使用under_score命名约定这些标识符更具可读性.

Quite often in PHP model code (at least in my own such code) there are direct references to MySQL table and field names, and since MySQL identifiers are for the most part case-insensitive I typically use the under_score naming convention to make those identifiers a bit more readable.

但是,与此同时,似乎大多数人在创建PHP类库时都使用camelCase约定,而我也一直在尝试这样做.

At the same time however, it seems that most folks use camelCase conventions when they create PHP class libraries, and I've been trying to do that, too.

最重要的是,PHP内置函数本身是不一致的.他们中的一些人使用camelCase,其他人使用under_scores,其他人使用C样式命名(例如"strtolower").

On top of that, the PHP built-in functions themselves are inconsistent. Some of them use camelCase, others use under_scores, and others use C-style naming (for example "strtolower").

结果是,代码的可读性往往比我喜欢的要差得多,在混合的camelCase,under_score和C风格的命名约定中,代码在彼此之间非常接近.

The result is that the code tends to be much less readable than I prefer, what with mixed camelCase, under_score, and C-style naming conventions showing up quite near each other in the code.

其他人如何处理呢?也许人们发现了某种方式来组织他们的工作,以致于不同的命名约定往往看起来不太接近?或者,也许有一些类库,如果使用得当,它们会使内容更简洁一些?我知道这些关于风格的讨论会变得很热烈-不需要去那里,请提供一些实用的建议!

How are other folks dealing with this? Perhaps there's some way people have found to organize their work so that the different naming conventions tend not to appear quite so close to each other? Or perhaps there are class libraries that if used properly, tend to make things a bit cleaner? I know these discussions of style can get heated -- no need to go there, just some practical suggestions please!

推荐答案

正如teresko所说,MySQL名称在* NIX平台上区分大小写,而在Windows上则不区分大小写.如果您开发的代码能够同时支持这两种情况(如我所做的那样),那么混合您的案例会引起巨大的麻烦:例如,在Windows上转储数据库并将其还原到* NIX上,所有案例都会丢失.出于这个原因,我们实际上不得不收集代码以检测和修复转储中的案件.

As teresko says, MySQL names are case sensitive on *NIX platforms and insensitive on Windows. If you develop code to support both (as I do) then mixing your cases can cause huge headaches: for example, dump a database on Windows and restore it onto *NIX and all your cases are lost. We actually had to kludge code to detect and fix the cases in a dump just for this reason.

如果您没有Windows,只要您保持一致,使用什么都没有关系.

If you're free of Windows though it doesn't really matter what you use, as long as you keep it consistent.

这篇关于PHP/MySQL命名约定:camelCase vs under_score?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆