#nocomments

71
// NO COMMENT! /* about the worthlessness of comments in clean code */ Created by / Björn Kimminich @bkimminich Follow @bkimminich Tweet 2 Follow @bkimminich 72 Star 1

Upload: bjoern-kimminich

Post on 09-Jan-2017

3.363 views

Category:

Presentations & Public Speaking


1 download

TRANSCRIPT

Page 2: #NoComments

BJÖRN KIMMINICHIT Architect & Security Officer @ Performing 2-day @ KNLecturer for Software Development @ Read and watched >32 episodesRevenant speaker at , et al.

Kuehne + NagelClean Code Training Workshops

Nordakademieboth books Clean Code

Clean Code Days JavaLand

Page 3: #NoComments

NARRATIVE ARC OF THIS TALK

1. Scientific Exposition2. Rising Action Examples3. Trademark-protected Climax4. Bonus Climax instead of Falling Action5. RaaTYS (Resolution-as-a-Thank-You-Slide)

Page 4: #NoComments

5. RaaTYS (Resolution-as-a-Thank-You-Slide)

UNCLE BOB DISLIKES COMMENTS"Comments are, at best, a necessary evil."

Page 5: #NoComments

STUDENTS LOVE EXTENSIVE COMMENTSAND I CAN PROVE IT!

Professors often like extensive documentation.

Professors often promote comments as documentation.

Extensive documentation leads to better grades.

Students love to get better grades.

q.e.d.

Page 6: #NoComments

* ALSO LIKES COMMENTSOPEN HUB"A high number of comments might

indicate that the code is well-documentedand organized, and could be a sign of a

helpful and disciplined developmentteam."

*Open Hub (formerly Ohloh.net) is an online community and public directory of free and open source software.

Page 7: #NoComments

I'M IN THE WORST 10%OPEN HUB"Across all Java projects on Open Hub,

31% all source code lines are comments.For ,

this figure is 1%. This lack of commentsputs among the lowest 10% of all Java projects

on Open Hub."

Code Kata: Trading Card Game (TCG)

Code Kata: Trading Card Game (TCG)

Page 8: #NoComments

* GOT IT RIGHT!SONARQUBE"If the source code needs too many

comments, it either means that it does notrespect coding standards (naming

conventions, design, etc.) or it is toocomplex."

*SonarQube (formerly Sonar) is an open platform to manage code quality.

Page 9: #NoComments

THIS IS IN LINE WITH UNCLE BOB"The proper use of comments is to

compensate our failure to express ourselfin code."

Page 10: #NoComments

GOES EVEN FURTHERSONARQUBE"Time consuming maintenance [...] may

lead to comments that are no longer up todate. Then comments go against their

primary goal: they mislead the developerwho will spend more time understanding

the source code."

Page 11: #NoComments

AGAIN IN SYNC WITH UNCLE BOB"Inaccurate comments are far worse than

no comments at all."

Page 12: #NoComments

SUMS IT UPGEEK & POKE

Page 13: #NoComments

ENOUGH OF THE "SCIENTIFIC" EXPOSITION!Let's rise the action with some examples, shall we?

Page 14: #NoComments

 BAD  COMMENTS MumblingRedundant CommentsMisleading CommentsMandated CommentsJournal CommentsNoise CommentsScary NoisePosition Markers

Closing Brace CommentsAttributions and BylinesCommented-Out-CodeNonlocal InformationToo much InformationInobvious ConnectionFunction HeadersJavadoc in nonpublic Code

Page 15: #NoComments

MUMBLING I

Page 16: #NoComments

MUMBLING II

Page 17: #NoComments

MUMBLING III

Page 18: #NoComments

MUMBLING IV

Page 19: #NoComments

REDUNDANT COMMENTS I

Page 20: #NoComments

REDUNDANT COMMENTS II

Page 21: #NoComments

REDUNDANT COMMENTS III

Page 22: #NoComments

REDUNDANT COMMENTS IV

Page 23: #NoComments

MISLEADING COMMENTS

Page 24: #NoComments

THE BATMAN MODE™ METAPHORWhen there is a mystery or crime to be solved, Batman will

utilize his brain and all kinds of fancy gadgets to get itdone! He will analyze, investigate and deduce until he has

the answer. For him as a costumed Super Hero Detective it'spart of the job! Software engineers should never have to go

into Batman Mode™ to investigate comments!

Page 25: #NoComments

WHAT POSSIBLE CONCLUSIONS ARE THERE?

There was a repaint happening some commits ago. The comment just got obsolete!There was a repaint happening some commits ago. That it's gone was an accident!There was no a repaint happening so far. But it should have been added by now!The repaint is still happening as a hidden side effect somewhere in the code!The developer actually wanted to type // repeat for all calendar days!

Page 26: #NoComments

MANDATED COMMENTS

Page 27: #NoComments

JOURNAL COMMENTS

