Alcides Fonseca

40.197958, -8.408312

Windows 11 manages power depending on clean energy availability

Starting with this build, we are introducing the Power Grid Forecast API. This API empowers app developers to optimize app behavior, minimizing environmental impact by shifting background tasks to times when more renewable energy is available in the local electrical grid.
Announcing Windows 11 Insider Preview Build 26052 (via Terence Eden)

Guilherme, Paulo and I submitted a proposal of a similar service (but for server workloads, where it makes more sense) back in 2020 for an EDP competition. It was not fancy enough as it was mostly transparent (the API was a job queue).

Our team is working on making energy usage first-class in programming languages, so developers have a better understanding of their impact when making design decisions.

A Golden Era of Blogging

“It reminds me a lot of how blogging changed around 2005-2009, when ad money came pouring in, and while it was great for bloggers that previously were just publishing for the heck of it (myself included), eventually the money tainted the process as many people rushed to improve their bottom line, often at the expense of whole reason they created their sites.” — Today’s YouTubers are repeating the mistakes of yesterday’s bloggers by Matt Haughey

Love, passion, and curiosity — more than money — fuel the majority of posts that show up in my RSS feed every day and I love it.
Forget the days of Google Reader, now is a golden era of blogging.

A Golden Era of Blogging by Jim Nielsen

I have always only subscribed to passion-driven blogs, and not for profit endeavors (RedMonk maybe being the exception). But you do see the trend on Youtube as the quality decreases as YouTubers become need-to-pay-my-employees sized.

Portable EPUBs

A simple answer is to improve the PDF format. After all, we already have billions of PDFs — why reinvent the wheel?

— Will Crichton, in Portable EPUBs

I’ve met Will last year during SPLASH and besides having awesome game host presentation skills, he is also very passionate about this topic. LaTeX was made for a world where paper is king. But I don’t read papers in paper anymore, I read them on my laptop, frequently on external screens. Sometimes even on my phone. And let me tell you that most of the time I have to pan around to read a single line. We desperately need responsive layouts in most written form. eBooks got it right (but not all books were ported properly, and some will never be, and that’s okay).

[1]

I’ve learned a lot from his post, mainly about the advanced PDF capabilities that open-source software usually doesn’t support. You wouldn’t even need to extend the PDF format.

He proposes that the best practical solution is to use self-contained ePUB written in a safe subset of HTML, CSS and Javascript. His notion of safe is left too much for interpretation to my liking, but the overall idea is a good one.

And while ACM is looking into improving the status of accessibility in PDF papers and whitelisting packages that support HTML exporting, antagonizing computer scientists have relied on advanced macros for decades, ArXiV did without asking anyone’s permission.

I’m still not sure that an HTML-based format is the solution. I don’t think we have the proper authoring tools. Yes, we have TinyMCE and friends, but that has limited support for templating. Heck, even Microsoft FrontPage would give you better control over the layout, at the cost of unreadable source code. But designers want Adobe Indesign and QuarkXPress so they can have some control about pagination and whitespace. Maybe we need a new generation of those tools that also targets responsive HTML views?

But what doesn’t convince me the most is HTML, CSS and Javascript evolutions. Those are languages that have and will continue to evolve at a faster pace than PDF or Postscript. I argue for the tradeoff of having a very basic layout and content language with Active-X plugins that authors can use, at the cost of being lost in time, just like those awesome little Flash games that no-one can play anymore.

1 Curiously, I couldn’t hot link this image from his own post, probably due to the way the ePUB is being dynamically uncompressed.

The risks of open sourcing (imaginary) government LLMs

Let’s take a theoretical example. Suppose the Government trains an AI to assess appeals to, say, benefits sanctions. An AI is fed the text of all the written appeals and told which ones are successful and which ones aren’t. It can now read a new appeal and decide whether it is successful of not. Now let’s open source it.

Terrence Eden

