Welcome Guest, Not a member yet? Register   Sign In
Avoiding nesting everything inside IF statements
#4

[eluser]BrianDHall[/eluser]
[quote author="kurucu" date="1254254810"]No, I use return like that to escape from the controller after displaying errors (e.g. when a specific index is not found, and showing a default is not valid). It hasn't bitten me yet.

I guess you'd have different things in place of $logged_in, if you want to test for a specific role etc?[/quote]

Actually I just stuck that variable there for simplicity, as what I actually am doing in that particular function is that if a person isn't presently working on an incomplete listing then they have no business trying to 'preview' it (which I determine by checking the existence of an ORM-powered class variable).

But yeah, for user login roles I was thinking of exactly that - sometimes it doesn't matter so long as they are logged in, and sometimes it does Smile

Quote:However... While having code nested inside a bunch of IF statements doesn't look nice, that doesn't mean it is necessarily inelegant code! It might be perfect logic and very efficient, but the human programmer is allergic to it Smile

Its really all the human element, you hit the nail on the head there. The problems I find with it are A) lots of nesting isn't pretty and distracts the eye and gives one more thing to have to fix occasionally if your editor gets confused, B) increased chance of mis-matching brackets, putting code in the wrong bracket, or worst of all putting code that assumes a certain security check in the wrong set of brackets, and C) being inside a loop increases human memory usage and requires concentration (you have to constantly remember you are in a loop and what conditions triggered your arrival there) even if it requires no computer over-head in terms of memory or CPU strain.

As ADDey (thats now a word, I just 'precedented' it) as I tend to be, I can't afford any extra mental overhead Wink

Quote:So I'm potentially waiting for the same wall to creep up on me!

Thanks kurucu, I'm really glad to hear it works as I thought it would as it seems like such a nice option to have in some functions and controllers. Gives me new appreciation for the whole point of pages being 'functions' to begin with - easy to end execution of them without breaking the page or other functions (like exit might do).


Messages In This Thread
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 08:46 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:06 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:26 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:34 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 01:00 PM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 04:26 PM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 06:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB