Welcome Guest, Not a member yet? Register   Sign In
casting could clean some code
#1

[eluser]tomfoth[/eluser]
Hi,

I'm new so please don't shoot me down!

I've been looking at some of the code and have notice several bit of code that I think could be improved. Although, there are probably good reasons not to that I don't yet know of, compatibility issues or something. Or more likely - it's such a minor issue.

in system/libraries/Loader.php (line 370 in my install)

...
if ( ! is_array($helpers))
{
$helpers = array($helpers);
}

foreach ($helpers as $helper)

..

could this not be simplified to the following?

...
foreach ( (array)$helpers as $helper )
...
#2

[eluser]xwero[/eluser]
It looks fine to me but like you said it's a minor thing, i wonder how much time it will shave of by reducing the file size and function calls?
#3

[eluser]tomfoth[/eluser]
probably not much by itself. It might even make it slower. I'm going to do some more testing after work. Purely out of curiosity - of course.

Also I get a bit anal about making code more simple. Some might argue that this would make is less obvious so some people, but to me it reads better.
#4

[eluser]sophistry[/eluser]
hi tomfoth and welcome to CI.

in my experience working with CI and seeing it evolve, the only time the CI devs will change code that is already proven and working is if you prove a startling difference in performance or uncover a real bug.

suggesting changing some bit of code that is working but has one extra if statement or one verbose expression is not going to get *any* traction. i love slim code and optimizing as much as the next advancing programmer, but at some point you have to focus on the bigger picture. Wink

here's an example of forum-developed code that actually convinced somebody inside Ellis Labs and they went ahead and used it: http://ellislab.com/forums/viewthread/51788/

WRT array casting, i believe it has implications for code readability and clarity as well as error reporting - however, i couldn't expound on it OTTOMH. also, supposing someone wanted to change that code to do a few more things when no array was detected... it's somewhat future proof because it is clear and structured (i know, lame argument).

cheers!
#5

[eluser]tomfoth[/eluser]
I see, I see. I've been looking at Kohana as an alternative. It's claims to be community driven instead of being company driven.

Maybe this isn't a discussion for the company owned fourm! shhhhh :-)




Theme © iAndrew 2016 - Forum software by © MyBB