Terrence explores the repercussions of open sourcing the training data, the training code and the trained weights of government data. I suggest reading the whole article, especially given that many Portuguese administrative organizations offer ChatGPT-based help.

How to generate random numbers in your head

Choose a 2-digit number, say 23, your “seed”.
Form a new 2-digit number: the 10’s digit plus 6 times the units digit.
The example sequence is 23 –> 20 –> 02 –> 12 –> 13 –> 19 –> 55 –> 35 –> …
and its period is the order of the multiplier, 6, in the group of residues relatively prime to the modulus, 10. (59 in this case).
The “random digits” are the units digits of the 2-digit numbers, ie, 3,0,2,2,3,9,5,… the sequence mod 10.

George Marsaglia via Hillel Wayne

The value of OpenSource

We estimate the supply-side value of widely-used OSS is $4.15 billion, but that the demand-side value is much larger at $8.8 trillion. We find that firms would need to spend 3.5 times more on software than they currently do if OSS did not exist. […] Further, 96% of the demand-side value is created by only 5% of OSS developers.

The Value of Open Source Software, Harvard Business School Strategy Unit, via Simon Willison

FFI troubleshoot in Haskell

When installing Haskell’s HLint via:

stack install hlint

I was getting the following error:


base-compat-batteries            > [  2 of 118] Compiling Control.Concurrent.Compat.Repl.Batteries                                          
hashable                         >                                                                                                          
hashable                         > /private/var/folders/3g/7tpj8zwx14qddcr3bt_w8jnr0000gn/T/stack-e594623fe9dbdb84/hashable-1.3.5.0/In file included from /var/folders/3g/7tpj8zwx14qddcr3bt_w8jnr0000gn/T/ghc52550_0/ghc_20.c:4:0: error:
hashable                         >                                                                                                          
hashable                         >                                                                                                          
hashable                         > In file included from /Users/alcides/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
hashable                         >                                                                                                          
hashable                         >                                                                                                          
hashable                         > /Users/alcides/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
hashable                         >      fatal error: 'ffitarget_arm64.h' file not found                                                     
hashable                         >   |                                                                                                      
hashable                         > 6 | #include "ffitarget_arm64.h"                                                                         
hashable                         >   |          ^                                                                                           
hashable                         > #include "ffitarget_arm64.h"                                                                             
hashable                         >          ^~~~~~~~~~~~~~~~~~~                                                                             
hashable                         > 1 error generated.                                                                                       
hashable                         > `gcc' failed in phase `C Compiler'. (Exit code: 1)   

The problem is that my clang was installed via home-brew. As such, there were a few missing paths. The solution was to run the following to find the location of this header:

find / -iname ffitarget_arm64.h

My output was:

find: /usr/sbin/authserver: Permission denied
find: /Library/Application Support/Apple/Screen Sharing/Keys: Permission denied
find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /Library/Application Support/Apple/Remote Desktop/Task Server: Permission denied
find: /Library/Application Support/Apple/Remote Desktop/Client: Permission denied
find: /Library/Application Support/ApplePushService: Permission denied
find: /Library/Application Support/com.expressvpn.ExpressVPN/data: Permission denied
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/ffi/ffitarget_arm64.h
/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include/ffi/ffitarget_arm64.h
...

Now you need to pick the first one (second to last line in the previous output) as copy the path up to include (inclusive). Now use it in the following line, or add it to your ~/.zshrc.

C_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/

Thank your family with Backups

It’s thanksgiving time in the US and we’re nearing Xmas time in many other places. I would recommend setting up backups for your loved ones as a wonderful and thoughtful gift.

Last month I had to deal with the loss of a relative’s entire photo library. She copied all the loose photos in ~/Pictures to Apple Photo’s (and therefore to ~/Pictures/Photos.photolibrary/) and, once she was done, she selected everything inside the Pictures folder, and deleted them. And to be sure, she also emptied her trashcan.

