News for hackers. Stuff that matters.
Re:Ask HN: PHP Tricks and Best Practices? by shaunxcode on Wednesday October 29, 2008 @02:35PM (#347800)
fluent expressions (when uses appropriately) can be great for constructing DSLs. Also any time you see boiler plate code take the time to refactor to eliminate it - often times figuring out how to do that will make new abstractions apparent. As a matter of practice search for the coolest things you can do in python (list comprehensions etc.), lisp and ruby and figure out how to do things in a similar way (if possible) in php.

Such as:

  //python version:
  noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]
  primes = [x for x in range(2, 50) if x not in noprimes]

  //phparrayplus version:
  $noprimes = xR(2,8)->for_each('xR($x*2,50,$x)->out()')->flatten();
  $primes = xR(2,50)->diff($noprimes);

  //common lisp:
  (loop for x from 0 to 100 if (> (* x x) 3) collect (* 2 x))

  //phparrayplus version:
  $C = xR(100)->if_only('($x*$x) > 3')->for_each('2*$x');

  //factorial in phparrayplus, nothing else to compare this too  - just cool:
  function fac($n){
    return xR(1,$n)->reduce('$x*$y'); 
  }
Re:Ask HN: PHP Tricks and Best Practices? by jamongkad on Wednesday October 29, 2008 @11:39PM (#348394)
Wow that shit is hot! Let us know when you have released the library.
Re:Ask HN: PHP Tricks and Best Practices? by apgwoz on Wednesday October 29, 2008 @04:02PM (#347928)
Is "phparrayplus" a library you wrote. If so, where can it be had?
Re:Ask HN: PHP Tricks and Best Practices? by shaunxcode on Wednesday October 29, 2008 @04:12PM (#347934)
yes, it should be available next week on http://code.google.com/p/phparrayplus