• Services
    • Oursourcing Services
      • Web Development
      • Mobile Development
      • Legacy Migration
      • Testing
      • Embedded System
    • Enterprise Services
      • SAP Services
      • Magento Services
      • Salesforce
  • Next-Gen Tech
    • AI
    • IoT
    • Blockchain
    • AR/VR
    • Big Data
    • Cloud
  • Industries
    • Automotive
    • Media & Entertainment
    • Heathcare
    • Security
    • Transportation
    • Retail
    • Finance
    • Energy
  • Case Study
  • About Us
    • Culture
    • Location
    • SETA Insight
  • enEnglish
  • Services
    • Outsourcing Services
      • Web Development
      • Mobile Development
      • Legacy Migration
      • Testing
      • Embedded System
    • Enterprise Services
      • SAP Services
      • Magento Services
      • Salesforce
  • Next-gen Tech
    • AI
    • IOT
    • Blockchain
    • Ar/Vr
    • Big Data
    • Cloud
  • Industries
    • Automotive
    • Media & Entertainment
    • Healthcare
    • Sercurity
    • Transportation
    • Retail
    • Finance
    • Energy
  • Case Study
  • About Us
    • Culture
    • Location
    • SETA Insight
  • Contact Us
  • enEnglish

Coding: Clean Code & Query Optimization

SETA International by SETA International
February 25, 2023
Home Technology
Share on FacebookShare on Twitter

Clean code

It turns out that to say that the code is clean and the system is designed correctly, easy reading of the code is not enough. It should have other qualities as well:

  • The code is easy to modify. With the right design and architecture, extending your code can be done without much time and expense. The entities of the code should not be closely related to each other; the code should be somewhat abstract and self-sufficient. Each entity that we operate during the development should be responsible only for its own part of the functionality.
  • The code must be stable, predictable, secure, and reliable. No matter how simple the code is to read, it should be covered by tests. Good code and tests are always there. Moreover, it is not only the number of tests that is important, it is also their quality. With this code, there are no problems when running and debugging, it does not cause changes in the environment.
  • Protected code. When writing any code, you must not forget about the overall security of the product. We recommend that you get to know the basic principles of security and stick to them. If we’re talking about web projects, we recommend OWASP.
  • A good code is a code that isn’t there. This does not mean that all the code should be written on one line, and you should definitely be proud of subtle methods. This means that the code should not be duplicated, and some of the common things should remain at the abstraction level. In theory, simplifying your code should lead to fewer defects.
  • Reading the code itself is also important. Each developer has their own writing style, and the level of reading depends on our experience. We all want to write a simple, beautiful and concise code.

To get away from the subjective assessment of the quality of your code, in 1961, the term “code smells” or “code with a smell” was introduced. This is a group of rules and guidelines that clearly define whether it’s time to refactor. Odor leads to code decay, and developers should always strive to eliminate it. The need for refactoring directly follows from the presence of a code smell, and by preventing the cause, we can avoid the consequence. You can find more information on the key signs that it’s time for you to refactor in Martin Fowler book Refactoring: Improving the Design of Existing Code.

According to experts from SETA International, clean code means:

  • Being easy to readClean Code
  • Having simple logic
  • Variable name, method and function names should be fully worded/ Avoid acronyms.
  • Capability of inheriting and reusing
  • One method/ function should have <100-line code lengths
  • Declaration the variable closest to where it is used
  • Absolutely not using the loop that does not determine the ending-point

Query optimization

Query optimization is the overall process of choosing the most efficient means of executing a SQL statement. SQL is a nonprocedural language, so the optimizer is free to merge, reorganize, and process in any order. The database optimizes each SQL statement based on statistics collected about the accessed data.

Some rules to have a good query:

  • Capitalizing all key words (SELECT, INSERT, UPDATE, DELETE, GETDATE, CASE, WHEN, etc.)
  • Not using * in query select, but specifically list each column name in the query
  • In the WHERE clause, sorting the filters by priority as follows: Primary Key, Numeric, Flag, TextData, Date Time.
  • If you must use a nested SELECT to filter, then add TOP 1 to that query
  • Always adding NOLOCK to all select tables query
  • Always using the ISNULL function for items that can have NULL values ​​for comparison
  • Using block comment /**/ instead of line comment —
  • Never using or naming stored procedures that start with sp_….

Ways to find queries that slow down the system

  • Waiting for QA/Customer to detect & complain about slow functionality

  • Judging by experience: any function that writes too long is the slowest
  • Adding log-time response into API(s)
  • Adding log store query

Ways to optimize query

  • Adding index to the table (should not create more than 2 indexes for 1 table)
  • Re-optimizing the storage or relation of the table
  • Reducing the number of returned records
  • Avoiding the use of Trigger in table

Sources:

Genuisee

SETA International

Tags: Clean codeIT OutsourcingQuery Optimization
SETA International

SETA International

ONE-STOP TECHNOLOGY SERVICE PROVIDER
We help companies to do digital transformations and digital innovations

Next Post
[SETA CULTURE] Open Talk – Clean Code & Query Optimization

[SETA CULTURE] Open Talk - Clean Code & Query Optimization

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Cloud Computing, Edge Computing and Fog Computing – the differences briefly explained

Cloud Computing, Edge Computing and Fog Computing – the differences briefly explained

September 10, 2021
The Top 5 Sectors Transformed by IoT Innovation

Top 5 Sectors Transformed by IoT Innovation

December 8, 2023

Trending.

SAP Fiori – Translation

SAP Fiori – Translation

February 25, 2023
6 IT outsourcing trends in 2023

6 IT outsourcing trends in 2023

January 17, 2023
Mobile app development

The Essential Development Guide for a Successful Mobile App

February 10, 2023
Top 10 Countries for IT outsourcing

Top 10 Countries for IT outsourcing

February 8, 2023
Full-Outsourcing and Subcontracting, what’s the difference?

Full-Outsourcing and Subcontracting, what’s the difference?

February 8, 2023

OUTSOURCING SERVICES

  • Web Development
  • Mobile Development
  • Legacy Migration
  • Testing
  • Embedded System

ENTERPRISE SERVICES

  • SAP Services
  • Magento Services
  • Salesforce

NEXT-GEN TECHNOLOGIES

  • AI
  • IoT
  • Blockchain
  • AR/VR
  • Big Data
  • Cloud

R&D

  • Research & Development

INDUSTRIES

  • Automotive
  • Media & Entertainment
  • Security
  • Heathcare
  • Transportation
  • Retail
  • Finance
  • Energy

RESOURCE CENTER

  • Case Studies

ABOUT US

  • Culture
  • Location
  • SETA Insight

Social EN

contact@setacinq.vn
  • Research & Development

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Copyright 2021 SETA International. All rights reserved.