Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Adegoke Obasa
Clean Code
What is Clean Code
“Clean code is a code that is written by
someone who cares” - Micheal Feathers
It is written by someone...
Focused
- SRP (Single Responsibility Principle)
- Must do one thing only
Not Redundant
- DRY rule (Don’t Repeat Yourself)
Pleasant
- Harry Potter :)
- Lord Of The Rings
- Asa’s Tunes
- KISS principle (Keep It Simple, Stupid!)
- YAGNI principle ...
Easily Extended
- You write code for other developers
- You could be that other developer
Smaller is Better
- There should be a standard for max number of lines in a method.
- Example
- Methods - Avg. 30 code lin...
Others
- Unit Tests
- Loose Coupling
- High Cohesion
- Design Patterns
- Frameworks
Demo
public class Xbps {
public void go(String s) {
List l = prm.ld(s);
List l2 = copy(l);
for (int i = 0; i < l.size(); i++) {...
public class ParametersValidator {
public void go(String s) {
List l = prm.ld(s);
List l2 = copy(l);
for (int i = 0; i < l...
public class ParametersValidator {
public void go(String s) {
List l = parameterStore.load(s);
List l2 = copy(l);
for (int...
public class ParametersValidator {
public void go(String webServiceName) {
List parameters =
parameterStore.load(webServic...
public class ParametersValidator {
public void removeInvalidParameters(String
webServiceName) {
List parameters =
paramete...
Lessons
- Good Naming Conventions
- PascalCasing
- camelCasing
- snake_casing
- Good Code Formatting
- Coding Standards
- ...
Q & A
Further Reading
http://blog.goyello.com/2013/01/21/top-9-
principles-clean-code/
..on Software
<http://bodtoki.blogspot.co...
Thanks :)
Adegoke Obasa
@goke_epapa
Upcoming SlideShare
Loading in …5
×

Clean code

402 views

Published on

  • Be the first to comment

Clean code

  1. 1. Adegoke Obasa Clean Code
  2. 2. What is Clean Code “Clean code is a code that is written by someone who cares” - Micheal Feathers It is written by someone who has treated it as an art and paid attention to all details.
  3. 3. Focused - SRP (Single Responsibility Principle) - Must do one thing only
  4. 4. Not Redundant - DRY rule (Don’t Repeat Yourself)
  5. 5. Pleasant - Harry Potter :) - Lord Of The Rings - Asa’s Tunes - KISS principle (Keep It Simple, Stupid!) - YAGNI principle (You Ain’t Gonna Need It)
  6. 6. Easily Extended - You write code for other developers - You could be that other developer
  7. 7. Smaller is Better - There should be a standard for max number of lines in a method. - Example - Methods - Avg. 30 code lines - Class - < 30 Methods - Packages - <= 30 Classes
  8. 8. Others - Unit Tests - Loose Coupling - High Cohesion - Design Patterns - Frameworks
  9. 9. Demo
  10. 10. public class Xbps { public void go(String s) { List l = prm.ld(s); List l2 = copy(l); for (int i = 0; i < l.size(); i++) { String p = (String) l.get(i); if (p.substring(5, 9).equals("9982")) { l2.remove(p); } } prm.sv(s, l2); }...
  11. 11. public class ParametersValidator { public void go(String s) { List l = prm.ld(s); List l2 = copy(l); for (int i = 0; i < l.size(); i++) { String p = (String) l.get(i); if (!p.substring(5, 9).equals("9982")) { l.remove(p); } } prm.sv(s, l2); } ...
  12. 12. public class ParametersValidator { public void go(String s) { List l = parameterStore.load(s); List l2 = copy(l); for (int i = 0; i < l.size(); i++) { String p = (String) l.get(i); if (!p.substring(5, 9).equals("9982")) { l.remove(p); } } parameterStore.save(s, l2); } ...
  13. 13. public class ParametersValidator { public void go(String webServiceName) { List parameters = parameterStore.load(webServiceName); List validParams = copy(parameters); for (int i = 0; i < parameters.size(); i++) { String parameter = (String) parameters.get(i); if (!parameter.substring(5, 9).equals("9982")) { validParams.remove(parameter); } } parameterStore.save(webServiceName, validParams); } ... }
  14. 14. public class ParametersValidator { public void removeInvalidParameters(String webServiceName) { List parameters = parameterStore.load(webServiceName); List validParams = copy(parameters); for (int i = 0; i < parameters.size(); i++) { String parameter = (String) parameters.get(i); if (isInvalid(parameter)) { validParams.remove(parameter); } } parameterStore.save(webServiceName, validParams); }
  15. 15. Lessons - Good Naming Conventions - PascalCasing - camelCasing - snake_casing - Good Code Formatting - Coding Standards - Good Comments - Not too Much
  16. 16. Q & A
  17. 17. Further Reading http://blog.goyello.com/2013/01/21/top-9- principles-clean-code/ ..on Software <http://bodtoki.blogspot.com/2010/12/1-good- names-good-code-series.html>
  18. 18. Thanks :) Adegoke Obasa @goke_epapa

×