Home

Files should not have too many lines of code

Description

    This rule states that files should not contain an excessive amount of code. This is to ensure that files are easier to read and understand. It is also important to keep code organized and manageable. Too much code can lead to confusion and difficulty in debugging and maintaining the code. This rule helps to keep code organized and maintainable. It is important to keep the code as concise as possible and to split up large files into smaller, more manageable chunks. This will ensure that the code is easier to read and understand.

Key Benefits

  • Easier to Read: Files with fewer lines of code are easier to read and understand.
  • Easier to Debug: Files with fewer lines of code are easier to debug and maintain.
  • Improved Performance: Files with fewer lines of code can run faster and more efficiently.
  • Increased Security: Files with fewer lines of code are less likely to be vulnerable to attack.

 

Non-compliant Code Example

Create PROCEDURE [DATA].INIT  --Non compliant code (File is having more than default limit of 100 line of code)
@orderId int, 
@productId int,
@emp_Id int,
@cust_id int
AS
BEGIN
EXEC [DATA].GetAllOrders;

EXEC [DATA].LogCleaner;

EXEC [DATA].sp_customer_List;

EXEC [DATA].sp_retrieve_employees;

EXEC [DATA].GetAllProducts;

EXEC [DATA].GetOrderById @orderId;

EXEC [DATA].GetAllItems @orderId;

EXEC [DATA].GetProductById @productId;

EXEC [DATA].LogCleaner;

EXEC [DATA].GetManagerOfEmployeeById @emp_Id;

EXEC [DATA].DeleteCustomerById @cust_id;

EXEC [DATA].DeleteOrderById @orderId;

EXEC [DATA].DeleteOrderItemById @orderId;

EXEC [DATA].DeleteProductById @productId;

Declare @fname nvarchar(50);
Declare @lname nvarchar(50);

BEGIN

SET @fname = "Mark";
SET @lname = "Pencile";

EXEC [DATA].sp_GetFullname @fname,@lname;

EXEC [DATA].InsertCustomer @fname,@lname;

END

BEGIN

SET @fname = "James";
SET @lname = "Smith";

EXEC [DATA].InsertEmployee @fname,@lname;

END


BEGIN

SET @fname = "Maria";
SET @lname = "Garcia";

EXEC [DATA].UpdateCustomerName @cust_id,@fname,@lname;

END

BEGIN

SET @fname = "Maria";
SET @lname = "Hernandez";

EXEC [DATA].UpdateEmployeeName @emp_Id,@fname,@lname;

END

BEGIN

Declare @price int;
SET @price = 200;

EXEC [DATA].UpdateProductPrice @productId,@price;

END


BEGIN
-- Query the Product and Customer table by using the synonym.  
Select * from [DATA].CloneProduct;

Select * from [DATA].CloneCustomer;
INSERT INTO [DATA].CloneCustomer (fname, lname) VALUES (@fname, @lname);

SET @fname = "Maria";
SET @lname = "Hernandez";

UPDATE [DATA].CloneCustomer
	SET FNAME=@fname, LNAME=@lname
	WHERE Id = @cust_id;
	
DELETE [DATA].CloneCustomer where ID = @cust_id;

END


BEGIN
-- Query the Product table by using the sequences.  
SELECT NEXT VALUE FOR [DATA].ProductSeq;  

END

END
GO
Visual Expert 2024
 VETSQLRULE75