Because I hadn’t set up a backup for this particular machine, I had to spend two weekends recovering all deleted photos among many trash lost in the remains of the HDD. For this purpose, I recommend Disk Drill.

As for Backups, I really recommend Backblaze, as it automatically backups all files to their cloud. You have optional encryption (which I don’t use, so I can access the file explorer on their website, to do selective backups). It’s a solution for non-technical folks that happens in the background with no need for user action. They might need your help to do a restore, but that’s very acceptable in my opinion. It has saved me several times for my own laptop.

If you are using this for a more technical use, you should be aware that by default, it does not back up large files like virtual machines or disk images. You should change this in the settings. Having said this, I also keep one time machine in an external disk, and another one in my NAS.

Aventura com as Giras

Apesar de adorar o conceito das Giras, — bicicletas partilhadas, com docas para não ficarem em qualquer sítio, com um passe anual tão baixo (25 euros) que incentiva as pessoas a usarem-nas em vez de transportes públicos como o metro ou autocarros — a implementação não tem sido nada feliz.

É certo que as demoras causadas pela falha de contrato de fornecedor não ajudaram, mas a minha principal queixa é a qualidade do software. Não que as bicicletas estejam sempre perfeitas, mas há forma de reportar e pedir que as arranjem.

Software pouco aperfeiçoado

Ora o primeiro problema (de muito menor importância) é que a aplicação em iOS não integra com o gestor de passwords nativo, pelo que é necessário autenticar-me sempre que abro a aplicação. É irritante, mas não me impede de usar o sistema. E mostra a pouca atenção que dão à experiência de utilização.

Assumem que tudo é perfeito.

Um problema bem mais significativo é o facto de quando se levanta uma bicicleta e se descobre que ela não funciona (desde coisas simples como o motor não funcionar, até não ter travões) e a devolvemos na própria estação ou na seguinte num prazo de 2 minutos, ele considera uma viagem completa e não deixa levantar outra num espaço de 5 minutos. A minha sugestão é não ter esse intervalo se a viagem tiver sido curta, e ter sido dado uma pontuação baixa indicando o problema com a bicicleta. Para ser usada como meio de transporte, não pode ter tantos entraves. E não é algo tão incomum que não deva ser levado a sério. Acontece-me uma vez a cada duas semanas.

Usam dark patterns.

Por falar em reportar problemas: no final de cada viagem é obrigatório pontuar a viagem. E no caso da pontuação ser baixa, é obrigatório escrever algo. Com cinco estrelas já não é. Ora, quando uma pessoa tem pressa vai dar 5 estrelas só para não escrever nada.

Para além de não dever ser obrigatório escrever algo, devia haver uma lista de problemas mais comuns por onde escolher. Torna-se a denúncia de problemas muito mais simples, e evita terem alguém no back-office a processar as mensagens dos vários utilizadores.

A história

Ora certo dia fui de bicicleta para o trabalho. Ao chegar, entreguei a bicicleta na doca e ela trancou a bicicleta. No entanto, na aplicação a viagem continuava a decorrer. Não a pude cancelar na aplicação, porque isso permitiria a qualquer um cancelar viagens sem devolver a bicicleta. Como infelizmente tem sido normal (e confirmado pelo suporte técnico), a doca não comunicou com sucesso com o servidor que a bicicleta tinha sido recebida. E como não foi a primeira vez, fiz o procedimento recomendado: ligar para o apoio técnico e esperar 5 minutos que o assunto ficasse resolvido.

Mas ninguém me atendeu a chamada. Segui para o meu trabalho e fiz o dia completo, esquecendo-me completamente do assunto. Quando quis regressar a casa, abri a aplicação e reparei que tinha tido a viagem a decorrer até ao momento. Reiniciei a aplicação e ele (finalmente) apercebeu-se que a viagem terminou. Mas tinha-me levado a saldo negativo. Tentei ligar para o suporte técnico outra vez, mas também ninguém me atendeu desta vez. Tive de carregar o saldo da aplicação, para poder ter saldo positivo e fazer a minha viagem de regresso.

