Guarantee Application Success Steven Feuerstein PL/SQL Evangelist, Quest Software

Similar documents
Three Simple Steps to Improving PL/SQL Code Quality

Impact Analysis with PL/Scope

Database Programming with PL/SQL

Weird PL/SQL Steven Feuerstein PL/SQL Evangelist, Quest Software

Use PL/SQL to automate standards compliance. Lewis Cunningham Data Architect and ACE Director

With Tom Kyte and Andy Mendelsohn. plus special guest appearances: Dan McGhan, Natalka Roshak, Chris Saxon


Database Programming with PL/SQL

You wrote WHAT? An examination of common coding mistakes made by PL/SQL developers (like yours truly!) and how you can avoid them yourself.

Developers and DBAs. Farmers and City Slickers have different mindsets

Promoting Component Architectures in a Dysfunctional Organization

Now, we can refer to a sequence without having to use any SELECT command as follows:

Introduction to Programming

Take Full Advantage of the PL/SQL Compiler

Introduction to Computer Science and Business

Software Design Models, Tools & Processes. Lecture 6: Transition Phase Cecilia Mascolo

CS 142 Style Guide Grading and Details

ICANN and Technical Work: Really? Yes! Steve Crocker DNS Symposium, Madrid, 13 May 2017

Quest Code Tester for Oracle 3.1. Installation and Configuration Guide

Oracle Database 12c Release 1 PL/SQL New Features

Exam Name: Oracle Database 11g: Program with PL/SQL

Software Design and Analysis CSCI 2040

Testing in a Test-driven World

Types of Software Testing: Different Testing Types with Details

10 Strategies for Effective Marketing Campaigns

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

Partial Backup Interview Questions And Answers In Oracle 10g Pl Sql

Reliable programming

The Stack, Free Store, and Global Namespace

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

CS103 Spring 2018 Mathematical Vocabulary

JSON and PL/SQL: A Match Made in Database

Wednesday. Wednesday, September 17, CS 1251 Page 1

Debugging. CSE 2231 Supplement A Annatala Wolf

Announcements. Chapter 7 for Friday

TestComplete 3.0 Overview for Non-developers

The perfect 12c PLSQL error handler. www. syntegris.de

Oracle Database 12c: Program with PL/SQL Duration: 5 Days Method: Instructor-Led

Exploring Edition-Based Redefinition

CO Oracle Database 12c: Advanced PL/SQL

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Checklist for Testing of Web Application

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

shortcut Tap into learning NOW! Visit for a complete list of Short Cuts. Your Short Cut to Knowledge

Ruby on Rails Welcome. Using the exercise files

COURSE 11 DESIGN PATTERNS

TestBase's Patented Slice Feature is an Answer to Db2 Testing Challenges

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

Week 5: Background. A few observations on learning new programming languages. What's wrong with this (actual) protest from 1966?

Oracle Database 11g: Program with PL/SQL Release 2

Database Developers Forum APEX

Rapid Software Testing Guide to Making Good Bug Reports

Book Typography: A Designer's Manual

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Oracle PLSQL Training Syllabus

Hardware versus software

Oracle Database 10g The Self-Managing Database

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL Ed 2

Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting

Programming Style. Quick Look. Features of an Effective Style. Naming Conventions

Hi everyone. Starting this week I'm going to make a couple tweaks to how section is run. The first thing is that I'm going to go over all the slides

Ms Sql Server 2008 R2 Check If Temp Table Exists

IZ0-144Oracle 11g PL/SQL Certification (OCA) training

Sql Server 2008 Query Table Schema Management Studio Create New

Memory Addressing, Binary, and Hexadecimal Review

Introduction to Object-Oriented Modelling and UML

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

Oracle Database 12c R2: Program with PL/SQL Ed 2 Duration: 5 Days

These are notes for the third lecture; if statements and loops.

Cognitive Disability and Technology: Universal Design Considerations

THE OFFICIAL (ISC)2 GUIDE TO THE CCSP CBK FROM SYBEX DOWNLOAD EBOOK : THE OFFICIAL (ISC)2 GUIDE TO THE CCSP CBK FROM SYBEX PDF

Conditionally control code flow (loops, control structures). Create stored procedures and functions.

Welcome to this IBM podcast, Realizing More. Value from Your IMS Compiler Upgrade. I'm Kimberly Gist

