Quantcast
Channel: Oracle Blog : apex
Viewing all articles
Browse latest Browse all 142

On the importance of keeping algorithmic logic separate from display logic

$
0
0
On the PL/SQL Challenge, all times are shown in the UTC timezone. Weekly quizzes end on Friday, midnight UTC. So I recently decided that when I display the time that the quiz starts and ends, I should add the string "UTC".

Our quiz website is built in Oracle Application Express 5.0, so I opened up the process that gets the date and found this:

DECLARE
l_play_date DATE
:= qdb_quiz_mgr.date_for_question_usage (:p46_question_id);
BEGIN
:p46_scheduled_to_play_on := TO_CHAR (l_play_date, 'YYYY-MM-DD HH24:MI');

"OK, then," says Steven the Fantastic Developer to himself. "I know exactly what to do."

And I did it:

DECLARE
l_play_date DATE
:= qdb_quiz_mgr.date_for_question_usage (:p46_question_id);
BEGIN
:p46_scheduled_to_play_on :=
TO_CHAR (l_play_date, 'YYYY-MM-DD HH24:MI')
|| ' UTC';

Ah, PL/SQL and APEX - so easy to use! :-)

Now, there are lots of things you could say about the change I made above, but here's one thing that is undeniably true:
P46_SCHEDULED_TO_PLAY_ON will never by NULL.
Right? Right. Of course, right.

So that's fine, though. Because that's what I wanted: to have "UTC" always show up, and there's always going to be a date when the question is used in a quiz, right?

Well, no. In fact, this code is part of our Quiz Editor page, and on that page we offer a button that allows you to easily and quickly schedule a quiz for play.

But only if it hasn't already been scheduled. If it hasn't already been scheduled, then the date is, oh wait, um, NULL.

And that's why we have a condition on that button:

Applications > 10001 - Oracle Dev Gym > Lists > Quiz Editor Actions > Entries > Schedule
AttributeCondition Expression1 (Specifies an expression based on the specific condition type selected.)
Value
:P46_SCHEDULED_TO_PLAY_ON IS NULL
AND
NVL (:P46_IS_TEMPLATE, 'N') = 'N'

And that's why Eli Feuerstein, the fine fellow who does most of the work on the PL/SQL Challenge and it's cool new sister, Oracle Dev Gym, reported an issue with this page:
The Schedule button never appears on the page!
Awwwwwwwwwww......

So two lessons learned (re-learned, and learned again, then forgotten, then re-learned, then learned again....):

1. When I am about to make a change, ask myself: "What impact might this have?" 

In the world of APEX, it's pretty easy: search for the string "P46_SCHEDULED_TO_PLAY_ON" and see how it is used in the application. 

2. Keep completely separate the data (in this case, APEX items) that is used for algorithmic logic and the data that is used for display purposes.

I could create a separate item for display purposes, or a different item to be used in conditions and other PL/SQL blocks. 

But I should not use the same item for both.

Viewing all articles
Browse latest Browse all 142


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>