Por amor al código Code snippets y reflexiones sobre tecnología

¿Por qué Linux?

Escuchar este artículo: (audio generado con la API de tts de OpenAI)

Logos de GNU y Linux

Desde hace años uso Linux, tanto en el trabajo como en casa. Cambié a Linux gradualmente, no soy una persona de extremos y tardo un poco en sacarle el jugo a las cosas.

Al principio solo era curiosidad por probar un sistema operativo más seguro y más fiable. La primera vez que probé la línea de comandos en la facultad me pareció todo anticuado y sin sentido, pero poco a poco fui familiarizándome con los comandos para manejar archivos, con la estructura de directorios de Linux y con los gestores de paquetes.

Poco a poco te das cuenta de que puedes modificar y configurar TODO. Linux no es simplemente un Sistema Operativo, es un sistema libre, que puedes leer, modificar y replicar. Hay más código y documentación del que podrás leer, más comandos de los que puedes aprender, más libertad de la que podrías soñar con cualquier otro sistema operativo.

He escrito comandos en una línea que me costaría cientos escribir en JavaScript o en Python para tener la misma funcionalidad. La línea de comandos tiene herramientas increíbles y lo mejor es que cuando aprendes algo puedes guardar el comando, o ponerlo en un script y lo tienes para siempre.

Imaginemos una situación típica: Tienes un montón de fotos que quieres convertir a blanco y negro con un filtro concreto para ver como quedan, porque estás buscando la mejor o quieres decidir cuál imprimir o lo que sea. Abres tu programa de edición gráfico favorito (por ejemplo GIMP) seleccionas el filtro que quieres, los valores, ves como queda y guardas la foto. Si te sabes los atajos de teclado, tal vez guardar la foto o incluso abrir la siguiente foto para aplicarle el mismo filtro puede que sea un par de golpes de teclado. Si no, tienes que hacer todo esto otra vez para cada foto, persiguiendo iconos minúsculos con el ratón. De cualquier forma tienes que abrir, editar y guardar CADA FOTO. A veces haces click sin querer en la opción que no es, o te equivocas al guardar y machacas la foto original… Creo que es fácil que te resulte familiar esta escena. Lo que muchos pensamos cuando hacemos esto es “¿No hay una forma mejor? ¿Por que no puedo decirle al ordenador que haga con todas esas fotos lo que acabo de hacer con esa?” La conclusión suele ser que el ordenador es imbécil, cuando no es así, simplemente estamos usando la herramienta errónea.

En la línea de comandos buscas el comando una vez, lo pruebas, y podrás usarlo un millón de veces. Podrás usar un comodín para ejecutarlo sobre todas tus imágenes, o meterlo en un bucle, en un script, usarlo dentro de seis meses sobre una nueva remesa de fotografías simplemente invocando un alias.

Las posibilidades son infinitas, porque no dependes de una serie de acciones más o menos conocidas con el ratón, lo tienes escrito.

Las macros que no dependen del ratón, sino que guardan tus acciones y las ejecutan también son una solución, pero normalmente dependen del programa que las crea y no se pueden componer o exportar a otros programas. La línea de comandos es lo más universal que tenemos ahora mismo. Funciona igual en tu escritorio que en un servidor en AWS, puedes componer comandos de diferentes herramientas, puedes crear scripts y en resumen puedes hacer todo eso que creíais que el ordenador era demasiado tonto para hacer. Solo requiere un punto de vista diferente.

En The Linux Comand Line (pdf), William E. Shotts explica muy bien esa sensación de posibilidades sin límites, con una analogía con los Erector Construction Set (más conocidos como Mecano para mi generación)

Linux Is About Imagination

When I am asked to explain the difference between Windows and Linux, I often use a toy analogy.

Windows is like a Game Boy. You go to the store and buy one all shiny new in the box. You take it home, turn it on and play with it. Pretty graphics, cute sounds. After a while though, you get tired of the game that came with it so you go back to the store and buy another one. This cycle repeats over and over. Finally, you go back to the store and say to the person behind the counter, “I want a game that does this!” only to be told that no such game exists because there is no “market demand” for it. Then you say, “But I only need to change this one thing!” The person behind the counter says you can’t change it. The games are all sealed up in their cartridges. You discover that your toy is limited to the games that others have decided that you need and no more.

Linux, on the other hand, is like the world’s largest Erector Set. You open it up and it’s just a huge collection of parts. A lot of steel struts, screws, nuts, gears, pulleys, motors, and a few suggestions on what to build. So you start to play with it. You build one of the suggestions and then another. After a while you discover that you have your own ideas of what to make. You don’t ever have to go back to the store, as you already have everything you need. The Erector Set takes on the shape of your imagination. It does what you want. Your choice of toys is, of course, a personal thing, so which toy would you find more satisfying?

