1 / 90

Uncomment Your Code

Shlomo Yona http://yeda.cs.technion.ac.il/~yona/ based on slides by Miki Tebeka. Uncomment Your Code. Only 90 slides!. Relax, it’ll be over faster than you think. I’ve read an article. Yes, at work. Thought it might interest you. It’s about not commenting your code.

agnes
Download Presentation

Uncomment Your Code

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shlomo Yona http://yeda.cs.technion.ac.il/~yona/ based on slides by Miki Tebeka Uncomment Your Code

  2. Only 90 slides!

  3. Relax, it’ll be over faster than you think

  4. I’ve read an article

  5. Yes, at work

  6. Thought it might interest you

  7. It’s about not commenting your code

  8. which will make it better

  9. A quote

  10. “Always write code as if the maintenance programmer were an axe murderer who knows where you live.”Mike Dunn

  11. He wasn’t joking

  12. Meet Donald E. Knuth

  13. Don’t ask “who is he?”

  14. Another quote

  15. “If something can be described in the language itself, one should do that, and not just mention it in a comment.”

  16. This is Bjarne Stroustrup

  17. Hope you know who he is

  18. Last quote (for now)

  19. “Do not comment bad code, rewrite it”

  20. This is Brian W. Kernighan

  21. Not so frightening as the other two

  22. Let’s get dirty

  23. /* Stores information printed on person badge */typedef struct {…} Badge;

  24. Looks OK?

  25. How about…

  26. typdef struct {…} InfoOnBadge;

  27. Wait, there’s more

  28. typedef struct { int pid; /* Person ID */ char *name; /* Person full name */} InfoOnBadge;

  29. can become

  30. typedef struct { int personId; char *personFullName;} BadgeInfo;

  31. We can do the same to parameters

  32. /* Create new badge information`id’ is the person id*/BadgeInfo *new_bagde_info(int id);

  33. will become

  34. BadgeInfo *new_bagde_info(int person_id);

  35. Also

  36. BadgeInfo *new_bagde_info(int person_id) {/* Load from database */Database *db = connect_to_database();…}

  37. Can be improved to

  38. BadgeInfo *new_bagde_info(int person_id) { BadgeInfo *badge = NULL; badge = load_from_database(person_id); …}

  39. Also delete useless comments

  40. /* Make a copy of original string */strcpy(new_string, old_string);

  41. turns to

  42. strcpy(new_string, old_string);

  43. Why delete the comments?

  44. We take shortcuts

  45. and write comments

  46. (which is easy)

  47. to explain unclear code

More Related