<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es" xml:base="https://componentsprogramming.com/"><title>Components Programming</title><subtitle>Notas sobre programación, algoritmos y las ideas detrás de un mejor software.</subtitle><link rel="self" href="https://componentsprogramming.com/feed-es.xml"/><link rel="alternate" href="https://componentsprogramming.com/inicio/"/><id>https://componentsprogramming.com/feed-es.xml</id><updated>2026-04-05T12:00:00.000Z</updated><author><name>Fernando Pelliccioni</name><uri>https://componentsprogramming.com/</uri></author><entry><title>C++26 está listo: notas desde la reunión de WG21 en Croydon</title><link rel="alternate" href="https://componentsprogramming.com/cpp26-reunion-wg21-croydon/"/><id>https://componentsprogramming.com/cpp26-reunion-wg21-croydon</id><published>2026-04-05T12:00:00.000Z</published><updated>2026-04-05T12:00:00.000Z</updated><content type="html">&lt;figure&gt;
&lt;img src=&quot;https://componentsprogramming.com/images/wg21-2026-croydon.png&quot; alt=&quot;Foto grupal de WG21 en la reunión de Croydon, marzo 2026&quot;&gt;
&lt;figcaption&gt;Crédito de la foto: Herb Sutter&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;El comité ISO C++ cerró C++26 el 28 de marzo en Croydon, UK. Participaron alrededor de 210 personas (130 presenciales, 80 remotas) representando a 24 naciones, resolviendo los últimos 411 comentarios de los organismos nacionales. De acá en adelante el documento va a su votación de aprobación final. No más features, no más adiciones. C++26 está listo.&lt;/p&gt;
&lt;p&gt;Esta fue mi primera reunión presencial de WG21. Soy miembro del comité desde 2022 y antes participé de forma remota, pero vengo siguiendo la evolución del lenguaje desde la era C++0x, cuando “0x” se estaba convirtiendo en un chiste y nadie estaba seguro de que llegaría a publicarse. Estar ahí para el cierre de C++26 se sintió como el momento justo para finalmente aparecer en persona.&lt;/p&gt;
&lt;h2 id=&quot;contracts-aprobados-debatidos-divisivos&quot;&gt;Contracts: aprobados, debatidos, divisivos&lt;/h2&gt;
&lt;p&gt;Contracts entró en C++26. La votación final fue 114 a favor, 12 en contra, 3 abstenciones. Ese nivel de oposición es inusual para una feature en esta etapa, y el debate en la sala fue palpable.&lt;/p&gt;
&lt;p&gt;Mi perspectiva sobre contracts viene de Eiffel y su filosofía de Design by Contract. En ese modelo, los contratos son parte de la semántica del programa. Una violación de precondición significa que el llamador tiene un bug. Una violación de postcondición significa que el implementador tiene un bug. La responsabilidad es inequívoca, y las violaciones son siempre bugs, nunca situaciones de runtime que deban manejarse con flexibilidad.&lt;/p&gt;
&lt;p&gt;C++ tomó un camino más configurable. Eso no es necesariamente malo; C++ siempre fue un lenguaje de opciones. Pero la flexibilidad adicional tiene un costo visible en simplicidad conceptual. La distancia entre lo que C++ llama “contracts” y la filosofía original de Design by Contract es mayor de lo que esperaba.&lt;/p&gt;
&lt;h2 id=&quot;reflection-lo-grande-de-verdad&quot;&gt;Reflection: lo grande de verdad&lt;/h2&gt;
&lt;p&gt;Si contracts fue la feature más debatida, reflection fue la más transformadora.&lt;/p&gt;
&lt;p&gt;Reflection en C++26 permite introspección en tiempo de compilación de tipos, miembros y estructura del programa, cosas que antes requerían herramientas externas o metaprogramación pesada con templates. GCC ya tiene una implementación mergeada en trunk.&lt;/p&gt;
&lt;p&gt;Esto cambia lo que es posible dentro del lenguaje. No incrementalmente, sino categóricamente. La forma en que escribimos bibliotecas, generamos código y expresamos abstracciones va a ser diferente. Creo que vamos a estar descubriendo nuevos patrones alrededor de reflection por mucho tiempo.&lt;/p&gt;
&lt;h2 id=&quot;la-sesión-vespertina-que-cambió-mi-rumbo&quot;&gt;La sesión vespertina que cambió mi rumbo&lt;/h2&gt;
&lt;p&gt;Una sesión vespertina trató sobre un problema estructural que viene creciendo hace años: hay muchas más propuestas (papers) que capacidad de implementación. Los equipos de compiladores en Clang, GCC y MSVC están al límite. El cuello de botella ya no es el diseño. Es la implementación. Las features se aprueban en papel y después tardan años en ser usables.&lt;/p&gt;
&lt;p&gt;Surgieron varias ideas: que los autores de papers traigan al menos implementaciones parciales, que las propuestas se prueben contra la realidad antes de avanzar, e incluso que herramientas asistidas por IA podrían ayudar a bajar la barrera. Esto último generó una reacción visible en la sala: murmullos, gente hablando fuera de turno, frustración. Fue un momento breve, pero revelador.&lt;/p&gt;
&lt;p&gt;Lo que me quedó fue el mensaje central de los implementadores. Al día siguiente, empecé a contribuir tanto a Clang como a GCC, a nivel de biblioteca y de compilador. No por un gran plan, sino porque el mensaje caló: si te importa que el lenguaje avance, ayudá a construirlo.&lt;/p&gt;
&lt;h2 id=&quot;estar-ahí&quot;&gt;Estar ahí&lt;/h2&gt;
&lt;p&gt;Hay algo en estar en la sala que la participación remota no puede replicar. Las conversaciones de pasillo, el lenguaje corporal durante los debates, la energía cuando cae una votación reñida.&lt;/p&gt;
&lt;p&gt;C++ sigue volviéndose más poderoso, y el costo de mantenerse al día es real. Pero la comunidad detrás del lenguaje está profundamente comprometida con hacerlo bien, y eso fue evidente en Croydon.&lt;/p&gt;
&lt;p&gt;Me alegra haber estado ahí para esta.&lt;/p&gt;
</content></entry><entry><title>¡Gracias nuevamente, Alex!</title><link rel="alternate" href="https://componentsprogramming.com/gracias-alex-nuevamente/"/><id>https://componentsprogramming.com/gracias-alex-nuevamente</id><published>2020-02-20T12:00:00.000Z</published><updated>2020-02-20T12:00:00.000Z</updated><content type="html">&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/FormularioMathematico.jpeg&quot; alt=&quot;FormularioMathematico&quot;&gt;&lt;/p&gt;
&lt;p&gt;Una vez más, me gustaría agradecerle a mis amigos Alex Stepanov y Paul McJones por este hermoso regalo.&lt;/p&gt;
&lt;p&gt;He estado buscando este libro por años. Es un libro muy difícil de conseguir.&lt;/p&gt;
&lt;p&gt;No tengo palabras para agradecerles.&lt;/p&gt;
&lt;p&gt;Simplemente, ¡gracias!&lt;/p&gt;
</content></entry><entry><title>Algoritmos y especificaciones</title><link rel="alternate" href="https://componentsprogramming.com/algoritmos-especificaciones/"/><id>https://componentsprogramming.com/algoritmos-especificaciones</id><published>2020-02-19T12:00:00.000Z</published><updated>2020-02-19T12:00:00.000Z</updated><content type="html">&lt;p&gt;En este artículo quiero hablar sobre 2 temas en los que creo que la mayoría de los programadores solemos fallar: Algoritmos y Especificaciones.&lt;/p&gt;
&lt;p&gt;Me voy a ayudar de una experiencia real, ocurrida ya hace un tiempo:&lt;/p&gt;
&lt;p&gt;Desde hace ya 4 años mantengo un nodo multimoneda (Bitcoin, Bitcoin Cash y Litecoin) llamado &lt;a href=&quot;https://github.com/k-nuth/kth&quot;&gt;Knuth&lt;/a&gt; (a.k.a. Bitprim).
En noviembre de 2017 &lt;a href=&quot;http://bitcoincashnode.org/&quot;&gt;Bitcoin Cash&lt;/a&gt; hizo su primer cambio de protocolo luego de su nacimiento en agosto del mismo año. Mi trabajo en ese momento era actualizar el código de nuestro nodo para que soporte los cambios de protocolo. Desde aquel momento que quiero escribir este artículo, pero… por alguna o varias razones no lo hice en ese momento, lo estoy haciendo ahora.&lt;/p&gt;
&lt;p&gt;El cambio más importante de fue en el &lt;em&gt;Algoritmo de Ajuste de Dificultad&lt;/em&gt;, en adelante &lt;em&gt;DAA&lt;/em&gt; (del inglés &lt;em&gt;Difficulty Adjustment Algorithm&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/nov-13-hardfork-spec.md#difficulty-adjustment-algorithm-description&quot;&gt;Aquí la descripción del algoritmo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;No quiero entrar en detalles acerca del concepto de &lt;em&gt;dificultad&lt;/em&gt; ni del DAA. Para ello puede referirse a: &lt;a href=&quot;https://en.bitcoin.it/wiki/Difficulty&quot;&gt;Difficulty&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Lo que me interesa son los puntos 2 y 3 de la descripción del DAA:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2.&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; Let B_last be chosen[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] from [B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, B_n].&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;3.&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; Let B_first be chosen[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] from [B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;145&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;144&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;].&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ambos apuntan a la nota al pie &lt;code&gt;[2]&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2.&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; A block is chosen via the following mechanism:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;Given a list: S &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, B_n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt;B_n&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;a. If timestamp(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]) greater than timestamp(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]) then swap S[0] and S[2].&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;b. If timestamp(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]) greater than timestamp(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]) then swap S[0] and S[1].&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;c. If timestamp(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]) greater than timestamp(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]) then swap S[1] and S[2].&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;d. Return S[1].&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;See GetSuitableBlock&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;La especificación del algoritmo apunta a su implementación, en una función llamada &lt;a href=&quot;https://github.com/Bitcoin-ABC/bitcoin-abc/commit/be51cf295c239ff6395a0aa67a3e13906aca9cb2#diff-ba91592f703a9d0badf94e67144bc0aaR208&quot;&gt;GetSuitableBlock&lt;/a&gt;. Aquí su código:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt; * To reduce the impact of timestamp manipulation, we select the block we are&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt; * basing our computation on via a median of 3.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;GetSuitableBlock&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt;pindex&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    assert&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(pindex-&amp;gt;nHeight &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    * In order to avoid a block is a very skewed timestamp to have too much&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    * influence, we select the median of the 3 top most blocks as a starting&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    * point.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; pindex;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; pindex-&amp;gt;pprev;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;pprev;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    // Sorting network.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;nTime &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;nTime) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;], blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;nTime &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;nTime) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;], blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;nTime &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]-&amp;gt;nTime) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;], blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;     // We should have our candidate in the middle now.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; blocks[&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lo que hace el algoritmo es básicamente crear una secuencia de 3 elementos (array), la ordena de menor a mayor y retorna el segundo elemento.&lt;/p&gt;
&lt;p&gt;La complejidad en tiempo de este algoritmo es:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Caso mejor:    0 swaps,   3 comparaciones&lt;/li&gt;
&lt;li&gt;Caso peor:     2 swaps,   3 comparaciones&lt;/li&gt;
&lt;li&gt;Caso promedio: 7/6 swaps, 3 comparaciones; asumiendo una distribución uniforme de los datos de entrada.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ahora, vuelva a observar con detenimiento el algoritmo. Se está creando un array (usando los datos de entrada), para luego ordenarlo ascendentemente y retornar el elemento del medio. Este es un algoritmo conocido y se llama &lt;a href=&quot;https://en.wikipedia.org/wiki/Median&quot;&gt;mediana&lt;/a&gt;, en particular, &lt;em&gt;mediana de 3 elementos&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;La mediana es un algoritmo de &lt;em&gt;selección&lt;/em&gt;. A diferencia de los algoritmos de ordenamiento (inplace), los algoritmos de selección no deberían mutar los datos de entrada, sino, retornar uno de ellos.&lt;/p&gt;
&lt;p&gt;Aquí les dejo un boceto del algoritmo &lt;em&gt;mediana de 3&lt;/em&gt;, en &lt;code&gt;C++&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;TotallyOrdered&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; max&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;TotallyOrdered&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3_ab&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    // precondition: a &amp;lt;= b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (c &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;        // a, b, c are sorted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;                       max&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(a, c);&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt; // b is not the median&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;TotallyOrdered&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3_ab&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(b, a, c)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;                 :&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3_ab&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(a, b, c);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;O si prefiere la versión &lt;em&gt;inline&lt;/em&gt; del algoritmo:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;TotallyOrdered&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (b &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (c &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a;&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;  // b, a, c are sorted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; max&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(b, c);&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;      // a is not the median&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    // a &amp;lt;= b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (c &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b;&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;  // a, b, c are sorted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; max&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(a, c);&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;      // b is not the median&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Dejo el análisis del código para el lector, para el vago: lo que hace el algoritmo es simplemente seleccionar el elemento del medio entre &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt; y &lt;code&gt;c&lt;/code&gt;, haciendo de cuenta que los 3 estuviesen ordenados ascendentemente. Esto lo hace sin mutar ni reordenar los datos de entrada.&lt;/p&gt;
&lt;p&gt;La complejidad en tiempo de &lt;code&gt;median_3&lt;/code&gt; es:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Caso mejor:    0 swaps, 2 comparaciones&lt;/li&gt;
&lt;li&gt;Caso peor:     0 swaps, 3 comparaciones&lt;/li&gt;
&lt;li&gt;Caso promedio: 0 swaps, 8/3 comparaciones; asumiendo una distribución uniforme de los datos de entrada.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ahora, podríamos usar nuestro nuevo algoritmo en la función &lt;code&gt;GetSuitableBlock&lt;/code&gt; original:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;static&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;CBlockIndex &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;const*&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; GetSuitableBlockNewVersion&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(CBlockIndex &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;const*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; pindex) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    assert&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(pindex-&amp;gt;nHeight &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;median_3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;pindex-&amp;gt;pprev-&amp;gt;pprev, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;pindex-&amp;gt;pprev, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;pindex);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mucho más breve y entendible, ¿no?.&lt;/p&gt;
&lt;p&gt;Antes de seguir, tenemos que corregir un problema: no sabemos si el &lt;em&gt;Ordenamiento Natural&lt;/em&gt; especificado en la clase &lt;code&gt;CBlockIndex&lt;/code&gt; está dado por el timestamp del bloque (atributo &lt;code&gt;nTime&lt;/code&gt;).
Necesitamos una versión de &lt;code&gt;median_3&lt;/code&gt; que acepte una forma de comparar especificado por el usuario: necesitamos que acepte una &lt;em&gt;relación de preorden total estricta&lt;/em&gt; (&lt;em&gt;strict weak ordering relation&lt;/em&gt;, &lt;a href=&quot;https://componentsprogramming.com/writing-min-function-part3/&quot;&gt;para más información consulte aquí&lt;/a&gt;).&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;Regular&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;StrictWeakOrdering&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; R&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; max&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;R&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(b, a) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;Regular&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;StrictWeakOrdering&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; R&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3_ab&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;R&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    // precondition: a &amp;lt;= b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(c, b) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;           // a, b, c are sorted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;                       max&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(a, c, r);&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt; // b is not the median&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;Regular&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;StrictWeakOrdering&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; R&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;R&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(b, a) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3_ab&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(b, a, c, r)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;                   :&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; median_3_ab&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(a, b, c, r);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ahora sí, podemos implementar correctamente &lt;code&gt;GetSuitableBlockNewVersion&lt;/code&gt;, comparando por &lt;code&gt;nTime&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;static&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;CBlockIndex &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;const*&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; GetSuitableBlockNewVersion&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(CBlockIndex &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;const*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; pindex) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    assert&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(pindex-&amp;gt;nHeight &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;median_3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;pindex-&amp;gt;pprev-&amp;gt;pprev, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;pindex-&amp;gt;pprev, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;pindex, [](&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; const&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#E36209;--shiki-dark:#FFAB70&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; a.nTime &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; b.nTime;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nos queda un último problema por resolver. Hagamos una pequeña prueba del algoritmo original y del nuevo:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    size_t&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; nHeight;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    size_t&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; nTime;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; pprev;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; ba {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558731500&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;nullptr&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; bb {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558731500&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;ba};&lt;/span&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;        //same nTime as previous&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;    CBlockIndex&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; bc {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558730000&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;bb};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    auto&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; GetSuitableBlockNewVersion&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;bc);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    cout &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#032F62;--shiki-dark:#9ECBFF&quot;&gt; &quot;GetSuitableBlockNewVersion: &quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; r-&amp;gt;nHeight &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; endl;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    r &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; GetSuitableBlock&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;bc);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    cout &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#032F62;--shiki-dark:#9ECBFF&quot;&gt; &quot;GetSuitableBlock:           &quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; r-&amp;gt;nHeight &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; endl;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;El código anterior imprime:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;GetSuitableBlockNewVersion: &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;GetSuitableBlock:           &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lo que estamos intentando probar con el código anterior es la &lt;em&gt;estabilidad&lt;/em&gt; de ambos algoritmos.
Nuestro algoritmo &lt;em&gt;median_3&lt;/em&gt; es &lt;em&gt;estable&lt;/em&gt; lo que quiere decir que el orden de los elementos equivalentes se preserva
(&lt;a href=&quot;https://componentsprogramming.com/writing-min-function-part5/&quot;&gt;para más información consulte aquí&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Para demostrarlo con datos, vamos a utilizar el ejemplo anterior, en el cual tenemos los siguientes datos de entrada para nuestros algoritmos:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;s &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [{&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558731500&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}, {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558731500&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}, {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558730000&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Donde el primer elemento de cada par es el identificador del bloque &lt;code&gt;nHeight&lt;/code&gt; y el segundo elemento es el timestamp &lt;code&gt;nTime&lt;/code&gt;.
Note que el &lt;code&gt;nTime&lt;/code&gt; de los primeros 2 elementos es igual.&lt;/p&gt;
&lt;p&gt;Si ordenamos la secuencia anterior por &lt;code&gt;nTime&lt;/code&gt; usando un algoritmo de ordenamiento estable, como por ejemplo &lt;a href=&quot;https://en.wikipedia.org/wiki/Merge_sort&quot;&gt;Merge sort&lt;/a&gt; nos quedaría algo así:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;s &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [{&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558730000&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}, {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558731500&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}, {&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1558731500&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note que el elemento del medio es el que tiene &lt;code&gt;nHeight = 1&lt;/code&gt;. Lo cual indica que nuestro algoritmo se comportó de manera estable pero no así el algoritmo original usado en el DAA de Bitcoin Cash.&lt;/p&gt;
&lt;p&gt;En mi primera implementación de DAA en el nodo Bitprim usé un código similar a &lt;code&gt;median_3&lt;/code&gt; el cual también era estable, dado que no había verificado el código de la especificación, yo había asumido erróneamente que también era estable.
Luego esto provocó errores en tiempo de ejecución de nuestro nodo ante un ajuste de dificultad. No se daba siempre, pero hubo un caso en particular en el que lo pudimos detectar. Luego de varias horas de debugging pude detectar que el problema era que el algoritmo usado por mí no era compatible con el “especificado” en DAA.&lt;/p&gt;
&lt;p&gt;Por lo tanto, tuve que “corregir” mi algoritmo para hacerlo no-estable de la misma forma que el de la especificación.&lt;/p&gt;
&lt;p&gt;En realidad, si mal no recuerdo, en la primera versión de la especificación de DAA no se mencionaba al código de &lt;code&gt;GetSuitableBlock&lt;/code&gt;, sino que decía que se calculaba la mediana de 3 elementos. Como la implementación de la mediana fue “incorrecta” tuvieron que adaptar la especificación para que se condiga con el código.
Tenga en cuenta, que una vez que el código de un nodo Bitcoin o de cualquier criptomoneda está en funcionamiento, una modificación en su comportamiento introduce incompatibilidades con versiones anteriores y produce los denominados &lt;em&gt;forks&lt;/em&gt;. Por lo que una vez que el código está corriendo, se trata de no cambiarlo. Por esta razón es por la que se tuvo que adaptar la especificación en vez de corregir el código.&lt;/p&gt;
&lt;p&gt;Antes de terminar, hagamos una comparación de ambos algoritmos, &lt;code&gt;GetSuitableBlock&lt;/code&gt; vs. &lt;code&gt;median_3&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;median_3&lt;/code&gt; no efectúa ningún swap, &lt;code&gt;GetSuitableBlock&lt;/code&gt; puede efectuar entre 0, 7/6 o 2 swaps, innecesariamente. (Eficiencia)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GetSuitableBlock&lt;/code&gt; crea un array innecesariamente. (Eficiencia)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;median_3&lt;/code&gt; realiza 2, 8/3 o 3 comparaciones, &lt;code&gt;GetSuitableBlock&lt;/code&gt; realiza siempre 3 comparaciones. (Eficiencia)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;median_3&lt;/code&gt; es estable, &lt;code&gt;GetSuitableBlock&lt;/code&gt; no lo es. &lt;code&gt;median_3&lt;/code&gt; es lo que cualquiera espera de un algoritmo que calcule la mediana de 3 elementos. (Correctitud)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Y ahora sí, para finalizar, algunas conclusiones:&lt;/p&gt;
&lt;p&gt;El autor de la especificación de DAA podría haber optado por usar un algoritmo conocido y “estándar”, pero no lo hizo.
Es más, quizás lo peor de todo esto es que la especificación hace referencia al código. &lt;strong&gt;El código no debe ser nunca especificación. El código debe ser creado a partir de una especificación.&lt;/strong&gt; Por lo que si una especificación hace referencia a código, no existe dicha especificación.&lt;/p&gt;
&lt;p&gt;¡Saludos!&lt;/p&gt;
&lt;hr&gt;
</content></entry><entry><title>Edición de Autores de Elements of Programming (free ebook)</title><link rel="alternate" href="https://componentsprogramming.com/elements-of-programming-edition-autores/"/><id>https://componentsprogramming.com/elements-of-programming-edition-autores</id><published>2019-06-28T12:00:00.000Z</published><updated>2019-06-28T12:00:00.000Z</updated><content type="html">&lt;p&gt;¡Último momento! ;P&lt;/p&gt;
&lt;p&gt;Este año Elements of Programming cumple 10 años desde su publicación, pero esta vez el regalo es para nosotros:&lt;/p&gt;
&lt;p&gt;Alex Stepanov y Paul McJones acaban de publicar la Edición de Autores de Elements of Programming y viene en dos versiones:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;PDF gratuito, &lt;a href=&quot;http://elementsofprogramming.com/&quot;&gt;hacé click acá para descargarlo&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Libro de bolsillo de la editorial Semigroup Press, por sólo USD 9,94; &lt;a href=&quot;http://www.lulu.com/shop/alexander-stepanov-and-paul-mcjones/elements-of-programming/paperback/product-24142479.html&quot;&gt;hacé clic acá para comprarlo&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Próximamente disponible en Amazon.&lt;/p&gt;
&lt;p&gt;¡Gracias de nuevo!, Alex y Paul.&lt;/p&gt;
</content></entry><entry><title>Mi charla: &apos;El regalo de los árabes&apos;</title><link rel="alternate" href="https://componentsprogramming.com/charla-regalo-arabes/"/><id>https://componentsprogramming.com/charla-regalo-arabes</id><published>2018-11-26T12:00:00.000Z</published><updated>2018-11-26T12:00:00.000Z</updated><content type="html">&lt;p&gt;¡Hola!&lt;/p&gt;
&lt;p&gt;Les comparto los enlaces al video y filminas de mi charla titulada &lt;em&gt;El regalo de los árabes&lt;/em&gt;, la cual que fue presentada en el meetup &lt;em&gt;Algorithms Study Group&lt;/em&gt; en mayo de 2017 en la ciudad de Buenos Aires.&lt;/p&gt;
&lt;p&gt;El contenido de mi charla está basado en &lt;a href=&quot;http://stepanovpapers.com/Journeys/Journeys-0.3.pdf&quot;&gt;Three Algorithmic Journeys&lt;/a&gt; y &lt;a href=&quot;https://www.amazon.es/Mathematics-Generic-Programming-Alexander-Stepanov/dp/0321942043&quot;&gt;From Mathematics to Generic Programming&lt;/a&gt; de &lt;a href=&quot;https://en.wikipedia.org/wiki/Alexander_Stepanov&quot;&gt;Alex Stepanov&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Es mi interpretación de lo que hubiera sido su cuarto episodio, que nunca fue presentado, y hubiera tenido el mismo nombre.&lt;/p&gt;
&lt;p&gt;¡Espero que les guste!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=ZgC6MDh7zJc&quot;&gt;Enlace a Video&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://componentsprogramming.com/images/fpelliccioni-ElRegaloDeLosArabes.pdf&quot;&gt;Enlace a Filmina&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;¡Saludos!&lt;/p&gt;
</content></entry><entry><title>Mención de Honor &apos;Senador Domingo Faustino Sarmiento&apos;</title><link rel="alternate" href="https://componentsprogramming.com/mencion-sarmiento/"/><id>https://componentsprogramming.com/mencion-sarmiento</id><published>2016-11-30T12:00:00.000Z</published><updated>2016-11-30T12:00:00.000Z</updated><content type="html">&lt;p&gt;El día 29 de noviembre de 2016 tuve el honor y agrado de recibir, como miembro del equipo científico de la &lt;a href=&quot;http://www.plataformaargentina.gov.ar/&quot;&gt;Comisión Nacional del Límite Exterior de la Plataforma Continental (COPLA)&lt;/a&gt;, la &lt;strong&gt;Mención de Honor “Senador Domingo Faustino Sarmiento”&lt;/strong&gt;, por nuestra labor, que posibilitó la determinación del nuevo &lt;em&gt;Límite Exterior de la Plataforma Continental de la República Argentina&lt;/em&gt;. &lt;a href=&quot;#Ref1&quot;&gt;[1]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;La distinción fue entregada por la vice presidente de la Nación, la Lic. &lt;a href=&quot;https://twitter.com/gabimichetti&quot;&gt;Gabriela Michetti&lt;/a&gt;, junto al senador &lt;a href=&quot;https://twitter.com/omarperotti&quot;&gt;Omar Perotti&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/copla/sarmiento1.jpg&quot; alt=&quot;Sarmiento1&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/copla/sarmiento2.png&quot; alt=&quot;Sarmiento2&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/copla/sarmiento3.jpg&quot; alt=&quot;Sarmiento3&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;blockquote&gt;
&lt;p&gt;La Mención de Honor “Senador Domingo Faustino Sarmiento” constituye el máximo galardón que entrega el Honorable Senado de la Nación a personas físicas o jurídicas del quehacer cultural, deportivo, profesional y académico, por su &lt;strong&gt;obra emprendedora destinada a mejorar la calidad de vida de sus semejantes&lt;/strong&gt;, de las instituciones y de sus comunidades.
El acto de entrega de la distinción fue realizado en el Salón Azul del Honorable Senado de la Nación.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;p&gt;Del evento también partiparon el vice canciller y presidente de &lt;a href=&quot;http://www.plataformaargentina.gov.ar/&quot;&gt;COPLA&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/cmforadori&quot;&gt;Carlos Foradori&lt;/a&gt;, el ex canciller &lt;a href=&quot;https://twitter.com/JorgeTaiana&quot;&gt;Jorge Taiana&lt;/a&gt;, el ex vice canciller Fernando Petrella, los senadores Mario Pais, Dalmacio Mera, Norma Durango, Beatriz Mirkin, y la diputada Daniela Castro. Además participaron destacadas figuras del ámbito académico y científico.&lt;/p&gt;
&lt;p&gt;La canciller &lt;a href=&quot;https://twitter.com/SusanaMalcorra&quot;&gt;Susana Malcorra&lt;/a&gt; no pudo estar presente ya que ha viajado a Cuba para los funerales de Fidel Castro en representación de la Argentina.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;referencias&quot;&gt;Referencias&lt;/h3&gt;
&lt;p&gt;&lt;a name=&quot;Ref1&quot;&gt;[1]&lt;/a&gt; El Límite fue aprobado el 11 marzo de 2016 por las &lt;a href=&quot;http://www.un.org/es/index.html&quot;&gt;Naciones Unidas&lt;/a&gt;, por consenso, es decir sin un solo voto en contra. Ver: &lt;a href=&quot;https://componentsprogramming.com/limite-aprobado/&quot;&gt;Límite Exterior de la Plataforma Continental&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;enlaces-a-noticias&quot;&gt;Enlaces a Noticias&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/SenadoArgentina/status/803687588653572096&quot;&gt;https://twitter.com/SenadoArgentina/status/803687588653572096&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/CancilleriaARG/status/803711684993024006&quot;&gt;https://twitter.com/CancilleriaARG/status/803711684993024006&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/gabimichetti/status/803697167063912448&quot;&gt;https://twitter.com/gabimichetti/status/803697167063912448&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/omarperotti/status/803723193844371456&quot;&gt;https://twitter.com/omarperotti/status/803723193844371456&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://omarperotti.com.ar/el-senado-distinguio-a-los-cientificos-que-trabajaron-en-el-nuevo-limite-de-la-plataforma-continental/&quot;&gt;http://omarperotti.com.ar/el-senado-distinguio-a-los-cientificos-que-trabajaron-en-el-nuevo-limite-de-la-plataforma-continental/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.senado.gov.ar/prensa/14718/noticias&quot;&gt;http://www.senado.gov.ar/prensa/14718/noticias&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.mrecic.gov.ar/copla-recibio-la-maxima-distincion-del-senado&quot;&gt;https://www.mrecic.gov.ar/copla-recibio-la-maxima-distincion-del-senado&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
</content></entry><entry><title>Mi charla: &apos;¿Fastware?&apos;</title><link rel="alternate" href="https://componentsprogramming.com/charla-fastware/"/><id>https://componentsprogramming.com/charla-fastware</id><published>2016-11-16T12:00:00.000Z</published><updated>2016-11-16T12:00:00.000Z</updated><content type="html">&lt;p&gt;¡Buenas!&lt;/p&gt;
&lt;p&gt;Les comparto el enlace a las &lt;em&gt;filminas&lt;/em&gt; de mi charla denominada &lt;a href=&quot;http://es.slideshare.net/FernandoPelliccioni/fastware-64059921&quot;&gt;“¿Fastware?”&lt;/a&gt; que fue expuesta en el &lt;a href=&quot;https://www.meetup.com/cpp-ba/events/232269015/&quot;&gt;“Segundo Encuentro de programadores C++ de Buenos Aires”&lt;/a&gt; el día 14 de Julio de 2016.&lt;/p&gt;
&lt;p&gt;En ese encuentro también tuvimos el agrado de presenciar la excelentes charlas brindadas por nuestros colegas: &lt;a href=&quot;http://talesofcpp.fusionfenix.com/&quot;&gt;Agustín (K-Ballo) Bergé&lt;/a&gt;, Francisco Tufró y Hernan Saez. &lt;a href=&quot;https://www.meetup.com/cpp-ba/pages/20784343/Presentaciones/&quot;&gt;Los links de las demás presentacines aquí.&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Espero que les gusten nuestras presentaciones y les de ganas de sumarse a &lt;a href=&quot;https://www.meetup.com/cpp-ba/&quot;&gt;nuestra comunidad&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;¡Saludos!&lt;/p&gt;
</content></entry><entry><title>Palíndromos y algo más</title><link rel="alternate" href="https://componentsprogramming.com/palindromos/"/><id>https://componentsprogramming.com/palindromos</id><published>2016-06-06T12:00:00.000Z</published><updated>2016-06-06T12:00:00.000Z</updated><content type="html">&lt;p&gt;Decidí escribir este artículo a partir de una pregunta que vi en &lt;a href=&quot;http://stackoverflow.com&quot;&gt;Stackoverflow&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://stackoverflow.com/questions/4138827/check-string-for-palindrome&quot;&gt;Aquí&lt;/a&gt; el enlace a la pregunta.&lt;/p&gt;
&lt;p&gt;El autor de la pregunta intenta escribir un algoritmo que identifique si una “palabra” es un &lt;a href=&quot;https://es.wikipedia.org/wiki/Pal%C3%ADndromo&quot;&gt;palíndromo&lt;/a&gt; o no lo es.
El algoritmo está escrito usando el &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_(programming_language)&quot;&gt;lenguaje de programación Java&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;No me interesa analizar el algoritmo propuesto por el autor, sino que me interesa analizar el algoritmo propuesto en la respuesta más votada. Este último tiene 73 votos contra 65 votos que tiene la respuesta aceptada (a día de la fecha, 6 de Junio de 2016).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://stackoverflow.com/a/4139065/1006264&quot;&gt;Aquí&lt;/a&gt; el enlace a la respuesta que me interesa.&lt;/p&gt;
&lt;p&gt;Acá el código:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; isPalindrome&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(String str) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;       new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; StringBuilder&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(str)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;       .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;reverse&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;       .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;El algoritmo funciona correctamente y la lógica es muy intuitiva. Básicamente compara por &lt;em&gt;igualdad&lt;/em&gt; la palabra original contra el reverso de la palabra.&lt;/p&gt;
&lt;p&gt;El problema con este algoritmo es que es muy ineficiente comparado con el algoritmo óptimo.&lt;/p&gt;
&lt;p&gt;Hice un comentario al autor de esta respuesta en Stackoverflow: “Compare the complexity of your algorithm with respect to others.”&lt;br&gt;
El usuario &lt;a href=&quot;http://stackoverflow.com/users/276052/aioobe&quot;&gt;@aioobe&lt;/a&gt; me respondió: “I think it’s the same complexity as the other solutions, no?”&lt;/p&gt;
&lt;p&gt;En parte tiene razón.
No fui muy específico en mi comentario. Seguramente @aioobe asumió que yo me refería a la &lt;a href=&quot;https://en.wikipedia.org/wiki/Asymptotic_computational_complexity&quot;&gt;complejidad computacional asintótica&lt;/a&gt; y está bien que lo haya asumido de esa forma, ya que usualmente cuando decimos “complejidad” sin especificar nada más, se asume que nos estamos refiriendo a la &lt;em&gt;complejidad computacional asintótica&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;complejidad-computacional-asintótica&quot;&gt;Complejidad Computacional Asintótica&lt;/h3&gt;
&lt;p&gt;Con &lt;em&gt;complejidad computacional asintótica&lt;/em&gt; nos referimos a cómo responden los algoritmos en tiempo/espacio a medida que el input crece.&lt;br&gt;
Usualmente está asociada a la &lt;a href=&quot;https://en.wikipedia.org/wiki/Big_O_notation&quot;&gt;O-notation&lt;/a&gt; introducida por &lt;a href=&quot;https://en.wikipedia.org/wiki/Paul_Gustav_Heinrich_Bachmann&quot;&gt;Paul Bachmann&lt;/a&gt; en su libro &lt;a href=&quot;https://archive.org/details/dieanalytischeza00bachuoft&quot;&gt;Die Analytische Zahlentheorie&lt;/a&gt; en 1894. &lt;a href=&quot;#Ref1&quot;&gt;[1]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;De esta forma podemos medir la escalabilidad de los algoritmos sin depender de la arquitectura de la máquina, de la velocidad del procesador, del lenguaje en el que está implementado el algoritmo, etc…&lt;/p&gt;
&lt;p&gt;Si bien es muy útil en muchas circunstancias, el problema de esta forma de medición es que no es exacta, sino que es &lt;strong&gt;aproximada&lt;/strong&gt;.\&lt;/p&gt;
&lt;p&gt;No quiero aquí extenderme en más detalles sobre &lt;em&gt;O-notation&lt;/em&gt; ni complejidad asintótica, para información referirse a &lt;a href=&quot;#Ref2&quot;&gt;[2]&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;complejidad-computacional-concreta&quot;&gt;Complejidad Computacional Concreta&lt;/h3&gt;
&lt;p&gt;Otra forma de medir algoritmos es no usar aproximaciones sino cantidades concretas de operaciones, dependiendo de la entrada al algoritmo.&lt;/p&gt;
&lt;p&gt;Por ejemplo, supongamos el algoritmo para encontrar el mínimo (o máximo) de \( n \) elementos. Podemos decir que dicho algoritmo tiene una complejidad (en tiempo) de \( O(n) \) o &lt;em&gt;lineal&lt;/em&gt;.
Pero específicamente se necesitan \( n - 1 \) comparaciones.&lt;/p&gt;
&lt;h3 id=&quot;volviendo-a-los-palíndromos&quot;&gt;Volviendo a los Palíndromos&lt;/h3&gt;
&lt;p&gt;Repito el código que queremos analizar:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; isPalindrome&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(String str) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;       new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; StringBuilder&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(str)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;       .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;reverse&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;       .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Al código anterior lo vamos a denominar &lt;em&gt;Algoritmo I&lt;/em&gt; (“I” de ineficiente).&lt;/p&gt;
&lt;p&gt;Podríamos decir que &lt;em&gt;Algoritmo I&lt;/em&gt; es \( O(n) \), pero, ¿Cómo podemos asegurarlo sin conocer la complejidad de los componentes en los que el algoritmo está basado?&lt;/p&gt;
&lt;p&gt;Para ello, debemos revisar la documentación provista por Java. Por ejemplo, veamos la función &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-&quot;&gt;String.equals()&lt;/a&gt;. &lt;a href=&quot;#Ref3&quot;&gt;[3]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Como habrán notado en la página anterior, la documentación de Java no incluye la complejidad en tiempo ni espacio de sus algoritmos y estructuras de datos.&lt;br&gt;
Considero esto una gran falta ya que nos dificulta la especificación de la complejidad de nuestros algoritmos, al menos de los algoritmos que están basados en clases provistas por Java.&lt;/p&gt;
&lt;p&gt;Para continuar tratando de especificar la complejidad del &lt;em&gt;Algoritmo I&lt;/em&gt;, no nos queda otra que revisar directamente el código fuente de las clases Java.&lt;br&gt;
Veamos el &lt;a href=&quot;http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/String.java&quot;&gt;código fuente de String.equals()&lt;/a&gt; (presione sobre el link y busque la función equals).&lt;/p&gt;
&lt;p&gt;Como ustedes pueden verificar, el código de String.equals() tiene complejidad lineal en tiempo, \( O(n) \).&lt;br&gt;
Específicamente se realizan \( n \) comparaciones por &lt;em&gt;desigualdad&lt;/em&gt;. (Más allá de todo el ruido impuesto por Java, como los casts, instanceof, etc…).&lt;/p&gt;
&lt;p&gt;La complejidad en espacio de String.equals() es constante, o sea, \( O(1) \).&lt;br&gt;
Esto quiere decir que se utiliza una cantidad de memoria constante más allá del input del algoritmo.&lt;/p&gt;
&lt;h3 id=&quot;determinando-la-complejidad&quot;&gt;Determinando la complejidad&lt;/h3&gt;
&lt;p&gt;Vamos a determinar la complejidad del &lt;em&gt;Algoritmo I&lt;/em&gt;, analizando uno a uno sus componentes.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-&quot;&gt;String.equals()&lt;/a&gt;. Tiempo lineal,  \( n \)  &lt;em&gt;comparaciones por desigualdad&lt;/em&gt;. Espacio constante.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/AbstractStringBuilder.java&quot;&gt;StringBuilder.reverse()&lt;/a&gt;. Tiempo lineal,  \( 2 \left\lfloor\dfrac{n}{2}\right\rfloor \) asignaciones. Espacio constante.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/StringBuilder.java&quot;&gt;StringBuilder.toString()&lt;/a&gt;. Tiempo lineal,  \( n \)  asignaciones. Espacio lineal,  \( n \)  elementos.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/StringBuilder.java&quot;&gt;StringBuilder constructor&lt;/a&gt;. Tiempo lineal,  \( n + 16 \)  asignaciones. Espacio lineal,  \( n + 16 \) elementos.&lt;/p&gt;
&lt;p&gt;Entonces, la complejidad total del &lt;em&gt;Algoritmo I&lt;/em&gt; es:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tiempo:&lt;/strong&gt;  En el peor caso, cuando la palabra es un &lt;em&gt;palíndromo&lt;/em&gt;, este algoritmo realiza \( n \)  comparaciones por &lt;em&gt;desigualdad&lt;/em&gt; y \( 2n + 2 \left\lfloor\dfrac{n}{2}\right\rfloor + 16 \) asignaciones.&lt;br&gt;
&lt;strong&gt;Espacio:&lt;/strong&gt;  \( 2n + 16 \) elementos.&lt;/p&gt;
&lt;p&gt;Como pueden observar, este algoritmo es muy ineficiente, hace uso de memoria innecesariamente y como veremos más adelante, realiza más de \( 8x \) operaciones que el &lt;a href=&quot;#RefAlgoritmoOptimo&quot;&gt;algoritmo óptimo&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;mejorando-el-algoritmo-versión-naïve&quot;&gt;Mejorando el algoritmo (versión naïve)&lt;/h3&gt;
&lt;p&gt;Llamemos al siguiente código &lt;em&gt;Algoritmo N&lt;/em&gt; (de naïve).
El &lt;em&gt;Algoritmo N&lt;/em&gt; presenta una mejora sustancial con respecto al &lt;em&gt;Algoritmo I&lt;/em&gt;.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; isPalindrome&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(String str) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;; i &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; n; &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;i) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(i) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Tiempo:&lt;/strong&gt; En el peor caso, cuando la palabra es un &lt;em&gt;palíndromo&lt;/em&gt;, este algoritmo realiza \( n \) comparaciones por &lt;em&gt;desigualdad&lt;/em&gt;.&lt;br&gt;
&lt;strong&gt;Espacio:&lt;/strong&gt; constante&lt;/p&gt;
&lt;p&gt;No se hace uso de memoria adicional y ejecuta aproximadamente \( \dfrac{1}{4} \) de las operaciones que el &lt;em&gt;Algoritmo I&lt;/em&gt;.
Si bien el código se hace un poco más complejo, es un código fácilmente entendible y el incremento en la complejidad es insignificante comparado a la mejora en eficiencia.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;RefAlgoritmoOptimo&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;algoritmo-óptimo&quot;&gt;Algoritmo óptimo&lt;/h3&gt;
&lt;p&gt;Como podemos ver en la siguiente imagen, no hace falta hacer \( n \) comparaciones para determinar si una palabra es un &lt;em&gt;palíndromo&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/OptimalAlgorithm.svg&quot; alt=&quot;Optimal Algorithm&quot;&gt;&lt;/p&gt;
&lt;p&gt;Con sólo hacer (aproximadamente) la mitad de las comparaciones nos basta:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Si n es par, se deben hacer \( \dfrac{n}{2} \) comparaciones&lt;/li&gt;
&lt;li&gt;Si n es impar, se deben hacer \( \dfrac{n - 1}{2} \) comparaciones.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;El siguiente código será denominado &lt;em&gt;Algoritmo O&lt;/em&gt; (de óptimo).&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; isPalindrome&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(String str) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;; i &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;i) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(i) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Tiempo&lt;/strong&gt;: En el peor caso, cuando la palabra es un &lt;em&gt;palíndromo&lt;/em&gt;, este algoritmo realiza \( \left\lfloor\dfrac{n}{2}\right\rfloor \) comparaciones por &lt;em&gt;desigualdad&lt;/em&gt;.&lt;br&gt;
&lt;strong&gt;Espacio&lt;/strong&gt;: constante&lt;/p&gt;
&lt;h3 id=&quot;análisis-detallado-del-algoritmo-i&quot;&gt;Análisis detallado del &lt;em&gt;Algoritmo I&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;Como vimos anteriormente, el &lt;em&gt;Algoritmo I&lt;/em&gt; es mucho más ineficiente que los algoritmos N y O.&lt;br&gt;
Pero además del análisis de complejidad que vimos antes, tenemos que tener en cuenta otras cuestiones que afectan la eficiencia del &lt;em&gt;Algoritmo I&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Cada componente usado en el &lt;em&gt;Algoritmo I&lt;/em&gt; viene con ciertas penalidades en performance que pasan desapercibidas.&lt;br&gt;
Analicémoslo en detalle.&lt;/p&gt;
&lt;h4 id=&quot;construcción-de-stringbuilder&quot;&gt;Construcción de &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html&quot;&gt;StringBuilder&lt;/a&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Asignación de memoria (memory allocation) dinámicamente para el objeto de tipo StringBuilder (&lt;a href=&quot;https://en.wikipedia.org/wiki/Memory_management#HEAP&quot;&gt;heap, free store&lt;/a&gt;, o como quieran llamarlo).&lt;/li&gt;
&lt;li&gt;Inicialización en cero (Zero-Initialization) de los miembros de StringBuilder. &lt;a href=&quot;#Ref4&quot;&gt;[4]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Asignación de memoria dinámica para el array interno dentro de StringBuilder.
De acuerdo con la documentación, el tamaño del array interno es de 16 caracteres sumado al tamaño del String original. &lt;a href=&quot;#Ref5&quot;&gt;[5]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Inicialización en cero (Zero-Initialization) de los miembros del array interno de StringBuilder. Length y del Array en sí. &lt;a href=&quot;#Ref4&quot;&gt;[4]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Copia de los bytes del string original al array interno del StringBuilder.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;reverse-stringbuilder&quot;&gt;reverse() (StringBuilder)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Sólo lo mencionado anteriormente. Esta función no utiliza memoria adicional y es eficiente en tiempo de ejecución.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;tostring-stringbuilder&quot;&gt;toString() (StringBuilder)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Asignación de memoria (memory allocation) dinámicamente para el objeto de tipo &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/String.html&quot;&gt;String&lt;/a&gt; (&lt;a href=&quot;https://en.wikipedia.org/wiki/Memory_management#HEAP&quot;&gt;heap, free store&lt;/a&gt;, o como quieran llamarlo).&lt;/li&gt;
&lt;li&gt;Inicialización en cero (Zero-Initialization) de los miembros de String. &lt;a href=&quot;#Ref4&quot;&gt;[4]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Asignación de memoria dinámica para el array interno dentro de String.&lt;/li&gt;
&lt;li&gt;Inicialización en cero (Zero-Initialization) de los miembros del array interno de String. Length y del Array en sí. &lt;a href=&quot;#Ref4&quot;&gt;[4]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Copia de los bytes del array interno de StringBuilder al array interno del nuevo String.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;equals-string&quot;&gt;equals() (String)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Sólo lo mencionado anteriormente. Esta función no utiliza memoria adicional y es eficiente en tiempo de ejecución.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;garbage-collection&quot;&gt;Garbage Collection&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;El GC debe liberar toda la memoria adicional (innecesaria) que fue utilizada y obviamente esta operación no es “gratuita”.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;data-cache-misses&quot;&gt;Data Cache Misses&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Otro inconveniente asociado al consumo innecesario de memoria es la probabilidad de que nuestros objetos sean muy grandes para entrar en el cache, provocando &lt;a href=&quot;https://en.wikipedia.org/wiki/CPU_cache#Cache_miss&quot;&gt;cache misses&lt;/a&gt; impactando en el tiempo de ejecución.&lt;/li&gt;
&lt;li&gt;Otro factor que aumenta la probabilidad de &lt;em&gt;cache misses&lt;/em&gt; son las indirecciones (referencias, punteros) a porciones distantes en memoria.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;consumo-de-memoria-memory-footprint&quot;&gt;Consumo de memoria (memory footprint)&lt;/h3&gt;
&lt;p&gt;Para analizar el consumo de memoria del &lt;em&gt;Algoritmo I&lt;/em&gt;, vamos a hacerlo con un ejemplo concreto. Vamos usar una palabra (de habla inglesa) de 9 caracteres, a palabra en este caso es “evitative” y es un palíndromo.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;isPalindrome&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62;--shiki-dark:#9ECBFF&quot;&gt;&quot;evitative&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Si bien consumo de memoria del &lt;em&gt;Algoritmo I&lt;/em&gt; depende de la &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_virtual_machine&quot;&gt;Virtual Machine&lt;/a&gt; y del &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_virtual_machine#Java_Runtime_Environment_from_Oracle&quot;&gt;Runtime Environment&lt;/a&gt; que estemos usando, en este caso vamos a usar una plataforma específica que está &lt;a href=&quot;#RefPlataforma&quot;&gt;detallada aquí&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Básicamente en nuestro ejemplo se crean dos objetos, uno de tipo StringBuilder y otro de tipo String.&lt;/p&gt;
&lt;h4 id=&quot;stringbuilder&quot;&gt;StringBuilder:&lt;/h4&gt;
&lt;p&gt;Los objetos de tipo &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html&quot;&gt;StringBuilder&lt;/a&gt; tienen la siguiente representación en memoria.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/JavaStringBuilderMemoryRepresentation64CompressedOopsEnabled.svg&quot; alt=&quot;Java StringBuilder memory representation&quot;&gt;&lt;/p&gt;
&lt;p&gt;Un objeto del tipo StringBuilder consiste de dos partes (no necesariamente contiguas en memoria):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Primera parte: tamaño de utilización del array (length() del StringBuilder) y una referencia al array donde están los datos.&lt;/li&gt;
&lt;li&gt;Segunda parte: tamaño del array (capacity() del StringBuilder) y el array con los datos.&lt;br&gt;
El tamaño del array es de 16 caracteres sumado a la cantidad de caracteres del String original (“evitative”) &lt;a href=&quot;#Ref5&quot;&gt;[5]&lt;/a&gt;. En la imagen se muestran esos 16 caracteres como recuadros de color rojo, debido a que es espacio desperdiciado.
Los caracteres en Java tienen un tamaño de 2 bytes. &lt;a href=&quot;#Ref6&quot;&gt;[6]&lt;/a&gt;&lt;br&gt;
O sea que en nuestro ejemplo el array va a tener un tamaño de \( 2 \cdot (9 + 16) = 50 \) bytes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;En Java todos los objetos tienen un &lt;a href=&quot;http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/oops/oop.hpp&quot;&gt;&lt;em&gt;header&lt;/em&gt;&lt;/a&gt; (si conoce alguna implementación que no los tenga, &lt;a href=&quot;https://twitter.com/ferpelliccioni&quot;&gt;me avisa&lt;/a&gt;), en nuestra plataforma el header es de 12 bytes. En otras plataformas populares puede ser de 8 o 16 bytes, cualquier cosa &lt;a href=&quot;#Ref7&quot;&gt;ver aquí [7]&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Otra cosa a tener en cuenta es el &lt;a href=&quot;https://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding&quot;&gt;padding&lt;/a&gt;, que básicamente es cierto espacio de memoria que se adiciona para satisfacer el &lt;a href=&quot;https://en.wikipedia.org/wiki/Data_structure_alignment&quot;&gt;alineamiento&lt;/a&gt; de los objetos. En nuestro caso, los objetos deben estar alineados en direcciones de memoria múltiplos de 8.&lt;/p&gt;
&lt;p&gt;En resumen, nuestro objeto StringBuilder tiene el siguiente tamaño en memoria (en bytes):&lt;/p&gt;
&lt;p&gt;Primera parte: \( 24 \)&lt;br&gt;
Segunda parte: \( 16 + 2n + 32 + padding \) &lt;a href=&quot;#Ref8&quot;&gt;[8]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Total: \( 8(\left\lceil\dfrac{n}{4}\right\rceil + 9) \) bytes&lt;/p&gt;
&lt;h4 id=&quot;string&quot;&gt;String:&lt;/h4&gt;
&lt;p&gt;Los objetos de tipo &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/String.html&quot;&gt;String&lt;/a&gt; tienen la siguiente representación en memoria.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/JavaStringMemoryRepresentation64CompressedOopsEnabledJdk18.svg&quot; alt=&quot;Java String memory representation&quot;&gt;&lt;/p&gt;
&lt;p&gt;Un objeto del tipo String consiste de dos partes (no necesariamente contiguas en memoria):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Primera parte: referencia al array donde están los datos y &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode--&quot;&gt;hash&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Segunda parte: tamaño del array (length() del String) y el array con los datos.\&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;El objeto String aquí descripto pertenece a la especificación de &lt;a href=&quot;http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/String.java&quot;&gt;Java 8&lt;/a&gt;. En &lt;a href=&quot;http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/814bf0775b52/src/share/classes/java/lang/String.java&quot;&gt;versiones anteriores&lt;/a&gt; de Java, la clase String contaba con más campos, por consiguiente su tamaño en memoria era mayor. &lt;a href=&quot;#Ref7&quot;&gt;[7]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;En resumen, nuestro objeto String tiene el siguiente tamaño en memoria (en bytes):&lt;/p&gt;
&lt;p&gt;Primera parte: \( 24 \)&lt;br&gt;
Segunda parte: \( 16 + 2n + padding \) &lt;a href=&quot;#Ref8&quot;&gt;[8]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Total: \( 8(\left\lceil\dfrac{n}{4}\right\rceil + 5) \) bytes&lt;/p&gt;
&lt;h4 id=&quot;total-de-memoria-consumida&quot;&gt;Total de memoria consumida:&lt;/h4&gt;
&lt;p&gt;El total de memoria consumida por nuestros objetos StringBuilder y String es de \( 16(\left\lceil\dfrac{n}{4}\right\rceil + 7) \) bytes.&lt;/p&gt;
&lt;p&gt;En nuestro ejemplo \( n = 9 \), así que la memoria consumida es \( 16(\left\lceil\dfrac{9}{4}\right\rceil + 7) \) bytes, que son &lt;strong&gt;160 bytes&lt;/strong&gt; adicionales de memoria, solo para determinar si “evitative” es un palíndromo o no.&lt;br&gt;
Recuerden que estos 160 bytes es un consumo totalmente innecesario de memoria.&lt;/p&gt;
&lt;h2 id=&quot;benchmarks&quot;&gt;Benchmarks&lt;/h2&gt;
&lt;p&gt;Estuve haciendo algunas mediciones de performance de los algoritmos y en las mismas se percibe una penalidad en tiempo de ejecución promedio de &lt;strong&gt;8.5x&lt;/strong&gt; del &lt;em&gt;Algoritmo I&lt;/em&gt; por sobre los &lt;em&gt;Algoritmos O y N&lt;/em&gt;. O sea, el &lt;em&gt;Algoritmo I&lt;/em&gt; es más de 8 veces más lento que los otros dos, en promedio.&lt;/p&gt;
&lt;p&gt;En ese promedio no estoy considerando un benchmark que arroja &lt;strong&gt;586x&lt;/strong&gt; de penalidad, ya que el algoritmo usado en este benchmark no fue presentado en este artículo. Lo veremos en un futuro artículo.&lt;/p&gt;
&lt;p&gt;Puede ver el código fuente de los benchmarks en &lt;a href=&quot;https://github.com/fpelliccioni/componentsprogramming/tree/master/palindrome/part1/java&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;La explicación del los benchmarks y el código quedará para un próximo artículo.&lt;/p&gt;
&lt;h3 id=&quot;algoritmo-n-vs-algoritmo-o&quot;&gt;&lt;em&gt;Algoritmo N&lt;/em&gt; vs &lt;em&gt;Algoritmo O&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;Si bien anteriormente vimos que el &lt;em&gt;Algoritmo O&lt;/em&gt; realiza la mitad de operaciones que el &lt;em&gt;Algoritmo N&lt;/em&gt;, en el peor caso; el tiempo de ejecución de ambos algoritmos se ve afectado por diversos factores, como por ejemplo: el largo de la palabra, si la palabra es palíndromo o no y otros factores correspondientes a la plataforma.&lt;/p&gt;
&lt;p&gt;En muchos casos el &lt;em&gt;Algoritmo N&lt;/em&gt; es más rápido en tiempo de ejecución que el &lt;em&gt;Algoritmo O&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Analizaremos esto en un futuro artículo.&lt;/p&gt;
&lt;h2 id=&quot;solución-definitiva&quot;&gt;¿Solución definitiva?&lt;/h2&gt;
&lt;p&gt;Considero que ninguno de los tres algoritmos presentados en este artículo representan una solución definitiva, ninguno es un &lt;a href=&quot;https://componentsprogramming.com/components-programming/&quot;&gt;Componente&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Un &lt;em&gt;componente&lt;/em&gt; debe ser algo que se pueda reutilizar y en muchos casos los algoritmos aquí descriptos no son aptos para ser reutilizados.\&lt;/p&gt;
&lt;p&gt;Además, los tres algoritmos sólo aceptan un String como input. Un palíndromo no sólo es una secuencia de caracteres que se lee igual al derecho y al revés. Un palíndromo puede encontrarse en forma de notas musicales, números y también en la naturaleza.&lt;/p&gt;
&lt;p&gt;No soy experto en genética, pero se que los &lt;a href=&quot;https://en.wikipedia.org/wiki/Palindromic_sequence&quot;&gt;palíndromos también pueden encontrarse en cadenas de ADN&lt;/a&gt;.&lt;br&gt;
Los palíndromos en el ADN son tan importantes que algunos los consideran como responsables de evitar la extinción de la especie humana (y también otras especies) ya que de no existir los palíndromos en el ADN, se producirían mutaciones genéticas irreversibles e incorregibles, que con el paso del tiempo provocarían la extinción de la especie.&lt;br&gt;
En algún futuro artículo charlaremos este tema.&lt;/p&gt;
&lt;h2 id=&quot;pendientes&quot;&gt;Pendientes&lt;/h2&gt;
&lt;p&gt;Replicar el &lt;em&gt;Algoritmo I&lt;/em&gt; en &lt;a href=&quot;https://en.wikipedia.org/wiki/C_Sharp_(programming_language)&quot;&gt;C#&lt;/a&gt; y analizar su eficiencia en tiempo de ejecución y consumo de memoria.&lt;/p&gt;
&lt;h2 id=&quot;conclusiones&quot;&gt;Conclusiones&lt;/h2&gt;
&lt;p&gt;El &lt;em&gt;Algoritmo I&lt;/em&gt; es un excelente ejemplo de &lt;a href=&quot;http://buscon.rae.es/drae/srv/search?val=concisiones&quot;&gt;concisión&lt;/a&gt; y legibilidad, hace buen uso de abstracciones disponibles para lograr este objetivo. El problema con el &lt;em&gt;Algoritmo I&lt;/em&gt; es que es un pésimo ejemplo de eficiencia.&lt;/p&gt;
&lt;p&gt;Las abstracciones facilitan nuestra labor, nos permiten concentrarnos en el problema a resolver sin tener que pensar en el contexto, en nuestro caso la computadora.&lt;/p&gt;
&lt;p&gt;Si bien las abstracciones son buenas, tienen una gran desventaja y es que nos hacen olvidar cómo funciona la máquina en la cual nuestro programa se ejecutará.&lt;br&gt;
Los programadores modernos suelen abusar de las abstracciones y carecen de conocimiento o no le dan importancia a cuestiones importantes que afectan el comportamiento de nuestros programas, como: cache, load/store buffers, branch prediction, pipelines, modelos de memoria, instrucciones vectoriales (SIMD), etc…&lt;/p&gt;
&lt;p&gt;Como programadores, debemos conocer en profundidad la computadora, el lenguaje de programación y la complejidad de los componentes que usamos. Pero, lamentablemente los programadores modernos se han olvidado de esto y están concentrados en otras cuestiones, como testing, agile, metaprogramming y frameworks/bibliotecas cuyo tiempo de vida no es mayor a dos años.&lt;/p&gt;
&lt;p&gt;Volviendo a las abstracciones, la mejor de todas ellas fue descubierta por &lt;a href=&quot;https://en.wikipedia.org/wiki/Gottfried_Wilhelm_Leibniz&quot;&gt;Leibniz&lt;/a&gt; en 1679. Esa abstracción es la que nos permite modelar el mundo real en una computadora. Esa abstracción es el &lt;a href=&quot;https://en.wikipedia.org/wiki/Bit&quot;&gt;&lt;strong&gt;Bit&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Por último, cabe destacar que el &lt;em&gt;Algoritmo I&lt;/em&gt; podría ser útil como postcondición:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;java&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; isPalindrome&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(String str) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D;--shiki-dark:#6A737D&quot;&gt;    //postcondition: Result := reverse(str) = str&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;; i &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;i) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(i) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; str.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(n&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#005CC5;--shiki-dark:#79B8FF&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h2 id=&quot;agradecimientos&quot;&gt;Agradecimientos&lt;/h2&gt;
&lt;p&gt;Quiero agradecer a Mario dal Lago y Javier Velilla por revisar el artículo y sugerir correcciones.&lt;br&gt;
Y por último, ya que se puede decir que &lt;em&gt;le debemos la vida a los palíndromos&lt;/em&gt;, un agradecimiento especial para ellos. :)&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;notas&quot;&gt;Notas&lt;/h2&gt;
&lt;p&gt;Byte = 8-bits.&lt;br&gt;
Hay arquitecturas donde 1 byte no necesariamente equivale a 8 bits. Estas arquitecturas son inusuales hoy en día.
No existe un estándar que especifique el tamaño de un byte, pero se puede decir que el estándar &lt;em&gt;de facto&lt;/em&gt; es que 1 byte = 8 bits, es lo más común en arquitecturas de computadoras modernas.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;RefPlataforma&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;plataforma-utilizada-para-el-análisis-en-este-artículo&quot;&gt;Plataforma utilizada para el análisis en este artículo:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;CPU
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://ark.intel.com/products/75117&quot;&gt;Intel Core i7-4700MQ&lt;/a&gt; CPU @ 2.40GHz, &lt;a href=&quot;https://en.wikipedia.org/wiki/Haswell_(microarchitecture)&quot;&gt;Haswell&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;4 Cores, 8 Threads&lt;/li&gt;
&lt;li&gt;L1 Data Cache Size  4 x 32 KBytes&lt;/li&gt;
&lt;li&gt;L1 Instructions Cache Size  4 x 32 KBytes&lt;/li&gt;
&lt;li&gt;L2 Unified Cache Size 4 x 256 KBytes&lt;/li&gt;
&lt;li&gt;L3 Unified Cache Size 6144 KBytes&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;RAM: 8192 MBytes, DDR3&lt;/li&gt;
&lt;li&gt;Operating System: Windows 10 Home 64-bit&lt;/li&gt;
&lt;li&gt;Java
&lt;ul&gt;
&lt;li&gt;Version 1.8.0_60\&lt;/li&gt;
&lt;li&gt;Java(TM) SE Runtime Environment (build 1.8.0_60-b27)\&lt;/li&gt;
&lt;li&gt;64-bit &lt;a href=&quot;https://en.wikipedia.org/wiki/HotSpot&quot;&gt;HotSpot VM&lt;/a&gt;.\&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/technotes/guides/vm/performance-enhancements-7.html#compressedOop&quot;&gt;Compressed Oops&lt;/a&gt; activado\&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Data_structure_alignment&quot;&gt;Objects alignment&lt;/a&gt;: 8 bytes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Para el análisis en otras plataformas, por favor &lt;a href=&quot;#Ref7&quot;&gt;referirse a [7]&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;referencias&quot;&gt;Referencias&lt;/h2&gt;
&lt;p&gt;&lt;a name=&quot;Ref1&quot;&gt;[1]&lt;/a&gt; Zahlen significa “Números”, en Alemán. De ahí que el conjunto de los números enteros se lo identifica con la letra \( \mathbb{Z} \).&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref2&quot;&gt;[2]&lt;/a&gt; The Art of Computer Programming Volume 1, by Donald E. Knuth [3rd Edition, page 107].&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref3&quot;&gt;[3]&lt;/a&gt; ¿Por qué llamo a String.equals() “función” y no “método”?. &lt;a href=&quot;https://componentsprogramming.com/usando-la-terminologia-adecuada-metodo/&quot;&gt;He aquí la respuesta&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref4&quot;&gt;[4]&lt;/a&gt; En Java los tipos integrales y los arrays de tipo integrales se inicializan en 0, garantizado por la especificación del lenguaje. &lt;a href=&quot;https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.12.5&quot;&gt;4.12.5 Initial Values of Variables&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref5&quot;&gt;[5]&lt;/a&gt; &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#StringBuilder-java.lang.String-&quot;&gt;Java String class&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref6&quot;&gt;[6]&lt;/a&gt; &lt;a href=&quot;https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&quot;&gt;Java Primitive Data Types&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref7&quot;&gt;[7]&lt;/a&gt; Análisis de consumo de memoria en otras plataformas (borrador sin publicar).&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref8&quot;&gt;[8]&lt;/a&gt; La fórmula para calcular el &lt;a href=&quot;https://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding&quot;&gt;padding&lt;/a&gt; de los arrays internos de StringBuilder y String son las siguientes (todo medido en bytes):&lt;br&gt;
      StringBuilder internal array padding = \( 8\left\lceil\dfrac{2n + 48}{8}\right\rceil - (2n + 48) \)&lt;br&gt;
      String internal array padding  = \( 8\left\lceil\dfrac{2n + 16}{8}\right\rceil - (2n + 16) \)\&lt;/p&gt;
&lt;p&gt;(Estas fórmulas son específicas para la plataforma descripta en el artículo)&lt;/p&gt;
&lt;p&gt;La fórmula general para calcular el padding de objetos es la siguiente:&lt;/p&gt;
&lt;p&gt;$$ alignment\left\lceil\dfrac{size}{alignment}\right\rceil - size $$&lt;/p&gt;
</content></entry><entry><title>Mi charla: &apos;Introducción a Generic Programming&apos;</title><link rel="alternate" href="https://componentsprogramming.com/charla-intro-generic-programming/"/><id>https://componentsprogramming.com/charla-intro-generic-programming</id><published>2016-06-02T12:00:00.000Z</published><updated>2016-06-02T12:00:00.000Z</updated><content type="html">&lt;p&gt;¡Buenas!&lt;/p&gt;
&lt;p&gt;Les comparto el enlace a las &lt;em&gt;filminas&lt;/em&gt; de mi charla denominada &lt;a href=&quot;http://prezi.com/fxhtgwvubb10/?utm_campaign=share&amp;amp;utm_medium=copy&amp;amp;rc=ex0share&quot;&gt;“Introducción a Generic Programming”&lt;/a&gt; que fue expuesta en el &lt;a href=&quot;http://www.meetup.com/cpp-ba/events/228427233/&quot;&gt;“Primer Encuentro de programadores C++ de Buenos Aires”&lt;/a&gt; el día 31 de Marzo de 2016.&lt;/p&gt;
&lt;p&gt;En ese encuentro también tuvimos el agrado de presenciar la excelente charla brindada por nuestro colega &lt;a href=&quot;http://talesofcpp.fusionfenix.com/&quot;&gt;Agustín (K-Ballo) Bergé&lt;/a&gt;, titulada &lt;a href=&quot;https://drive.google.com/open?id=0B1jygKCWf7aSQWt2NGlhTGtUdFM0VUVBQnU2SlQyNDQ1Z213&quot;&gt;“The C++ Way”&lt;/a&gt;, donde nos cuenta acerca de las nuevas características incorporadas en C++11 y C++14.&lt;/p&gt;
&lt;p&gt;Espero que les gusten nuestras presentaciones y les de ganas de sumarse a &lt;a href=&quot;https://www.meetup.com/cpp-ba/&quot;&gt;nuestra comunidad&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;¡Saludos!&lt;/p&gt;
</content></entry><entry><title>Invitación a Vino de Honor</title><link rel="alternate" href="https://componentsprogramming.com/vino-honor/"/><id>https://componentsprogramming.com/vino-honor</id><published>2016-05-04T12:00:00.000Z</published><updated>2016-05-04T12:00:00.000Z</updated><content type="html">&lt;p&gt;El día 4 de mayo de 2016, he sido invitado por la señora Ministra de Relaciones Exteriores y Culto (Canciller), Da. &lt;a href=&quot;https://twitter.com/SusanaMalcorra&quot;&gt;Susana Malcorra&lt;/a&gt;, al &lt;em&gt;Vino de Honor&lt;/em&gt; que tuvo lugar en el Salón Dorado del Palacio San Martín, en ocasión del Saludo a los miembros de la &lt;a href=&quot;http://www.plataformaargentina.gov.ar/&quot;&gt;Comisión Nacional del Límite Exterior de la Plataforma Continental (COPLA)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/copla/vinohonor1.jpg&quot; alt=&quot;Canciller&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/copla/vinohonor2.jpg&quot; alt=&quot;Equipo COPLA&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;¡Muchas gracias a la Sra. Canciller y felicitaciones a todo el equipo!&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;blockquote&gt;
&lt;p&gt;El límite más extenso de la Argentina – Nuestra frontera con la humanidad&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h3 id=&quot;referencias&quot;&gt;Referencias&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://twitter.com/SusanaMalcorra/status/727976624239554560&quot;&gt;Twitter oficial de Susana Malcorra&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
</content></entry><entry><title>Límite Exterior de la Plataforma Continental</title><link rel="alternate" href="https://componentsprogramming.com/limite-aprobado/"/><id>https://componentsprogramming.com/limite-aprobado</id><published>2016-03-11T12:00:00.000Z</published><updated>2016-03-11T12:00:00.000Z</updated><content type="html">&lt;p&gt;El día 11 de marzo de 2016, el plenario de la 40º Sesión de la &lt;a href=&quot;http://www.un.org/depts/los/clcs_new/clcs_home.htm&quot;&gt;Comisión de Límites de la Plataforma Continental (CLPC) de las Naciones Unidas&lt;/a&gt;, aprobó por consenso, es decir sin un solo voto en contra, las Recomendaciones sobre la presentación argentina del Límite Exterior de la Plataforma Continental. La República Argentina había presentado el límite exterior de la plataforma continental de todo el territorio argentino —continental, insular y Antártida Argentina— ante la CLPC el 21 de abril de 2009.&lt;/p&gt;
&lt;p&gt;Ha sido un honor y orgullo el haber sido miembro de este equipo y de este proyecto, que espero que sirva para mejorar la calidad de vida de todos los argentinos.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/copla/copla1.jpg&quot; alt=&quot;Equipo COPLA&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;¡Felicitaciones a todo el equipo!&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;blockquote&gt;
&lt;p&gt;El límite más extenso de la Argentina – Nuestra frontera con la humanidad&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h3 id=&quot;referencias&quot;&gt;Referencias&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://www.plataformaargentina.gov.ar/userfiles/userfiles/FOLLETO-COPLA-2016_1.pdf&quot;&gt;FOLLETO-COPLA-2016_1&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
</content></entry><entry><title>Alex se jubiló</title><link rel="alternate" href="https://componentsprogramming.com/jubilacion-alex/"/><id>https://componentsprogramming.com/jubilacion-alex</id><published>2016-01-14T12:00:00.000Z</published><updated>2016-01-14T12:00:00.000Z</updated><content type="html">&lt;p&gt;Alex se ha jubilado.&lt;/p&gt;
&lt;p&gt;Les comparto una estampilla conmemorativa, diseñada por &lt;a href=&quot;https://twitter.com/joycecroft&quot;&gt;Joyce Croft&lt;/a&gt; y Alexander Zeyliger de &lt;a href=&quot;http://a9.com/&quot;&gt;A9&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/Stepanov_poster_FINAL.png&quot; alt=&quot;Alex Stepanov Commemorative Stamp&quot;&gt;&lt;/p&gt;
&lt;p&gt;Tengo que confesar que siento tristeza, ya que me hubiera gustado que Alex siga aportando ideas por mucho tiempo más tiempo.&lt;br&gt;
Pero se ha retirado y estoy feliz por él.&lt;/p&gt;
&lt;p&gt;Le deseo tenga un excelente y merecido descanso con su familia y amigos.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light github-dark&quot; style=&quot;background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;auto&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt; who &lt;/span&gt;&lt;span style=&quot;color:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6F42C1;--shiki-dark:#B392F0&quot;&gt; successor&lt;/span&gt;&lt;span style=&quot;color:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(alex);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;¡Gracias!&lt;/p&gt;
</content></entry><entry><title>¡Gracias Alex!</title><link rel="alternate" href="https://componentsprogramming.com/gracias-alex/"/><id>https://componentsprogramming.com/gracias-alex</id><published>2015-11-25T12:00:00.000Z</published><updated>2015-11-25T12:00:00.000Z</updated><content type="html">&lt;p&gt;Estoy muy contento de haber recibido estos dos regalos.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/FM2GP.jpg&quot; alt=&quot;Alex autograph FM2GP&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/EoP.jpg&quot; alt=&quot;Alex autograph EoP&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://componentsprogramming.com/images/EoPAndFM2GP.jpg&quot; alt=&quot;Elements of Programming and From Mathematics to Generic Programming&quot;&gt;&lt;/p&gt;
&lt;p&gt;Son dos excelentes libros.&lt;/p&gt;
&lt;p&gt;Es un honor para mí que estén autografiados por uno de los más grandes de nuestra disciplina.&lt;/p&gt;
&lt;p&gt;No te prives del placer de leerlos.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.amazon.com/Elements-Programming-Alexander-A-Stepanov/dp/032163537X/&quot;&gt;Elements of Programming en Amazon&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.amazon.com/Mathematics-Generic-Programming-Alexander-Stepanov/dp/0321942043/&quot;&gt;From Mathematics to Generic Programming en Amazon&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;¡Gracias nuevamente Alex!&lt;/p&gt;
</content></entry><entry><title>¿Cuál es tu sabor de Objeto preferido?</title><link rel="alternate" href="https://componentsprogramming.com/cual-es-tu-sabor-de-objeto-preferido/"/><id>https://componentsprogramming.com/cual-es-tu-sabor-de-objeto-preferido</id><published>2015-09-26T12:00:00.000Z</published><updated>2015-09-26T12:00:00.000Z</updated><content type="html">&lt;p&gt;En este artículo quiero continuar la discusión sobre la terminología que usamos los programadores diariamente, siguiendo con la línea de &lt;a href=&quot;https://componentsprogramming.com/usando-la-terminologia-adecuada-metodo/&quot;&gt;“Usando la terminología adecuada: ¿Método?”&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;introducción&quot;&gt;Introducción&lt;/h2&gt;
&lt;p&gt;Los programadores, sobre todo desde la popularización de la &lt;em&gt;Programación Orientada a Objetos&lt;/em&gt;, usamos la palabra &lt;em&gt;Objeto&lt;/em&gt; sin realmente pensar en su significado.\&lt;/p&gt;
&lt;p&gt;Desde siempre me llamó la atención toda la terminología relacionada al &lt;em&gt;Paradigma de Orientación a Objetos&lt;/em&gt; ya que considero que muchas de las definiciones de dicho paradigma son ambiguas o muy dispares entre los distintos autores.&lt;/p&gt;
&lt;h2 id=&quot;qué-significa-objeto&quot;&gt;¿Qué significa “Objeto”?&lt;/h2&gt;
&lt;p&gt;En ciencias de la computación, y especialmente en programación, no existe una definición formal ni única de “Objeto”.&lt;br&gt;
Diferentes autores de lenguajes de programación y autores de textos le han atribuido diferentes significados a la misma.&lt;/p&gt;
&lt;p&gt;Intentaré en este artículo exponer y analizar las diferentes definiciones y llegar a una conclusión sobre cuál es la definición más acorde al estilo de programación adoptado en este blog.&lt;/p&gt;
&lt;h3 id=&quot;simula&quot;&gt;Simula&lt;/h3&gt;
&lt;p&gt;La definición aportada por los autores del lenguaje de programación &lt;a href=&quot;https://en.wikipedia.org/wiki/Simula&quot;&gt;Simula&lt;/a&gt; es la siguiente:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An object is a self-contained program (block instance) having its own &lt;strong&gt;local data&lt;/strong&gt; and &lt;strong&gt;actions&lt;/strong&gt; defined by a “class declaration”. The class declaration defines a program (data and action) pattern, and objects conforming to that pattern are said to “belong to the same class”. &lt;a href=&quot;#Ref1&quot;&gt;[1]&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;La definición anterior es importante, ya que Simula es considerado el primer lenguaje de programación &lt;em&gt;Orientado a Objetos&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Tres cosas se destacan en la definición:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Un objeto tiene datos propios.&lt;/li&gt;
&lt;li&gt;Un objeto incluye acciones.&lt;/li&gt;
&lt;li&gt;Pertenencia de un objeto a una clase.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;smalltalk&quot;&gt;Smalltalk&lt;/h3&gt;
&lt;p&gt;Si bien Simula es el primer lenguaje de programación orientado a objetos, el &lt;em&gt;marketing fuerte&lt;/em&gt; del paradigma de objetos surgió con el lenguaje &lt;a href=&quot;https://en.wikipedia.org/wiki/Smalltalk&quot;&gt;Smalltalk&lt;/a&gt;.
Se puede decir que Smalltalk es el lenguaje más influyente en lo que respecta a &lt;em&gt;Objetos&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Según el Manual de instrucciones de Smalltalk-72: &lt;a href=&quot;#Ref2&quot;&gt;[2]&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Every entity in Smalltalk’s world is called an object. Objects can &lt;strong&gt;remember things&lt;/strong&gt; and &lt;strong&gt;communicate&lt;/strong&gt; with each other by sending and receiving messages. Every object belongs to a class…&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Se destacan las mismas tres cosas que en la definición de Simula, pero con variaciones:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Un objeto tiene datos propios: “remember things”.&lt;/li&gt;
&lt;li&gt;Un objeto incluye acciones: La comunicación mediante mensajes es una forma particular de acción.&lt;/li&gt;
&lt;li&gt;Pertenencia de un objeto a una clase.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Y, según el &lt;a href=&quot;#Ref3&quot;&gt;estándar de Smalltalk [3]&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An object is a computational entity that is capable of &lt;strong&gt;responding&lt;/strong&gt; to a well defined set of messages. An object may also encapsulate some (possibly mutable) &lt;strong&gt;state&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Se destaca:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Un objeto tiene datos propios: “state”.&lt;/li&gt;
&lt;li&gt;Un objeto incluye acciones: La comunicación mediante mensajes es una forma particular de acción.&lt;/li&gt;
&lt;li&gt;Se agrega el concepto de &lt;em&gt;mutabilidad&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;eiffel---object-oriented-software-construction&quot;&gt;Eiffel - Object-Oriented Software Construction&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://www.amazon.com/Object-Oriented-Software-Construction-CD-ROM-Edition/dp/0136291554&quot;&gt;Object-Oriented Software Construction&lt;/a&gt; es una de las más importantes referencias disponibles en cuanto a &lt;em&gt;orientación a objetos&lt;/em&gt;. Fue escrito por &lt;a href=&quot;https://en.wikipedia.org/wiki/Bertrand_Meyer&quot;&gt;Bertrand Meyer&lt;/a&gt;, el diseñador del &lt;a href=&quot;https://en.wikipedia.org/wiki/Eiffel_(programming_language)&quot;&gt;lenguaje de programación Eiffel&lt;/a&gt;.\&lt;/p&gt;
&lt;p&gt;Eiffel es uno de los denominados &lt;em&gt;lenguajes puramente orientados a objetos&lt;/em&gt;, ya que incluso sus tipos básicos (built-in types), como &lt;em&gt;integer&lt;/em&gt; o &lt;em&gt;real&lt;/em&gt;, están creados mediante clases.&lt;/p&gt;
&lt;p&gt;Aquí la definición de &lt;em&gt;objeto&lt;/em&gt; dada por Meyer en OOSC &lt;a href=&quot;#Ref4&quot;&gt;[4]&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Object: A run-time data structure made of zero or more &lt;strong&gt;values, called fields&lt;/strong&gt;, and serving as the computer representation of an abstract object. Every object is an &lt;strong&gt;instance of some class&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;En la definición anterior se establece que:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Un objeto tiene datos propios: “made of zero or more values”.&lt;/li&gt;
&lt;li&gt;Pertenencia de un objeto a una clase.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;c&quot;&gt;C++&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/C%2B%2B&quot;&gt;C++&lt;/a&gt; es un lenguaje que soporta la tecnología de objetos.&lt;br&gt;
C++ tiene una definición de &lt;em&gt;objeto&lt;/em&gt; muy distinta a la que la mayoría de los programadores está acostumbrado.&lt;/p&gt;
&lt;p&gt;Según el &lt;a href=&quot;#Ref5&quot;&gt;estándar de C++ [5]&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;… An object is a &lt;strong&gt;region of storage&lt;/strong&gt;. [Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do. —end note] …&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;c-lenguaje-de-programación&quot;&gt;C (lenguaje de programación)&lt;/h3&gt;
&lt;p&gt;Ustedes se preguntarán por qué estoy incluyendo al &lt;a href=&quot;https://en.wikipedia.org/wiki/C_(programming_language)&quot;&gt;lenguaje de programación C&lt;/a&gt; en esta lista si este no incluye características de lenguajes orientados a objetos.&lt;/p&gt;
&lt;p&gt;Si bien el lenguaje C no es un lenguaje orientado a objetos, este incluye en su  &lt;a href=&quot;#Ref6&quot;&gt;estándar [6]&lt;/a&gt; la definición de &lt;em&gt;objeto&lt;/em&gt;:\&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;object: &lt;strong&gt;region of data storage&lt;/strong&gt; in the execution environment, the contents of which can represent values…&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;elements-of-programming&quot;&gt;Elements of Programming&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;Elements of Programming&lt;/a&gt; es la &lt;em&gt;magnum opus&lt;/em&gt; de &lt;a href=&quot;http://www.stepanovpapers.com&quot;&gt;Alexander Stepanov&lt;/a&gt; y &lt;a href=&quot;http://www.softwarepreservation.org/author/pmcjones&quot;&gt;Paul McJones&lt;/a&gt;.&lt;br&gt;
Según mi consideración, va camino a convertirse en un texto clásico de la programación, así que recomiendo a todo aquel amante de esta hermosa disciplina que no se prive de leerlo.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An object is a representation of a &lt;a href=&quot;#RefConcreteEntity&quot;&gt;concrete entity&lt;/a&gt; as a &lt;strong&gt;value in memory&lt;/strong&gt;. An object has a &lt;strong&gt;state&lt;/strong&gt; that is a value of some value type. The state of an object is &lt;strong&gt;changeable&lt;/strong&gt;. Given an object corresponding to a concrete entity, its state corresponds to a snapshot of that entity…&lt;br&gt;
…&lt;br&gt;
An object type is a pattern for &lt;strong&gt;storing and modifying&lt;/strong&gt; values in memory. Corresponding to every object type is a value type describing states of objects of that type. Every object &lt;strong&gt;belongs to an object type&lt;/strong&gt;. An example of an object type is integers represented in 32-bit two’s complement little-endian format aligned to a 4-byte address boundary. &lt;a href=&quot;#Ref7&quot;&gt;[7]&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;En la definición anterior, Stepanov y McJones, intentan tomar distancia de cualquier tipo de paradigma de programación y establecer una definición más general de lo que un &lt;em&gt;objeto&lt;/em&gt; significa. Si bien se notan claras diferencias con las definiciones anteriores, se pueden ver algunas semejanzas:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Un objeto tiene datos propios: “value in memory”, “state”.&lt;/li&gt;
&lt;li&gt;Un objeto incluye acciones: “storing and modifying values in memory” son básicamente acciones o comportamiento.&lt;/li&gt;
&lt;li&gt;Pertenencia de un objeto a una &lt;em&gt;object type&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Un objeto es mutable.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;conclusiones&quot;&gt;Conclusiones&lt;/h2&gt;
&lt;p&gt;Como ustedes habrán notado, existe una gran variedad de definiciones de &lt;em&gt;objeto&lt;/em&gt;. Algunas de ellas coinciden en ciertas características y otras difieren en otras.&lt;/p&gt;
&lt;p&gt;El autor del blog prefiere la definición dada por Stepanov y McJones en &lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;Elements of Programming&lt;/a&gt;. Considero que es la definición más completa, práctica, amplia y con mayor base matemática.&lt;/p&gt;
&lt;p&gt;Es la definición más completa, porque comienza desarrollando una taxonomía de ideas como &lt;em&gt;Entity&lt;/em&gt;, &lt;em&gt;Species&lt;/em&gt;, &lt;em&gt;Genus&lt;/em&gt;, que sirve como base para la definición de objeto y otras definiciones. Estas definiciones no están incluídas en este artículo, para conocer más al respecto por favor referirse &lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;al libro&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Es la definición más práctica, ya que se es consciente que todo programa se ejecuta en computadoras que poseen memoria y estas constituyen la única realización disponible de un dispositivo computacional universal. No depende de dispositivos computacionales teóricos o imaginarios.&lt;/p&gt;
&lt;p&gt;Es la definición más amplia, ya que en ella no se excluye a lenguajes no pertenecientes al paradigma de objetos.&lt;/p&gt;
&lt;p&gt;Nuevamente, yo hice mi elección, pero no hace falta decir que usted puede elegir la definición que más le guste, sólo asegúrese de que su pensamiento esté libre de influencias difundidas por la maquinaria propagandística de &lt;em&gt;Objetos&lt;/em&gt; :).&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;serie-terminología&quot;&gt;Serie “Terminología”:&lt;/h2&gt;
&lt;p&gt;   &lt;a href=&quot;https://componentsprogramming.com/usando-la-terminologia-adecuada-metodo/&quot;&gt;Usando la terminología adecuada: ¿Método?&lt;/a&gt;&lt;br&gt;
   &lt;a href=&quot;https://componentsprogramming.com/cual-es-tu-sabor-de-objeto-preferido/&quot;&gt;¿Cuál es tu sabor de Objeto preferido?&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;notas--referencias&quot;&gt;Notas / Referencias&lt;/h2&gt;
&lt;p&gt;Aclaración: El énfasis/negrita en cada una de las definiciones presentadas va por cuenta del autor del artículo.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref1&quot;&gt;[1]&lt;/a&gt; SIMULA 67: COMMON BASE LANGUAGE, by Ole-Johan Dahl, Bjørn Myhrhaug and Kristen Nygaard. Publication No. S-22. Classes 1. 3. 3 [page 6]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref2&quot;&gt;[2]&lt;/a&gt; Smalltalk-72 Instruction Manual by Adele Goldberg and Alan Kay [page 44]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref3&quot;&gt;[3]&lt;/a&gt; &lt;a href=&quot;http://smalltalk.org/versions/ANSISmalltalk/ANSISmalltalkStandard_v1.9_199712_NCITS_X3J20_draft.pdf&quot;&gt;ANSI Smalltalk Standard v1.9 199712 NCITS X3J20 draft&lt;/a&gt;, Section 3.1 [page 9]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref4&quot;&gt;[4]&lt;/a&gt; Object-Oriented Software Construction (2nd Ed) by Bertrand Meyer [1997, page 1198]\&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref5&quot;&gt;[5]&lt;/a&gt; &lt;a href=&quot;http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf&quot;&gt;ISO International Standard ISO/IEC 14882:2014(E) – Programming Language C++, current working draft (at Aug, 2015)&lt;/a&gt;, section: 1.8 [intro.object] paragraph 1.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref6&quot;&gt;[6]&lt;/a&gt; &lt;a href=&quot;http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1539.pdf&quot;&gt;ISO/IEC 9899:201x Committee Draft – Programming languages — C (last draft available at Aug, 2015)&lt;/a&gt;, section: 13.15.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref7&quot;&gt;[7]&lt;/a&gt; &lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;Elements of Programming&lt;/a&gt; by Stepanov and McJones [2009, page 4]\&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;RefConcreteEntity&quot;&gt;EoP’s concrete entity definition: &lt;/a&gt; An abstract entity is an individual thing that is eternal and unchangeable, while a &lt;strong&gt;concrete entity&lt;/strong&gt; is an individual thing that comes into and out of existence in space and time… Blue and 13 are examples of abstract entities. Socrates and the United States of America are examples of concrete entities…&lt;/p&gt;
</content></entry><entry><title>Usando la terminología adecuada: ¿Método?</title><link rel="alternate" href="https://componentsprogramming.com/usando-la-terminologia-adecuada-metodo/"/><id>https://componentsprogramming.com/usando-la-terminologia-adecuada-metodo</id><published>2015-08-12T12:00:00.000Z</published><updated>2015-08-12T12:00:00.000Z</updated><content type="html">&lt;p&gt;En esta serie de artículos mi intención es revisar por qué los programadores usamos cierta terminología, ciertas palabras, algunas de las cuales considero inadecuadas.&lt;br&gt;
En este caso quiero hablar sobre la palabra &lt;em&gt;método&lt;/em&gt; (&lt;em&gt;method&lt;/em&gt; en inglés).&lt;/p&gt;
&lt;p&gt;Antes que nada…&lt;/p&gt;
&lt;h3 id=&quot;qué-es-un-método&quot;&gt;¿Qué es un &lt;em&gt;método&lt;/em&gt;?&lt;/h3&gt;
&lt;p&gt;Cualquier programador sabe que un &lt;a href=&quot;#Ref1&quot;&gt;&lt;em&gt;objeto&lt;/em&gt; [1]&lt;/a&gt; tiene &lt;em&gt;estado&lt;/em&gt; y &lt;em&gt;comportamiento&lt;/em&gt;.
El estado se almacena en &lt;em&gt;campos&lt;/em&gt; (&lt;em&gt;fields&lt;/em&gt; en inglés) y el comportamiento se logra a través de &lt;em&gt;métodos&lt;/em&gt;.&lt;br&gt;
Un &lt;em&gt;método&lt;/em&gt; (en el contexto de la programación) es una secuencia de instrucciones, es parte de un objeto o clase. &lt;a href=&quot;#Ref2&quot;&gt;[2]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Pero…&lt;/p&gt;
&lt;h3 id=&quot;por-qué-método&quot;&gt;¿Por qué “&lt;em&gt;método&lt;/em&gt;”?&lt;/h3&gt;
&lt;p&gt;¿Qué diferencia hay entre un &lt;em&gt;método&lt;/em&gt; y un &lt;em&gt;procedimiento&lt;/em&gt;?&lt;br&gt;
Un &lt;em&gt;procedimiento&lt;/em&gt; es una secuencia de instrucciones. &lt;a href=&quot;#Ref2&quot;&gt;[2]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;¿La única diferencia consiste en que un método debe pertenecer a una clase mientras en que un procedimiento no se aclara nada con respecto a clases? (De hecho el término
“procedimiento” es usado desde mucho antes de la existencia del término “clase”).&lt;/p&gt;
&lt;p&gt;Resumiendo, un método es un procedimiento que es miembro de una clase.&lt;br&gt;
Entonces, tenemos procedimientos que son &lt;em&gt;miembros&lt;/em&gt; y procedimientos &lt;em&gt;libres&lt;/em&gt; (fuera de una clase).&lt;/p&gt;
&lt;p&gt;Me sigo preguntando, …&lt;/p&gt;
&lt;h3 id=&quot;por-qué-usamos-el-término-método-y-no-procedimiento&quot;&gt;¿Por qué usamos el término “&lt;em&gt;método&lt;/em&gt;” y no “&lt;em&gt;procedimiento&lt;/em&gt;”?&lt;/h3&gt;
&lt;p&gt;Mi hipótesis es que con el establecimiento de &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_(programming_language)&quot;&gt;Java&lt;/a&gt; como uno de los lenguajes de programación más populares, también se produjo la popularización de su terminología. A partir de ese momento, otros lenguajes y programadores adoptan la terminología popularizada por Java y se vuelve más frecuente su uso que la terminología tradicional.&lt;/p&gt;
&lt;p&gt;Quiero ahora hacer una búsqueda a través de la historia de los lenguajes de programación para entender por qué comenzamos a llamar “método” a los “procedimientos”. Voy a ir desde tiempos más modernos a tiempos más remotos…&lt;/p&gt;
&lt;h3 id=&quot;java&quot;&gt;Java&lt;/h3&gt;
&lt;p&gt;En &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_(programming_language)&quot;&gt;Java&lt;/a&gt;, no existen los &lt;em&gt;procedimientos libres&lt;/em&gt;, todos los procedimientos deben ser miembro de una clase, estos procedimientos miembro efectivamente se llaman métodos.&lt;/p&gt;
&lt;p&gt;Según la &lt;a href=&quot;#Ref3&quot;&gt;especificación de Java 8 [3]&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The body of a class declares members (fields and methods and nested classes and interfaces), instance and static initializers, and constructors.&lt;/li&gt;
&lt;li&gt;Method declarations describe code that may be invoked by method invocation expressions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;La especificación de Java describe la relación entre un método y una clase, aunque no establece cuál es la definición de la palabra “método”.&lt;/p&gt;
&lt;p&gt;Más allá de la definición, en la especificación no vamos a encontrar por qué los diseñadores del lenguaje decidieron llamar “método” a los procedimientos, así que debemos ir más atrás.&lt;/p&gt;
&lt;p&gt;Java hereda la mayor parte de su sintaxis (no así su semántica) y terminología de &lt;a href=&quot;https://en.wikipedia.org/wiki/C%2B%2B&quot;&gt;C++&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;c&quot;&gt;C++&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/C%2B%2B&quot;&gt;C++&lt;/a&gt; nace, a finales de la década de 1970, como un súper-conjunto del &lt;a href=&quot;https://en.wikipedia.org/wiki/C_(programming_language)&quot;&gt;lenguaje de programación C&lt;/a&gt; con el agregado tecnología de objetos.&lt;/p&gt;
&lt;p&gt;Por lo tanto, en C++ tenemos procedimientos miembros y libres, denominados &lt;em&gt;member&lt;/em&gt; y &lt;em&gt;non-member functions&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Según el &lt;a href=&quot;#Ref4&quot;&gt;estándar de C++ [4]&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Member functions: Functions declared in the definition of a class, excluding those declared with a friend specifier, are called member functions of that class.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;O sea, en C++ no se usa la palabra “método”. Puede que algunos programadores C++ usen la palabra “método” debido a que el término es muy popular hoy día; pero, tanto el estándar C++ como los programadores más cercanos al riñón del lenguaje no lo utilizan.&lt;/p&gt;
&lt;p&gt;Entonces… ¿Cuál es el término correcto para designar el código que modela el comportamiento de los objetos? ¿Es “método”? ¿Es “procedimiento”? ¿Qué lenguaje usa la terminología más adecuada?&lt;/p&gt;
&lt;p&gt;Para ello debo ir aún más atrás.&lt;br&gt;
C++ hereda su “parte” de objetos del &lt;a href=&quot;https://en.wikipedia.org/wiki/Simula&quot;&gt;lenguaje de programación Simula&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;simula&quot;&gt;Simula&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Simula&quot;&gt;Simula&lt;/a&gt; es considerado el primer lenguaje de programación &lt;em&gt;orientado a objetos&lt;/em&gt;.
Es un lenguaje de tipado estático basado en &lt;a href=&quot;https://en.wikipedia.org/wiki/ALGOL_60&quot;&gt;ALGOL 60&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Simula permite que los procedimientos sean declarados dentro de una clase y también fuera de ella. A los primeros los denomina &lt;em&gt;local procedures&lt;/em&gt; y a los últimos &lt;em&gt;non-local procedures&lt;/em&gt;. &lt;a href=&quot;#Ref5&quot;&gt;[5]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Entonces, si C++ y Simula no hacen mención a algo llamado “método”, ¿De dónde saca Java esa palabra? ¿Es una invención de los diseñadores del lenguaje? ¿La copia de algún otro lenguaje?&lt;/p&gt;
&lt;p&gt;La respuesta es…&lt;/p&gt;
&lt;h3 id=&quot;smalltalk&quot;&gt;Smalltalk&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Smalltalk&quot;&gt;Smalltalk&lt;/a&gt; es un lenguaje de programación orientado a objetos, inspirado en Simula (en parte), que fue desarrollado durante la década de 1970 y vio la luz a principios de los 80’s.
A diferencia de Simula, Smalltalk es un lenguaje de tipado dinámico.&lt;/p&gt;
&lt;p&gt;Smalltalk incorpora los conceptos de mensajes y métodos.&lt;/p&gt;
&lt;p&gt;Según el &lt;a href=&quot;#Ref6&quot;&gt;estándar de Smalltalk [6]&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A message is a request to perform a designated computation. An object is a computational entity
that is capable of responding to a well defined set of messages. An object may also encapsulate
some (possibly mutable) state.&lt;/li&gt;
&lt;li&gt;An object responds to a message by executing a method. Each method is identified by an
associated method selector. A behavior is the set of methods used by an object to respond to
messages.&lt;/li&gt;
&lt;li&gt;A method consists of a sequence of expressions. Program execution proceeds by sequentially
evaluating the expressions in one of more methods. There are three types of expressions:
assignments, message sends, and returns.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Como no pude encontrar referencias anteriores a Smalltalk sobre algún otro lenguaje que utilice la palabra “método”, le consulté a &lt;a href=&quot;http://www.softwarepreservation.org/author/pmcjones&quot;&gt;Paul McJones&lt;/a&gt;, miembro del &lt;a href=&quot;http://www.softwarepreservation.org/&quot;&gt;Software Preservation Group&lt;/a&gt; y coautor de &lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;Elements of Programming&lt;/a&gt;. Considero a Paul una eminencia en lo que respecta a historia de la computación y en particular los lenguajes de programación.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Fernando: … Do you know any programming language, before Smalltalk, that use the word “method”? …&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Paul: You ask a very interesting question. I think you are correct that the word “method” was first used in that sense by the Smalltalk community. I looked through some early documents, such as the Smalltalk-72 Instruction Manual, and I don’t see “method” being used yet…
Dan Ingalls’s 1978 POPL paper on Smalltalk-76 is the earliest paper I’ve found so far that uses method in the sense you are interested in…&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Paul cree, al igual que yo, que la palabra “método” fue usada por primera vez por la comunidad de programadores Smalltalk. Además me indica que estuvo revisando viejos manuales y en el manual de Smalltalk-72 &lt;a href=&quot;#Ref7&quot;&gt;[7]&lt;/a&gt; no se hace mención sobre “método”, pero sí es mencionado en un paper de 1978 que habla sobre Smalltalk-76. &lt;a href=&quot;#Ref8&quot;&gt;[8]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;O sea, estoy casi seguro que la comunidad Smalltalk acuñó el término, pero no lo hizo desde el principio sino a medida que el lenguaje fue evolucionando.&lt;/p&gt;
&lt;h3 id=&quot;otros-lenguajes&quot;&gt;Otros lenguajes&lt;/h3&gt;
&lt;p&gt;Quiero aquí analizar otros lenguajes que también soportan tecnología de objetos para verificar como nomenclan a sus procedimientos.&lt;/p&gt;
&lt;h3 id=&quot;eiffel&quot;&gt;Eiffel&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Eiffel_(programming_language)&quot;&gt;Eiffel&lt;/a&gt; es un lenguaje que nace a mediados de 1980 y, al igual que C++, es heredero directo de Simula.&lt;/p&gt;
&lt;p&gt;En Eiffel todo miembro de una clase se lo llama &lt;em&gt;feature&lt;/em&gt;. Al estado se lo denomina &lt;em&gt;attributes&lt;/em&gt; y al comportamiento &lt;em&gt;routines&lt;/em&gt;. A su vez, las &lt;em&gt;routines&lt;/em&gt; se dividen en &lt;em&gt;functions&lt;/em&gt; y &lt;em&gt;procedures&lt;/em&gt; dependiendo si retornan o no un resultado. &lt;a href=&quot;#Ref9&quot;&gt;[9]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;En Eiffel todas las &lt;em&gt;routines&lt;/em&gt; son miembros de una clase, no se permite la existencia de procedimientos libres.&lt;/p&gt;
&lt;h3 id=&quot;python&quot;&gt;Python&lt;/h3&gt;
&lt;p&gt;El lenguaje de programación &lt;a href=&quot;https://en.wikipedia.org/wiki/Python_(programming_language)&quot;&gt;Python&lt;/a&gt; admite tanto procedimientos libres como procedimientos miembros. Los denomina &lt;em&gt;functions&lt;/em&gt; y &lt;em&gt;methods&lt;/em&gt; respectivamente. &lt;a href=&quot;#Ref10&quot;&gt;[10]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Python me llamó la atención porque es creado unos años antes que Java; la primera implementación de Python es de 1989 &lt;a href=&quot;#Ref11&quot;&gt;[11]&lt;/a&gt; mientras que la primera de Java es de 1995 &lt;a href=&quot;#Ref12&quot;&gt;[12]&lt;/a&gt;.&lt;br&gt;
Pareciera que este hecho rompe mi conjetura de que Java fue el &lt;em&gt;impulsor&lt;/em&gt; de la palabra “método”.&lt;/p&gt;
&lt;p&gt;Si bien la primera implementación de Java sale a la luz en 1995, en tan solo unos años, en 1998, ya era unos de los lenguajes más populares. En cambio Python tuvo un camino bastante más lento hacia su popularización, recién comenzó a ser popular por los años 2003/2004. &lt;a href=&quot;#Ref13&quot;&gt;[13]&lt;/a&gt;&lt;br&gt;
Por lo que mi conjetura todavía sigue siendo válida, el impulsor de “método” fue Java y no Python.&lt;/p&gt;
&lt;p&gt;Volviendo a Python, la palabra “método” es mencionada en las versiones recientes (3.4.3 y 2.7.10) de la documentación del lenguaje.
Entonces dudé sobre si Python utiliza “método” desde sus orígenes o si fue mutando su terminología con el tiempo, sobre todo con la popularización de Java.&lt;br&gt;
Gracias a que los muchachos de &lt;a href=&quot;http://python.org&quot;&gt;python.org&lt;/a&gt; hacen un excelente trabajo manteniendo las versiones históricas de la documentación, pude verificar que la palabra “método” es utilizada desde la versión 0.9.1 &lt;a href=&quot;#Ref14&quot;&gt;[14]&lt;/a&gt; (salvo que la documentación haya sido alterada con el tiempo, pero confiemos en que no sea así).&lt;/p&gt;
&lt;p&gt;O sea, Python es el primer lenguaje, después de Smalltalk, en usar la palabra “método”. Al menos de los lenguajes que he podido verificar.&lt;/p&gt;
&lt;p&gt;Al igual que me lo pregunto con Java, ¿Por qué Python usa método y no algún otro término más común para esa época?.&lt;/p&gt;
&lt;p&gt;Nadie mejor que el creador del lenguaje, &lt;a href=&quot;https://en.wikipedia.org/wiki/Guido_van_Rossum&quot;&gt;Guido van Rossum&lt;/a&gt; para iluminarme. Me tomé el atrevimiento de escribirle un correo electrónico; Guido fue muy amable en responderme y permitir que lo cite en este artículo:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Fernando: Why did you use “method” instead of any other word? Have you taken from Smalltalk?  Or,… from any other programming language?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Guido: Good question. I don’t recall, but it’s likely that I was somehow influenced by Smalltalk, or people around me who were influenced by Smalltalk. I definitely opened a big book about Smalltalk to learn about byte code, and I also recall we had a Smalltalk implementation that we sometimes played with (some things that were wrong with that influenced some of my philosophy for Python).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Guido no recuerda bien, pero admite haber sido influenciado por Smalltalk en aquella época.&lt;/p&gt;
&lt;h3 id=&quot;c-1&quot;&gt;C#&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/C_Sharp_(programming_language)&quot;&gt;C#&lt;/a&gt; es un lenguaje de programación que nace siendo muy similar a Java (casi idéntico) con algunas reminiscencias de C++.
Luego, con los años el lenguaje formó su propia identidad.&lt;/p&gt;
&lt;p&gt;C# copia en su gran mayoría la terminología de Java. Una de las palabras que copia es “método”.&lt;/p&gt;
&lt;p&gt;Según el &lt;a href=&quot;#Ref15&quot;&gt;estándar C# [15]&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A method is a member that implements a computation or action that can be performed by an object or class.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A diferencia de Java, el estándar C# sí define el significado de la palabra “método”.&lt;/p&gt;
&lt;p&gt;Al ser un lenguaje muy usado, especialmente por seguidores de la “filosofía” Microsoft, C# también ha contribuido a la popularización del término.&lt;/p&gt;
&lt;h3 id=&quot;objective-c&quot;&gt;Objective-C&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Objective-C&quot;&gt;Objective-C&lt;/a&gt; es un lenguaje desarrollado a principios de los 1980’s. Al igual que C++, nace como un súper-conjunto de C al que se le agrega tecnología de objetos.&lt;br&gt;
A diferencia de C++, el modelo de objetos de Objective-C está basado en Smalltalk y no en Simula.&lt;/p&gt;
&lt;p&gt;Objective-C cuenta con el concepto de mensajes y también el de método. &lt;a href=&quot;#Ref16&quot;&gt;[16]&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;lenguajes-anteriores-a-smalltalk&quot;&gt;Lenguajes anteriores a Smalltalk&lt;/h3&gt;
&lt;p&gt;He buscado en manuales, estándares y documentación de lenguajes de programación anteriores a Smalltalk, no relacionados con &lt;em&gt;orientación a objetos&lt;/em&gt;, pero sí muy reconocidos por su influencia sobre los demás lenguajes de programación.&lt;br&gt;
Específicamente los lenguajes son: &lt;a href=&quot;https://en.wikipedia.org/wiki/Fortran&quot;&gt;Fortran&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/ALGOL&quot;&gt;Algol&lt;/a&gt; y &lt;a href=&quot;https://en.wikipedia.org/wiki/C_(programming_language)&quot;&gt;C&lt;/a&gt;. En la documentación de ninguno de ellos se hace mención a la palabra “método”. En cambio usan términos como &lt;em&gt;routine&lt;/em&gt;, &lt;em&gt;subroutine&lt;/em&gt;, &lt;em&gt;procedure&lt;/em&gt; o &lt;em&gt;function&lt;/em&gt; &lt;a href=&quot;#Ref17&quot;&gt;[17]&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;otras-fuentes&quot;&gt;Otras fuentes&lt;/h3&gt;
&lt;p&gt;Para mejorar mi investigación he hecho una búsqueda en la bibliografía (sobre programación en general) que tengo a mi disposición, textos que considero clásicos.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;Elements of Programming&lt;/a&gt; by Alexander A. Stepanov and Paul McJones&lt;/li&gt;
&lt;li&gt;The Art of Computer Programming Volumes 1, 2, 3 and 4A by Donald E. Knuth&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;En ninguna de las 3.456 páginas de estos 5 libros he encontrado la palabra “método” haciendo referencia a un “procedimiento”. Obviamente la palabra “método” aparece en varias oportunidades, pero no en el sentido que estoy buscando.&lt;/p&gt;
&lt;h3 id=&quot;pendientes&quot;&gt;Pendientes&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Leer documentación/manuales originales sobre los siguientes lenguajes de programación:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lisp&lt;/li&gt;
&lt;li&gt;Scheme&lt;/li&gt;
&lt;li&gt;Ada&lt;/li&gt;
&lt;li&gt;Modula-2&lt;/li&gt;
&lt;li&gt;Common Lisp&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Buscar en algunos textos clásicos:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Discipline-Programming-Edsger-W-Dijkstra/dp/013215871X/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1440444447&amp;amp;sr=1-1&quot;&gt;A Discipline of Programming&lt;/a&gt; by Edsger W. Dijkstra&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Algorithms-Data-Structures-Niklaus-Wirth/dp/0130220051/ref=pd_sim_14_5?ie=UTF8&amp;amp;refRID=1WFYYC7DTMCR58G3TVVA&quot;&gt;Algorithms and Data Structures&lt;/a&gt; by Niklaus Wirth&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Structured-Programming-A-P-I-C-studies-processing/dp/0122005503/ref=pd_sim_14_3?ie=UTF8&amp;amp;refRID=1WFYYC7DTMCR58G3TVVA&quot;&gt;Structured Programming, First Edition Edition&lt;/a&gt; by Edsger W. Dijkstra, C. A. R. Hoare and Ole-Johan Dahl&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Systematic-Programming-Introduction-Prentice-Hall-Computation/dp/0138803692/ref=pd_sim_14_4?ie=UTF8&amp;amp;refRID=0E9BAZYMCCHZFEB38592&quot;&gt;Systematic Programming: An Introduction&lt;/a&gt; by Niklaus Wirth&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enviar mi consulta a los siguientes diseñadores de lenguajes de programación:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Alan Kay&lt;/li&gt;
&lt;li&gt;Dan Ingalls&lt;/li&gt;
&lt;li&gt;Dick Gabriel&lt;/li&gt;
&lt;li&gt;James Gosling&lt;/li&gt;
&lt;li&gt;Anders Hejlsberg&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;He tratado de contactar a alguno de ellos, pero no he recibido respuesta aún.&lt;/p&gt;
&lt;h2 id=&quot;conclusiones&quot;&gt;Conclusiones&lt;/h2&gt;
&lt;p&gt;La palabra “método” ha sido introducida al mundo de la programación por el lenguaje Smalltalk. Al ser un lenguaje prácticamente no usado en la industria, la palabra no era muy conocida allá por los 80’s y principios de los 90’s.&lt;/p&gt;
&lt;p&gt;Quizás fue un error de los diseñadores de Smalltalk el no haber utilizado nomenclatura existente, o quizás no fue un error, ya que Smalltalk introdujo un modelo de objetos distinto al de Simula y ese cambio quizás ameritó un cambio de nombres. Es muy difícil de determinar si fue una decisión equivocada o no.&lt;/p&gt;
&lt;p&gt;Java y Python adoptan terminología de Smalltalk en su vocabulario. No encuentro un vínculo muy fuerte entre Smalltalk y Java/Python que justifique el uso del término, esto me hace pensar en que el uso de “método” es un error en estos lenguajes. Aunque, como dije antes, es muy difícil de juzgar si la decisión de usar cierta nomenclatura es errónea.&lt;/p&gt;
&lt;p&gt;C++, Objective-C y Eiffel utilizan terminología similar a sus predecesores, puede que con algunas variaciones, que pueden ser mínimas o necesarias para adaptarse a cambios introducidos por los lenguajes.&lt;/p&gt;
&lt;p&gt;Algunos lenguajes, como C#, copian características de Java, pero también copian el “error” de incorporar “método” a su terminología.&lt;/p&gt;
&lt;p&gt;La palabra “método” se &lt;strong&gt;infiltra&lt;/strong&gt; en el vocabulario de los programadores.&lt;br&gt;
Ya no hay vuelta atrás ;)&lt;/p&gt;
&lt;p&gt;Usted use el término que más le guste, yo me voy a seguir usando &lt;strong&gt;procedimiento&lt;/strong&gt; o &lt;strong&gt;función&lt;/strong&gt; (siempre y cuando recuerde que no me gusta la palabra “método”).&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;agradecimientos&quot;&gt;Agradecimientos&lt;/h2&gt;
&lt;p&gt;Un agradecimiento especial para Paul McJones y Guido van Rossum por responder amablemente a mis preguntas y por brindarme información trascendental.&lt;br&gt;
También quiero agradecer a Mario dal Lago y Javier Velilla por revisar el artículo y sugerir correcciones.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;notas--referencias&quot;&gt;Notas / Referencias&lt;/h2&gt;
&lt;p&gt;&lt;a name=&quot;Ref1&quot;&gt;[1]&lt;/a&gt; Aquí nos referimos a la definición de “objeto” en el contexto de la &lt;em&gt;Programación Orientada a Objetos&lt;/em&gt;:&lt;br&gt;
      Object-Oriented Software Construction (2nd Ed) by Bertrand Meyer [1997, page 1198]&lt;br&gt;
