Skip to main content

On Debugging

One of the stand-out collaborations of my career has been with my buddy Damien George. He's the creator of MicroPython ~ a lean and efficient implementation of the Python programming language optimised to run in constrained environments. When Damien created MicroPython I think he imagined "constrained environments" to mean microcontrollers - the small single chip computers beloved of embedded systems engineers, Internet of Things enthusiasts and the Maker community.

Little did he realise that MicroPython was an amazing fit for another computing context: the browser.

MicroPython

The browser is an interesting space in which to work because of its unique combinations of constraints.

Firstly, everything needed to view a web page needs to be delivered over the network. So, the smaller the asset to be delivered can be, the better. MicroPython, when compressed for delivery to the browser is only around 170k in size - smaller than most images you find on most websites.

Secondly, the browser is perhaps the world's most battle tested sand boxed computing environment. By this I mean that web browsers encounter all sorts of interesting, nefarious, ill-performing, badly written and otherwise shonky code. Such code should be constrained into a virtual sandbox, so it can't do any damage to the user's wider system. Because of the recent development of web assembly (shortened to WASM ~ a sort of virtual microprocessor working in the browser), code written in C can be compiled to run in the browser. MicroPython is written in C and Damien and his collaborators have worked together to create a port for web assembly.

Third and finally, the browser makes available to the developer of websites a JavaScript object called globalThis, through which all the other objects, functions and data structures needed to access the capabilities of the browser are made available. By constraining developers to a single means of interacting with the browser, there is only one way to go about making things happen. MicroPython compiled to WASM has access to the full capabilities of the sandboxed browser thanks to some of Damien's recent work on a foreign function interface (FFI) that interacts with the JavaScript based APIs and capabilities defined by globalThis.

Given this context, what does MicroPython allow you to do?

From within MicroPython running in the browser, one simply imports the js module (short for JavaScript). It's an object in MicroPython that acts as a proxy for globalThis in the browser. It makes interacting with the browser from MicroPython an absolute joy. It's worth pointing out that Damien's work is based upon the js work done as part of the Pyodide project (a version of the CPython interpreter for the browser), so no matter the version of Python you use in the browser, you access the browser's capabilities in exactly the same way.

But recently, there was a problem.

I was due to give a talk about PyScript (a platform for taking MicroPython and Pyodide and making them easy to use in the browser) at EuroPython and I was putting together code examples of ever increasing complexity to present as part of my talk. But I kept hitting strange errors when using MicroPython. My colleague and web-guru Andrea managed to isolate the problem but had been unable to work out why it was happening. Put simply, somewhere in MicroPython's FFI, at that point where JavaScript and MicroPython were interacting, unwanted JavaScript objects were unexpectedly leaking into the MicroPython world thus causing things to crash. Think of it as a JavaScript shaped spanner in the MicroPython works.

This wasn't a good situation to find oneself in, a few days before presenting at one of the Python world's largest and most prestigious conferences.

Damien and I decided to debug the problem, and we recorded ourselves doing so because Andrea wasn't available at the time of our call. We figured that if he could watch our debugging session, he might spot something we hadn't and suggest a fix.

In any case, what followed was a lot of fun, and the video of the debugging session is embedded below.

There are some things you need to know before you watch the video:

  • Both Damien and I know JavaScript to a sufficient level to be "dangerous". We can get stuff done, but we're not guru level like Andrea.
  • Damien is an expert in C (the language used to implement MicroPython) and clearly knows his way around the MicroPython codebase including the FFI that kept crashing. I am familiar enough with C to be able to read it, but not very experienced at writing it, and I certainly don't know anything about the MicroPython internals, including the FFI.
  • We were using a collaboration technique called pair programming: where one developer (Damien) is the "pilot" with the other developer (me) acting as "co-pilot". As you'll see in the video, Damien was sharing his screen so I could see what he was looking at and he'd often describe things, processes or problems to me, only for me to confirm them, explain them back or ask questions as a way to help maintain focus. As the one most ignorant of the language and code-base, I was in a good position to play the beginner to Damien's expert, and ask for clarifications.
  • Our debugging involved taking very careful steps to investigate and change the code so the problem was (happily) eventually revealed, tested and fixed. As the Chinese proverb explains: when crossing a river, it's best to do so slowly and by feeling with one's toes.
  • Both of us were having a lot of fun in different ways. Damien was clearly fascinated by delving into the problem. I was enjoying Damien's virtuosic debugging performance, and found out some fun stuff as we went along.