05. SINGLETON PATTERN. One of a Kind Objects

Oracle. Exam Questions 1Z Oracle 11g: Advanced PL/SQL. Version:Demo. 1Z0-146 Exam Questions Demo

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

Oracle Application Express How It s Made November 15, 2011

Product Review: James F. Koopmann Pine Horse, Inc. SoftTree s SQL Assistant. Product Review: SoftTree s SQL Assistant

Etiquette FOR A BUSY WORLD. Brevity can be off-putting. Always reply

9 th CA 2E/CA Plex Worldwide Developer Conference 1

The Z-Files: Field reports from the world of business critical PHP applications

Database Programming with PL/SQL

Sample Exam ISTQB Advanced Test Analyst Answer Rationale. Prepared By

Most of the class will focus on if/else statements and the logical statements ("conditionals") that are used to build them. Then I'll go over a few

Up and Running Software The Development Process

Basic Keywords Practice Session

Compilers. Prerequisites

Communicating Through Top 10 Dos and Donʼts! Presented by Geri Ann Fuller!

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Application Development at

The first program: Little Crab

Volume 8, Issue 1 Payment Processing News from Shift4 Corporation November 2005

Learning By Sample Series. Learning By Sample - T-SQL : Part 3

Oracle PL/SQL - 12c & 11g [Basic PL/SQL & Advanced PL/SQL]

Read & Download (PDF Kindle) XML For Dummies

Why Deprecating async() is the Worst of all Options

Chapter 5 Errors. Bjarne Stroustrup

Introduction to Programming Style

Transcription:

Guarantee Application Success Steven Feuerstein PL/SQL Evangelist, Quest Software www.stevenfeuerstein.com www.toadworld.com/sf Copyright 2009 Quest Software

Obsessed with PL/SQL... Three courses in programming -1979-1980 Oracle pre-sales - 1987-1992 First book published - 1995 PL/SQL Evangelist, Quest Software 2001-Present Oracle PL/SQL Programming 5th Edition Book Signing Wednesday 15:45 Quest Booth Copyright 2008 Steven Feuerstein Copyright 2000-2008 Steven Feuerstein - Page 1

Welcome to My Obsession PL/SQL Obsession http://www.toadworld.com/sf Take advantage of all the resources available at PL/SQL Obsession. Standards, presentations, videos, puzzles, code... You have my permission to use all these materials to do internal trainings and to build your own applications. But remember: this code is generally not production ready. You must test them and modify them to fit your needs. filename_from_demo_zip.sql 2 Copyright 2008 Steven Feuerstein

What makes an application successful? That is the whole point of what we do, correct? And if our applications are successful, we are successful. It seems like the answer to this question should be obvious. But is it? Copyright 2008 Steven Feuerstein Page 3

What makes an application successful? So let's start with the really big picture. Our application is successful if and only if... Copyright 2008 Steven Feuerstein Page 4

How do we make our users happy? We make sure that the application... Is correct. The application should do what the user specified. Is fast enough to avoid user frustration and keep users productive. Is maintainable. As user requirements change, the application must change along with it without high cost. Copyright 2008 Steven Feuerstein Page 5

How do we achieve CORRECT, FAST (enough) and MAINTAINABLE? There is only way to prove that an application is correct: we test it. A lot. test Proactive: apply key optimization features test Reactive: stress/load test; isolate and remove bottlenecks. Establish, follow, verify best practices. Build and run regression tests. test Copyright 2008 Steven Feuerstein Page 6

"Regression" Test why is it called that? You've probably all heard of this kind of test. Why call it "regression" test? It is supposed to verify that your code has not regressed, gone backwards. If it worked in version 1.3, it really should work in version 1.4. How could this happen? I use (and need) that function key every day! Well, to be honest, we make changes and we really have no idea what the impact is. Sorry! Copyright 2008 Steven Feuerstein Page 7

Correct Applications are Tested Applications Testing is absolutely fundamental to successful applications. So why don't we test more thoroughly? Testing is hard work, in any and every language at least if we do it manually. For thorough testing, you should expect to have to write at least 10 lines of test code for every line of application code that needs testing! Testing is boring. We are not creating code or writing interesting algorithms and we are spoiled. Copyright 2008 Steven Feuerstein Page 8

