Blog

  • Servicios públicos

    En el reino de Taifas en que resido hay, teóricamente, un servicio para acceder a los datos sanitarios: pedir y revisar citas, ver analíticas, medicación… Digo teóricamente porque no hay forma de acceder. Ni con Firefox, ni con Chrome, ni con Safari, ni con Tor, ni con Edge (así de aburrido estaba hoy), ni desde el móvil, ni desde un ordenador, ni con la mano derecha, ni con la mano izquierda, ni con la dentadura de mi suegra… se puede entrar en tal servicio.

    Desde fuera tiene buena pinta. Hasta sería útil. Si funcionase. Puede que sea porque hoy es miércoles. La semana pasada el error era distinto: simplemente no tenía constancia de mis datos, los mismos con los que puedo acceder a asturSalud (sin el posesivo).

    Volviendo a miasturSalud… ¿es cuestión de falta de interés (muy posible, es un servicio público desarrollado y gestionado por el peor postor)? ¿De falta de testing (remítase a la primera pregunta)? ¿De falta de monitorización del servicio? Es un problema endémico en este país (antes España) que los sistemas, tanto de cara al ciudadano como internos, sean extremadamente hostiles. Que las consultoras que los desarrollan/mantienen tengan la política de ‘si encontramos un fallo no lo arreglamos hasta que el cliente lo note y podamos facturarle’.

    Acepto que es mala época para los navegadores, con la seguridad cada vez más estricta (lo cual me parece estupendo aunque en algún caso me haya hecho arrancarme algunos de los pocos pelos que porto). Pero eso no es (no debería ser) una sorpresa para las empresas que usan un navegador como plataforma para proporcionar un servicio/aplicación/whatever. No hay tantos navegadores en los que testear, si se tiene interés en comprobar que cualquier usuario puede realmente acceder a nuestro producto. Quizás el problema es que para las consultoras que desarrollan/mantienen estos servicios el producto es el folleto que cuenta las bondades del servicio. Que luego funcione, ya tal.

    Finalmente una pregunta poco técnico… ¿qué pasa con las personas (más) mayores? ¿Cómo se manejan cuando tienen que usar uno de esos ‘servicios’?

  • He’s Alive!

    Restarting this blog after a short hiatus of just 10 years. Not that I didn’t write anything in that time. I just didn’t publish it.

    For now I’m reviewing the old posts, translating some to enlish, deleting those of them that were not relevant even 10 or 12 years ago and shaping up this WP instance.

  • Programando una extensión de Google Chrome

    Escribir una extensión para cualquier aplicación que lo soporte suele ser tan complicado como detallada sea la documentación que ofrece. En el caso que nos ocupa, Google Chrome, la documentación es bastante completa aunque haya que navegar por distintos negociados de la web de desarrolladores de Chrome para encontrar todas las piezas. Y una de las partes difíciles de encontrar es cómo depurar nuestra extensión. Usando como base la que se encuentra aquí vamos a entender un poco mejor como funcionan las extensiones para Google Chrome. (more…)

  • De la diferencia entre censura y autodefensa

    Esta entrada ha estado macerando en el disco duro durante un buen tiempo. Cubre un tema que no me gusta y que me convierte, a mis tiernos ojos, en algo que tampoco me gusta: un censurador. La excusa, nosotros contra ellos.

    Ellos son, esta vez, las empresas. Centrémonos en una empresa periodística. Transparente en casi todos sus aspectos. Con buen contenido, casi siempre. Esos “casis” aparecen por todas partes, en todos los aspectos de nuestras vidas. Pero esta empresa concreta se metió en un jardín: hazte socio y no verás publicidad. Casi. En su afán por conseguir contenido han perdido el control sobre lo que publican. O esa es la impresión que dan. (more…)

  • Be careful what and how you “optimize”

    Sometimes we tend to over-engineer our code. Just because we think it will look smarter, or run faster, or be more canon-compliant. Let’s take, for example, this function that gets a value from the server and translates it into a class name to apply to an element.

    angular.module('widgetTransactionsFilters', [])
           .filter('transactionType', function() {
    	return function(input) {
    		var strClass = 'type-0';
    
    		switch(input) {
    			case 'Payment Credit Card':
    				strClass = 'type-1';
    				break;
    			case 'Cash Withdrawl':
    				strClass = 'type-2';
    				break;
    			case 'Bill Payment':
    				strClass = 'type-3';
    				break;
    			case 'Salary':
    				strClass = 'type-4';
    				break;
    			case 'Online Transfer':
    				strClass = 'type-5';
    				break;
    		}
    		return strClass;
    	};
    });

    it’s not the most elegant filter, but hey, it’s mine! As they say, devil will find code for idle hands to refactor. In this case, I decided, don’t ask me why, to change the switch for an array lookup. To make it less legible, mainly. To make any changes to the filter slightly difficult? Who knows. In any case, this was the second version.

    angular.module('widgetTransactionsFilters', [])
           .filter('transactionType', function() {
    	return function(input) {	
    		return 'type-' + 
    				(['Payment Credit Card',
    				'Cash Withdrawl',
    				'Bill Payment',
    				'Salary',
    				'Online Transfer'].indexOf(input) + 1);
    	};
    });

    Despite my feeble attempts at AngularJS I know some things about JS. One of these things is that most of the array methods are not very optimized. So maybe it’s time to check which version is faster. Or less slow. Fortunately there’s an online tool that can help us to quickly solve this questions: jsperf.com.

    Using jsperf.com. you can create a set of tests that will be run in a loop for some time. The speed of the test will be determined by the number of loops executed in that time. Additionally you can run the same tests using different browsers in different platforms. This is specially useful when you’re optimizing your code for an hybrid app where you know the browser and the platform.

    You can code your setup, and add a number of tests. This is the setup:

    <script>
      Benchmark.prototype.setup = function() {
        function bySwitch(input) {
            var strClass = 'type-0';
        
            switch(input) {
                    case 'Payment Credit Card':
                            strClass = 'type-1';
                            break;
                    case 'Cash Withdrawal':
                            strClass = 'type-2';
                            break;
                    case 'Bill Payment':
                            strClass = 'type-3';
                            break;
                    case 'Salary':
                            strClass = 'type-4';
                            break;
                    case 'Online Transfer':
                            strClass = 'type-5';
                            break;
            }
            return strClass;
        }
        
        function byArray(input) {   
            return 'type-' + 
                            (['Payment Credit Card',
                            'Cash Withdrawal',
                            'Bill Payment',
                            'Salary',
                            'Online Transfer'].indexOf(input) + 1);
        }
      };
    </script>

    And these are the tests, along with the results.

    performance1

    As you can see, the array lookup is way more slow than the old fashioned switch. Not surprises here, people. The only surprise can be the huge difference of performance between Chrome Canary and WebKit when you perform the same test in both browsers.

    performance2

    Corollary: be careful when you start refactoring and always test the performance of your code.

    UPDATE: Vyacheslav Egorov, aka @mraleph, noticed this post and thankfully redirected me to this excellent presentation on how to avoid benchmarking pitfalls due to the JIT optimization. Basically “optimizer eats µbenchmarks for breakfast”.

    performance3

    I’ve modified the first function to force the switch input NOT to be treated by the compiler as a constant, by changing it from switch(input) to switch(input.toString()). And here are the updated results.

    performance4

    The difference is still there, both between browsers and ways to test for the string. But the number of iterations for each test shows that all (or most) of the code in each of my tests is being executed. Or so I hope. BTW, the benchmark is located here. Feel free to use and abuse it.

    So, the bottom line is: 1. don’t trust blindly in microbenchmarks, 2. don’t assume anything about the language and 3. run, don’t walk, to see mraleph’s presentation.