Should I use ORM in my team? What are the disadvantages of using SQL statements?

Source: Internet
Author: User
As the question. The team size is 10 members. The programming environment is PHP + Python. I personally think that when you are familiar with SQL and master some SQL skills, using SQL statements in a unified manner can be more intuitive in future performance tuning. I don't know what a high opinion you have on people. In addition, is it necessary to include... in the Model.
The team size is 10 members. The programming environment is PHP + Python.
I personally think that when you are familiar with SQL and master some SQL skills, using SQL statements in a unified manner can be more intuitive in future performance tuning. I don't know what a high opinion you have on people.
In addition, is it necessary to re-encapsulate the phpredis function as An ORM in the Model? I feel that Redis itself is a speed. If I add some parsing, judgment, and encapsulation at the entrance, is it against Redis's purpose, in addition, the Model involving data interaction is only the responsibility of two persons in our team. The problem of coding standardization should not be a problem.

Reply content:

As the question.
The team size is 10 members. The programming environment is PHP + Python.
I personally think that when you are familiar with SQL and master some SQL skills, using SQL statements in a unified manner can be more intuitive in future performance tuning. I don't know what a high opinion you have on people.
In addition, is it necessary to re-encapsulate the phpredis function as An ORM in the Model? I feel that Redis itself is a speed. If I add some parsing, judgment, and encapsulation at the entrance, is it against Redis's purpose, in addition, the Model involving data interaction is only the responsibility of two persons in our team. The problem of coding standardization should not be a problem.

SQL is a big headacheUnlimited(Or the permission is not limited ). Writing errors of an SQL statement may destroy all data of the entire system.

Therefore, almost all frameworks, including WordPress, do not advocate that the hard code of SQL statements should be directly encapsulated in the program.

Don't think that there is no need to encapsulate it when only two people do it-there is a lack of rules, and there are also fewer people.

You can use some lightweight ORM with the following benefits:
1. fast development and many details are encapsulated, such as the use and release of database connections.
2. The object-oriented development method makes the code easier to understand and maintain
3. You will not be limited to SQL optimization, such as lightweight ORM like mybatis, or use SQL to access data.

There are AR classes on the Internet. You can use them at will and do not directly write SQL statements. If you want to adjust the performance, you can add a layer of logging to record slow queries and methods.
I have seen many people encapsulate redis as An ORM interface. For ease of use, it is too normal to package some judgments and loads, we can encapsulate the ORM, Cache, Count, and Queue of redis as needed, which has little impact on performance. The most important thing is accelerated development and maintainability.

The advantage of using SQL is a little intuitive, but the disadvantage is more obvious than the advantage. For example, hard-coded maintainability is low, and front-end personnel are not good enough. You cannot guarantee that everyone writes the same SQL statement, the most important thing is that the writing speed is slow. I think front-end developers should not even directly access the database statements.

In projects, it is more inclined to write SQL directly, rather than using ORM. For weak types of languages such as Python, it is even worse. SQL expressions are very powerful, simple, and easy to use.

Programmers learn SQL with the following benefits:
1. SQL statements can be executed in the command line (mysql) & other graphical tools, modified while debugging.
2. There are many SQL documents on the Internet, but fewer ORM documents. When there are difficulties, it is easier to find answers
3. SQL is more common. You may have learned a lot about ORM, but you don't understand SQL. Can you understand ORM yourself?

Programmers, familiar with SQL, and then databases, are their own requirements. This may be about DBA, but it is also a method for your progress and value-added.

You can refer to the discuz encapsulation. In addition, you can review all SQL-related changes by about 2 persons.

Http://www.cnblogs.com/needrunning/archive/2011/11/15/2250068.html

I personally think

Benefits of Using orm
1. saving time refers to the programmer's time. If the subject is not a matter of high efficiency requirements, the time saved by the entire team will be objective. I like the phrase "I 'd rather spend a minute on the machine, I don't need to spend a second as a programmer. "I chose python as the subject. I believe I have a deep understanding of it. (I am using python for a short time ~) 2. it is suitable for projects. For the same type of requirements, basically different people write the same thing. SQL has this problem. If a person writes something complicated, what should the member leave, this code will become a weed (very difficult to understand, very painful). It will be rewritten by the maintainer later in the evening, and the code logic of the orm is clearer.
Disadvantages of orm
1. efficiency: there will be some efficiency problems in the case of orm. After all, some other code will be generated during compilation. It may be a complicated requirement to write 4 or 5 dozen rows of SQL efficiency> orm efficiency, but it is really a pain 2. learning costs, many people learn SQL first, and then come into contact with orm. Naturally, there is a learning cost problem, and the use of orm must comply with the orm specifications, some Efficient orm usage is a hidden additional skill and needs to be continuously explored.
To sum up

For a team that regards the programmer's time as the first team (it is normal that the project is out of date), if the execution efficiency requirement on the program is not very high, it is definitely easy to use orm.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.