Manual Testing is a Dead End If we write test code ourselves and stare at the screen until we are "sure" our code "works", we will never break out of the vicious cycle: We work long, hard hours yet always fall behind. Copyright 2008 Steven Feuerstein Page 9

Automation is Key to Thorough Testing There is really only one practical solution: automate code testing as fully as possible. It is, after all, precisely what we do to help our users. Automation allows us to... Find more bugs Repeat our tests Put regression tests in place Integrate testing into the development process. Copyright 2008 Steven Feuerstein Page 10

Options for automated testing of PL/SQL dbfit Based on the FitNesse platform, a tabular scripting approach, implemented in Java. utplsql and its variants Open-source framework, part of the xunit family. Essentially, "Junit for PL/SQL" PL/Unit and PLUTO are utplsql variants. SQL Developer 2.1 Unit testing integrated into the editor Quest Code Tester for Oracle Dedicated automated testing tool Copyright 2008 Steven Feuerstein Page 11

Successful Application are Fast (Enough) Applications This is the best understood leg of the tripod. Quest Software and others offer a number of tools to automate the tuning of SQL, and to stress test your code. Beyond that, it is critically important that you take advantage of key performancerelated features of PL/SQL. Copyright 2008 Steven Feuerstein Page 12

Key PL/SQL Performance Features The optimizing compiler Never set optimization level below 2. Collections Oracle's array-like structures, the foundation for most performance-related features of PL/SQL FORALL and BULK COLLECT Improve performance of multi-row SQL operations by an order of magnitude or more. The Oracle11g Function Result Cache Fantastic new declarative mechanism for data caching 11g_frc*.* Copyright 2008 Steven Feuerstein Page 13

Successful Applications are Maintainable Applications The code we write will be in use for years, perhaps decades. We should have all learned a big lesson from Y2K. The cost of maintaining an application can easily exceed the cost of initially building the application. It is critical that we pay attention not only to meeting the initial delivery deadline, but also to reducing the cost of changing the application over time. Copyright 2008 Steven Feuerstein Page 14

Steps to more maintainable code Build (and maintain) regression tests. Establish strong foundation of standards upon which code will be built. If everyone writes code their own way, the software is much harder to understand. Make it easy to follow standards. Don't just leave standards inside documents. Help developers establish new habits based on the standards. Verify that the standards were followed. If you don't check to make sure standards are followed, they will be ignored. Copyright 2008 Steven Feuerstein Page 15

What should be standardized? Don't start a new application until you have set standards in these areas... Basic coding standards and naming conventions. How to handle and log errors How, when and where to write SQL statements Copyright 2008 Steven Feuerstein Page 16

Basic coding conventions & naming standards Visit PL/SQL Obsession and select "PL/SQL Standards" to download a variety of suggested standards. Most important... Apply standards consistently and as comprehensively as possible. Check to make sure that standards are being followed. I will come back to this later. Copyright 2008 Steven Feuerstein Page 17

Standardize: How to Handle and Log Errors We don't like to deal with the negative, so we tend to avoid or minimize focus on exception management. Big mistake! It's very important to... Take full advantage of PL/SQL's error management features. Communicate problems in a consistent way to both users and support. Make it easy for developers to quickly and easily handle and log errors. Copyright 2008 Steven Feuerstein Page 18

Use a Shared Error Manager All developers should use the same mechanism to raise, handle, log errors. Many groups have built their own. If you need one... Quest Error Manager, available from www.toadworld.com/sf Logger from Oracle's samplecode on OTN Copyright 2008 Steven Feuerstein Page 19

How, When and Where to Write SQL Yes, that sounds about right, doesn't it? Imagine writing PL/SQL programs and not writing any SQL statements... Does that sound painful? I think it sounds wonderful! Copyright 2008 Steven Feuerstein Page 20

What's so bad about SQL? There's nothing wrong with SQL. The problem is with where, when and how we write SQL in our applications. Everyone has naming conventions and no one has any rules for SQL. Very strange... Stop taking SQL for granted. It is the source of many problems and challenges. Every SQL statement you write is a hard-coding that is worse than a hard-coded literal value! Copyright 2008 Steven Feuerstein Page 21

Set Rules for Writing SQL If you don't control how SQL is written, you will not be able to easily optimize and maintain your code. Use Bryn Check out Bryn Llewellyn's white paper "Doing SQL in PL/SQL: Best and Worst Practices" available on the Oracle Technology Network. Generally, apply the same principle to SQL that you should everything else in your code: Copyright 2008 Steven Feuerstein Page 22

