神秘命名
Functions, modules, variables, or classes have names that don't clearly express what they do.
Good naming is one of the fundamental aspects of clean code. When names don't clearly express what they do, it makes the code harder to understand and maintain. Mysterious names force readers to spend extra mental effort to understand the code's purpose.
data, info, manager, handler without contextMysterious names create unnecessary cognitive load for anyone reading the code. By using clear, descriptive names, we make the code self-documenting and reduce the need for additional comments. Good names should answer three key questions: Why does it exist? What does it do? How is it used?
import java.util.*;class DataProcessor {// Mysterious variable namesprivate int x = 100;private String s = "default";private List<Object> lst = new ArrayList<>();// Mysterious method namespublic void proc(String inp) {// What does 'proc' do? What is 'inp'?String tmp = inp.toLowerCase();lst.add(tmp);}public int calc(int a, int b) {// What kind of calculation?return a * b + x;}public boolean chk(Object obj) {// Check what?return obj != null && obj.toString().length() > 5;}// Mysterious class with unclear responsibilitystatic class Mgr {private Map<String, Object> data = new HashMap<>();public void handle(String k, Object v) {// Handle what? What operation?data.put(k, v);}public Object get(String k) {return data.get(k);}public void doStuff() {// What stuff?data.clear();}}// Method with misleading namepublic void calculateTotal() {// This method doesn't calculate anything!System.out.println("Processing completed");lst.clear();}// Abbreviated names that lose meaningpublic void updateUsrPrf(String usrId, Map<String, String> prfData) {// usr = user? prf = profile?for (String k : prfData.keySet()) {// More mysterious single lettersString v = prfData.get(k);System.out.println(k + ": " + v);}}// Generic unhelpful namespublic void processInfo(List<String> items) {// What kind of info? What processing?for (String item : items) {String result = item.trim();if (result.length() > 0) {lst.add(result);}}}}