hisham hm

🔗 Receita de frango ao curry

Ingredientes:

* 400g de peito de frango
* 1 caixinha de creme de leite (200 ml)
* 3 colheres de sopa de curry
* 1 colher de sopa de açafrão
* 2 colheres de sopa de açúcar mascavo
* 2 colheres de sopa de shoyu
* 1 copo de água filtrada
* 2 colheres de sopa de manteiga
* 1 pitada de pimenta-do-reino
* cebola e alho a gosto (a receita original listava 2 cebolas pequenas e 3 dentes de alho)

Modo de Preparo:

* Corte o frango em cubinhos.
* Coloque a cebola e o alho para fritar na manteiga (quando a cebola começar a amolecer, acrescente o alho)
* Quando o alho começar a cheirar, acrescente o curry, a pimenta, o açafrão e o frango.
* Refogar mexendo por cerca de 3 minutos.
* Acrescentar o açúcar mascavo e mexer novamente.
* Acrescente a água, aos poucos, sempre mexendo.
* Acrescente o shoyu (a receita original não dizia em que passo acrescentar o shoyu)
* Deixar cozinhar em fogo médio, até reduzir a água e formar um molho um pouco mais grosso (cerca de 15 minutos, depende do fogão).
* Experimente o frango para ver se ficou bem cozido (o frango, quando cozido, reduz bastante seu tamanho original).
* Acrescente o creme de leite, mexendo sempre e baixe o fogo.
* Cozinhe por cerca de 2 minutos, ou até o creme aquecer.
* Sirva com arroz.

Fonte: https://cozinhadaraquel.blogspot.com/2006/08/frango-ao-curry-com-creme-de-leite.html

🔗 When listing repeated things, make pyramids

Often, in code, we have to write lists of repeated things. For example, attribute initialization in Java constructors:

this.foo = foo;

or required modules in Lua:

local foo = require("foo")

There are a few different ways people stack these when they need to list a number of them: randomly, alphabetic, aligned… working on a codebase that has all these approaches in different modules, I realized that “pyramid” is best. Let’s compare a few examples:

Random

This is what you end up doing if you don’t really think about it:

this.medium = medium;
this.aLongOne = aLongOne;
this.foo = foo;
this.veryLongOne = veryLongOne;
this.short = short;

⊖ ⊖ very bad to read - your eyes move back and forth horizontally and need to scan the whole thing vertically
easy to maintain - just add or remove entries arbitrarily

Alphabetical

This is what you end up doing if you get annoyed about the order when writing. I did this for a while.

this.aLongOne = aLongOne;
this.foo = foo;
this.medium = medium;
this.short = short;
this.veryLongOne = veryLongOne;

bad to read - your eyes move back and forth horizontally, but it’s easy to scan vertically
easy to maintain - no question where a new entry should go

Aligned

This is what you end up doing if you start to get annoyed when reading. Readability is more important than writability, after all!

this.aLongOne    = aLongOne;
this.foo         = foo;
this.medium      = medium;
this.short       = short;
this.veryLongOne = veryLongOne;

⊕ ⊕ very easy to read easy on the eyes horizontally, and if alphabetical it’s easy vertically as well
⊖ ⊖ very bad to maintain terrible for diffs, changes mess up `git blame` for unrelated lines

Pyramid

Finally, we get to the pyramid, which seems an ideal compromise keeping the advantages of an aligned list while avoiding its drawbacks:

this.veryLongOne = veryLongOne;
this.aLongOne = aLongOne;
this.medium = medium;
this.short = short;
this.foo = foo;

easy to read - easy on the eyes horizontally as the eyes follow the diagonal, and easy vertically as well as you usually know if you’re looking for a long or short word
easy to maintain - no question where entries go; you can use alphabetical order as a tie breaker for entries of same length

You can of course do the pyramid “ascending” or “descending”. I don’t really have a preference (and I couldn’t find any practical advantages to either yet).

In conclusion, it’s a silly little thing, but something that improves the ergonomics of the code and which I’ll try to adopt in my code more consistently from now on.

(PS: Of course, all of this applies to lists where the entries are not semantically related: when listing color components one would always do “red, green, blue”, and not “green, blue, red” :) )


Follow

🐘 MastodonRSS (English), RSS (português), RSS (todos / all)


Last 10 entries


Search


Admin