Hide SQL Behind a Data Access Layer Protect application code from change. Prepare to take advantage of new features Like the Oracle11g function result cache. Improve productivity and code quality. Application Code Intermediate Layer Order Table Item Table Copyright 2008 Steven Feuerstein Page 23

Verify standards are being followed It's not enough to set rules, you need to check the code afterwards for compliance. Choose from any and all of the following: Peer/team code review (manual) Queries against various data dictionary views Compile-time warnings PL/Scope IDE- based analysis tools Copyright 2008 Steven Feuerstein Page 24

Peer / Team Code Review No critical code should make it to production unless another human being looks it over. You could go "extreme": Pair Programming of XP Team meetings to review code help in many ways... Share knowledge about applications and programs within Technology expertise is shared as senior developers point out other/better ways to do things Reading of code often can uncover "deep" bugs and better algorithms. Copyright 2008 Steven Feuerstein Page 25

Handy Data Dictionary views for PL/SQL ALL_SOURCE Source code of all accessible programs ALL_PROCEDURES Information about every subprogram you can execute ALL_ARGUMENTS Information about every argument of every subprogram you can execute ALL_PLSQL_OBJECT_SETTINGS Compile-time settings of PL/SQL program units Copyright 2008 Steven Feuerstein valstd.* show_all_arguments.* Copyright 2000-2008 Steven Feuerstein - Page 26

Compile-time warnings framework Enable warnings and the compiler will give you feedback on the quality of your code.. Review the PLW category in the Error Messages manual to see which warnings are most important to you. Use the Oracle11g version if at all possible. ALTER SESSION SET plsql_warnings = 'enable:all enable:all'; ALTER SESSION SET plsql_warnings = 'enable:06002', 'enable:performance enable:performance', 'ERROR:05005'; Copyright 2008 Steven Feuerstein Page 27

Compiler time warnings an example Check for unreachable end code. SQL> CREATE OR REPLACE PROCEDURE unreachable_code IS 2 x NUMBER := 10; 3 BEGIN 4 IF x = 10 THEN 5 x := 20; 6 ELSE 7 x := 100; -- unreachable code 8 END IF; 9 END unreachable_code; 10 / SP2-0804: Procedure created with compilation warnings SQL> show err Errors for PROCEDURE UNREACHABLE_CODE: LINE/COL ERROR -------- ------------------------------------- 7/7 PLW-06002: Unreachable code plw*.sql Copyright 2008 Steven Feuerstein Page 28

PL/Scope Oracle11g A compiler-driven tool that collects information about identifiers and makes it available through a data dictionary view. Use PL/Scope to answer questions like: Where if a variable assigned a value in a program? What variables are declared inside a given program? Which programs call another program (that is, you can get down to a subprogram in a package)? Find the type of a variable from its declaration. Copyright 2008 Steven Feuerstein Page 29

Some PL/Scope examples Enable gathering of PL/Scope data. ALTER SESSION SET plscope_settings='identifiers:all' Verify PL/Scope setting for a program. SELECT plscope_settings FROM user_plsql_object_settings WHERE NAME = 'PACK1' AND TYPE = 'PACKAGE BODY' Identify all declarations for the specified set of programs whose names do not start with "L_". SELECT name, signature, tyhpe FROM user_identifiers WHERE name NOT LIKE 'L\_%' ESCAPE '\' ' AND USAGE = 'DECLARATION' AND object_name LIKE '&1' 11g_plscope.sql 11g_plscope_amis.sql Copyright 2008 Steven Feuerstein Page 30

IDE-Integrated Code Analyzers Automatically check code against a set of rules and recommendations. Toad and SQL Navigator offer CodeXpert, which is largely driven by ideas in my Oracle PL/SQL Best Practices book. Copyright 2008 Steven Feuerstein Page 31

Guarantee Application Success You need to... Prove correctness don't just hope and pray. Make sure it is fast enough. Write readable, maintainable code. We can do all of this, but only if we... Think about the future. Don't just code for today. Take full advantage of PL/SQL's features. Automate the testing process. Ask our managers to protect us from deadline pressures. Copyright 2008 Steven Feuerstein Page 32

And some other incredibly fantastic and entertaining websites for PL/SQL Copyright 2008 Steven Feuerstein Page 33