You're never right (or wrong) about naming conventions. As you go from employer to employer, you'll encounter different conventions at every workplace, and you'll always have to adapt. You've already stated what you prefer, so when working on your own projects, simply use that, except your system is built on top of something else, that consistently uses another convention. Then I'd say you'd be better off using that convention in that project. Consistency > Preference.
Please keep calm if you don't like this idea, but did you consider column names independent from table names ?
Semantics
The semantic would be : "if two fields are called startDate and endDate, then they designates the dates that determine the period considered for the current table."
That semantic usually crosses tables, so having a consistent name is good.
Implementation concerns
In the database
Maybe some people say that they still understand if that common column name is prefixed by the table name. But in several use cases, we got bitten by this and prefer:
To you use meta-requests (ex. create a request to read all columns named startDate, or find all tables that use some reference data) efficiently, fixed names are much easier.
Stored procedure or triggers also can be reused easier if the names are fixed.
ORM
ORM are really good at letting you define a field once, then create subclasses that will have that field automatically (composition is also used). The database has no subclassing, but
If the various tables mapped on the classes use the same name for columns, everything is natural.
Otherwise, you have to hand-code (or declare) the fact that the startDate in the code is implemented in the database as XXXStartDate or XXX_start_date...
Requiring Aliases
Some requests are self-joins, joining the same table twice, thus requiring to use aliases for table names in every case.
Most other hand-coded requests join several tables. This naming policy would increase the likelihood that two columns have the same name, so that would require to use aliases. Is that a problem? I think it isn't because:
Using aliases is often recommended anyway, and considered good-practice.
Using aliases in both cases allow for a more consistent coding environment.
Using aliases allow a few advantages over table names: a. Can allow long and clear table names, including a prefix to group the tables by "modules", as a shorter alias can be used in requests. b. While a table name is fixed for all modules of all applications that access the database, applications or modules can use varying aliases in their requests, allowing to provide more semantic in the requests (just like the choice of naming a variable in the code, with the same rules).
both naming conventions you've shown are completely acceptable. writingLikeThis is easier to type, but writing_like_this is easier to read. The most important thing is consistency. Pick one naming convention and stick with it.
发布评论
评论(3)
关于命名约定,你永远不会是对的(或错的)。当你从一个雇主换到另一个雇主时,你会在每个工作场所遇到不同的惯例,并且你总是必须适应。您已经说明了自己喜欢什么,因此在处理自己的项目时,只需使用它即可,除非您的系统是构建在其他始终使用另一个约定的东西之上的。那么我想说你最好在该项目中使用该约定。一致性>偏爱。
You're never right (or wrong) about naming conventions. As you go from employer to employer, you'll encounter different conventions at every workplace, and you'll always have to adapt. You've already stated what you prefer, so when working on your own projects, simply use that, except your system is built on top of something else, that consistently uses another convention. Then I'd say you'd be better off using that convention in that project. Consistency > Preference.
如果您不喜欢这个想法,请保持冷静,
但是您是否考虑过列名称独立于表名称?
语义
语义是:
“如果两个字段称为 startDate 和 endDate,则它们指定确定当前表所考虑的期间的日期。”
该语义通常跨表,因此具有一致的名称是很好的。
实现问题
在数据库中
也许有人说如果那个公共列名以表名为前缀他们还是明白的。但在几个用例中,我们被这个问题困扰并且更喜欢:
ORM
ORM 确实擅长让您定义一次字段,然后创建自动具有该字段的子类(也使用组合)。数据库没有子类,但是
需要别名
有些请求是自联接,两次联接同一个表,因此需要在每种情况下都使用表名的别名。
大多数其他手工编码的请求都会连接多个表。此命名策略会增加两列具有相同名称的可能性,因此需要使用别名。这是一个问题吗?我认为这不是因为:
一个。可以允许长且清晰的表名称,包括按“模块”对表进行分组的前缀,因为可以在请求中使用较短的别名。
b.虽然访问数据库的所有应用程序的所有模块的表名称都是固定的,但应用程序或模块可以在其请求中使用不同的别名,从而允许在请求中提供更多语义(就像命名的选择一样)代码中的变量,具有相同的规则)。
Please keep calm if you don't like this idea,
but did you consider column names independent from table names ?
Semantics
The semantic would be :
"if two fields are called startDate and endDate, then they designates the dates that determine the period considered for the current table."
That semantic usually crosses tables, so having a consistent name is good.
Implementation concerns
In the database
Maybe some people say that they still understand if that common column name is prefixed by the table name. But in several use cases, we got bitten by this and prefer:
ORM
ORM are really good at letting you define a field once, then create subclasses that will have that field automatically (composition is also used). The database has no subclassing, but
Requiring Aliases
Some requests are self-joins, joining the same table twice, thus requiring to use aliases for table names in every case.
Most other hand-coded requests join several tables. This naming policy would increase the likelihood that two columns have the same name, so that would require to use aliases. Is that a problem? I think it isn't because:
a. Can allow long and clear table names, including a prefix to group the tables by "modules", as a shorter alias can be used in requests.
b. While a table name is fixed for all modules of all applications that access the database, applications or modules can use varying aliases in their requests, allowing to provide more semantic in the requests (just like the choice of naming a variable in the code, with the same rules).
您所显示的两种命名约定都是完全可以接受的。 writingLikeThis 更容易输入,但writing_like_this 更容易阅读。最重要的是一致性。选择一种命名约定并坚持使用。
both naming conventions you've shown are completely acceptable. writingLikeThis is easier to type, but writing_like_this is easier to read. The most important thing is consistency. Pick one naming convention and stick with it.