The document discusses whether clean code principles can be applied to PL/SQL. It defines clean code as code that is written by someone who cares and for people first rather than computers. While clean code principles primarily target modern object-oriented languages, the document argues that many of the principles directly apply to PL/SQL as well, since it is compiled, imperative/procedural, and structured similarly to Java. Specific clean code topics like meaningful naming, formatting, comments, functions, and unit testing are examined in the context of PL/SQL. The conclusion is that clean code principles apply to PL/SQL to a certain extent and the document encourages readers to consider applying them.
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Can Clean Code Practices Improve PL/SQL
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
●
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
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
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/
35. 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.
●
36. PETER KOFLER, CODE-COP.ORG
FANATIC ABOUT CODE QUALITY
Other Object Oriented Stuff?
●
Encapsulation
●
Coupling (between packages)
●
Cohesion
●
Cyclomatic Complexity