Can PL/SQL
Be Clean?
AOUG, Oct. 2013
Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop.org

Copyright Peter Kofler, lic...
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Peter Kofler
• Ph.D. (Appl. Math.)
• Software Developer
for 14 yea...
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Agenda
Define Clean Code
● Define PL/SQL
● Apply Clean Code to PL/...
What is Clean Code?
“Craftsmanship
Over Crap“
(Robert C. Martin)
“Clean code looks
like it was written
by someone who
cares.”
(Michael Feathers)
Rule 1)
Written by
someone who
cares.
What is Clean Code?
Clean Code
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Clean Code is Not New
Clean Coder, 2011
● Clean Code, 2008
● Imple...
Quick And Dirty
Code Complete
“Write Programs for
People First,
Computers Second.”
(Steve McConnell)
Rule 2)
Written for
People First.
So how would
You
like the code to be?
(besides working correctly)
Code which does
not make me want
to kill the author.
http://programmers.stackexchange.com/a/13594/15057
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Easy and Simple!
Easy to read.
● Easy to follow.
● Easy to underst...
Procedural Language/
Structured Query Language
Should you write
PL/SQL with care?
Should you write
PL/SQL for people?
Tadaaa!
Clean PL/SQL
looks like it was
written by someone who cares.
Write PL/SQL for
People First,
Databases Second.
But...
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

PL/SQL is not Java
• Clean Code targets “modern” languages
– Java,...
Do these guidelines
apply to PL/SQL?
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

PL/SQL is...
• compiled
• imperative/procedural with modules
– fun...
Sounds much like
Java to me ;-)
Examples from
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Meaningful Names


Names should reveal intent.



Use pronouncea...
http://theprofoundprogrammer.com/post/26561881517/text-single-letter-variables-who-the-fuck-do
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Other Chapters
●

Formatting 

●

Comments 

●

Functions 

●

...
/3 of “Clean Code”
applies directly

1
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Single Responsibility Principle
„SRP“
● Do one thing.
● One reason...
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Other Object Oriented Stuff?
●

Encapsulation 

●

Coupling (betw...
½ of “Clean Code”
applies (in some way)
Conclusion
1)
Clean code always
looks like it was
written by someone who cares.
2)
Clean Code Applies
to PL/SQL
(at least to a certain extend)
3) Read It!
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Peter Kofler
@codecopkofler
www.code-cop.org
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

CC Images
●

cleaning: http://www.flickr.com/photos/inf3ktion/4477...
Can PL/SQL be Clean? (2013)
Upcoming SlideShare
Loading in...5
×

Can PL/SQL be Clean? (2013)

1,602

Published on

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • This is so obvious that it is strange that it has to be said. But it needs to be said and it is good that you do it Peter!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total Views
1,602
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Can PL/SQL be Clean? (2013)

  1. 1. Can PL/SQL Be Clean? AOUG, Oct. 2013 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  2. 2. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Peter Kofler • Ph.D. (Appl. Math.) • Software Developer for 14 years • “fanatic about code quality” • Pair Programming #CodeCopTour
  3. 3. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Agenda Define Clean Code ● Define PL/SQL ● Apply Clean Code to PL/SQL ● Examples ● Discussion ●
  4. 4. What is Clean Code?
  5. 5. “Craftsmanship Over Crap“ (Robert C. Martin)
  6. 6. “Clean code looks like it was written by someone who cares.” (Michael Feathers)
  7. 7. Rule 1) Written by someone who cares.
  8. 8. What is Clean Code?
  9. 9. Clean Code
  10. 10. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Clean Code is Not New Clean Coder, 2011 ● Clean Code, 2008 ● Implementation Patten, 2007 ● Agile Software Development, 2002 ● The Pragmatic Programmer, 1999 ● Refactoring, 1999 ● Code Complete 1st Ed, 1993 (!) ●
  11. 11. Quick And Dirty
  12. 12. Code Complete
  13. 13. “Write Programs for People First, Computers Second.” (Steve McConnell)
  14. 14. Rule 2) Written for People First.
  15. 15. So how would You like the code to be? (besides working correctly)
  16. 16. Code which does not make me want to kill the author. http://programmers.stackexchange.com/a/13594/15057
  17. 17. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Easy and Simple! Easy to read. ● Easy to follow. ● Easy to understand. ● Easy to modify. ● Easy to test. ● Easy ... ● http://stackoverflow.com/a/954582/104143
  18. 18. Procedural Language/ Structured Query Language
  19. 19. Should you write PL/SQL with care?
  20. 20. Should you write PL/SQL for people?
  21. 21. Tadaaa!
  22. 22. Clean PL/SQL looks like it was written by someone who cares.
  23. 23. Write PL/SQL for People First, Databases Second.
  24. 24. But...
  25. 25. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY PL/SQL is not Java • Clean Code targets “modern” languages – Java, C# – Ruby, Python – maybe C++ • Clean Code is about – Object Orientation – Test Driven Development
  26. 26. Do these guidelines apply to PL/SQL?
  27. 27. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY PL/SQL is... • compiled • imperative/procedural with modules – function/procedure/package • structured – if/loop/continue/exit – with exceptions • static typed with strong type safety • kind of object-orientated (version 8) http://en.wikipedia.org/wiki/PL/SQL
  28. 28. Sounds much like Java to me ;-)
  29. 29. Examples from
  30. 30. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Meaningful Names  Names should reveal intent.  Use pronounceable names.  Use Problem Domain Names. e.g. http://www.zero1design.com/2011/10/31/cleaner-code-in-t-sql-part-1-%E2%80%93-naming-stored-procs-views/
  31. 31. http://theprofoundprogrammer.com/post/26561881517/text-single-letter-variables-who-the-fuck-do
  32. 32. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Other Chapters ● Formatting  ● Comments  ● Functions  ● Unit Testing 
  33. 33. /3 of “Clean Code” applies directly 1
  34. 34. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Single Responsibility Principle „SRP“ ● Do one thing. ● One reason for a function to change. ● One level of abstraction per function. ● Maybe applies to packages as well. ●
  35. 35. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Other Object Oriented Stuff? ● Encapsulation  ● Coupling (between packages)  ● Cohesion  ● Cyclomatic Complexity 
  36. 36. ½ of “Clean Code” applies (in some way)
  37. 37. Conclusion
  38. 38. 1) Clean code always looks like it was written by someone who cares.
  39. 39. 2) Clean Code Applies to PL/SQL (at least to a certain extend)
  40. 40. 3) Read It!
  41. 41. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Peter Kofler @codecopkofler www.code-cop.org
  42. 42. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY CC Images ● cleaning: http://www.flickr.com/photos/inf3ktion/4477642894/ ● dump: http://www.flickr.com/photos/sanmartin/2682745838/ ● thumb: http://www.flickr.com/photos/leehaywood/4481372869/ ● knife: http://www.flickr.com/photos/21232564@N06/2234726613/ ● finish: http://www.flickr.com/photos/jayneandd/4450623309/
  1. A particular slide catching your eye?

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

×