En In the begining was the command line Neal Stephenson compara los sistemas operativos con coches, y Linux con un tanque ligero, indestructible, que consume lo mismo que un coche y puede circular por ciudad, con voluntarios que lo mantienen y te explican cómo funciona, todo completamente gratis…

Fotografía de un tanque ligero

Imagine a crossroads where four competing auto dealerships are situated. One of them (Microsoft) is much, much bigger than the others. It started out years ago selling three-speed bicycles (MS-DOS); these were not perfect, but they worked, and when they broke you could easily fix them.

There was a competing bicycle dealership next door (Apple) that one day began selling motorized vehicles–expensive but attractively styled cars with their innards hermetically sealed, so that how they worked was something of a mystery.

The big dealership responded by rushing a moped upgrade kit (the original Windows) onto the market. This was a Rube Goldberg contraption that, when bolted onto a three-speed bicycle, enabled it to keep up, just barely, with Apple-cars. The users had to wear goggles and were always picking bugs out of their teeth while Apple owners sped along in hermetically sealed comfort, sneering out the windows. But the Micro-mopeds were cheap, and easy to fix compared with the Apple-cars, and their market share waxed.

Eventually the big dealership came out with a full-fledged car: a colossal station wagon (Windows 95). It had all the aesthetic appeal of a Soviet worker housing block, it leaked oil and blew gaskets, and it was an enormous success. A little later, they also came out with a hulking off-road vehicle intended for industrial users (Windows NT) which was no more beautiful than the station wagon, and only a little more reliable.

Since then there has been a lot of noise and shouting, but little has changed. The smaller dealership continues to sell sleek Euro-styled sedans and to spend a lot of money on advertising campaigns. They have had GOING OUT OF BUSINESS! signs taped up in their windows for so long that they have gotten all yellow and curly. The big one keeps making bigger and bigger station wagons and ORVs.

On the other side of the road are two competitors that have come along more recently.

One of them (Be, Inc.) is selling fully operational Batmobiles (the BeOS). They are more beautiful and stylish even than the Euro-sedans, better designed, more technologically advanced, and at least as reliable as anything else on the market–and yet cheaper than the others.

With one exception, that is: Linux, which is right next door, and which is not a business at all. It’s a bunch of RVs, yurts, tepees, and geodesic domes set up in a field and organized by consensus. The people who live there are making tanks. These are not old-fashioned, cast-iron Soviet tanks; these are more like the M1 tanks of the U.S. Army, made of space-age materials and jammed with sophisticated technology from one end to the other. But they are better than Army tanks. They’ve been modified in such a way that they never, ever break down, are light and maneuverable enough to use on ordinary streets, and use no more fuel than a subcompact car. These tanks are being cranked out, on the spot, at a terrific pace, and a vast number of them are lined up along the edge of the road with keys in the ignition. Anyone who wants can simply climb into one and drive it away for free.

Customers come to this crossroads in throngs, day and night. Ninety percent of them go straight to the biggest dealership and buy station wagons or off-road vehicles. They do not even look at the other dealerships.

Of the remaining ten percent, most go and buy a sleek Euro-sedan, pausing only to turn up their noses at the philistines going to buy the station wagons and ORVs. If they even notice the people on the opposite side of the road, selling the cheaper, technically superior vehicles, these customers deride them cranks and half-wits.

The Batmobile outlet sells a few vehicles to the occasional car nut who wants a second vehicle to go with his station wagon, but seems to accept, at least for now, that it’s a fringe player.

The group giving away the free tanks only stays alive because it is staffed by volunteers, who are lined up at the edge of the street with bullhorns, trying to draw customers’ attention to this incredible situation. A typical conversation goes something like this:

Hacker with bullhorn: “Save your money! Accept one of our free tanks! It is invulnerable, and can drive across rocks and swamps at ninety miles an hour while getting a hundred miles to the gallon!”

Prospective station wagon buyer: “I know what you say is true…but…er…I don’t know how to maintain a tank!”

Bullhorn: “You don’t know how to maintain a station wagon either!”

Buyer: “But this dealership has mechanics on staff. If something goes wrong with my station wagon, I can take a day off work, bring it here, and pay them to work on it while I sit in the waiting room for hours, listening to elevator music.”

Bullhorn: “But if you accept one of our free tanks we will send volunteers to your house to fix it for free while you sleep!”

Buyer: “Stay away from my house, you freak!”

Bullhorn: “But…”

Buyer: “Can’t you see that everyone is buying station wagons?”

Por último, quería volver a incidir en la propiedad más destacable de Linux, que cada vez parece más ahogada en esta nueva era de código abierto que no es código libre: Linux es Software Libre, no solo puedes ver el código, puedes ejecutarlo, copiarlo, distribuirlo. Está ahí para que todos podamos aprovecharlo y construir encima de él, ese es su gran valor y su gran fortaleza.

Si quieres comentar, corregir algo o contribuir, puedes hacerlo en twitter o en Github. Cualquier comentario, crítica o contribución será bien recibido.