So grab your popcorn, and enjoy the show:

Rejection and Renewal

In June I was contacted by a friend in the EuroPython community.

They were looking for articles about how to deal with rejection and what to do when one's proposal for a conference talk wasn't accepted. Since they couldn't find anything suitable, they asked ChatGPT for suggestions, and this is how it responded:

In an entirely predictable turn of events, ChatGPT was wrong (no such post existed at that time), and so I puckishly proposed writing such a post. We can't have ChatGPT telling lies can we?

This is it.


What to do when your talk is not accepted

It is a rare privilege to find oneself in a community who genuinely cherish and support the participation of all. Such company guarantees we encounter folk who are different to ourselves: an opportunity to learn from each other's contrasting backgrounds, experiences and perspectives. It's why diversity is a precondition for growth: our worlds are mutually enlarged by our differences.

But this isn't an easy journey.

It takes compassion, empathy and thoughtfulness to nurture a safe space where such encounters take place. Participants - through their actions, attitudes and attention - embody and live the inclusive and open minded ethos necessary for such a precious situation. This is a complex relationship between the individual participant's personal outlook and the collective esprit de corps that emerges from the aggregate contributions and interactions of many different individuals.

Here's the challenge: it's not enough for a group to say they're inclusive, open-minded and whatnot... that's just empty virtue signalling. Merely "going through the motions" is an ignorant and insidious sort of cultural cargo cult ~ communication at the expense of community. It happens far too often, and normalizing such behaviour actively diminishes the possibility of a genuinely inclusive and open-minded space.

Rather, such a community spirit springs from the quality of the interactions between individual participants. Sometimes such interactions are unavoidably painful: as when a proposed contribution to a community event is rejected by the organisers.

Yet it is at these moments when embodiment by individuals, and the emergent community spirit, are so important.

This equally applies both to organisers and participants.

If you are an organiser of a community event, and have a call for proposals but limited space, then you will inevitably reject (and therefore exclude) some of the proposed contributions. If you believe in a diverse and inclusive culture then this process may feel deeply uncomfortable and paradoxical.

But this is the puzzle you face, and (I'm sorry to say) there's no right answer.

Actually, the notion that there is an answer to such a situation is, I believe, deeply flawed. Rather, how you choose to conduct yourself, pay attention to the situation and engage with the unfolding events will reveal your community's spirit. I hope you make a conscious personal decision to choose compassion, empathy and thoughtfulness over going through the motions of a performative brain dead cultural cargo cult.

Alternatively for participants, it can be deeply upsetting if your contribution to an event has been rejected. All sorts of complicated feelings may come up (although some may just shrug and move on). I want to reassure you that it is natural and understandable to feel sad, disappointed or upset by such rejection. Lean into such feelings and give them the time and space they deserve. The worst thing you can do is ignore them.

Most importantly, pay attention to what happens next.

If the organisers of the event embody an inclusive and empowering community spirit, their interactions with you will be affirmative, compassionate and supportive. If you engage in good faith, such organisers will likely welcome feedback or suggestions. But please remember they're human beings too and they may respectfully disagree with you. This is what it is to be in a diverse community - you'll meet folk with different outlooks to your own.

It's an opportunity to learn!

As an exercise in self-understanding and growth, you may want to explore why your proposal was rejected (if this hasn't already been explained). Such feedback is best received in a spirit of constructive collaboration. You'll either discover how to improve your next proposal or come to see how the event in question isn't a good fit for what you want to contribute.

If the former, reflect and refine for next time.

If the latter, your niche might be elsewhere, so keep exploring!

If the event organisers are simply going through the motions, you'll know to avoid the event in future.

In any case, be you an organiser of or participant in community events, best of luck. Just remember flouishing and fulfilling communities are all about the quality of individual interactions, something over which you have direct control: how you choose to participate.

Peace.