Formatting PL/SQL like SQL

In going through reams of PL/SQL code it dawned on me that procedural language is often formatted differently than structured query language in the same code sample. I decided to take a shot at formatting procedural language code like SQL and I like the result.

declare
	var1 number(9) 	:= 0;
	var2 number(9) 	:= 0;
	var3 number(9) 	:= 0;
	var4 number(9) 	:= 0;
	var5 number(9) 	:= 0;
	var6 number(9) 	:= 0;
	var7 number(9) 	:= 0;
	var8 number(9) 	:= 0;
	var9 number(9) 	:= 0;
begin
	if 	var1 	= var2
	and 	var3 	= var4
	or 	var5 	= var6
	then
		while 	var1 	< var9
		and 	var2 	is null
		or 	var4 	is not null
		loop
			select 	a.col1
			into 	var6
			from 	table1 a
			, 	table2 b
			where 	a.col1 	= b.col1
			and 	a.col2 	= var7
			or 	b.col2 	= var8;

			var1 	:= var1 + 1
		end loop;
	elseif 	var1 	= var2
	and 	var1 	<> var3
	or 	var1 	<> var4
	then
		insert
		into 	table3
		( 	col1
		, 	col2
		, 	col3
		)
		values
		( 	var1
		, 	var2
		, 	var3
		);
	else
		var9 	:= 100;
		if 	var4 	is not null
		then
			var8 	:= 100;
		endif;
	endif;
end

Note that I am using ten character tabs throughout the code and formatting and aligning as I would with SQL. I find the conditional structures in the IF and WHILE statements much clearer this way.

*Footnote: I recently used the TOAD formatter command and have found it surpasses my own standard for formatting. If you have TOAD I highly recommend the use of the formatter for all code. The saving in effort for the maintenance people that follow in your development footsteps is well worth it.

formatting plsql like sql formatting plsql like sql formatting plsql like sql

Code Slobs

I have been having quite a time at work these days as I have been assigned the task of doing an impact analysis on the addition of a column into the database schema.  I have found myself without documentation and having to go into the source of hundreds of programs and scripts looking for the implications of the change.  The code is completely unformatted and trying to rectify the situation to save my bleeding eyes has been hell.

What obstacles do I face?  My Team Leader says she doesn’t look at code so she doesn’t care what format it is in.  My Senior Oracle Developer says he formats all his code, but he doesn’t consider code formatting important.   The remaining development team writes functioning code, but has no education in how to format PL/SQL so it’s readable.  In otherwords, I am surrounded by Code Slobs.

How do you deal with code slobs?  First, automation.  I have persuaded all of them to use the TOAD code formatter in the future so people without TOAD can make some sense of their product when doing maintenance.  Second, roll up your sleeves and clean up the legacy code.  I have to go through the code looking for the impact of a column change anyways, so along the way I am formatting all the code I read.  I know there will be more impact analysis tasks and code maintenance, so I am hoping to make it easier for future code readers and maintenance programmers.

So, look out code slobs, I am going into every nook and cranny and sorting out the detrius,  so someone, anyone can have a better chance of giving your work a longer life span, simply by making it readable.

Zachman Tetrads

R. Buckminster Fuller’s books reveal a characteristic of his thinking. He would always return to his simplest system, the tetrahedron, and travel on ever new tangents. I decided to look at Zachman again with a different orientation and apply tetrads.

zachmantetrad.jpg

It is important to note that each of the columns is a design perpective. The one to one column is not the real entity but a physical design perspective of the entity.

Maslow’s B-Values and Predictability

