Codejunk Ignitesd

781
-1

Published on

Eliminate Codejunk : Maximize the Data:Ink Ratio in Your Code.

My talk for Ignite San Diego.

Published in: Design, Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
781
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Codejunk Ignitesd

  1. 1. Chartjunk is ink that does not tell the viewer anything new. Maximize the data:ink ratio. Kill the frills and get to the point!
  2. 2. The present letter is a very long one, simply because I had no leisure to make it shorter. Code is read much more often than it is written. It's harder to read code than to write it.
  3. 3. eliminate codejunk maximize the data:ink ratio in your code
  4. 4. "junk" is context-dependent • Language • IDE • Project type • Project size
  5. 5. my context • Language: Java • IDE : Eclipse • Project type : application (not library) • Project size : small
  6. 6. codejunk: unnecessary braces for (int i : array) { for (int i : array) sum += i; sum += i; }
  7. 7. codejunk: gratuitous super() public class Foo { public class Foo { int n; int n; public Foo(int n) { public Foo(int n) { super(); this.n = n; this.n = n; } } } }
  8. 8. codejunk: superfluous this public void increment() { public void increment() { this.total++; total++; this.notifyListeners(); notifyListeners(); } }
  9. 9. codejunk: warts private String fName; private String name; int[] aiValues; int[] values;
  10. 10. codejunk: split variable declarations int n; int n = 1; n = 1;
  11. 11. codejunk: pointless comments /** * @return the bar */ public int getBar() { public int getBar() { return bar; return bar; } } /** public void setBar(int bar) { * @param bar the bar to set this.bar = bar; */ } public void setBar(int bar) { this.bar = bar; }
  12. 12. codejunk: commented-out code int three() { int three() { int i; int i; i = 1; i = 1; //System.out.println(i); i += 2; i += 2; return i; return i; } }
  13. 13. codejunk: unused variables int three() { int three() { int i; int i; int n; i = 1; i = 1; i += 2; i += 2; return i; return i; } }
  14. 14. codejunk: scope end labels for (int i : array) { for (int i : array) { sum += i; sum += i; count++; count++; } // end for }
  15. 15. codejunk: excessively specific variable names public int countCapitals(String mixedCaseString) { int count = 0; for (char c : mixedCaseString.toCharArray()) if (Character.isUpperCase(c)) count++; return count; } public int countCapitals(String string) { int count = 0; for (char c : string.toCharArray()) if (Character.isUpperCase(c)) count++; return count; }
  16. 16. codejunk: change comments for (int i : array) { for (int i : array) { // changed 01/20/09 cjm sum += i; sum += i; count++; count++; } }
  17. 17. codejunk: unnecessary annotations @Override public String toString() { public String toString() { return "something"; return "something"; } }
  18. 18. codejunk: long temporary variable names for (int index = 0; index < array.length; index++) sum += array[index]; for (int i = 0; i < array.length; i++) sum += array[i];
  19. 19. Let your IDE help Eclipse detects: • unused imports • unused variables • unread variables • unnecessary else statements • unnecessary casts
  20. 20. my point It's not that "anyone It's that you can benefit who uses braces is by being conscious of evil", or that "you should codejunk and not be writing what I methodical in its consider codejunk." definition and application to your projects.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×