Em casa escrevi um email muito zangado. Não era a primeira vez que me acontecia e já tinha oferecido os meus serviços para tentar solucionar o problema.
Responderam ao email num PDF em anexo (??).Devolveram-me o custo da viagem, afirmando que era uma excepção e que a culpa era minha. Isto depois do suporte técnico ao telefone em vezes anteriores me confirmar que eram as docas que nem sempre reportavam bem a actividade. Quanto ao dinheiro extra que tive de usar para carregar o saldo desnecessariamente fica do lado dele, desse não abrem a mão.

Conclusão: o software da Gira é mau, não tem sido melhorado, e o suporte técnico atira primeiro a culpa para os utilizadores, e demora imenso a admitir que o problema é deles, e não está disponível a devolver dinheiro introduzido na plataforma. Claramente as plataformas concorrentes privadas não sofrem destes problemas, porque têm concorrência, e pretendem que os utilizadores usufruam ao máximo da plataforma. Em justiça para a Gira, nenhuma plataforma privada faria preços tão baixos. Mas não é motivo para não se esforçarem na qualidade do software.

The First Lecture of My Compilers Class

Every year I have taught compilers, I start the first class by writing a compiler, even before going into the syllabus. Students are aware of what a compiler is, but not necessarily how it works. This introduction gives them this context, and allows students to make better sense of the syllabus and the contents for the rest of the semester.

As this is a very limited compiler (both in scope, and in quality), identifying those challenges also gives a perspective of why is it relevant to spend one or two classes on parsing.

Weekly Links

Academia

Development

Programming Languages

Another Puzzle with z3

On twitter, I’ve found another puzzle that could be trivially solved using z3, and serves as a good introductory example. Here is a very simple solution:

Software Engineering Practices

  • Documentation in the same repo as the code
  • Mechanisms for creating test data
  • Rock solid database migrations
  • Templates for new projects and components
  • Automated code formatting
  • Tested, automated process for new development environments
  • Automated preview environments

(I really like his rejection of the term “best practices” here: I always feel it’s prescriptive and misguiding to announce something as “best”.) — Simon Willison

Understandable and Useful Error Messages for Liquid Types @ WITS2022

Early at the WITS workshop at this year’s POPL I presented why we need to improve the error messages of languages with liquid types, in order to increase adoption. This presentation resulted from our experiences using (LiquidHaskell) and developing (Aeon, LiquidJava and MLVP) languages with liquid types. They are very useful to have guarantees of correctness, but you usually don’t know if it is an error in the usage of functions, or in their specification. We end up proposing some suggestions to improve the state of the art, in which we are working on.

The video:

And the slides:

LiquidHaskell on the M1

Getting a M1 Max MacBook Pro, I had to figure out how to install all the software I had on my old Intel Mac. One of the most challenging was LiquidHaskell. Here are the instructions for others to save some time.

Install z3

LiquidHaskell requires an SMT solver to handle constraint-solving. Z3 is my go to solver.

brew install z3
z3 --version
# Z3 version 4.8.14 - 64 bit

Install LLVM 12

Because of this bug in homebrew’s LLVM 13 that solves other problems, we need LLVM 12.

brew install llvm@12

Install latest version of stack.

The stable version of stack will not install GHC on OSX arm installations. To overcome that, we need to install the latest version.

brew install --HEAD stack

Setup a Demo Repository

I recommend using this scaffold project to get LiquidHaskell running on the command line and VS Code. It might work on other editors, but I have not tested them.

git clone https://github.com/alcides/lh-plugin-demo.git
cd lh-plugin-demo
stack build
stack ghci

This last line should open ghci, doing all the liquid type verifications necessary. You should see two green lines with 1 and 3 constraints checked, respectively.

You can do the exercise of editing src/Demo/Lib.sh and changing x + 1 to x - 1 and running the command again. You should now see an error.

