A classic example of over-engineering your software

Sometimes I encounter a typical example of what I call “over-engineering”. Someone has been enthusiastically designing a webpage, and added a few business rules too many.

The example below could have been funny if the consequences weren’t so dangerous.

I was creating an account on the Vodafone 360 site. When I provided my password, I noticed they had a “password security indicator”. I was also pleased to see that I entered an extremely safe password; 4 out of 4!!
Then I got this message:

how not to restrict a password

It says, my password is restricted to digits and characters only. And apparently, only capitals too. Isn’t that odd? It severely restricts me in providing a safe password, and it violates every guideline ever created about passwords.

Shouldn’t any designer who thinks of such a rule shouldn’t be fired on the spot? I mean, what was he thinking?  The password strength isseriously reduced by limiting the allowable characters. The math is simple: a single character can be any key on your keyboard; digits, lowercase letters, uppercase letters, and symbols. A total of, let’s say 100 characters.

A one-character password can have a hundred combinations. A two-character password already a hundred times hundred (100²), or 10.000 combinations. And a three-character password 100³ combinations, summing up to 1 million. If I apply the restriction on this site, I can use 27+10=37 characters. 37³ =  a maximum of 50653 combinations. Or 20 times less!

A Brave New World… or better: Era

Once upon a time, a long time ago, computers where something most people never saw for real. They were as big as apartment blocks and operated and maintained by highly specialized technicians. And the use for computers was sort of a niche market. From the perspective of that time, it wasn’t really strange that Thomas J. Watson (president of IBM) said in 1943 that there would be a world market for about 5 computers.

Since then, so much has changed that it is almost mind boggling. I remember my teacher at primary school being really mad at me because I took a creditcard-sized calculator to class. Yes, they were quite new in those days. A year later or so I was the first in school having a home computer, the legendary Sinclair ZX Spectrum. Up till then, computers where only used in companies, where sometimes an entire department shared one terminal. If the system wasn’t down for maintenance.

That was the beginning. 5 years later, some people even had a PC at home, another 5 years later, most people did. And who doesn’t remember 1995, when Windows ’95 dropped like a bomb with a new graphical user interface. With a spectacular market share, it has become the de facto standard in how we interact with our computers in the past 15 years. In fact, apart from some added eye candy and barely functional visual effects, how much really has changed in that period of time?

Yes, you have a bigger harddrive, more memory and a cpu that runs circles around the once so proverbial Silicon Graphics workstations. Wireless networking adds some convenience (and often, a lot of frustration too!), and thank God for USB and HDMI. We all ran the ratrace of megahertzes, megapixels and gigaflops, up to the point were we have something on our lap that is truly magnificent in performance.

That’s an intriguing and probably arguable observation. Somehow we still do not differ much from those technicians I mentioned earlier. Installing a printer, a wireless router or even some new software is not a trivial thing for the average user. Don’t come talking to them about configuring startup services or a firewall, hooking up the printer to the new wireless router, or even worse, recovering from a system crash. Heck, people haven’t the faintest idea where their Gmail or Hotmail emails are stored!
The computer has become a commodity, we say.  But although it’s cheap and ubiquitous, is it really easy to operate your computer? Yes, it can more things than you ever could imagine, but isn’t that also the weakness of this device. Every advance has his price: complexity.

And this complexity is just the thing which is going to be beyond our ‘event horizon’ in the future. Yes, it will be still there, but my prediction is that the software for managing your household commodities (good time to get rid of that 80-ies word ‘computer’) will rapidly become more mature and more user friendly. That is the next revolution to come. And also the point that we  may stop bothering about processortype, connection protocol and compatibility issues. I can’t wait, really!

What is multitasking on iPhone or iPad anyway?

With the introduction of the iPad a new discussion has arisen. The question of what is multitasking on iphone or iPad. And of course the fact that the iPad lacks this ability. At least, that is what the iPad opponents (what’s the use of being against a handheld device, I wonder?) keep repeating (along with the non-Flash argument of course).

At first I went along with the multitasking argument. How can this device be useful if you cannot play music while checking your email? Because I am sure that is exactly what I would use the iPad for. And then it dawned to me. What do we mean with ‘multi-tasking’ anyway?

Getting the facts

Our friend Wikipedia provides an interesting definition: In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is actively executing instructions for that task. Multitasking solves the problem by scheduling which task may be the one running at any given time, and when another waiting task gets a turn.

So, what does this definition imply? Multitasking means that multiple processes share the same CPU, and parts of those process are in fact running seriated. By means of a context switch the processes are reassigned to the CPU. When the frequency of context switches is high enough, the illusion of parallelism is achieved. Of course, with multiple CPU’s or CPU cores, true parallelism is possible.

With this information in mind, let ’s go back to the iPad (or iPhone, which has basically the same OS). The iPad OS is, if we may believe various sources on the internet, capable of running background processes, in any case for the built in software. If that is the case, nothing stands in your way  to listen to your favourite album while typing an email. At the same time! Well, perhaps with some context switching, but you won’t be bothered by that at all.

Leaves us one other question. What is multitasking from the end users point of view? I think most users will come up with the vision of having dozens applications on their desktop, where they reside next to each other and  the user is constantly switching between programs and making them interact in many ways.

… in fact, most applications seldom interact with each other, at the most in the case of copying information from one to another. Be honest, that describes most of your in-between application activities when working on your desktop OS. And any decent user interface should be able to copy and paste data between applications. Yes, that includes the iPhone.

