in reply to The -w switch on a web application
Below I posted two pieces of the code. The first one is checking for defines, the second - doesn't. The second one is more nicer, because if we don't check for undef values, we can delegate function calls to each other without having intermediate variables. If I start checking for defines, my code becomes full of if and unless sentences.
The code is creating a menu object and setting the active menu for it, which it has to display say in a different color. Of course, the checking for the active menu could be done inside the Menu object, but in my design it's outside. So, my code has to check for the undef value from the CGI param() function and from my get_active_menu_id() functions as well, because they don't always return a defined value.
I lose the flexibility of perl and I worry pretty much about it. What should you do in such a situation?
The checks for defined version:
my $main_menu = new Menu("main"); my $menu_item = param('menu_item'); if(defined($menu_item)) { my $active_menu_id = get_active_menu($menu_item); $main_menu->active_menu_id($active_menu_id) unless !$active_menu_id; } $main_menu->output;
No checks for defined version:
my $main_menu = new Menu("main"); $main_menu->active_menu_id(get_active_menu(param('menu_item'))); $main_menu->output;
So what do you think, is it worth checking for defines on such a code or not?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The -w switch on a web application
by Aristotle (Chancellor) on Jan 31, 2003 at 14:08 UTC | |
|
Re^2: The -w switch on a web application
by diotalevi (Canon) on Jan 31, 2003 at 14:26 UTC | |
|
Re: Re: The -w switch on a web application
by l2kashe (Deacon) on Jan 31, 2003 at 14:09 UTC |