<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2097478384981689221</id><updated>2026-09-17T04:28:45.896-06:00</updated><category term="chido"/><category term="php"/><category term="scripter"/><category term="ftw"/><category term="relax"/><category term="patterns"/><category term="javascript"/><category term="oop"/><category term="wtf"/><category term="cli"/><category term="css"/><category term="html"/><category term="jquery"/><category term="loco"/><category term="shell"/><title type='text'>Mamá, no soy un vagales</title><subtitle type='html'>Al tiempo que vago también codeo, y no con el codo, sino para con el código.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-7828601145675070187</id><published>2011-10-13T01:16:00.001-05:00</published><updated>2011-10-13T01:38:25.620-05:00</updated><title type='text'>Blocks, closures y objetos</title><content type='html'>Cuando ando de paseo por el mundo &lt;b&gt;Ruby&lt;/b&gt; (especialmente RoR) me suelo encontrar con bastantes &lt;code&gt;do&lt;/code&gt; y &lt;code&gt;end&lt;/code&gt; (ciertamente me recuerdan PASCAL), o en una sola linea &lt;code&gt;{&lt;/code&gt; y &lt;code&gt;}&lt;/code&gt;, esto es lo que llamamos convencionalmente bloques (de instrucciones).&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-ruby&quot;&gt;# método de configuración
config :scope, do |bag|
  bag.set :key, &#39;value&#39;
end&lt;/pre&gt;
&lt;br /&gt;
Nada nuevo, tampoco para aburrirse, lo bonito de este lenguaje es la manera en que maneja estos conceptos de bloques. Pero también tiene una sintaxis poderosa, breve y bastante agradable de leer y escribir.&lt;br/&gt;
¿Hago mal en preferir un lenguaje también por su estética?&lt;br /&gt;
&lt;br /&gt;
Tampoco voy a dar una clase de &lt;a href=&quot;http://www.raulparolari.com/Ruby2/lambda_Proc&quot;&gt;bloques en ruby&lt;/a&gt;, pero me interesa en concreto el concepto de &lt;code&gt;lambda&lt;/code&gt; y su utilización como &lt;i&gt;callback&lt;/i&gt; en algunos escenarios cotidianos en los lenguajes de programación de alto nivel como lo es también &lt;b&gt;PHP&lt;/b&gt;.&lt;br /&gt;
&lt;blockquote&gt;
Y no hay que buscar demasiado, la versión mas reciente del pre-procesador de hipertexto ya venía con torta bajo el brazo, pues ofrece bastante potencial en la orientación a objetos así como con este bonito concepto que es un &lt;i&gt;closure&lt;/i&gt;. De hecho, en php un &lt;i&gt;closure&lt;/i&gt; por si mismo es un objeto, una clase.&lt;/blockquote&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;// método de configuración
config(&#39;scope&#39;, function ($bag) {
  $bag-&amp;gt;set(&#39;key&#39;, &#39;value&#39;);
});&lt;/pre&gt;
&lt;br /&gt;
Finalmente me parece que su funcionalidad es la misma, 
contener un grupo de instrucciones en un contexto aislado, sin importar 
si devuelve un resultado o no.&lt;br /&gt;
&lt;br /&gt;
Así como el ejemplo de un método de configuración cualquiera se pueden dar otras alternativas mas flexibles, aquí otra definición:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;// agregamos un nuevo libro en alguna colección
function add_book_to($user, Closure $describe) {
  $book = $user-&gt;books-&gt;build();
  $describe($book);
  $book-&amp;gt;save();
}

