Can PL/SQL be Clean? (2013)
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Can PL/SQL be Clean? (2013)

on

  • 815 views

 

Statistics

Views

Total Views
815
Views on SlideShare
815
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 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!
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Can PL/SQL be Clean? (2013) Presentation Transcript

  • 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. 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. 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. What is Clean Code?
  • 5. “Craftsmanship Over Crap“ (Robert C. Martin)
  • 6. “Clean code looks like it was written by someone who cares.” (Michael Feathers)
  • 7. Rule 1) Written by someone who cares.
  • 8. What is Clean Code?
  • 9. Clean Code
  • 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. Quick And Dirty
  • 12. Code Complete
  • 13. “Write Programs for People First, Computers Second.” (Steve McConnell)
  • 14. Rule 2) Written for People First.
  • 15. So how would You like the code to be? (besides working correctly)
  • 16. Code which does not make me want to kill the author. http://programmers.stackexchange.com/a/13594/15057
  • 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. Procedural Language/ Structured Query Language
  • 19. Should you write PL/SQL with care?
  • 20. Should you write PL/SQL for people?
  • 21. Tadaaa!
  • 22. Clean PL/SQL looks like it was written by someone who cares.
  • 23. Write PL/SQL for People First, Databases Second.
  • 24. But...
  • 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. Do these guidelines apply to PL/SQL?
  • 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. Sounds much like Java to me ;-)
  • 29. Examples from
  • 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. http://theprofoundprogrammer.com/post/26561881517/text-single-letter-variables-who-the-fuck-do
  • 32. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Other Chapters ● Formatting  ● Comments  ● Functions  ● Unit Testing 
  • 33. /3 of “Clean Code” applies directly 1
  • 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. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Other Object Oriented Stuff? ● Encapsulation  ● Coupling (between packages)  ● Cohesion  ● Cyclomatic Complexity 
  • 36. ½ of “Clean Code” applies (in some way)
  • 37. Conclusion
  • 38. 1) Clean code always looks like it was written by someone who cares.
  • 39. 2) Clean Code Applies to PL/SQL (at least to a certain extend)
  • 40. 3) Read It!
  • 41. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Peter Kofler @codecopkofler www.code-cop.org
  • 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/