Programming help/tips


#21

I would put that into a new function and split the logic into parts with early returns.
Something like this:

if(!rSight && !lSight)
    return 0;
if(rSight && lSight){
    if(rSight == lSight)
         return 0;
    return leftRightTest();
} else if(rSight)
    return 1;
else if(lSight)
    return -1;

Something like that. I can’t think of a better way to reduce complex if-else nesting. (I didn’t make sure that that code is actually right, and I didn’t add comments which is very critical here to explain to future readers what the logic is about)


(He who abuses the search function) #22

Thanks, now that I think about it using a function does make it a lot “cleaner” or so to say. I’ll try this out next time I’m working on it.