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

Copyright Peter Kofler, licensed under CC-BY.
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
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Agenda
Define Clean Code
● Define PL/SQL
● Apply Clean Code to PL/SQL
● Examples
● Discussion
●
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
● Implementation Patten, 2007
● Agile Software Development, 2002
● The Pragmatic Programmer, 1999
● Refactoring, 1999
● Code Complete 1st Ed, 1993 (!)
●
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 understand.
● Easy to modify.
● Easy to test.
● Easy ...
●

http://stackoverflow.com/a/954582/104143
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, C#
– Ruby, Python
– maybe C++
• Clean Code is about
– Object Orientation
– Test Driven Development
Do these guidelines
apply to PL/SQL?
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
Sounds much like
Java to me ;-)
Examples from
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/
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 

●

Unit Testing 
/3 of “Clean Code”
applies directly

1
Can PL/SQL be Clean? (2013)
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.
●
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Other Object Oriented Stuff?
●

Encapsulation 

●

Coupling (between packages) 

●

Cohesion 

●

Cyclomatic Complexity 
½ 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/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/

More Related Content

PDF
TDD and Related Techniques for Non Developers (2012)
PDF
Concepts of Functional Programming for Java Brains (2010)
PDF
Prime Factors Code Kata (2010)
PDF
Designing Test Cases for the Gilded Rose Kata (2013)
PDF
The Brutal Refactoring Game (2013)
PDF
Code Retreat Graz, Austria 2013
PDF
Clean Readable Specifications (ETC 2016)
PDF
Software Craftsmanship Journeyman Tour (2013)
TDD and Related Techniques for Non Developers (2012)
Concepts of Functional Programming for Java Brains (2010)
Prime Factors Code Kata (2010)
Designing Test Cases for the Gilded Rose Kata (2013)
The Brutal Refactoring Game (2013)
Code Retreat Graz, Austria 2013
Clean Readable Specifications (ETC 2016)
Software Craftsmanship Journeyman Tour (2013)

What's hot (20)

PDF
TDD as if You Meant It (2013)
PDF
GDCR15 in Las Palmas, Gran Canaria
PDF
Coding Dojo Object Calisthenics (2016)
PDF
Deliberate Practice (Agile Slovenia 2015)
PDF
Deliberate Practice, New Learning Styles (2015)
PDF
Brutal Coding Constraints (ITAKE 2017)
PDF
Designing Test Cases for the Gilded Rose Kata v2 (2015)
PDF
Designing Test Cases for the Gilded Rose Kata v3 (2016)
PPTX
Architectural changes in Orion
PDF
Refactoring the Tennis Kata v2 (2016)
PDF
Python for Swift
PDF
An introduction to go programming language
PPTX
Future of PERL in IT
PDF
Lets Go - An introduction to Google's Go Programming Language
PDF
TDD with Rails
PPT
A First Look at Google's Go Programming Language
PDF
Code Reviews in Python - PyZh
PDF
UnDeveloper Studio
KEY
Using Aspects for Language Portability (SCAM 2010)
TDD as if You Meant It (2013)
GDCR15 in Las Palmas, Gran Canaria
Coding Dojo Object Calisthenics (2016)
Deliberate Practice (Agile Slovenia 2015)
Deliberate Practice, New Learning Styles (2015)
Brutal Coding Constraints (ITAKE 2017)
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Architectural changes in Orion
Refactoring the Tennis Kata v2 (2016)
Python for Swift
An introduction to go programming language
Future of PERL in IT
Lets Go - An introduction to Google's Go Programming Language
TDD with Rails
A First Look at Google's Go Programming Language
Code Reviews in Python - PyZh
UnDeveloper Studio
Using Aspects for Language Portability (SCAM 2010)
Ad

Similar to Can PL/SQL be Clean? (2013) (20)

PPTX
Oracle Database 11g: Learn and Master PL/SQL | Course Outline
PPT
Writing Maintainable Code
PPT
Writing maintainable Oracle PL/SQL code
PDF
Plpgsql russia-pgconf
PDF
PLSQL Standards and Best Practices
PDF
PL/SQL Complete Tutorial. All Topics Covered
PDF
plsql_tutorial.pdf
PPTX
Clean coding in plsql and sql
PDF
PLSQL tutorial...
PDF
PPTX
Clean coding in plsql and sql, v2
PPTX
PL/SQL is a block structured language that enables developers to combine the ...
PDF
Oracle Plsql Programming Sixth Edition Steven Feuerstein Bill Pribyl
PDF
Oracle PL SQL Programming Animal Guide 5th Edition Steven Feuerstein
PPT
L9 l10 server side programming
PDF
PL_SQL
PPTX
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PDF
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
PPTX
PLSQL Tutorial
PPTX
Pl sql Prograaming of Database management system
Oracle Database 11g: Learn and Master PL/SQL | Course Outline
Writing Maintainable Code
Writing maintainable Oracle PL/SQL code
Plpgsql russia-pgconf
PLSQL Standards and Best Practices
PL/SQL Complete Tutorial. All Topics Covered
plsql_tutorial.pdf
Clean coding in plsql and sql
PLSQL tutorial...
Clean coding in plsql and sql, v2
PL/SQL is a block structured language that enables developers to combine the ...
Oracle Plsql Programming Sixth Edition Steven Feuerstein Bill Pribyl
Oracle PL SQL Programming Animal Guide 5th Edition Steven Feuerstein
L9 l10 server side programming
PL_SQL
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
PLSQL Tutorial
Pl sql Prograaming of Database management system
Ad

More from Peter Kofler (20)

PDF
Coding Dojo: Baby Steps Push Challenge (2021)
PDF
Coding Dojo: Naming with Dices (2021)
PDF
Writing Tests with the Unity Test Framework
PDF
Outside-in Test Driven Development - the London School of TDD
PDF
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
PDF
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
PDF
Coding Dojo: Asynchronous Clock-In (2016)
PDF
Mob Programming (2016)
PDF
Code Retreat Venice (2016)
PDF
Coding Dojo: Data Munging (2016)
PDF
JUnit Boot Camp (GeeCON 2016)
PDF
Extract Method Refactoring Workshop (2016)
PDF
Coding Dojo: Functional Calisthenics (2016)
PDF
Pair Programming (2015)
PDF
Coding Dojo: Bank OCR Outside-In (2015)
PDF
Pragmatic Introduction to PHP Unit Testing (2015)
PDF
Coding Dojo: Fun with Tic-Tac-Toe (2014)
PDF
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
PDF
Coding Dojo: Mars Rover (2014)
PDF
Code Refactoring - Live Coding Demo (JavaDay 2014)
Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Naming with Dices (2021)
Writing Tests with the Unity Test Framework
Outside-in Test Driven Development - the London School of TDD
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Coding Dojo: Asynchronous Clock-In (2016)
Mob Programming (2016)
Code Retreat Venice (2016)
Coding Dojo: Data Munging (2016)
JUnit Boot Camp (GeeCON 2016)
Extract Method Refactoring Workshop (2016)
Coding Dojo: Functional Calisthenics (2016)
Pair Programming (2015)
Coding Dojo: Bank OCR Outside-In (2015)
Pragmatic Introduction to PHP Unit Testing (2015)
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
Coding Dojo: Mars Rover (2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Modernizing your data center with Dell and AMD
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Modernizing your data center with Dell and AMD
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
NewMind AI Monthly Chronicles - July 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Spectral efficient network and resource selection model in 5G networks
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
The AUB Centre for AI in Media Proposal.docx
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx

Can PL/SQL be Clean? (2013)