Sh*t Code to Clean Code

Source: WTF per Minute — commadot.com

First tip: Proper variable and function naming

String? a;
String b = 'File Name';
File? c;
bool function() {
return a != null && b != "File Name"
&& c != null;
}
String? _attachmentType;
String _attachmentName = 'File Name';
File? _attachmentItem;
bool _valuesAreNotEmpty() {
return _attachmentType != null && _attachmentName != "File Name"
&& _attachmentItem != null;
}

Second tip: Organized Layout Formatting

Future getImage() async { final pickedFile = await imagePicker.getImage(source: ImageSource.camera);
setState(() { if (pickedFile != null) { _attachmentItem = File(pickedFile.path); initialState = false;}
});
}
Future getImage() async {
final pickedFile = await imagePicker.getImage(source: ImageSource.camera);

setState(() {
if (pickedFile != null) {
_attachmentItem = File(pickedFile.path);
initialState = false;
}
});
}

Third tip: Efficient Comments

int calculateDiagonalSideTriangle() {
diagonal_side = sqrt(none_diagonal_side_1**2 +
none_diagonal_side_2**2);
return diagonal_side;
}
int veryComplexAlgorithm() {
//This function helps another function to count something
...
return;
}
String? a;
String b = 'File Name';
File? c;
bool function() { //This function of for checking if a,b,and c is empty or not
return a != null && b != "File Name"
&& c != null;
}

Fourth tip: Error Handling

Future getImage() async {
final pickedFile = await imagePicker.getImage(source: ImageSource.camera);

setState(() {
if (pickedFile != null) {
_attachmentItem = File(pickedFile.path);

initialState = false;
}
});
}

Fifth tip: Simple Functions

int calculateDiagonalSide() {
diagonal_side = sqrt(none_diagonal_side_1**2 +
none_diagonal_side_2**2);
return diagonal_side;
}
  • Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, Prentice Hall, 2008
  • My own code

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store