// seleccionamos a un usuario
$me = user::first_by_name(&#39;Alvaro&#39;);

// agregamos el libro
add_book_to($me, function ($book) {
  $book-&amp;gt;title = &#39;Fake title&#39;;
  $book-&amp;gt;description = &#39;Fake description&#39;;
}); &lt;/pre&gt;
&lt;br /&gt;
Y la verdad es que una función anónima implementada en php tiene 
bastantes desventajas a comparación de otros lenguajes, pero tampoco es 
inútil. Se pueden conseguir &lt;i&gt;features&lt;/i&gt; interesantes en cuanto a flexibilidad en php. &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Chiro-liro&lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/7828601145675070187/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/7828601145675070187' title='12 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/7828601145675070187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/7828601145675070187'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/10/blocks-closures-y-objetos.html' title='Blocks, closures y objetos'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-6548018434877505986</id><published>2011-09-07T10:28:00.005-05:00</published><updated>2011-09-07T11:16:29.871-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="ftw"/><category scheme="http://www.blogger.com/atom/ns#" term="loco"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="relax"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><title type='text'>¿Pachequés o flexo?</title><content type='html'>&lt;p&gt;Disculpen el título. &lt;em&gt;Nel&lt;/em&gt;, ni se que dije.&lt;/p&gt;

&lt;p&gt;Bueno... aquí traigo otra de las cosas locas -y divertidas- que me laten de &lt;strong&gt;PHP&lt;/strong&gt;, ya me dirán.&lt;br&gt;
Trabajando un poco en un proyecto que tengo alojado en mi cuenta de &lt;strong&gt;GitHub&lt;/strong&gt; quise darle la vuelta a un problema especifico: diseñar una &lt;strong&gt;API&lt;/strong&gt; que fuese amigable y divertida a la vez, desde luego me refiero al lenguaje mismo y no más.&lt;/p&gt;

&lt;p&gt;Así pues descubrí que dos conceptos pueden existir bajo el mismo nombre, y hablo en serio:&lt;/p&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function foo()
{
}

class foo
{
}&lt;/pre&gt;

&lt;p&gt;¿Y que chingados con eso?&lt;/p&gt;
&lt;p&gt;Pues eso, de alguna extraña forma php permite nombrar de la misma manera una función y/o clase. Esto evidentemente nos brinda la posibilidad de escribir una serie scripts de diversa índole bajo el mismo &quot;&lt;em&gt;namespace&lt;/em&gt;&quot; o algo parecido.&lt;/p&gt;

&lt;p&gt;Vamos a imaginar una librería para manejar sesiones:&lt;/p&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;session_start();

class session
{
  public static function fetch($item)
  {
    return $_SESSION[$item];
  }
  public static function assign($item, $value)
  {
    $_SESSION[$item] = $value;
  }
  public static function remove($item)
  {
    unset($_SESSION[$item]);
  }
}

function session($item, $value = NULL)
{
  if (func_num_args() === 1)
  {
    return session::fetch($item);
  }
  elseif (is_null($value))
  {
    session::remove($item);
  }
  else
  {
    session::assign($item, $value);
  }
}&lt;/pre&gt;

&lt;p&gt;En mi experiencia esto facilita las cosas de una forma sumamente agradable y consistente, si no me creen hagan la prueba.&lt;/p&gt;

&lt;p&gt;¡Diviertanse!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/6548018434877505986/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/6548018434877505986' title='13 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/6548018434877505986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/6548018434877505986'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/09/pacheques-o-flexo.html' title='¿Pachequés o flexo?'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-4924488514446114551</id><published>2011-09-03T21:27:00.010-05:00</published><updated>2011-09-03T23:00:11.179-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="ftw"/><category scheme="http://www.blogger.com/atom/ns#" term="oop"/><category scheme="http://www.blogger.com/atom/ns#" term="patterns"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="relax"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><title type='text'>Classy patch</title><content type='html'>&lt;p&gt;Ahora que lo pienso no se si existe algo parecido a esto.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/pateketrueke&quot;&gt;Diviertiendome&lt;/a&gt; pensé que sería divertido jugar con alguna otra cualidad de &lt;strong&gt;PHP&lt;/strong&gt;. Hice un podo de &lt;em&gt;research&lt;/em&gt; y no hallé al respecto así que me dedique a diseñar algo así.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php&quot;&gt;// registramos el buen autoloader
spl_autoload_register(function($class)
{
  rescue($class);
});

// registramos filtros
function resolve(Closure $with = NULL)
{
  static $patch = array();


  if (func_num_args() === 0)
  {
    return $patch;
  }

  $patch []= $with;
}

// y los ejectuamos
function rescue($class)
{
 foreach (resolve() as $callback)
 {
   $callback($class);
 }
}&lt;/pre&gt;

&lt;p&gt;Si, es un sistema de &lt;em&gt;autoload&lt;/em&gt;, sin embargo no es una convencional. Y tiene varias ventajas mas.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pa&#39;&lt;/em&gt; sonreír, ¿no?&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/4924488514446114551/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/4924488514446114551' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/4924488514446114551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/4924488514446114551'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/09/classy-patch.html' title='Classy patch'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-6996828086654275968</id><published>2011-08-31T08:52:00.004-05:00</published><updated>2011-08-31T09:09:59.199-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="ftw"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="relax"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><title type='text'>Radical, un pensamiento natural</title><content type='html'>&lt;p&gt;Lo que me fascina de los lenguajes es el potencial que tienen para mejorar nuestra concepción del pensamiento mismo. Cada día me sorprendo mas.&lt;/p&gt;

&lt;p&gt;Pero hablemos al chile (y no hablo del país), yo no soy fanático ni mucho menos obsesivo con ningún lenguaje. Solo trato de ser justo y humano, al final todo es cuestión de gusto.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Aquí es donde entra el radicalismo, no me gusta la forma tradicional de programar ni 100% objetos, ni 100% funcional. Creo que una buena combinación de ambos es perfecta para mi: &lt;strong&gt;PHP&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Cuando observamos &lt;strong&gt;Javascript&lt;/strong&gt; no parece que todo fuera un objeto, pero así lo es. Así mismo pasa con &lt;strong&gt;Ruby&lt;/strong&gt;, y así cualquiera se acostumbra. Ni hablar de JAVA. No lo uso ni de &lt;em&gt;keyword&lt;/em&gt;...&lt;/p&gt;

&lt;p&gt;Ando tratando de llevar todo lo que he aprendido al limite, explotando todos los medios para desarrollar algo loco, la verdad solo busco mas aprendizaje y no más. Si gustan revisen mi &lt;a href=&quot;https://github.com/pateketrueke/&quot;&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Después de todo soy &lt;em&gt;scripter&lt;/em&gt;, ya lo verán.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/6996828086654275968/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/6996828086654275968' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/6996828086654275968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/6996828086654275968'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/radical-un-pensamiento-natural.html' title='Radical, un pensamiento natural'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-7403167819185065530</id><published>2011-08-18T13:59:00.005-05:00</published><updated>2011-08-18T14:38:58.026-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="relax"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><category scheme="http://www.blogger.com/atom/ns#" term="wtf"/><title type='text'>Nel pastel</title><content type='html'>&lt;p&gt;Recién vagando por mi &lt;em&gt;TL&lt;/em&gt; y en algún tema de &lt;strong&gt;@forosdelweb&lt;/strong&gt; mo topé con &lt;a href=&quot;http://wiki.python.org/moin/PythonVsPhp&quot;&gt;éste&lt;/a&gt; enlace.&lt;br&gt;
He visto cosas muy locas entre lenguajes, y una de las cosas que me gustan es la &quot;negación infinita&quot;, si, ya se que suena raro pero así es.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php&quot;&gt;$foo = TRUE;

if ( !!!!!!!!!!!!!!!!!!!!!!!! $foo)
{
  echo &#39;Damn.&#39;;
}&lt;/pre&gt;

&lt;p&gt;¿Saben lo que significa?&lt;br&gt;
Como cuando te dicen &quot;no digas nada&quot;, yo lo entiendo como un &quot;not(say(null))&quot; osea que me quedo igual, &quot;dí algo&quot;, true.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function not($is)
{
  return !!! $is;
}

function say($something)
{
  return $something;
}

echo not(say(null)) ? &#39;algo&#39; : &#39;nada&#39;;&lt;/pre&gt;

&lt;p&gt;La neta la primera vez que torcí un &lt;var&gt;!!&lt;/var&gt; no entendía ni madres, sin embargo un poco de reflexión &lt;em&gt;pachequera&lt;/em&gt; me aclaro las cosas, casi como leí en un tema acerca de lo &lt;a href=&quot;http://stackoverflow.com/questions/1485841/python-behaviour-of-increment-and-decrement-operators&quot;&gt;siguiente&lt;/a&gt; (que en &lt;strong&gt;PHP&lt;/strong&gt;, obviamente no es posible).&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php&quot;&gt;$a = 5;
$b = $a ++ 5; // Parse error: syntax error, unexpected T_LNUMBER in...&lt;/pre&gt;

&lt;blockquote&gt;&lt;p&gt;Lo que si, esto que dicen está &lt;em&gt;chingón&lt;/em&gt;:&lt;/p&gt; &lt;cite&gt;on PHP you can do this: if($a == $b) { echo &quot;true&quot;; } else { echo &quot;false&quot;; } : try to do that whith Python&lt;/cite&gt;&lt;/blockquote&gt;

&lt;p&gt;No más &lt;a href=&quot;http://hyperpolyglot.org/scripting&quot;&gt;chequen&lt;/a&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/7403167819185065530/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/7403167819185065530' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/7403167819185065530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/7403167819185065530'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/nel-pastel.html' title='Nel pastel'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-2229172135148732455</id><published>2011-08-10T09:22:00.008-05:00</published><updated>2011-08-10T10:19:55.252-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="ftw"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery"/><category scheme="http://www.blogger.com/atom/ns#" term="patterns"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><title type='text'>¿Donde quedó la bolita?</title><content type='html'>&lt;p&gt;Una de las cosas &lt;em&gt;chidas&lt;/em&gt; que aprendí de &lt;strong&gt;jQuery&lt;/strong&gt; es la forma en que maneja los argumentos, de forma casi &lt;em&gt;predictiva&lt;/em&gt;. A lo que me refiero es la manera en que permite que los argumentos de la derecha se puedan emplear hacía la izquierda y así sucesivamente.&lt;/p&gt;

&lt;p&gt;jQuery.post( url, [data,] [success(data, textStatus, jqXHR),] [dataType] )&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js&quot;&gt;jQuery.post(&#39;url.php&#39;, { foo: bar }, function(){}, &#39;json&#39;);
jQuery.post(&#39;url.php&#39;, function(){}, &#39;json&#39;);&lt;/pre&gt;

&lt;p&gt;O algo así, la onda es que me late hacer lo mismo con &lt;strong&gt;PHP&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function foo($bar = &#39;&#39;, $candy = 0, $does = array(), $nothing = NULL, $else = FALSE)
{
  if (is_integer($bar))
  {
    $candy = $bar;
    $bar = &#39;&#39;;
  }

  if (is_array($candy))
  {
    $does = $candy;
    $candy = 0;
  }

  if (is_callable($does))
  {
    $nothing = $does;
    $does = array();
  }

  if (is_bool($nothing))
  {
    $else = $nothing;
    $nothing = NULL;
  }
}&lt;/pre&gt;

&lt;p&gt;Aquí la clave está en conocer bien el tipo de argumentos que necesita nuestra función, y en base a ello omitir o redefinir los argumentos. En el ejemplo se hace de forma muy abusiva, confusa y complicada.&lt;/p&gt;

&lt;p&gt;Si una función espera mas de 4 argumentos entonces lo que yo hago es agrupar las opciones mas triviales y restantes en un solo último argumento a modo de arreglo asociativo. Así los primeros tres argumentos -&lt;em&gt;los mas relevantes&lt;/em&gt;- son mas fáciles de comparar &lt;em&gt;predictivamente&lt;/em&gt;, suponiendo que alguno de ellos es igualmente un arreglo asociativo para combinarlo con las últimas opciones.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function request($url, $method = &#39;GET&#39;, array $params = array())
{
  static $defaults = array(
    &#39;url&#39; =&gt; &#39;&#39;,
    &#39;vars&#39; =&gt; array(),
    &#39;method&#39; =&gt; &#39;GET&#39;,
    &#39;headers&#39; =&gt; array(),
    &#39;status&#39; =&gt; 200,
    &#39;timeout&#39; =&gt; 30,
    &#39;callback&#39; =&gt; &#39;print&#39;,
  );


  if (is_array($url))
  {
    $params += $url;
  }


  if (is_array($method))
  {
    $params += $method;
  }


  $params = array_merge($defaults, $params);

  extract($params);
}&lt;/pre&gt;

&lt;blockquote&gt;&lt;p&gt;Aquí hay otro tip: el &lt;em&gt;type-hinting&lt;/em&gt; de php es realmente útil en estos casos, neta. Esto cambia radicalmente nuestra forma de emplear una función, método o como se llame.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Así mismo la idea es trabajar directamente con la variable de opciones, o bien, usar &lt;code class=&quot;prettyprint lang-php&quot;&gt;extract()&lt;/code&gt; para abreviar.&lt;/p&gt;

&lt;p&gt;Yo le llamo patrón de predicción.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/2229172135148732455/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/2229172135148732455' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/2229172135148732455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/2229172135148732455'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/donde-quedo-la-bolita.html' title='¿Donde quedó la bolita?'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-2854397500938128828</id><published>2011-08-07T21:55:00.004-05:00</published><updated>2011-08-07T22:36:51.807-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="cli"/><category scheme="http://www.blogger.com/atom/ns#" term="ftw"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="relax"/><category scheme="http://www.blogger.com/atom/ns#" term="shell"/><title type='text'>Consola carajo</title><content type='html'>&lt;p&gt;No se de donde saque la idea pero creo que sí. Solo que no se si es legal poner una imagen en el post, me da igual. Mejor no pongo la &lt;a rel=&quot;nofollow nocache&quot; href=&quot;https://lh4.googleusercontent.com/-umr6Yi_CgbM/Tj4LMaTcqdI/AAAAAAAAJGI/I3bkukMdG68/w402/geek-war-1.jpeg&quot;&gt;imagen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Bueno, la neta nunca había usado la consola de php.&lt;/p&gt;

&lt;p&gt;Como fanático &lt;em&gt;xubuntero&lt;/em&gt; que soy pues me late usar cualquier terminal de consola, y eventualmente cuando desarrollo ando usándola. Casi siempre.&lt;br/&gt;
Con &lt;strong&gt;PHP&lt;/strong&gt; no me refiero a programar &lt;em&gt;scripts&lt;/em&gt; para la consola, sino usarla para ejecutar código interactivamente.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;A chinga, me dije. He pecado de pe#$&amp;\!.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Pues ya, la primer consola interactiva que emplee fue &lt;kbd&gt;irb&lt;/kbd&gt; de &lt;strong&gt;Ruby&lt;/strong&gt; o alguna de &lt;strong&gt;Javascript&lt;/strong&gt;, no me acuerdo.&lt;/p&gt;

&lt;p&gt;En corto, primero un &lt;kbd&gt;$ php --help | grep shell&lt;/kbd&gt;&lt;/p&gt;
&lt;pre&gt;  -a               Run as interactive shell&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;¡Papas!&lt;/em&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/2854397500938128828/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/2854397500938128828' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/2854397500938128828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/2854397500938128828'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/consola-carajo.html' title='Consola carajo'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-7861444131266892619</id><published>2011-08-06T04:47:00.007-05:00</published><updated>2011-08-06T05:41:58.112-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="oop"/><category scheme="http://www.blogger.com/atom/ns#" term="patterns"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><title type='text'>¿Tengo problemas?</title><content type='html'>&lt;p&gt;Me he estado preguntando últimamente si tengo problemas para programar, que igual tiene que ver con la razón de que estoy loco o algo así.&lt;/p&gt;

&lt;p&gt;No soy tan adicto de la programación orientada a objetos al puro estilo de &lt;strong&gt;JAVA&lt;/strong&gt;, y si comparamos con &lt;strong&gt;Ruby&lt;/strong&gt; o &lt;strong&gt;Javascript&lt;/strong&gt; pues definitivamente no hay comparación. Menos aún con &lt;strong&gt;PHP&lt;/strong&gt;.&lt;br/&gt;
Pero debo confesar  que también pase por la obsesión de programar 100% objetos desde que conocí &lt;strong&gt;CodeIgniter&lt;/strong&gt;, era algo bizarra su implementación &lt;strong&gt;OOP&lt;/strong&gt; aún con &lt;strong&gt;PHP4&lt;/strong&gt;. Desde ahí se me zafaron los tornillos, &lt;em&gt;chale&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Pero igual con el paso del tiempo he ido tomando mis propias decisiones con respecto a determinado patrones, honestamente yo comencé como &lt;em&gt;scripter&lt;/em&gt; empleando funciones y toda la cosa. Es más, antes de leerme un buen libro de Javascript pensaba que &lt;code class=&quot;prettyprint lang-js&quot;&gt;alert()&lt;/code&gt; era una función. Errado he.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;En fin, no se ustedes pero al menos yo si me divierto programando cosas fuera de lo común, como implementar -&lt;em&gt;seudos&lt;/em&gt;- &lt;em&gt;singleton&lt;/em&gt; con funciones, &lt;em&gt;factory&lt;/em&gt;, &lt;em&gt;registry&lt;/em&gt; o incluso &lt;em&gt;prototype&lt;/em&gt; con clases estáticas.&lt;/p&gt;

&lt;h3&gt;Singleton&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function instance($class)
{
  static $set = array();

  if (empty($set[$class]))
  {
    $set[$class] = new $class;
  }

  return $set[$class];
}

// ejemplo

$foo = instance(&#39;stdClass&#39;);
$foo-&gt;bar = &#39;buzz&#39;;

echo instance(&#39;stdClass&#39;)-&gt;bar; // =&amp;gt; buzz&lt;/pre&gt;

&lt;h3&gt;Factory&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function load($class)
{
  return new $class;
}

// ejemplo

$foo = load(&#39;stdClass&#39;);
$foo-&gt;bar = &#39;buzz&#39;;

echo load(&#39;stdClass&#39;)-&gt;bar; // error&lt;/pre&gt;

&lt;h3&gt;Registry&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;function bag()
{
  static $set = NULL;

  if (is_null($set))
  {
    $set = new stdClass;
  }

  return $set;
}

function get($key, $value)
{
  bag()-&gt;$key = $value;
}

function set()
{
  return bag()-&gt;$key;
}

// ejemplo

$obj = new stdClass;
$obj-&gt;bar = &#39;buzz&#39;;

set(&#39;foo&#39;, $obj);

echo get(&#39;foo&#39;)-&gt;bar; // =&amp;gt; buzz

get(&#39;foo&#39;)-&gt;bar = strtoupper($obj-&gt;bar);

echo get(&#39;foo&#39;)-&gt;bar; // =&amp;gt; BUZZ

unset($obj-&gt;bar);

echo get(&#39;foo&#39;)-&gt;bar; // error&lt;/pre&gt;

&lt;h3&gt;Prototype&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;class prototype
{
  private static $stack = array();

  public static function method($name, $callback)
  {
    self::$stack[$name] = $callback;
  }

  public static __callStatic($name, $args)
  {
    return call_user_func_array(self::$stack[$name], $args);
  }
}

// ejemplo

prototype::method(&#39;bye&#39;, function()
{
  echo &#39;Adios pinchi mundo!&#39;;
});

prototype::bye(); // =&amp;gt; Adios pinchi mundo!&lt;/pre&gt;

&lt;p&gt;Me queda claro que puede no ser correcto, pero concluyo que es completamente valido. Además estoy seguro que no todo se puede conseguir sin objetos, de ser necesario uso objetos.&lt;br/&gt;
No soy religioso con respecto a ello.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Et voilà.&lt;/em&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/7861444131266892619/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/7861444131266892619' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/7861444131266892619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/7861444131266892619'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/tengo-problemas.html' title='¿Tengo problemas?'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-1371878159899390345</id><published>2011-08-03T19:44:00.018-05:00</published><updated>2011-08-06T05:00:56.046-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="ftw"/><category scheme="http://www.blogger.com/atom/ns#" term="html"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>Chido One</title><content type='html'>&lt;p&gt;Así fue mi carnal, de una &lt;a href=&quot;http://lmgtfy.com?q=blogger+prettyprint&quot;&gt;búsqueda&lt;/a&gt; que me llevó menos de 5 segundos de mi estúpida vida copie y pegué los códigos necesarios para jalar al &lt;em&gt;blog&lt;/em&gt; el &lt;em&gt;chingón&lt;/em&gt; script que usa &lt;strong&gt;GoogleCode&lt;/strong&gt;, el famoso con ganas google-code-prettify (&lt;em&gt;aka &lt;strong&gt;PrettyPrint&lt;/strong&gt;&lt;/em&gt;).&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;No le pienso dar crédito al primer resultado que me salio hasta ver por mi mismo que funciona y todo, ¿verdad?&lt;/p&gt;
&lt;h3&gt;PHP&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-php&quot;&gt;&amp;lt;?= &#39;Hola pinche mundo!&#39;; ?&amp;gt;&lt;/pre&gt;
&lt;h3&gt;Javascript&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-js&quot;&gt;(function(){
  console.log(&#39;esta es una prueba&#39;);
})();&lt;/pre&gt;
&lt;h3&gt;HTML&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-html&quot;&gt;para &amp;lt;strong&amp;gt;resaltar&amp;lt;/strong&amp;gt; el código&lt;/pre&gt;
&lt;h3&gt;CSS&lt;/h3&gt;
&lt;pre class=&quot;prettyprint lang-css&quot;&gt;/* que mas a menudo */
strong {
  text-shadow: 2px 2px 2px #000;
  content: &quot;utilizo.&quot;;
}&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://lmgtfy.com?q=FTW&quot;&gt;FTW&lt;/a&gt;, ¿no?&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Pues eso era todo, no más queriendo comprobar su efectividad.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/1371878159899390345/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/1371878159899390345' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/1371878159899390345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/1371878159899390345'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/chido-one.html' title='Chido One'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2097478384981689221.post-6308063556811504377</id><published>2011-08-03T18:22:00.010-05:00</published><updated>2011-08-10T11:06:37.983-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chido"/><category scheme="http://www.blogger.com/atom/ns#" term="relax"/><category scheme="http://www.blogger.com/atom/ns#" term="scripter"/><category scheme="http://www.blogger.com/atom/ns#" term="wtf"/><title type='text'>WTF!</title><content type='html'>&lt;p&gt;¿Que que pedo?&lt;br/&gt;
&lt;em&gt;Okey&lt;/em&gt;, esta bien. Soy ese mero, un &lt;em&gt;scripter&lt;/em&gt; común y corriente.
&lt;br/&gt;&lt;br/&gt;
¿De que se trata todo eso?&lt;br/&gt;
Ni puta idea. Pero como me late la &lt;em&gt;programeada&lt;/em&gt; voy a escribir de eso, sin censura.
&lt;br/&gt;&lt;br/&gt;
Wey, ¿y si te atoran?
No pus yo que, la neta &lt;em&gt;chido&lt;/em&gt; el que me entienda, yo solo escribo porque que me &lt;em&gt;pachequea&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Y mientras escribo esto fijo una regla semántica: aquellos términos que mi corrector de idioma en uso marque como mal escritos, dejaré como con énfasis.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Aquí el &lt;em&gt;core&lt;/em&gt;, cosas que vengo escuchando mas a menudo, es &lt;em&gt;scriptear&lt;/em&gt; un rato.&lt;br/&gt;
Si unos lo pueden hacer de forma profesional y casi dogmática, ¿por que no hacerlo al contrario pregunto me yo?&lt;/p&gt;

&lt;p&gt;No más no se fijen de como escribo y parloteo, si se escribir bien, no mas me da hueva.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptales.blogspot.com/feeds/6308063556811504377/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2097478384981689221/6308063556811504377' title='5 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/6308063556811504377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2097478384981689221/posts/default/6308063556811504377'/><link rel='alternate' type='text/html' href='http://scriptales.blogspot.com/2011/08/wtf.html' title='WTF!'/><author><name>Alvaro Cabrera Durán</name><uri>http://www.blogger.com/profile/13514507430432167930</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuMfhmsFvJgFlW-FJaljqw3UW5yg-LRvJ9giPuuLP0ytICkAxJsHP6RIubEI2WqhQ9OAgduHi5AG1qWbfmXh3WaV8B5bTlhmEeegaPPgu7BotB0o_8mgipMViu__VIyo/s220/patteoad.jpg'/></author><thr:total>5</thr:total></entry></feed>