我在大约8个开发人员的团队中,在大约1'000'000行源代码的基础上开发代码库.我们的代码基本上是一个使用Oracle数据库的应用程序,但代码随着时间的推移而发展(我们有很多来自九十年代中期的源代码!).
团队之间就我们用于查询Oracle数据库的语法发生争执.目前,绝大多数查询使用"旧"Oracle语法进行连接,这意味着我们的代码看起来像这样......
内连接示例
select customers.*
, orders.date
, orders.value
from customers, orders
where customers.custid = orders.custid
Run Code Online (Sandbox Code Playgroud)
外连接示例
select customers.custid
, contacts.ContactName
, contacts.ContactTelNo
from customers, contacts
where customers.custid = contacts.custid(+)
Run Code Online (Sandbox Code Playgroud)
随着新开发人员加入团队,我们注意到他们中的一些人似乎更喜欢使用SQL-92查询,如下所示:
内连接示例
select customers.*
, orders.date
, orders.value
from customers inner join orders
on (customers.custid = orders.custid)
Run Code Online (Sandbox Code Playgroud)
外连接示例
select customers.custid
, contacts.ContactName
, contacts.ContactTelNo
from customers left join contacts
on (customers.custid = contacts.custid)
Run Code Online (Sandbox Code Playgroud)
A组说每个人都应该使用"旧"语法 - 我们有很多这种格式的代码,我们应该重视一致性.我们没有时间通过现在重写数据库查询的代码,如果我们有,它将不会付给我们.他们还指出"这是我们一直这样做的方式,我们对它感到满意......"
然而B组表示他们同意我们没有时间返回并更改现有查询,我们真的应该采用我们在此处编写的代码上的"新"语法.他们说开发人员只是真的一次查看一个查询,只要开发人员知道这两种语法,就没有什么可以从严格遵守旧语法中获得的,这可能会在将来的某个时候被弃用.
在没有宣布我忠诚于哪个群体的情况下,我有兴趣听取公正观察员的意见 - 所以让游戏开始吧!
马丁.
PS.我已经把它变成了一个社区wiki,以免被人看作只是公然追问问题点...
类似的东西在这里,但没有那么多的开发人员,而不是旧的代码.我正在使用更新的东西,年长的人正在使用较旧的风格,但我们都知道对方正在尝试做什么.
就个人而言,我会说使用哪种风格更容易让个别开发人员使用.除非你运行基准测试并发现一个基准测试速度快于另一个基准测试(因为,重要的是差异很大),并且新旧旧的都可以阅读并理解他们看到的查询,所以没有理由改变它们.
但是,我的个人投票是保留旧的东西,并使用较新的语法编写新的查询,因为使用JOINs USING和ON等等更容易阅读,并知道发生了什么,然后有一堆AND x.col = y.col AND z.col = a.col在该WHERE部分.
那个,新人可能会更长,所以他们最终会得到他们的方式......
不知道你们其他人,但我讨厌不得不尝试使用旧式的加入来计算这样的东西(或写这个):
SELECT DISTINCT product_zone_map_id, zh.name_english, zh.name_french, zone_id, ad.attribute_value_english AS bullprep_region_type,
product_zone_type_id, ad.attribute_value_english, language_english, product_code, office_code,
(
SELECT attribute_value_english
FROM presentation p JOIN presentation_details ad USING(presentation_id)
WHERE dimension_id = 4
AND object_id = product_zone_map_id
AND attribute_type = 'BULLPREP PARENT ID'
AND p.usage_start_date <= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss')
AND (p.usage_end_date >= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss') OR p.usage_end_date IS NULL)
) AS bullprep_parent_id,
(
SELECT attribute_value_english
FROM presentation p JOIN presentation_details ad USING(presentation_id)
WHERE dimension_id = 4
AND object_id = product_zone_map_id
AND attribute_type = 'BULLPREP GROUP ID'
AND p.usage_start_date <= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss')
AND (p.usage_end_date >= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss') OR p.usage_end_date IS NULL)
) AS bullprep_group_id, product_zone_seq
FROM zone z JOIN zone_history zh ON(z.zone_id = zh.zone_id)
JOIN product_zone_map pzm ON(z.zone_id = pzm.zone_id)
JOIN product USING(product_id)
JOIN product_history ph USING(product_id)
JOIN language_reference USING(language_id)
LEFT OUTER JOIN product_zone_attribute_details pzad USING(product_zone_map_id)
LEFT OUTER JOIN attribute_details ad USING(attribute_id)
JOIN zone_geocode_map USING(zone_id)
JOIN geocode USING(geocode_id)
WHERE zh.usage_start_date <= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss')
AND (zh.usage_end_date >= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss') OR zh.usage_end_date IS NULL)
AND pzm.usage_start_date <= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss')
AND (pzm.usage_end_date >= TO_TIMESTAMP('2010-05-12', 'yyyy-mm-dd hh24:mi:ss') OR pzm.usage_end_date IS NULL)
AND (attribute_type = 'BULLPREP REGION TYPE' OR attribute_type IS NULL)
AND product_id = 2075
ORDER BY product_zone_seq
Run Code Online (Sandbox Code Playgroud)