Home

Files should not have too many lines of code

Description

    This rule states that files should not contain too many lines of code. This is to ensure that the code is well-structured, easy to read and maintain, and that the code is logically organized. It is also important to ensure that the code is not overly complicated or difficult to understand. This rule is especially important for larger projects, where the code can become difficult to manage if it is too long or convoluted. It is also important to keep the code organized in a way that is easy to understand and navigate. By limiting the length of each file, developers can ensure that their code is well-structured and easy to maintain.

Key Benefits

  • Reduce Complexity: Keeping lines of code to a minimum helps reduce the complexity of the code.
  • Ease of Maintenance: Fewer lines of code make it easier to maintain and update the code.
  • Increased Readability: Keeping the code concise and organized makes it easier to read.
  • Improved Performance: Fewer lines of code can lead to improved performance.

 

Non-compliant Code Example

forward //Non compliant code (Maximum line of code should be less than 100)
global type te_n_cst_tmanager from t_n_cst_tmanager
end type
end forward

global type te_n_cst_tmanager from t_n_cst_tmanager
end type
global te_n_cst_tmanager te_n_cst_tmanager

on te_n_cst_tmanager.create
call super::create
end on

on te_n_cst_tmanager.destroy
call super::destroy
end on

event t_extendedaction;

/*_____________________________________________________________________________

Description	:	Adds a new action extends Test standard actions.

Comment		:	


Arguments	:	apo_target_object : The target object on which the action must be processed.
					
					as_action 			: string containing the name of the action 
					
					as_param 			: string containing parameters of action. Each parameter is separated by comma.

Return		:	integer -1 if the action is failed, 2 if the action is unknown, 1 otherwise.

Subject:			Test

Historique	:	
					V1.00 - HC - 07/06/2000 - Initial version.

_____________________________________________________________________________
*/
// Unknown action 

//Unknown action 

integer 	i_colnum, i
String s_modify, s_objecttype
datawindow ldw_target
string ls_column
CHOOSE CASE as_action
	CASE "disable column" // Extend 'disable column' action
		// Verify if the type of the target object is correct for this action
		IF TypeOf (apo_target_object) = datawindow! THEN
			// This action can disable a group of columns. Each column is separated by comma.
			ldw_target = apo_target_object
			DO WHILE as_param <> ""
				ls_column = t_f_get_token(as_param,",")
				// Make the column's background opaque
				IF ldw_target.Modify (ls_column + ".Background.Mode='1'") <> "" THEN 
					Return -1
				END IF
			LOOP

			Return 1

		ELSE
			Return -1
		END IF
	CASE "enable column" // Extend 'enable column' action
		// Verify if the type of the target object is correct for this action
		IF TypeOf (apo_target_object) = datawindow! THEN
			// This action can disable a group of columns. Each column is separated by comma.
			ldw_target = apo_target_object
			DO WHILE as_param <> ""
				ls_column = t_f_get_token(as_param,",")
				// Make the column's background transparent
				IF ldw_target.Modify (ls_column + ".Background.Mode='1'") <> "" THEN 
					Return -1
				END IF
			LOOP
			Return 1
		ELSE
			Return -1
		END IF
	CASE	"extended readonly" // Add a specific action

		if TypeOf (apo_target_object) <> datawindow! THEN Return -1

		ldw_target = apo_target_object

		IF ldw_target.Modify ("DataWindow.ReadOnly='Yes'") <> "" THEN 

			Return -1
		END IF
		// Unknown action 
		
		i_colnum = Integer(ldw_target.Describe("datawindow.column.count"))
		
		IF i_colnum < 1 THEN Return -1 
		
		FOR i = 1 TO i_colnum
			
			IF Long(ldw_target.describe("#" + String(i) + ".x")) <> 0  THEN
				s_modify = s_modify + " #"+String(i)+".background.mode = '1'"
			END IF
			
		NEXT
		
		IF ldw_target.Modify(s_modify) <> "" THEN 

			Return -1

		END IF

		// Unknown action 

		Return 1
END CHOOSE

// Unknown action 
Return 2
//Return 1
//Return 11
//Return 21
//Return 31
//Return 41
// Unknown action 

end event
// Unknown action
Visual Expert 2024
 VEPBRULE67