Improving Code Readabilty

Nested conditional statements

Nested conditional statements are automatically grouped in one statement with both conditions.

Before

	a as Int
	
	if a > 2 then
	    if a < 10 then
	        a = 5
	    end
	end
	

After

	a as Int
	
	if a > 2 and a < 10 then
	    a = 5
	end
	

Identifiers for Exceptions

Identifiers for exception handlers are automatically added when they are not specified.

Before

	message as String
	
	do
	    message = "Ok" 
	on Exception
	    message = Exception.message
	end
	

After

	message as String
	do
	    message = "Ok"
	on e as Exception
	    message = e.message
	end
	

Bounded loop instead of unbounded loop

Unbounded loops are converted to bounded loops when possible.

Before

	i = 0
	
	while i <= 10 do
	    i = i + 1
	end
	

After

	for i in 0..10 do
	end
	

Conditional Exit

Conditional statements with an exit statement are transformed to conditional exits.

Before

	array as Int[] = [10, 20, 30]
	
	for each e in array do
	   if e = 20 then
	       exit
	   end 
	end
	

After

	array as Int[] = [10, 20, 30]
	
	for each e in array do
	    exit when e = 20
	end
	

Redundant negation

Redundant negations are removed.

Before

	a as Int = 5
	
	if not a != 2 then    
	end
	

After

	a as Int = 5
	
	if a = 2 then
	end
	

Conditional statement inside else blocks

Before

	a as Int = 2
	if a < 2 then
	    a = 2
	else 
	    if a > 5 then
	        a = 5    
	    end        
	end
	

After

	a as Int = 2
	
	if a < 2 then
	    a = 2
	elseif a > 5 then
	    a = 5
	end
	

Check for null value

Before

	s as String
	
	if s != null then
	end
	

After

	s as String
	
	if s is not null then
	end
	

Right order for 'is not'

Before

	s as String
	
	if not s is null then
	end
	

After

	s as String
	
	if s is not null then
	end
	

Redundant equality

Before

	found as Bool
	
	if found = false then
	end
	

After

	found as Bool
	
	if not found then
	end
	

Explicit argument names

Before

	open TextFile using "", ""
	

After

	open TextFile using name = "", 
	                    lineSeparator = ""
	

Unneeded parenthesis

This refactory is applied to 'if' and 'while' conditions in Process Business Language (PBL).

Before

	a as Int = 2
	
	if (a > 2) then    
	end
	

After

	a as Int = 2
	
	if a > 2 then
	end
	

Legacy multi path conditional statements

Before

	a as Int = 2
	
	switch a in
	  case 2: 
	     display "Two"  
	  case 4:  
	     display "Four"
	end
	

After

	a as Int = 2
	
	case a
	when 2 then
	    display "Two"
	when 4 then
	    display "Four"
	end
	

Functions

Functions are rewritten using functional syntax.

Before

	a as Int
	a = a.abs()
	

After

	a as Int
	a = abs(a)
	

Wrong symbols

In PBL, some invalid symbols (e.g: &&, ||, !, ==) are accepted but they are automatically fixed when the code is rewritten.

Before

	a as Int = 2
	b as Int = 4
	
	if ((a > 2 && a < 10) || b == 4) then
	end
	

After

	a as Int = 2
	b as Int = 4
	
	if (a > 2 and a < 10) or b = 4 then
	end
	

Misspelled member names

Before

	Open TextFile using name = "", 
	                    lineSeparator = ""
	
	Mail.content_type = ""
	

After

	open TextFile using name = "", 
	                    lineSeparator = ""
	
	Mail.contentType = ""
	

Methods equals() and toString()

Before

	if object.equals(this) then
	    string = object.toString()
	end
	

After

        if equals(object, arg1 : this) then
            string = toString(object)
        end