Design by contract in a spreadsheet!

Today I wanted to format a boolean value in a spreadsheet so that true values are shown as “Sì” and false as “No” (italian words for “yes” and “no”). I was easy as librelive describe in Change Boolean to Yes/No instead of True/False – Ask LibreOffice

i suggest basically the same as m.a.riosv wrote, but a little better:

in format cells dialogue fill format code input with the following:

[=1]"Yes";[=0]"No";General – this means it will be yes on true/1 values, no on false/0 values and will use general format otherwise.

one may even use the following string to format it as / instead of yes/no and color differentiation: [GREEN][=1]"✓";[RED][=0]"✗";[BLUE]General;[BLUE]@

this works on libreoffice calc v6.1.5.2 for ubuntu – i’ve tested

i call it “a little bit better” solution because it implements design by contract pattern, i.e. if for some unexpected reason the value will be something else than a boolean, then it will be displayed as usual, and not hidden, thus hiding a possible error in design!

But the real gem is finding a reference to design by contract!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.