在团队中是否应统一使用 ORM?使用 SQL 语句有什么坏处?
如题。
团队规模为10人。编程环境为 PHP + Python。
个人觉得在大家都会 SQL,并且掌握一些 SQL 技巧时,统一使用 SQL 语句可以在以后性能调优时更直观。不知各位“过来人”有何高见。
另外在 Model 里有没有必要把 phpredis 的函数重新封装为 ORM ?感觉 Redis 本身就是为速度存在的,如果再在入口处加一些解析、判断、封装,是不是会有悖于 Redis 的主旨,而且涉及数据交互的 Model 在我们团队里仅由2人负责,编码规范化的问题应该不是问题。
回复内容:
如题。
团队规模为10人。编程环境为 PHP + Python。
个人觉得在大家都会 SQL,并且掌握一些 SQL 技巧时,统一使用 SQL 语句可以在以后性能调优时更直观。不知各位“过来人”有何高见。
另外在 Model 里有没有必要把 phpredis 的函数重新封装为 ORM ?感觉 Redis 本身就是为速度存在的,如果再在入口处加一些解析、判断、封装,是不是会有悖于 Redis 的主旨,而且涉及数据交互的 Model 在我们团队里仅由2人负责,编码规范化的问题应该不是问题。
SQL一个比较大的麻烦就是不限权(或者是限权不细)。一个SQL语句的书写失误,可能毁掉整个系统的所有数据。
因此甚至包括WordPress在内的,几乎所有的框架都不怎么提倡直接把SQL语句硬编码(hard code)在程序中,而是必须封装起来。
不要觉得只有两个人做就不必封装了——缺少规矩,人少也出事儿。
可以使用一些轻量级的ORM,好处就是:
1、开发快,很多细节封装起来了,比如数据库连接的使用和释放
2、面向对象的开发方式让代码更易理解和维护
3、完全不会限制你做SQL调优,比如类似mybatis这样轻量级的ORM,还是使用SQL访问数据
网上有的是AR类,随便搞一个用,不要直接写SQL,要是想调节性能你可以加一层logging专门记录慢查询和方法。
我见过很多人把redis封装成ORM的接口,为了使用方便,包裹一些判断和加载那都太正常了,我们可以按需要给redis的ORM、Cache、Count、Queue分别封装, 这处性能影响不大。最主要是加速开发以及可维护性。
使用SQL的好处是直观一点, 但坏处比好处更多,例如硬编码的维护性低、前端人员水平良莠不齐你不能保证每个人写的SQL都一样,最主要的是编写速度慢,我觉得数据库语句这种东西,前端开发人员甚至不该直接接触。
在项目中,更偏向于直接写SQL,而不是用ORM,对于Python之类的弱类型语言,更甚。 SQL表达能力已经很强,比较简单,易于上手。
程序员学习SQL,好处有:
1. SQL语句,可以在命令行(mysql) & 其它图形化工具 执行,一边修改,一边调试。
2. 在互联网上,SQL的文档很多,而ORM的文档偏少。有困难时,比较容易找到解答
3. SQL更通用,你可能学习了很多ORM,但不明白SQL,你能说自己懂ORM了么?
程序员,熟悉SQL,进而数据库,是对自己的要求。这可能是DBA的事,但也是你进步,增值的方法。
可以参考discuz的封装,另外对所有涉及到sql的更改都进行2人左右的review
http://www.cnblogs.com/needrunning/archive/2011/11/15/2250068.html
个人觉得
使用orm的好处
<code>1. 节约时间,指的是程序员的时间,如果题主不是做效率要求很高的东西,整个团队节约下来的时间是很客观的,非常喜欢一句话“宁花机器一分,不花程序员一秒”,题主选择了python,相信应个对这个体会比较深吧(生命苦短,我用python~) 2. 适合工程,对同一类需求,基本上不同人写出来的东西是一样的,sql有这种问题,如果一个人写了很复杂的东西,这个成员离职或怎样,这段代码就会变成野草(非常难看懂,非常痛苦),早晚会被之后的维护者重写的,orm的话代码逻辑比较清晰。 </code>
orm的坏处
<code>1. 效率,orm的话会存在一些效率的问题,毕竟编译的时候会生成一些别的代码,可能一个复杂的需求写4、5十行sql的效率 > orm的效率,不过实在是很蛋疼 2. 学习成本,很多人都是先学sql,然后接触orm,自然有学习成本的问题,而且使用orm就要符合orm的规范,有些高效的orm使用方式还是一种隐藏的附加技能,需要不断探索 </code>
综上
对于一个把程序员的时间看作第一位的团队(项目超期是很正常的事情),如果对程序的执行效率要求不是超高的话,是用orm绝对是让你轻松的一件事情。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to download DeepSeek Xiaomi? Search for "DeepSeek" in the Xiaomi App Store. If it is not found, continue to step 2. Identify your needs (search files, data analysis), and find the corresponding tools (such as file managers, data analysis software) that include DeepSeek functions.

The key to using DeepSeek effectively is to ask questions clearly: express the questions directly and specifically. Provide specific details and background information. For complex inquiries, multiple angles and refute opinions are included. Focus on specific aspects, such as performance bottlenecks in code. Keep a critical thinking about the answers you get and make judgments based on your expertise.

Just use the search function that comes with DeepSeek. Its powerful semantic analysis algorithm can accurately understand the search intention and provide relevant information. However, for searches that are unpopular, latest information or problems that need to be considered, it is necessary to adjust keywords or use more specific descriptions, combine them with other real-time information sources, and understand that DeepSeek is just a tool that requires active, clear and refined search strategies.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

DeepSeek is not a programming language, but a deep search concept. Implementing DeepSeek requires selection based on existing languages. For different application scenarios, it is necessary to choose the appropriate language and algorithms, and combine machine learning technology. Code quality, maintainability, and testing are crucial. Only by choosing the right programming language, algorithms and tools according to your needs and writing high-quality code can DeepSeek be successfully implemented.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Question: Is DeepSeek available for accounting? Answer: No, it is a data mining and analysis tool that can be used to analyze financial data, but it does not have the accounting record and report generation functions of accounting software. Using DeepSeek to analyze financial data requires writing code to process data with knowledge of data structures, algorithms, and DeepSeek APIs to consider potential problems (e.g. programming knowledge, learning curves, data quality)

Arrays are linear data structures used to process data in programming. Sometimes when we are processing arrays we need to add new elements to the existing array. In this article, we will discuss several ways to add elements to the end of an array in PHP, with code examples, output, and time and space complexity analysis for each method. Here are the different ways to add elements to an array: Use square brackets [] In PHP, the way to add elements to the end of an array is to use square brackets []. This syntax only works in cases where we want to add only a single element. The following is the syntax: $array[] = value; Example