VSCode Configuration

Now that we have error reporting on the command-line, we can move to the more convenient code editor. In my case that means VSCode1.

The first step is to uninstall all Haskell plugins. Just trust me on this, they are all pretty much incompatible with each other, except when they aren’t. Now you need to install Simple GHC (Haskell) Integration. On the CLI:

brew install visual-studio-code
code --install-extension dramforever.vscode-ghc-simple

However, this will not work for a M1-unrelated reason: LiquidHaskell and Haddock are not compatible (unfortunately). So the first step is to disable it.

Go to Settings > Extensions > GHC Simple config > Ghc Simple > Startup Commands and remove :set -haddock.

Cmd+shit+P and select GHC: Restart GHCi Sessions if it doesn’t restart on its own.

And now you should have localized errors in your Haskell files.

1 Textmate’s support for Haskell is pretty minimal. Stack and Cabal support is completely missing.

Enforcement by Software

Suppose, for example, that your driver’s license is on your mobile phone. (…) You no longer need to go to a government office to get your new driver’s license. However, it now makes it possible for a civil servant to decide that you cannot drive your car on Tuesdays. They do not need a new law, they do not need your consent, they can just switch a flag inside a server.

Enforcement by Software by Daniel Lemire

This is something that has been worrying me, especially in the cases where software doesn’t follow the law and leads tens or thousands of users to follow processes illegally, just because there is no other way of doing it. Maybe society should invest more in legal verification of software and processes.

Installing Lean4 on the M1 architecture

I upgraded to a new M1Max MacbookPro (will have to review it next), and I had to install lean4 today. Unfortunately, elan does not work in the M1 architecture as expected, so I had to use rosetta. here’s how I set it up:

1. Install VSCode: brew install --cask visual-studio-code && code --install-extension jroesch.lean
2. Install Rosetta2 /usr/sbin/softwareupdate --install-rosetta --agree-to-license
3. Install elan manually: curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | arch -x86_64 sh
4. Install latest lean: elan default leanprover/lean4:nightly
5. Configure the lean path in the lean4 vs code extension to point to this lean: “Lean4: Executable Path” to arch -x86_64 lean

It will work. Now let’s hope that elan adds supports for arm64 binary fetching.

T-shaped People and Academia

When I’m looking for potential students, I always try to identify T-shaped people: those who can go deep into one topic, but also have a broad view of other aspects of Software Engineering. But what Bastien Rieck says is completely true.

In any case, many graduate schools and resume reviewers tend to ignore the breadth of a person’s skills, focusing instead only on the depth.

T-Shaped People and Academia, by Bastien Rieck

T-shaped people not only help in several aspects of the development of a project, but also identify bridges with other areas, and allow your work to be applied to other problems.

ImportError in numpy caused by missing libgfortran

Today I got the following error when executing regular numpy code in my homebrew Python3.9 installation.

ImportError: dlopen(/usr/local/lib/python3.9/site-packages/scipy/linalg/_fblas.cpython-39-darwin.so, 0x0002): Library not loaded: /usr/local/opt/gcc/lib/gcc/10/libgfortran.5.dylib Referenced from: /usr/local/lib/python3.9/site-packages/scipy/linalg/_fblas.cpython-39-darwin.so Reason: tried: '/usr/local/opt/gcc/lib/gcc/10/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file)

The issue was that I had gcc 11 installed (you can check via brew info gcc), but homebrew-installed bumpy expected gcc 10 to be installed.

Reinstalling numpy from bottle or from source didn’t work.

The workaround:

brew install gcc@10
sudo ln -s /usr/local/opt/gcc@10/lib/gcc/10/libgfortran.dylib /usr/local/lib/libgfortran.5.dylib  
sudo ln -s /usr/local/opt/gcc@10/lib/gcc/10/libquadmath.0.dylib /usr/local/lib/libquadmath.0.dylib