Small nuisances



  • You know how there's stuff in your codebase that works properly, but still irks you? This is a snippet from a recent commit. I'd refactor, but there's no point; this will just be copy-pasted somewhere else tomorrow...

    for ($i=$min;$i<=$max;$i++) {
          if ($i==$max) $isLastPage=1;   
          if ($page==$i)
                 $isActive=1;
          else
                 $isActive=0;
                   
           $pageArr[ ]=array('pageNumber'=>$i,
                                        'isLastPage' => $isLastPage,
                                        'isActive' => $isActive
                               );

    }




  • I'd propose this:

    for($i = $min; $i <= $max; $i++) {
      $pagesArr[] = array(
        'pageNumber' => $i,
        'isLastPage' => ($i == $max),
        'isActive' => ($i == $page),
      );
    }
    

    But I don't see the point of this snippet (out of context)



  • @DOA said:

    I'd refactor, but there's no point; this will just be copy-pasted somewhere else tomorrow...

    Um … isn't that precisely why you should refactor it, or am I missing something?

    +50 FTFYs beats +50 WTFs IMHO. :)



  • @Cad Delworth said:

    Um … isn't that precisely why you should refactor it, or am I missing something?
    Stuff like this has permeated the codebase. It's all over the place by now. Even if I fix this, the next project will be the same crap copy-pasted from somewhere else. It's like a virus now. And no I'm not going to go insane fixing a few hundred instances of this.



  • That's why you bring out the power tools.



  • @ltouroumov said:

    I'd propose this:

    [snipped]

    Nice. Care to explain how that works?



  • @Faxmachinen said:

    Nice. Care to explain how that works?

    I had no WYSYHYG on chrome, so i forgot to escape the < >

    for($i = $min; $i <= $max; $i++)

    Community server sucks ! (chrome too but I chose the lesser of three evils)



  • Aww. For a second I thought PHP was much less boring than I remembered it.


Log in to reply