Que difiere de la definición de “objeto” dada en:&lt;br&gt;
      &lt;a href=&quot;http://www.elementsofprogramming.com/&quot;&gt;Elements of Programming&lt;/a&gt; by Stepanov and McJones [2009, page 4]&lt;br&gt;
Esta última definición es la preferida por el autor del blog, en caso de que no se aclare a cuál de las dos definiciones se hace referencia, el lector debe asumir que se está hablando de la definición dada por Stepanov.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref2&quot;&gt;[2]&lt;/a&gt; Definición simplificada, para una definición más detallada referirse a:&lt;br&gt;
      Object-Oriented Software Construction (2nd Ed) by Bertrand Meyer [1997, page 174]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref3&quot;&gt;[3]&lt;/a&gt; &lt;a href=&quot;https://docs.oracle.com/javase/specs/jls/se8/jls8.pdf&quot;&gt;The Java Language Specification (Java SE 8 Edition)&lt;/a&gt;, Chapter 8 [pages 191, 192]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref4&quot;&gt;[4]&lt;/a&gt; &lt;a href=&quot;http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf&quot;&gt;ISO International Standard ISO/IEC 14882:2014(E) – Programming Language C++, current working draft (at Aug, 2015)&lt;/a&gt;, sections: 9.3 [class.mfct] and 8.3.5 [dcl.fct]\&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref5&quot;&gt;[5]&lt;/a&gt; Hay muy poca bibliografía disponible acerca del lenguaje, pero &lt;a href=&quot;http://www.edelweb.fr/Simula/&quot;&gt;aquí&lt;/a&gt; pueden encontrar un excelente trabajo de recopilación de viejos manuales.\&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref6&quot;&gt;[6]&lt;/a&gt; &lt;a href=&quot;http://smalltalk.org/versions/ANSISmalltalk/ANSISmalltalkStandard_v1.9_199712_NCITS_X3J20_draft.pdf&quot;&gt;ANSI Smalltalk Standard v1.9 199712 NCITS X3J20 draft&lt;/a&gt;, Section 3.1 [page 9]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref7&quot;&gt;[7]&lt;/a&gt; Smalltalk-72 Instruction Manual by Adele Goldberg and Alan Kay [page 44]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref8&quot;&gt;[8]&lt;/a&gt; &lt;a href=&quot;https://classes.soe.ucsc.edu/cmps112/Spring03/readings/Ingalls78.html&quot;&gt;The Smalltalk-76 Programming System. Design and Implementation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref9&quot;&gt;[9]&lt;/a&gt; Se especifica en:&lt;br&gt;
      Object-Oriented Software Construction (2nd Ed) by Bertrand Meyer [1997, pages 174, 175]&lt;br&gt;
