Quick Short Answer:
There are different ways to solve a problem, wheter is Collegue or Full-Time-Job.
Things like "Best Practices" are very useful, but, as many things, should be applied in a practical manner, meanning many times you applied, a few times, not.
Long Boring Descriptive Answer
One real world case, I had. I worked in a company where the business application had some legacy code, and the chief of developers, old guy, didn't care about "Best Pratices". Some of that code, was working so bad, that really need a full start from scratch.
There where also new modules, done or supervised by the second main developer, a young person that just finished school, that want everybody to use "Software Patterns". And you may know there are several software patterns, not just one. And he insisted on using the patterns, even if it was the wrong one.
Example of different "Best Practices"
In your example of "ID" in databases tables, some people use:
Example 1 (Same fieldname can be used for different keys & fields):
SaleItem = {
int Id,
int Product,
int Qty,
double Price,
}
ProductItem = {
int Id,
int Name,
double UnitPrice,
}
/* has to rename a lot of fields, */
/* "WHERE" sentence fields are different for the same concept */
SELECT
SaleItem.Id AS SaleId,
Product.Id AS ProductId,
Product.Name AS ProductName,
SaleItem.Qty,
SaleItem.Price
FROM
SaleItem INNER JOIN Product
ON
(SaleItem.Product = Product_Id)
Others:
Example 2 (Same field concept still has different names):
SaleItem = {
int SaleId,
int Product,
int Qty,
double Price,
}
ProductItem = {
int ProductId,
int Name,
double UnitPrice,
}
/* "WHERE" sentence fields are different for the same concept */
SELECT
SaleItem.SaleId,
Product.ProductId,
SaleItem.Qty,
Product.ProductName,
SaleItem.Price
FROM
SaleItem INNER JOIN Product
ON
(SaleItem.Product = Product_Id)
Me:
Example 3 (Verbose, but, same field concept uses the same across tables):
SaleItem = {
int SaleId,
int ProductId,
int SaleQty,
double SalePrice,
}
ProductItem = {
int ProductId,
int ProductName,
double ProductUnitPrice,
}
/* (with "redneck" voice) */
/* "Look ma', no aliases and the keys have the same name !!! " */
SELECT
SaleItem.SaleId,
Product.ProductId,
SaleItem.SaleQty,
Product.ProductName,
SaleItem.SalePrice
FROM
SaleItem INNER JOIN Product
ON
(SaleItem.Product_Id = Product_Id)
This example shows that "Best Practices", altought very useful, must be well supported by facts, and cannot be applied to all cases. And in some cases, is subjective to the people who use them.
goto. – SK-logic Oct 19 '11 at 14:22"In theory, there's no difference between theory and practice. In practice, there is."Obligatory goto comic: xkcd.com/292 – StuperUser Oct 19 '11 at 14:26gotoin any language (I voted for SK-logic's comment because I interpreted it sarcastically);Idis a lousy name for a primary key. These things are not absolute, but they point you in the right direction. – Caleb Oct 19 '11 at 15:00