Along with the Hierarcy of Needs, Abraham Maslow also compiled a set of Being Values. 

  • WHOLENESS (unity; integration; tendency to one-ness; interconnectedness; simplicity; organization; structure; dichotomy-transcendence; order);
    
    
  • PERFECTION (necessity; just-right-ness; just-so-ness; inevitability; suitability; justice; completeness; “oughtness”);
    
    
  • COMPLETION (ending; finality; justice; “it’s finished”; fulfillment; finis and telos; destiny; fate);
    
    
  • JUSTICE (fairness; orderliness; lawfulness; “oughtness”);
    
    
  • ALIVENESS (process; non-deadness; spontaneity; self-regulation; full-functioning);
    
    
  • RICHNESS (differentiation, complexity; intricacy);
    
    
  • SIMPLICITY (honesty; nakedness; essentiality; abstract, essential, skeletal structure);
    
    
  • BEAUTY (rightness; form; aliveness; simplicity; richness; wholeness; perfection; completion; uniqueness; honesty);
    
    
  • GOODNESS (rightness; desireability; oughtness; justice; benevolence; honesty);
    
    
  • UNIQUENESS (idiosyncrasy; individuality; non-comparability; novelty);
    
    
  • EFFORTLESSNESS (ease; lack of strain, striving or difficulty; grace; perfect, beautiful functioning);
    
    
  • PLAYFULNESS (fun; joy; amusement; gaiety; humor; exuberance; effortlessness);
    
    
  • TRUTH (honesty; reality; nakedness; simplicity; richness; oughtness; beauty; pure, clean and unadulterated; completeness; essentiality).
    
    
  • SELF-SUFFICIENCY (autonomy; independence; not-needing-other-than-itself-in-order-to-be-itself; self-determining; environment-transcendence; separateness; living by its own laws).

When you examine these values in the context of intelligence being the power to predict it becomes clear that many of these B-Values derive their appeal by affording us predictability.  We find satisfaction in life when it meets our preparation to expect the expected or expect the unexpected.

What Do the Boxes and Lines Mean?

For the past several posts I have been listing tetrads in juxtaposition to a set of graphics:

idef1x.jpg

 

These four graphics are representative of the four fundamental relationships in the relational model using a notational style called IDEF1X.  These four relationships are used to design relational databases.  I am of the opinion that these relationships form what I call a “tetrad”, a term I borrow from Marshall McLuhan, and that it shares characteristics with other tetrads.

I invite you to look at the other posts under the tetrad category in my blog.

God, Abram and Abraham Maslow

“Leave your country, your people and your father’s household
And go to the land I will show you.
I will make you into a great nation
And I will bless you
I will make your name great
And you will be a blessing
I will bless those who bless you
And whoever curses you I will curse
And all nations on earth
will be blessed through you.”

Genesis 12:1-3, NIV

The above passage is referred to as God’s promise to Abram. In it God tells Abram all the needs that will be fulfilled in Abram’s life if he simply depends on God to fulfill his physiological needs. God would eventually rename Abram to Abraham.

A few thousand years after this was written, Abraham Maslow came up with his renowned “hierarchy of needs”. This hierarchy had the five following components:

  1. Physiological
  2. Safety
  3. Belonging
  4. Esteem
  5. Self-Actualization

When I looked at this hierarchy the alarm bells went off, because I was deeply familiar with the book of Genesis and God’s promise to Abram in particular.

Leave your country, your people and your father’s household and go to the land I will show you fulfills the physiological requirement.

I will make you into a great nation and I will bless you fulfills the belonging requirement.

I will make your name great and you will be a blessing fulfills the esteem requirement.

I will bless those who bless you and those who curse you I will curse fulfills the safety requirement.

All nations on earth will be blessed through you fulfills the self-actualization requirement.

So, what is it that Maslow revealed to us that the authors of the Old Testament haven’t already recognized as fundamental needs? It appears to me that Maslow at best reinvented the wheel. At worst he plagiarized and secularized a Bible passage.

On further examination of this passsage and of Maslow’s hierarchy we can find that there is a defining quality between the physiological and the remaining needs. The physiological need does not require social interaction, the four remaining needs do. This produces another tetrad.

maslow.jpg

God, Abram and Abraham Maslow digg

Schools Must Cultivate Creativity

Sir Ken Robinson discusses how we are strip mining the minds of our children and creating educational inflation because we do not cultivate creativity in schools.

conceptual.jpg

Think about this tetrad while you watch the video. Do we cultivate toward the physical or the conceptual in our children? How do we balance education to develop each facet equally? How do we get them outside the tetrad?