Graham Knapp

AI design patterns django e57 feature flags pointcloud python Rhino 3D talks TypeScript wind engineering

The Zen of Python: Gur Mra bs Clguba. 🔗

written by Graham Knapp on 2025-01-14

I love The Zen of Python - one of the delights of the language is typing import this in a REPL and discovering this gem:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

It neatly captures the way in which Guido van Rossum and a group of Pythonistas thought about the language, constructed and used it, sharing thoughts on user forums in in-person meetings.

Read Full Post


Feature flags Pt 2: Start small 🔗

written by Graham Knapp on 2025-01-05

In our team we started with the smallest possible shareable system - a flags namespace in our front-end code. We later adopted an existing open source library in the back end. This got me thinking - what is the smallest possible feature flag system?

Britains Deetail Waterloo British Officer with Sword and Flag by Sclight

Here's a Hello World example...

The world without flags

# greet.py
print("Hello, world!")



Read Full Post


Feature flags Pt 1: Faster feature development with flags. 🔗

written by Graham Knapp on 2025-01-02

The greatest accelerator of my team's work last year was adopting feature flags. With flags we ship features faster, more confidently and with less stress. We have fewer merge conflicts despite frequently working together on the same part of the code base.

Men in colourful mediaeval costumes throwing huge flags into the air in a central Italian flagged square, thousands of onlookers in the background

Read Full Post


Result pattern - An exceptional way to handle errors 🔗

written by Graham Knapp on 2024-12-30

People often say that in Python you should use exceptions - "Easier to Ask Forgiveness than Permission" (EAFP) over guard clauses - "Look Before You Leap" (LBYL), but the Result design pattern - returning an object which explicitly states whether the operation succeeded is a useful alternative where error handling is required and, as I learned by exploring in more depth, it can be compatible with both approaches.

As my design patterns repo approaches 100⭐ on GitHub I decided to add the Result design pattern to the mix

EAFP vs LBYL

or Graham plays with GitHub Code Search

Prompted by a post on Mastodon I looked a bit more into which patterns people are using for error handling specifically for attribute lookup: I'm surprised to see twice as many references to hasattr as for "except AttributeError"

and not only for dynamic lookups but also for general attribute search, so a win for LBYL vs EAFP style with Python, despite the latter often being recommended ?


Ma reconversion dans la tech 🔗

written by Graham Knapp on 2024-11-08

En novembre 2011 j'ai eu l'opportunité de parler de ma reconversion du monde du bùtiment vers le métier de développeur informatique avec les apprenantes de l'Ada Tech School, Nantes. J'ai parlé de ma découverte de la programmation a partir de 2015 dans mon travail d'ingénieur chef de projet au CSTB, mon parcours de formation, mes craintes et à-prioris par rapport au monde de l'informatique et la réalité de mon quotidien au startup Acernis.

C'était sympa à faire - j'encourage tout le monde de faire ce type d'exercice avant qu'il soit trop tard pour se remettre dans la position de débutant sur le chemin. Bon courage à toutes les personnes qui se trouvent sur ce type de chemin en ce moment!


City Modelling with Generative AI: Tool or toy? 🔗

written by Graham Knapp on 2023-01-02

AI tools such as Chat-Gpt (text generation) and Dall-E (image generation) are making impressive leaps, allowing people to rapidly generate text, code and images from simple input prompts. The next frontier in generative AI may be 3D modelling, and OpenAI recently released the open source 3D modelling software Point·E. Could computer games, films and even architecture use these techniques to replace or improve manual city modelling?

33 3D mesh models, each generated from the text prompt "a buildng"​

33 3D mesh models, each generated from the text prompt "a buildng"​

Read Full Post


đŸŽŒTrouver un musicothĂ©rapeuteđŸŽŒ 🔗

written by Graham Knapp on 2021-07-20

Ma femme est non seulement une superbe musicienne mais aussi une musicothĂ©rapeute : elle soigne les gens, ou les aide Ă  se soigner eux-mĂȘmes, avec de la musique!

J'ai crée cette carte des musicothérapeutes français avec la méthode suivante:

  • Scrape le site web de la FĂ©dĂ©ration Française de MusicothĂ©rapie avec Requests et Beautiful Soup
  • GĂ©ocoder les addresses de tous les musicothĂ©rapeutes via OSM (cette partie prend plusieurs minutes)
  • CrĂ©er une carte avec un marqueur par musicothĂ©rapeute avec Folium.
  • Enregistrer la carte sous format html

J'utilise la fonction suivantes pour générer mes tags HTML pour les marqueurs:

def tagged(txt:str, tag:str):
    str = txt.strip()
    if str:
        return f"<{tag}>{txt}</{tag}>\n"
    else:
        return ""

Voici le script complet sous forme de Jupyter Notebook.


Fail fast - coder sereinement : Tests dans Jupyter 🔗

written by Graham Knapp on 2021-06-14

Following the "fail fast" principal I have found it really useful when coding engineering and data science code in Jupyter to follow this pattern:

  1. Write the code in a Jupyter notebook - this is a great option for scientific and technical computing as it lets you combine code, visualisation and documentation all in the same place.
  2. Find independent sample calculations from text books or other commonly used tools - the key is that the examples should not be generated from your own code.
  3. Add sample calculations with assert statements in the same cell as the function definition to demonstrate that the function works.

This last point is the key to the method I suggest here - the tests are run every time you update your definition but if the test is slow it will only be run the first time you reopen the notebook, once you are happy with the function you can reuse it without re-running the tests

https://github.com/dancergraham/fail_fast


Aerodynamic Behaviour and Structural Safety of Tower Cranes 🔗

written by Graham Knapp on 2021-05-18

Upon moving to work at the French national scientific research organisation for the built environment, CSTB, I was surprised to see the attention to detail in tower crane studies - looking at the risk of strong winds, construction site exposure and swirling winds potentially setting tower cranes rotating.

Following some LinkedIn posts and academic articles on the subject I was invited by the UK Wind Engineering Society to give an online talk. I gave some of the history of the subject, the key factors influencing risk levels and the methods used by the CSTB and by French insurers to assess and reduce risk levels.

đŸ“șWatch here

Read Full Post


En attendant la PyConFr (02/2021) — Traitement des rĂ©sultats d’essai en soufflerie 🔗

written by Graham Knapp on 2021-02-18

Un résumé de mes expériences de l'utilisation de Python en équipe d'ingénierie du vent https://pyvideo.org/en-attendant-la-pyconfr-2020-2021/traitement-des-resultats-dessai-en-soufflerie.html