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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
"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)
[ "C absurdity"
https://github.com/FFmpeg/FFmpeg/commit/86f73277bf014e2ce36dd2594f1e0fb8b3bd6661
https://download.mikroe.com/documents/compilers/mikroc/arm/help/integer_constants.htm
https://www.tutorialspoint.com/cprogramming/c_data_types.htm
https://en.wikipedia.org/wiki/C_data_types#Main_types
(conflicting data types and bizarre logic...)
.
https://github.com/FFmpeg/FFmpeg/commit/7a089ed8e049e3bfcb22de1250b86f2106060857
https://www.cybersecurity-help.cz/vdb/SB2024122032
[ ^ https://trac.ffmpeg.org/ticket/11537#comment:1 ]
"uint32_t"
https://old.reddit.com/r/C_Programming/comments/dj42mi/what_is_the_benefit_of_using_these_data_types/?sort=old#f40sk0o
[ ^ https://undelete.pullpush.io/r/C_Programming/comments/dj42mi ]
https://old.reddit.com/r/learnprogramming/comments/ihtow9/what_is_the_difference_between_uint32_t_uint/?sort=old#g32emh7
.
https://stackoverflow.com/questions/48833976/failing-to-understand-what-the-expression-uint32-t-does#48834118 ]
=== 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