Page 28: #NoComments

NOISE COMMENTS

Page 29: #NoComments

SCARY NOISE

Page 30: #NoComments

POSITION MARKERS

Page 31: #NoComments

EXCEPTION: GOOD POSITION MARKERSIf you are using some graphical UI editor or other code

generator, the position markers they introduce are fine!Removing them would most likely break stuff!

Page 32: #NoComments

CLOSING BRACE COMMENTS I

Page 33: #NoComments

CLOSING BRACE COMMENTS II

Page 34: #NoComments

CLOSING BRACE COMMENTS III

Page 35: #NoComments

ATTRIBUTIONS AND BYLINES I

Page 36: #NoComments

ATTRIBUTIONS AND BYLINES II

Page 37: #NoComments

EXPLAINSGEEK & POKECOMMENTED-OUT-CODE

Page 38: #NoComments

COMMENTED-OUT-CODE I

Page 39: #NoComments

COMMENTED-OUT-CODE II

Page 40: #NoComments

COMMENTED-OUT-CODE III

Page 41: #NoComments

NONLOCAL INFORMATION I

Page 42: #NoComments

NONLOCAL INFORMATION II

Page 43: #NoComments

TOO MUCH INFORMATION

Page 44: #NoComments

INOBVIOUS CONNECTION

Page 45: #NoComments

FUNCTION HEADERS

Page 46: #NoComments

JAVADOC IN NONPUBLIC CODE

Page 47: #NoComments

AND NOW FOR SOMETHINGCOMPLETELY DIFFERENT

(Intentionally unexpected intermission in the narrative arc)

Page 48: #NoComments

 GOOD  COMMENTS Legal CommentsPublic API JavadocInformative CommentsExplanation of IntentClarificationWarning of ConsequencesTODO Comments

Page 49: #NoComments

LEGAL COMMENTS

Page 50: #NoComments

PUBLIC API JAVADOC

Page 51: #NoComments

INFORMATIVE COMMENTS I

Page 52: #NoComments

INFORMATIVE COMMENTS II

Page 53: #NoComments

EXPLANATION OF INTENT I

Page 54: #NoComments

EXPLANATION OF INTENT II

Page 55: #NoComments

CLARIFICATION I

Page 56: #NoComments

CLARIFICATION II

Page 57: #NoComments

WARNING OF CONSEQUENCES I

Page 58: #NoComments

WARNING OF CONSEQUENCES II

Page 59: #NoComments

TODO COMMENTS I

Page 60: #NoComments

TODO COMMENTS II

Page 61: #NoComments

TODO COMMENTS III

Page 62: #NoComments

LEFT-OVER TODO COMMENTS

Page 63: #NoComments

BUT YOU PROMISED US A CLIMAX!!!Closing a talk about how bad most comments are with good

examples seems pretty anticlimactic! I guess we needsomething climactically bad to get back on track now...

Page 64: #NoComments

CLIMAX: UNCAMELCASING™The art of splitting class/method names into Javadoc while

providing zero additional information.

There are different skill levels of this art comparable to belts in martial arts.

Page 65: #NoComments

UNCAMELCASING™ EXAMPLE SKILL LEVEL  WHITE BELT 

Page 66: #NoComments

UNCAMELCASING™ EXAMPLE SKILL LEVEL  GREEN BELT 

Page 67: #NoComments

UNCAMELCASING™ EXAMPLE SKILL LEVEL  BROWN BELT 

Page 68: #NoComments

UNCAMELCASING™ EXAMPLE SKILL LEVEL  BLACK BELT 

It is impossible to reach a black belt in UnCamelCasing™...

...at least with manually writing code comments, that is!

The real "pro" UnCamelCasers™ go even further...

...and automate the UnCamelCasing™ process entirely!

Page 69: #NoComments

BONUS CLIMAX: JAUTODOC"JAutodoc is an Eclipse Plugin for

automatically adding Javadoc and fileheaders to your source code. It optionallygenerates initial comments from element

name by using Velocity templates forJavadoc and file headers."

Page 70: #NoComments

// NO COMMENT!

Page 71: #NoComments

THANKS FOR YOURATTENTION...

...and for not writing comments unless you absolutely have to!

...and for deleting all bad comments you come across from now on!

...and for not using UnCamelCasing™ to create documentation!

...and for never installing/immediately uninstalling JAutodoc!

BY BJÖRN KIMMINICH / KIMMINICH.DEThese slides are publicly available on and .

Copyright (c) 2015 Björn Kimminich - Created with - The HTML Presentation Framework

Most code examples shown in this presentation are from real-life project code. The @author tags or other personal data have been anonymized in order to protect the authors from prosecution by Clean Code zealots or other Quality Assurance authorities. No softwareengineers were harmed during or after the creation of this presentation! Please consider the environment before printing this slide deck!

GitHub Slidesharereveal.js