Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
optional parameters of "component"
#21
Comparison of the variants:
Code:
Component   Component    Component        Result    Result
exists     has errors    returns         mvlcek    ZegnÃ¥t
===============================================================
  yes         yes          false           true      false  <=
  yes         yes     nothing/not false    true      false  <=
  yes         no           false           true      false  <=
  yes         no      nothing/not false    true      true
  no          yes          false           false     false
  no          yes     nothing/not false    false     false
  no          no           false           false     false
  no          no      nothing/not false    false     false

In the important case - Component has no errors and returns nothing, both variants return the same.

So my only issues with Zegnåt's approach is that it is overly complex:
  • It tests, if the component has errors. But will users really check the return value for this? Is anybody - except in special cases - writing code to test, if some other code compiles???
  • On the other hand, in a realistic call, for which the return code of get_component was intended (by me, at least, based on feature requests in the forum) - like get_component('sidebar-'.return_page_slug()) || get_component('sidebar') - ZegnÃ¥t's approach has no advantages for testing/debugging. See below.

I'm assuming that component 'sidebar' has no errors, as it is the default and was already tested.
My approach:
  • sidebar is displayed, but shouldn't => sidebar-xxx does not exist
  • nothing or an error message is displayed => there is an error in sidebar-xxx
Zegnåt's approach:
  • sidebar is displayed, but shouldn't => sidebar-xxx does not exist or sidebar-xxx has an error (or sidebar-xxx returns false)
  • nothing or an error message is displayed => can't happen

Having said this and trying to keep it simple, I prefer my simple approach, because support for it is much simpler - it's easier to ask "does the component exist?" instead of "Does the component exist and compile and not return anything or at least not false?" - but I'm happy with either way.

BTW: I don't care if break or return is used - if the code works ;-)
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply


Messages In This Thread
optional parameters of "component" - by bugman - 2011-06-08, 21:29:05
optional parameters of "component" - by bugman - 2011-06-08, 21:46:44
optional parameters of "component" - by mvlcek - 2011-06-08, 21:53:29
optional parameters of "component" - by bugman - 2011-06-08, 22:03:32
optional parameters of "component" - by bugman - 2011-06-08, 22:23:43
optional parameters of "component" - by mvlcek - 2011-06-18, 07:23:05
optional parameters of "component" - by mvlcek - 2011-06-18, 21:33:07
optional parameters of "component" - by ccagle8 - 2011-06-20, 09:10:54
optional parameters of "component" - by mvlcek - 2011-06-20, 16:27:53
optional parameters of "component" - by mvlcek - 2011-06-20, 19:36:30
optional parameters of "component" - by mvlcek - 2011-06-20, 20:45:03
optional parameters of "component" - by mvlcek - 2011-06-20, 23:55:27
optional parameters of "component" - by mvlcek - 2011-06-21, 05:28:08



Users browsing this thread: 1 Guest(s)