Programming languages' semantic #15
Replies: 1 comment
-
Recently I was invited to a questionnaire about code smell detection tools. === |1| Code smell === Code smell refers to the coding style, structure, or design that is: Code smells are mainly divided into: ==== Class level ==== Class level code smells, often involve the structure and design of the entire class: reflecting the complexity and maintainability of the class. [ "Data Class" public class Person {
private String firstName;
private String lastName;
// Constructor:
public Person (
String firstName,
String lastName
) {
this.firstName = firstName;
this.lastName = lastName;
};
// Getter, Setter:
public String getFirstName () {
return firstName;
};
public String getLastName () {
return lastName;
};
public void setFirstName ( String firstName ) {
this.firstName = firstName;
};
public void setLastName ( String lastName ) {
this.lastName = lastName;
};
}; ]] [ "God Class" public class Customer {
// >>>> (0)
private String name;
private String address;
private String phoneNumber;
private List<Order> orders;
//
// Constructor, Getter, Setter:
// Methods that perform various tasks.
//
public void processOrders () {
// Complex logic involving orders.
};
//
// ... (more methods)
// God-like class caring too much.
//
public void performCustomerTasks () {
validateCustomerData();
processOrders();
sendCustomerEmails();
// ... (more tasks)
};
private void validateCustomerData () {
// Complex data validation logic.
};
private void sendCustomerEmails () {
// Complex email sending logic.
};
// <<<< (0)
}; ]] ==== Method level ==== Method level code smells, focus on the design and implementation of individual methods: which can involve aspects such as length, complexity, etc. . [ "Feature Envy" public class Car {
private String color;
public String getColor () {
return color;
};
};
public class Driver {
private Car car;
public void printCarColor () {
String carColor = car.getColor();
System.out.println( "The car's color is: " + carColor );
};
}; ]] [ "Long Method" public class DataProcessor {
// >>>> (0)
public void processUserData ( User user ) {
// |1| Validate user data:
if ( user != null ) {
// Validation logic...
// |2| Process user data:
// Data processing logic...
System.out.println( "User data processed successfully." );
// |3| Update user statistics:
// Statistics update logic...
System.out.println( "User statistics updated." );
} else {
System.out.println( "Invalid user data." );
};
};
// <<<< (0)
}; ]] Heuristic based code smell detection tools/technologies extract the software features related to the code smell from the original code: Machine/Deep learning based code smell detection tools/technologies can extract software features from the original code: [ [1] [ "Efficiency and time saving" [ "Improve code readability" [ "Improve code performance" [ "Adherence to coding norms" [ "Prevent potential bugs" [ "Coverage" [ "Fast processing speed" [ "Accuracy" [ "Custom rules and configurations" [ "Provide explanations and recommendations" [ "Improve code quality" [ "Ease of use" Specifically, in the era of large language models like ChatGPT: Corest: All these are solely designed to solve 1 problem: coders unable to tell what the code does. To effectively address which, something must be done on the languages themselves. 烂泥滩上修高楼: 白搭. |
Beta Was this translation helpful? Give feedback.
-
"var" vs. "$var": Is it variable or keyword?
"print" vs. "print()": Is it keyword or function (or method, routine whatsoever) call?
"${Arbitrary Non-Sense's}"?
"${ /Array\d+(?:_\d+)?/ }"..?
"${Array${i}}"?
`${ "Array" + ( exist ${j} ? "${i}_${j}" : ${i} ) }`?
[[
print "123" "456"
print( "123", "456" )
]]
Significant overhead. But desirable for clarity. [1] [2]
Interactive vs. Canonical: shortcut for quick input.
[ [1]
`a 1 b 2`??? [ One such failure: SVG "d" [4]. ]
`a 1 $( b 2 )`: Unix Shell.
`a( 1, b( 2 ) )`: Classical functional. ]
[ [2]
Certain functionality expects no extra input:
E.g. `goto ":Label"` [3], "break", "break 2"
.
Wrapping the parentheses would be excessive. ]
[ [3]
[[
:Label for jump-back; a!
...
goto ":Label for jump-back; a!";
]] ]
[ [4]
More than 1 way to draw the same curve...
Much reminds me of the RISC vs. CISC design choice.
.
Extreme invert. Excess amok.
Further reading on SVG: https://github.com/MasterInQuestion/Markup/issues/2 ]
=== Pointer type (reference) cause ===
[[
${Variable to Meddle} = Hefty-Whatsoever();
${Name of Variable to Meddle} = "Variable to Meddle";
ObscureMeddling( ${Name of Variable to Meddle} );
]]
Pass by reference (to the original) [2] or pass by copy (where causes a new instance of "Hefty-Whatsoever" [1]).
"ObscureMeddling" may have different expectation.
[1] Though compiler may automatically reduce such overhead, to some extent.
[2] Also accomplishable by "eval" alike.
[[
${var}
\${ref}
${ \${deref} }
]]
... Where exactly C and Perl so on failed: over-abstraction.
(though not in exactly the same shape, much resembles)
=== Type casting directive ===
[[
[utf16( LE )]
[utf8( 2,048 )]
[str( 8,192 )]
[int( 7 )]
[bool]
[int64]
[float( 32, 8 )]
]]
Typeless can at the same time be strictly typed.
These are much used as memory allocation hint: no extra limit imposed on actual parsing.
Data, are no more than data. It is all upon: the interpretation.
[[
( [int8] 128 == all( -128, 128 ) ) == true
( -128 == 128 ) == false
]]
See:
=== See also ===
Relationship between high-level logic and low-level representation
https://github.com/MasterInQuestion/talk/discussions/24
Beta Was this translation helpful? Give feedback.
All reactions