Don’t forget that the average user is not so capable of multitasking himself. Try doing any number of tasks simultaneously and you’ll find yourself switch-tasking in no time. And that is usually the least effective way of getting things done, because we are not as capable of switch-tasking as the average CPU.

Conclusion

So, wrapping this up, I’ve come to the conclusion that the limited ability of using multiple applications simultaneously is not the big disadvantage some people want us to believe. Even more if you keep in mind where the iPad is meant for: the more casual work and entertainment, using only one or two productivity apps simultaniously.

Macheist mania

Now that I discovered the site, the hype is probably already over it’s top. But I find it intriguing. You buy a bundle of Mac OS X applications with a huge discount. And you support some charity organizations along the way. And if you’re lucky, some apps wil be added along the way. Because a minimum number of downloads is reached, or just for fun. And of course, the offer is limited.

And they call it Macheist. At the time of writing they’re offering a Nanobundle. I’m still not sure what’s the difference between the nanobundles and the regular ones, but I’ll find out in time.

Check it out at http://www.macheist.com and see for yourself if the $20 is well spent on this software collection. And if the requirements will be met for Monkey Island, of course!

Something about null values in Oracle SQL

Something I’ve posted before…. but I thought it was time to rewrite it a little.

We all are at least a bit aware of the awkward behaviour of NULL in Oracle. But it still is difficult every time we encounter it in a function or where-clause.
Some examples to keep in mind when comparing NULL values:

1. null equals what?

Null equals nothing, in fact. It doesn’t even equals to itself.
And because of that, a condition does not always behave in the way you would expect.

Let’s start straightforward.

a := 10
a is null results in FALSE
a is not null results in TRUE
a := null
a is null results in TRUE
a is not null results in FALSE

We’ve all been there, done that and got ourselves the t-shirt.

a := null
b := null

This is a situation that you’re bound to encounter sooner or later. Both a and b are null. Let’s compare it!

select 'x' from dual where a = b;

What is the result? FALSE?

Wrong! But it’s certainly not TRUE either. This expression results to UNKNOWN. And that state is a very dangerous one to be in!

Because UNKNOWN acts very similar to FALSE you might be tricked in thinking that they always behave the same. And that is not true. When a condition evaluates to UNKNOWN, no rows will be returned. In that sense it is similar. But look at this:

SQL> create table nulls( id number(9), value1 varchar2(20));

Table created.

SQL> insert into nulls values ( 1, 'A collection of ');

1 row created.

SQL> insert into nulls values( 2, null );

1 row created.

SQL> insert into nulls values( 3, 'something else');

1 row created.

SQL> select id
2  from nulls
3  where value1 = 'A collection of '
4  /
 ID
 ----------
         1

That is exactly what we expected. “Where value1 = ‘A coll…’ ” evaluates to TRUE, so a row is returned, and “Where value1 = null” evaluates to UNKNOWN. No row is returned.
Finally, “Where value1 = ’something else’ “, evaluates to FALSE and no row is returned. All expected behaviour.

SQL> select id from nulls where NOT( value1 = 'A collection of ');

  ID
  ----------
          3

If we place a NOT operator around the conditions, the difference becomes clear. TRUE has become FALSE, FALSE has become TRUE, and UNKNOWN… is still UNKNOWN. And hence row 2 is not displayed.

2. Nulls in indexes

I’ve created a table with one varchar2 column and 5000 records. The column contains a normal B-Tree index (tst1) and a function based-index tst2 (with function “where NVL( value1, ‘|empty|’ )”. One record is NULL, and unfortunately, that is exactly the one I am looking for. How does this affect performance?

SQL> select count(*) from psi_test where value1 is null;

1 row selected.

Execution plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=11 Card=1 Bytes=11)
   1    0   SORT (AGGREGATE)
   2    1     TABLE ACCESS (FULL) OF 'PSI_TEST' (TABLE) (Cost=11 Card=509 Bytes=5599)

SQL> select count(*) from psi_test where nvl(value1, '|empty|') = '|empty|';

1 row selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=11)
   1    0   SORT (AGGREGATE)
   2    1     INDEX (RANGE SCAN) OF 'TST2' (INDEX) (Cost=2 Card=510 Bytes=5610)
As you see, the optimizer does a full table scan on the first example, and an index range scan on the second. Of course, this is a very basic example, but it explains the idea.

3. null functions

NVL is well-known, it’s been there for ages. The function NVL returns the value of its second argument if its first argument is null.

SQL>  select value1, nvl( value1, '!! NULL values....' ) from nulls;

VALUE1               NVL(VALUE1,'NULLVALU
-------------------- --------------------
A collection of      A collection of
                     !! NULL values....
something else       something else

Powerful, very convenient, so often used.
And what if you want to determine the returned value based on whether an expression is null or not null? NVL is not so useful for that. But NVL2 is. NVL2 has not two but three arguments. The first is the tested value. If that is not null, the second expression is returned. If it’s null, the third expression is returned.

Example:

SQL> select id , nvl2( value1 , 'this column is not null' , 'and this columns is NULL' ) test from   nulls;

        ID TEST
---------- ------------------------
         1 this column is not null
         2 and this columns is NULL
         3 this column is not null

I think these little examples cover most of the issues you can encounter with null values. Don’t get tricked by a null!

By using this site you acknowledge the use of cookies (which are mostly harmless, btw) More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below you are agreeing to these settings.

Close