y en:&lt;br&gt;
      &lt;a href=&quot;http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-367.pdf&quot;&gt;Standard ECMA-367. Eiffel: Analysis, Design and Programming Language. 2nd edition (June 2006)&lt;/a&gt;, Section 8.5.10 [page 38]\&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref10&quot;&gt;[10]&lt;/a&gt; &lt;a href=&quot;https://docs.python.org/2/download.html&quot;&gt;Python 2.7.10 Documentation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref11&quot;&gt;[11]&lt;/a&gt; &lt;a href=&quot;http://python-history.blogspot.com.ar/2009/01/brief-timeline-of-python.html&quot;&gt;A Brief Timeline of Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref12&quot;&gt;[12]&lt;/a&gt; &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/overview/javahistory-index-198355.html&quot;&gt;The History of Java Technology&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref13&quot;&gt;[13]&lt;/a&gt; Sobre la popularización de los lenguajes, una de las fuentes en las que me baso es &lt;a href=&quot;http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html&quot;&gt;Tiobe Index&lt;/a&gt;. Aunque tengo ciertas dudas sobre el método de medición de Tiobe, hoy en día es lo mejor que tenemos.&lt;br&gt;
La otra fuente es mi memoria. No recuerdo a Python como un lenguaje popular en los 90’s.&lt;br&gt;
Yo creo que Python comienza a popularizarse con el boom de los lenguajes dinámicos a comienzo de los 2000’s y tiene un empuje aún mayor con la creación del framework web &lt;a href=&quot;https://en.wikipedia.org/wiki/Django_(web_framework)&quot;&gt;Django&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref14&quot;&gt;[14]&lt;/a&gt; &lt;a href=&quot;https://www.python.org/ftp/python/src/&quot;&gt;Repositorio de viejas versiones de Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref15&quot;&gt;[15]&lt;/a&gt; &lt;a href=&quot;http://www.ecma-international.org/publications/standards/Ecma-334.htm&quot;&gt;Standard ECMA-334. C# Language Specification. 4th edition (June 2006)&lt;/a&gt;, Section 8.7.3 [page 34]&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref16&quot;&gt;[16]&lt;/a&gt; Objective-C no cuenta ni con un estándar ni una especificación. Lo más “formal” que encontré fue una página web:&lt;br&gt;
      &lt;a href=&quot;https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html&quot;&gt;Programming With ObjectiveC&lt;/a&gt;&lt;br&gt;
Kimberley Hagan me escribió para compartir un recurso que cree que puede ser valioso para programadores Objective-C, así que aquí dejo el enlace por si quieren pegarle una mirada:&lt;br&gt;
      &lt;a href=&quot;http://www.whoishostingthis.com/resources/objective-c/&quot;&gt;Objective-C: Guide and Resources&lt;/a&gt;\&lt;/p&gt;
&lt;p&gt;&lt;a name=&quot;Ref17&quot;&gt;[17]&lt;/a&gt; Para documentación sobre &lt;a href=&quot;http://www.softwarepreservation.org/projects/FORTRAN/&quot;&gt;FORTRAN&lt;/a&gt;, &lt;a href=&quot;http://www.softwarepreservation.org/projects/ALGOL/&quot;&gt;ALGOL&lt;/a&gt; y C: &lt;a href=&quot;http://www.open-std.org/JTC1/SC22/WG14/&quot;&gt;ISO/IEC JTC1/SC22/WG14 - The international standardization working group for the programming language C&lt;/a&gt;.&lt;/p&gt;
</content></entry></feed>