Toad World® Forums

Readability of formatted code

All,

A simple question of readability and maintainability of code.
This is an example of a call to our exception handler as formatted in 12.11 and up with Dynamic arrangement:
exception
when others
then – log the error and re-raise exception to inform caller
utl_krg.msg_log.standard_exception_handler(
p_schema =>
g_my_schema
, p_package =>
g_my_package
, p_routine =>
l_my_routine
, p_action =>
l_action
, p_msg_code =>
sqlcode
, p_local_msg_prefix =>
g_my_msg_prefix
, p_message =>
'On ’
|| ora_database_name
|| ‘: ’
|| sqlerrm
|| ’ - p_item_name=’
|| coalesce(p_item_name, ‘<*Null>’)
|| ‘, p_item_key=’
|| coalesce(p_item_key, ‘<*Null>’)
|| ‘, p_timestamp=’
|| coalesce(trim(to_char(p_timestamp, ‘yyyy-mm-dd hh24:mi:ss.ff’)), ‘<*Null>’)
, p_row_count =>
l_row_count
);

The same code by the 12.10 formatter:
exception
when others
then – log the error and re-raise exception to inform caller
utl_krg.msg_log.standard_exception_handler(
p_schema => g_my_schema
, p_package => g_my_package
, p_routine => l_my_routine
, p_action => l_action
, p_msg_code => sqlcode
, p_local_msg_prefix => g_my_msg_prefix
, p_message => 'On ’
|| ora_database_name
|| ‘: ’
|| sqlerrm
|| ’ - p_item_name=’
|| coalesce(p_item_name, ‘<*Null>’)
|| ‘, p_item_key=’
|| coalesce(p_item_key, ‘<*Null>’)
|| ‘, p_timestamp=’
|| coalesce(trim(to_char(p_timestamp, ‘yyyy-mm-dd hh24:mi:ss.ff’)), ‘<*Null>’)
, p_row_count => l_row_count
);

The latter is - at least to my mind and eyes - much better readable.

  1. is has a clear distinction between parmnames area and parmvalues area
  2. is uses far fewer lines, which helps in maintaining a view of the statement within its context. (screens are always too small)

My issue with the new formatter is not that it uses parmname area for holding parmvalues when a parameter value specification is very long, but I do object to reusing the parmname area for all parmvalues as soon as any one of them uses it. It causes visual clutter on the left-hand side, leaves available space at the right-hand side unused and unnecessarily stretches the block of code vertically.

Just my opinion. Please be invited to share your thoughts.

Kind regards,
Abe Kornelis

Hello Abe,

I fully agree with you. Latest formatter doesn’t seem to listen to the Parameter settings, so this looks like a bug. I’ll look into this asap.

Thanks,
Andre

Abe,

Actually it turns out that the overly long p_message parameter puts the whole parameter list in “wrapped” mode, and none of the parameter settings don’t work anymore.

How about doing that wrapping for only those parameters which exceed the right margin? In your code below I added a copy of a few parameters after the p_message, to better illustrate the effect:

exception
when others
then – log the error and re-raise exception to inform caller
utl_krg.msg_log.standard_exception_handler (
p_schema => g_my_schema,
p_package => g_my_package,
p_routine => l_my_routine,
p_action => l_action,
p_msg_code => SQLCODE,
p_local_msg_prefix => g_my_msg_prefix,
p_row_count => l_row_count,
p_message =>
'On ’
|| ora_database_name
|| ‘: ’
|| SQLERRM
|| ’ - p_item_name=’
|| COALESCE (p_item_name, ‘<*Null>’)
|| ‘, p_item_key=’
|| COALESCE (p_item_key, ‘<*Null>’)
|| ‘, p_timestamp=’
|| COALESCE (
TRIM (TO_CHAR (p_timestamp, ‘yyyy-mm-dd hh24:mi:ss.ff’)),
‘<*Null>’),
p_action2 => l_action,
p_msg_code2 => SQLCODE,
p_local_msg_prefix2 => g_my_msg_prefix);
end;

Andre

Andre,

that would be Great!

Thanks in advance,
Abe

(this also answers everything in:

QP-2344

For now no extra formatter option, just a change in behavior described above in this thread. This will appear in QP5 version 5.319 next week.

I attached a small video showing output while decreasing the margin from around 250 down to about 60. You can see how the code starts folding as the margin narrows. Sorry the actual margin is not shown, but the video should give an idea. You may want to select resolution 720 to read text.

Thanks,
Andre

Link embedding (for video) may not work, so here’s the link:

www.youtube.com/watch

Andre,

thanks for the video.
Looks good to me.

Kind regards,
Abe

Fixed in component QP5 version 5.319.