Code Quality
- Home /
- Categories /
- Code Quality
What Name for This Method?
What Name for This Method?
public class OptionsAwareObject {
private Options options;
public void updateOptions(String fontName, int fontSize) {
options.setFontName(fontName);
options.setFontSize(fontSize);
}
}
class Options {
private int foregroundColor;
private int backgroundColor;
private String fontName;
private int fontSize;
// ...
}
Is updateOptions
a good name for this method? Of course not! updateOptions
is a general name that suggests a comprehensive update of options. Meanwhile, we are only updating font-related information. The responsibility of the method is thus the change of font-related options. A better name would be:
Cleaning Up Code: Not Just About Refactoring Part 2
Due to formatting problems with code on Blogspot, it is recommended to read this article in PDF format. You can download the PDF version of the article here.
Read MoreCode Cleanliness: More Than Just Refactoring Part 1
Initially, my intention was to create an article about refactoring. However, the more I pondered the subject, the clearer it became that I would not be writing solely about refactoring. It’s about something much more significant—conveying a vast amount of knowledge, essentially experience, related to code creation. Code that not only works or is well-designed but is most importantly easy to read. When we achieve this skill, we stand on the threshold of professionalism. Programming professionalism.
Read More