{"article":{"slug":"how-rust-changed-me-as-a-developer","title":"How Rust Changed Me As A Developer","subtitle":null,"summary":"Martijn Faassen reflects on how years of developing in Rust changed the way he thinks about software, and why that experience still matters as AI shifts the tradeoffs in development.","content_type":"essay","language":"en","canonical_url":"https://blog.startifact.com/posts/how-rust-changed-me/","author":{"name":"Martijn Faassen","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Secret Weblog","url":"https://blog.startifact.com/","listing_slug":null,"listing":null},"topics":[{"name":"rust","slug":"rust","url":"https://listedarticles.com/topics/rust"},{"name":"programming","slug":"programming","url":"https://listedarticles.com/topics/programming"},{"name":"programming-languages","slug":"programming-languages","url":"https://listedarticles.com/topics/programming-languages"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":3747,"reading_minutes":16,"published_at":"2026-11-16T00:00:00.000Z","added_at":"2026-11-16T19:49:05.003Z","updated_at":"2026-11-16T19:49:05.003Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/how-rust-changed-me-as-a-developer","markdown_url":"https://listedarticles.com/articles/how-rust-changed-me-as-a-developer.md","example":false,"citation":"Martijn Faassen, Secret Weblog. \"How Rust Changed Me As A Developer.\" 16 Nov 2026. https://blog.startifact.com/posts/how-rust-changed-me/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://blog.startifact.com/posts/how-rust-changed-me/"},"body_markdown":"# How Rust Changed Me As A Developer\n\nThe programming language you use affects how you think as a software developer\n[1](#why). That may seem surprising to you; you may have picked up JavaScript\npretty quickly knowing Python, and it didn't really affect how you think or\ndevelop. That's because those languages are pretty similar. The more different a\nprogramming language is from what you're used to, the more it can change you.\nRust was quite different to me, so it did.\n\nI've been developing with Rust for over 6 years; more than 4 years\n[professionally](https://github.com/faassen/xot)\n[now](https://github.com/Paligo/xee). One of the reasons I really wanted to\nbecome more proficient with Rust is because I knew it would challenge me, and\nhopefully change me for the better as a developer. I think it did.\n\nWhat I learned and am going to discuss here is not exclusive to Rust. You can\nencounter many of these concepts in other contexts, and indeed I had encountered\nquite a few of them already. But in this case, Rust helped bring them into\nbetter focus.\n\n## Where were enums all my life?\n\nWe're all familiar with product types, though not usually under that name:\n\n```\nstruct Human {\n    first_name: String,\n    last_name: String,\n}\n```\n\nThe fields of the `Human` struct [2](#struct) can vary independently from each\nother, and we have to deal with all possible combinations: all possible first\nnames and last names, combined. The *product* of their combinations, to to\nspeak.\n\nBut it turns out there's another type thing that's been around forever but that\nthe programming community has mostly been been ignoring [3](#impoverished): the sum\ntype. A sum type expresses variants: something is either one thing, or another,\nout of a bunch of variants:\n\n```\nenum Person {\n    Human { first_name: String, last_name: String },\n    Cat { name: String, cuteness: Cuteness }\n}\n```\n\nA `Person` is *either* a human or a cat: that's the *sum* of the possiblities.\nEach variant can have data associated with it, and this can be a product type,\nbut the `Person` type is just these options (two in this case). In code where\nyou need to deal with a person, you need to handle each variant by `match` in on\nthe object. The Rust compiler enforces this.\n\n```\nmatch some_person {\n    Human { first_name, last_name } => { \n\t    // do a thing with first_name and last_name\n    },\n    Cat { name, cuteness } => {\n\t   // do a thing with name and cutenes\n    }\n}\n```\n\nWhen you handle the human variant, you only need to worry about `first_name` and\n`last_name`. You don't have to worry about `name` or `cuteness` at all. These\ncases are distinct from each other.\n\nIt turns out that it's really helpful to model stuff using sum types. People\nusing functional programming languages already knew this. You can model\noptionality (`null`) this way: you got either some value, or nothing. You can\nalso model errors: it's either okay (with whatever value you return in case of\nsuccess), or an error (with a value describing the error).\n\nAny language without sum types now feels impoverished to me. I know I can\nsimulate it with some type field, but the job of a programming language is to\nhelp me handle basic stuff, and this is basic stuff.\n\n## Enums and abstraction\n\nIn an object oriented programming language, you handle variants using dynamic\ndispatch and an interface (or inheritance). You do this:\n\n```\ninterface Person {\n    def do_one_thing()\n    def do_another_thing\n}\n\nclass Human implements Person {\n    ...\n}\n\nclass Cat implements Person {\n   ...\n}\n```\n\nThe idea is that you can now use `Person` anywhere without worrying about the\ndetails inside: it's loosely coupled. You only use their interface.\n\nThis is indeed a great idea, but Rust taught me that this has tradeoffs I may\nnot want to pay for. You pay two things: performance, and the need to create the\ninterface.\n\nLet's talk about the need to create the interface. You need to devise an\ninterface that actually makes sense for your application: *how* are you using\nhumans and cats everywhere? Doing this work of abstraction may be extremely\nworthwhile to do, especially if you anticipate unknown future persons that you\nneed to be able to plug in later without having to modify the code that uses\nthem -- you want your code use the [open/closed\nprinciple](https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle).\n\nBut what if you are developing a single domain, and inside that you just want to\nbe able to handle cats and humans and that's it? There's just no need to plug in\nother types of persons, and certainly not from outside.\n\nOr let's say you do want to add a new variant once every while. Say you want to\nadd `Dog`. Maybe you're actually okay going through the code that handles\n`Human` and `Cat` and add handling for dogs too? Maybe it actually is helpful to\nsee those other handlers right there too when you do so? The compiler is going\nto ensure you don't miss any spots!\n\nOr what if the abstraction you are trying to devise *is* the variance and that's\nmore or less what you can say about it? For error handling, the abstraction is\neither okay with some value, *or* some error value.\n\nIn this case you may be paying the price of creating an interface without it\nbeing worthwhile.\n\n`enum` may be all you actually need -- low ceremony, and statically checked.\nFinally I'll note that enums don't lock you out from creating that abstraction -\nyou can add methods to an enum too, just like on a struct.\n\n**Enums made me a better programmer as now I have another elementary, simple,\neasy to understand language construct for abstraction in my mental toolbox.**\n\n## Dispatch galore\n\nIn many languages there are two types of dispatch: dynamic dispatch, which we've\ndiscussed in case of our `Person` interface, and conditional dispatch, like\nthis:\n\n```\nif something {\n   do_this_thing()\n} else\n   do_another()\n}\n```\n\nRust has dynamic dispatch, if you ask for it. It also has the powered up version\nof conditional dispatch I already discussed: match on enums. It has conditional\ndispatch too - that's just [a special\ncase][https://docs.rs/bool/latest/bool/enum.Boolean.html].\n\nThere's another type of dispatch that Rust makes you think about: dispatch\nthat's statically compiled.\n\nWhat if you're dealing *either* with groups of humans *or* groups of cats, and\nyou want to do some operations on them, and those operations have common\nbehavior (say, you want to count them). The group, or collection, doesn't really\ncare about what's in it, as long as every item fulfills certain basic\nproperties.\n\nYou could create an enum `Person`; either an enum or an interface with multiple\nimplementations, and then dispatch during runtime to every member of the group\nbased on whether that entry is a human or a cat. But this means you have to\naccount for mixed groups of humans and cats, even though we just said those\ndon't actually exist.\n\nInstead, you can express this differently in Rust. You still have a `Person`\ninterface (trait), but you compose your individual type of `Person` (`Human` or\n`Cat`) during compile time.\n\n```\nstruct Group<T> {\n   // some fields\t\n}\n\n// compile time assembly, \n// then runtime creation of the assembled group of cats\nlet cat_group: Group<Cat> = Group::new();\n```\n\nRust now refuses to compile if you use non-cat operations on items in the group,\nThat's an invariant you now do not need to worry about anymore. This will be\nfamiliar to you with generics in other languages like TypeScript or Python.\n\nIn Rust, when you process your group of cats, there *is* no individual check\nsomewhere whether an entry is a human or a cat, as it already knows it's all\ncats before the program even ran. Rust directly dispatches to the cat code, and\nthe human code is not play. You avoid indirect dispatch for every group member,\nwhich can matter in situations where performance is important.\n\n**Rust made me a better programmer as I now better understand the connection\nbetween dispatch and performance.**\n\n## Type driven development\n\nWhen I discovered Python coming from C++ back in the late 1990s, dynamic typing\nwas a revelation. You could so much with so little ceremony. For the last decade\nor so I have been on a long winding road back to types (far more ergonomic\ntypes) and more ceremony. I have the impression many have been on this journey\nalong with me [4](#if_types_anyway).\n\nTypes can statically check your code before it runs. In Rust, they can help the\ncompiler compile stuff down to really high performance code. Both are great. But\ntypes can also have more subtle benefits. Let me get into this by analogy.\n\nWhy create automated tests?\n\n**Obvious**: Automated tests ensure various properties of your code work and\nremain working.\n\n**Subtle**: Writing tests forces you to think about the architecture and APIs\nyou're implementing more carefully. Making code testable can lead to better\narchitecture. This is the insight of test driven development.\n\nWhy write documentation?\n\n**Obvious**: People (and now machines) can understand [5](#understand) the why and\nwhat of your software by reading the documentation.\n\n**Subtle**: The act of writing the documentation can force you think about the\narchitecture and APIs of your software. If you can't write about it, maybe you\nhaven't gotten it right yet? That's documentation driven development.\n\nWhy write types?\n\n**Obvious**: Statically check your code before it runs! Prevent runtime errors!\nPerformance!\n\n**Subtle**: You model the domain model using types, trying to make sure it hangs\ntogether. Enums are really valuable here. You express [parse, don't\nvalidate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)\nin them. The types guide the architecture and APIs of your software.\n\nThis perhaps sounds like big design up front processes where people write all\nthe tests, or all the docs, or all the types, in advance, and *then* do the\nimplementation. [6](#big_design) I'm not talking about this -- I'm talking about\niterative development where you keep going back to tests, docs and types as you\nlearn.\n\nRust brought into focus how types are yet another tool to help me think while I\ndevelop.\n\n**Rust made me a better programmer as it let me fully embrace type driven\ndevelopment.**\n\n## The Biggest Surprise\n\nHere is the biggest surprise I had coming to Rust. Much of the behavior I\nassociated with dynamic interpreted languages with a rich runtime like Python\ncan actually be done statically in Rust using macros.\n\nLet's talk about magic.\n\nSay you want to dump the state of a Python object -- you inspect all its fields,\nlook at their type, turn each into a string, combine all the strings together\ninto a big one. Now you can store it somewhere. Later on you restore that string\nback into an object. You can save and load any objects: magic! Python calls this\n[pickle](https://docs.python.org/3/library/pickle.html).\n\nWhat if you need to serialize to JSON? Python has a type system, and a library\nlike [Pydantic](https://pydantic.dev) inspects the type objects during runtime\nand then uses this information to let you automatically serialize a Python\nobject to JSON, or parse it back into Python again. More magic!\n\nRust is a compiled language. Types aren't runtime objects. Without reflection,\nwhich [takes special effort](https://facet.rs/), runtime introspection of types\nis not a thing in Rust.\n\nBut Rust can still do what Pickle and Pydantic do, at compile time.\n\nWith [serde](https://serde.rs/), Rust's answer to pickle and Pydantic, you use a\nnormal Rust type, annotate it with a few declarations, and then you can\nserialize it to JSON, or toml config format, and many other formats, and load it\nback again. The annotation looks like this:\n\n```\n#[derive(Serialize, Deserialize)]\nstruct Human {\n    first_name: String,\n    last_name: String\n}\n```\n\nWith [clap](https://docs.rs/clap/latest/clap/), you create the type that\nexpresses exactly what command line arguments you expect (with `enum`s too!),\ndocument it using the normal way you document any API in Rust, and boom, you\nhave a CLI with built in help. The code that handles the various cases gets\nwell-typed data - at that point it's been parsed correctly already, using the\nsame type you used to express the CLI.\n\nLike this:\n\n```\n/// My first CLI\n#[derive(Parser)]\nstruct MyFirstCli {\n    /// How many cats do you want?\n    #[arg(long, short)]\n    amount_of_cats: usize\n}\n```\n\nAgain declarative `#[]` stuff going on. It looks a lot like decorators in\nPython. But Python decorators are executed during runtime, and we just said Rust\ndoesn't normally let you do that.\n\nHow does that work in Rust? Macros! Macros lets you write code that generates\ncode during compile time. With serde, the macro generates a whole bunch of\nserialization code and deserialization code for the types annotated with it.\nThis generated code gets compiled along with the rest of your code. The compiler\ncan optimize it just like any other code.\n\nCode generation is scary. Macros are scary. Doing introspection in a dynamically\ntyped language is a lot easier than using Rust macros, where code is parsed and\ngenerated. Macros shouldn't be randomly mixed with application code; macros\nbelong in frameworks. That said, something being easy doesn't mean it should be\nused casually: in Python you typically want to carefully encapsulate your magic\nin a declarative framework too.\n\n**Rust made me a better programmer as I learned about a new class of framework\npatterns.**\n\n## Ownership and Architecture\n\nRust famously lets you write code without memory leaks that doesn't use a\ngarbage collector. It also stops you from mutating data you're also reading\nelsewhere, making it impossible to stumble into whole classes of weird undefined\nbehavior, especially with code that runs in parallel.\n\nRust's ownership system is one of the main things that makes learning Rust hard.\nPython, JavaScript, Java and many other languages have mutable references\neverywhere, and you can just create cyclic data structures. Rust won't let you\ndo either out of the box.\n\nThe equivalent of this does not compile in Rust:\n\n```\nclass Item:\n    def __init__(self, value):\n        self.value = value\n      \nclass Container:\n    def __init__(self, items):\n        self.items = items\n\nmy_item = Item()\nmy_container = Container()\nmy_container.items.append(my_item)\nmy_item.value = \"I change you!\"\n```\n\nThis also doesn't compile:\n\n```\nclass Node:\n   def __init__(self, parent, value):\n       self.parent = parent\n       self.value = value\n       self.children = []\n\n   def add_child(self, node):\n       node.parent = self\n       self.children.append(node)\n```\n\nRust won't just let you have circular references, in this case both children\n*and* a parent reference.\n\nThis feels very limiting at first! What do you do instead? For mutating stuff,\nyou learn how to separate mutation (often during construction) from using your\ndata. That is a thing that's good to do in many contexts -- less invariants\nmakes it's easier to reason about, but it takes a bit of getting used to Rust\nstrictly enforcing it.\n\nFor circular references it's trickier. I will go into it next, when I discuss\narenas.\n\nA weird thing happens: if you lean into this friction it can improve the\narchitecture of your codebase. Code becomes less coupled. It's hard to create\nweird backchannels with action at a distance that makes code difficult to\nunderstand, test and debug [7](#not_impossible).\n\nRust code locally can be difficult to understand. But how the data flows, what\ndoes what, in the larger codebase, tends to be cleaner.\n\n**Rust made me a better programmer as I now think about ownership more\ncarefully, which has a positive impact on architecture.**\n\n## The arena pattern everywhere\n\nA few years ago I analyzed a bunch of XML tree libraries in Rust. The best I\nfound, [roxmltrree](https://docs.rs/roxmltree), has an immutable tree. But I\nneeded a mutable tree. I found quite a few libraries that did support\nmutability, but many did not support parent references. You couldn't walk up the\nancestor chain of a node. This, along with missing support for some XML\nfeatures, is why I created my own in the form of\n[Xot](https://docs.rs/xot/latest/xot/).\n\nThe reason for this surprising lack of parent references is the ownership\nlimitation I discussed before: Rust makes circular references difficult. You can\nget around it using reference counted types and internal mutability, but in a\nlot of cases this pattern isn't really optimal -- it's verbose, less performant,\nand reference count cycles risk memory leaks. What you do instead is store nodes\nin an array and you use the array indexes to node as your reference. You can\nthen have an index referencing your parent, and use index references to your\nchildren, or any other circular reference.\n\nA fancy word for this pattern is an 'arena' and in Rust they show up everywhere.\n\nIn an arena, you store a lot of objects together in the same region of memory\n(in an array). What does it let you do?\n\n- iterate fast over its contents. Objects being in the same memory region means\n  the CPU can use its cache effectively. This is *much* faster than arbitrary\n  main memory access and loops really benefit.\n- fast allocation. The arena is allocated from the heap as a block, and after\n  that your allocations may just be a few increments.\n- interning: you store something once in the arena and use it in many places, so\n  you don't duplicate data.\n- the arena owns its stuff. Everything in the arena has the same lifetime.\n  Indexes between objects in an arena can be circular without worrying.\n\nRust pushes you to use arenas. This involves more ceremony than just using a\ndirect reference, but it also means Rust pushes you to write code that computers\ncan execute really efficiently.\n\n## Performance has a quality all its own\n\nI mentioned performance a number of times. But what about [premature\noptimization](https://blog.startifact.com/posts/is-premature-optimization-the-root-of-all-evil/)? The\ngreat irony of this quote is that it comes from a paper where the author, Knuth,\nargues in favor of keeping the `goto` statement around, as it's essential for\nwriting efficient software.\n\nRust lets you know what you pay for. Reference counting? Dynamic dispatch? You\ncan do it, but it's going to be visible in your code. Rust *also* often lets you\nknow when you *don't* want to pay for it: just look at [tower\nmiddleware](https://docs.rs/tower/) and despair about all the generic types and\ntype constraints that get piled onto a relatively simple abstraction.\n\nWhen you have these tools available, need to develop new wisdom about tradeoffs\nthat never seemed to matter. If you write Python code you're not too worried\nabout hash tables being a performance bottle neck, but in Rust code they\ncertainly can be. You can get lost along the way into hyper optimization land.\nOften you need to just get go [8](#clone_and_own). Many patterns that are just\nplain readable Rust code anyway happen to also be friendly to the CPU executing\nit.\n\nBut Rust overwhelming you with details you may not want to think about is not\nthe whole story, because performance is not just quantitative: if your code can\ntruly be more performance, it can access new qualities. When you can write code\nthat uses no memory and no CPU time [9](#exaggeration), it changes how you\nthink. It changes what's possible.\n\nSometimes the quality of performance is obvious: if you write numerical code, or\na simulation, of course you don't want to wait for the answer. Being able to do\nmany computations really fast is key to making AI possible.\n\nBut it's more subtle that that: modern computers are *really* powerful, and\n*ridicously* fast, and we generally ignore that and just throw more resources at\nour problems. There are good reasons [why this\nhappens](https://blog.startifact.com/posts/bloat-retrofuturism/). But if we open our eyes a little,\nthere are new architectural possibilities we can explore.\n\nWhile the power of macros were the biggest language surprise, I think this is\nthe biggest shift in my thinking: access to performance unlocks possibilities I\nhadn't considered before. Take my experiment\n[Colchis](https://github.com/faassen/colchis): a library can store vast amounts\nof JSON in memory, while retaining full access, even indexed access (I still\nhope to add jsonpath one day!), to JSON data. Before Rust, this was a\npossibility that wasn't even on my radar.\n\n**Rust made me a better programmer because I can make the computer do more with\nless, opening up new areas of opportunity.**\n\n## Conclusion\n\nRust is one of the most difficult programming languages I've learned -- and thus\none of the languages that changed me the most. There's a simple part of Rust\nthat isn't much harder to manage than any language, and in some cases may\nactually make your life easier -- `enum`s, declarative type-driven frameworks,\nand the excellent dev tooling come to mind. Even arenas are fundamentally not\nthat difficult to understand. The complexity is in unlearning some habits and\nlearning new ones. And then there's a more challenging complex Rust, mostly, but\nnot always under the surface, there when you need it.\n\nRust expands the reach of what I can build. That's what makes me happy I\nwent on this journey. [10](#all_the_tradeoffs)\n\n1\n\nAI agents write a lot of code. They know the programming language, so do\nyou need to know it? Does the language still affect the developer? If you share\nmy belief it's good [to look at the code](https://blog.startifact.com/posts/sigh-coding/), then it helps\nif you understand the code you're reading. I also think it's never been more\nimportant to think about how the systems you use affect the way you think and\nbehave.\n\n2\n\nIf you don't know what a struct is, just call it a class in your\nhead, and you're good.\n\n3\n\nYou have them in many languages but in impoverished forms, like\n`true`/`false`, or C's `enum`.\n\n4\n\nIf you're going to do static type checking anyway for the\nguarantees it brings, perhaps use a language designed around it (enums!) that\nalso gives you performance benefits?\n\n5\n\nDoes AI truly understand? Do you want to have a philosophical\ndebate? What do we mean by *understand*? Natural language is [inherently\nstretchable](https://en.wikipedia.org/wiki/Pragmatics).\n\n6\n\nWith AI we've seen the return of big design up front. I may be\nwrong, but I'm still skeptical of this approach, and still a fan of iterative\ndevelopment and incremental learning and theory building.\n\n7\n\nNot impossible. I've seen it. People can do it if they really\ntry, and it still makes life harder; it makes it much harder to test. But at\nleast it's more obvious and more difficult to do.\n\n8\n\nClone and own all the stuff! Which incidentally can also lead\nto more contiguous memory layouts...\n\n9\n\nNo memory and no CPU time is an exaggeration, but little Rust\nprograms sometimes feel that way.\n\n10\n\nAI development is shifting all the tradeoffs in software\ndevelopment - they're not gone, but they have shifted. The AI can write Rust,\neven if you don't know it. But I trust plenty of contexts remain where my Rust\nexperience plus AI leads to a better outcome than AI by itself.\n","body_html":"<h1 id=\"how-rust-changed-me-as-a-developer\">How Rust Changed Me As A Developer</h1>\n<p>The programming language you use affects how you think as a software developer\n<a href=\"#why\">1</a>. That may seem surprising to you; you may have picked up JavaScript\npretty quickly knowing Python, and it didn&#39;t really affect how you think or\ndevelop. That&#39;s because those languages are pretty similar. The more different a\nprogramming language is from what you&#39;re used to, the more it can change you.\nRust was quite different to me, so it did.</p>\n<p>I&#39;ve been developing with Rust for over 6 years; more than 4 years\n<a href=\"https://github.com/faassen/xot\" rel=\"nofollow ugc noopener\">professionally</a>\n<a href=\"https://github.com/Paligo/xee\" rel=\"nofollow ugc noopener\">now</a>. One of the reasons I really wanted to\nbecome more proficient with Rust is because I knew it would challenge me, and\nhopefully change me for the better as a developer. I think it did.</p>\n<p>What I learned and am going to discuss here is not exclusive to Rust. You can\nencounter many of these concepts in other contexts, and indeed I had encountered\nquite a few of them already. But in this case, Rust helped bring them into\nbetter focus.</p>\n<h2 id=\"where-were-enums-all-my-life\">Where were enums all my life?</h2>\n<p>We&#39;re all familiar with product types, though not usually under that name:</p>\n<pre><code>struct Human {\n    first_name: String,\n    last_name: String,\n}</code></pre>\n<p>The fields of the <code>Human</code> struct <a href=\"#struct\">2</a> can vary independently from each\nother, and we have to deal with all possible combinations: all possible first\nnames and last names, combined. The <em>product</em> of their combinations, to to\nspeak.</p>\n<p>But it turns out there&#39;s another type thing that&#39;s been around forever but that\nthe programming community has mostly been been ignoring <a href=\"#impoverished\">3</a>: the sum\ntype. A sum type expresses variants: something is either one thing, or another,\nout of a bunch of variants:</p>\n<pre><code>enum Person {\n    Human { first_name: String, last_name: String },\n    Cat { name: String, cuteness: Cuteness }\n}</code></pre>\n<p>A <code>Person</code> is <em>either</em> a human or a cat: that&#39;s the <em>sum</em> of the possiblities.\nEach variant can have data associated with it, and this can be a product type,\nbut the <code>Person</code> type is just these options (two in this case). In code where\nyou need to deal with a person, you need to handle each variant by <code>match</code> in on\nthe object. The Rust compiler enforces this.</p>\n<pre><code>match some_person {\n    Human { first_name, last_name } =&gt; { \n        // do a thing with first_name and last_name\n    },\n    Cat { name, cuteness } =&gt; {\n       // do a thing with name and cutenes\n    }\n}</code></pre>\n<p>When you handle the human variant, you only need to worry about <code>first_name</code> and\n<code>last_name</code>. You don&#39;t have to worry about <code>name</code> or <code>cuteness</code> at all. These\ncases are distinct from each other.</p>\n<p>It turns out that it&#39;s really helpful to model stuff using sum types. People\nusing functional programming languages already knew this. You can model\noptionality (<code>null</code>) this way: you got either some value, or nothing. You can\nalso model errors: it&#39;s either okay (with whatever value you return in case of\nsuccess), or an error (with a value describing the error).</p>\n<p>Any language without sum types now feels impoverished to me. I know I can\nsimulate it with some type field, but the job of a programming language is to\nhelp me handle basic stuff, and this is basic stuff.</p>\n<h2 id=\"enums-and-abstraction\">Enums and abstraction</h2>\n<p>In an object oriented programming language, you handle variants using dynamic\ndispatch and an interface (or inheritance). You do this:</p>\n<pre><code>interface Person {\n    def do_one_thing()\n    def do_another_thing\n}\n\nclass Human implements Person {\n    ...\n}\n\nclass Cat implements Person {\n   ...\n}</code></pre>\n<p>The idea is that you can now use <code>Person</code> anywhere without worrying about the\ndetails inside: it&#39;s loosely coupled. You only use their interface.</p>\n<p>This is indeed a great idea, but Rust taught me that this has tradeoffs I may\nnot want to pay for. You pay two things: performance, and the need to create the\ninterface.</p>\n<p>Let&#39;s talk about the need to create the interface. You need to devise an\ninterface that actually makes sense for your application: <em>how</em> are you using\nhumans and cats everywhere? Doing this work of abstraction may be extremely\nworthwhile to do, especially if you anticipate unknown future persons that you\nneed to be able to plug in later without having to modify the code that uses\nthem -- you want your code use the <a href=\"https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle\" rel=\"nofollow ugc noopener\">open/closed\nprinciple</a>.</p>\n<p>But what if you are developing a single domain, and inside that you just want to\nbe able to handle cats and humans and that&#39;s it? There&#39;s just no need to plug in\nother types of persons, and certainly not from outside.</p>\n<p>Or let&#39;s say you do want to add a new variant once every while. Say you want to\nadd <code>Dog</code>. Maybe you&#39;re actually okay going through the code that handles\n<code>Human</code> and <code>Cat</code> and add handling for dogs too? Maybe it actually is helpful to\nsee those other handlers right there too when you do so? The compiler is going\nto ensure you don&#39;t miss any spots!</p>\n<p>Or what if the abstraction you are trying to devise <em>is</em> the variance and that&#39;s\nmore or less what you can say about it? For error handling, the abstraction is\neither okay with some value, <em>or</em> some error value.</p>\n<p>In this case you may be paying the price of creating an interface without it\nbeing worthwhile.</p>\n<p><code>enum</code> may be all you actually need -- low ceremony, and statically checked.\nFinally I&#39;ll note that enums don&#39;t lock you out from creating that abstraction -\nyou can add methods to an enum too, just like on a struct.</p>\n<p><strong>Enums made me a better programmer as now I have another elementary, simple,\neasy to understand language construct for abstraction in my mental toolbox.</strong></p>\n<h2 id=\"dispatch-galore\">Dispatch galore</h2>\n<p>In many languages there are two types of dispatch: dynamic dispatch, which we&#39;ve\ndiscussed in case of our <code>Person</code> interface, and conditional dispatch, like\nthis:</p>\n<pre><code>if something {\n   do_this_thing()\n} else\n   do_another()\n}</code></pre>\n<p>Rust has dynamic dispatch, if you ask for it. It also has the powered up version\nof conditional dispatch I already discussed: match on enums. It has conditional\ndispatch too - that&#39;s just [a special\ncase][<a href=\"https://docs.rs/bool/latest/bool/enum.Boolean.html]\" rel=\"nofollow ugc noopener\">https://docs.rs/bool/latest/bool/enum.Boolean.html]</a>.</p>\n<p>There&#39;s another type of dispatch that Rust makes you think about: dispatch\nthat&#39;s statically compiled.</p>\n<p>What if you&#39;re dealing <em>either</em> with groups of humans <em>or</em> groups of cats, and\nyou want to do some operations on them, and those operations have common\nbehavior (say, you want to count them). The group, or collection, doesn&#39;t really\ncare about what&#39;s in it, as long as every item fulfills certain basic\nproperties.</p>\n<p>You could create an enum <code>Person</code>; either an enum or an interface with multiple\nimplementations, and then dispatch during runtime to every member of the group\nbased on whether that entry is a human or a cat. But this means you have to\naccount for mixed groups of humans and cats, even though we just said those\ndon&#39;t actually exist.</p>\n<p>Instead, you can express this differently in Rust. You still have a <code>Person</code>\ninterface (trait), but you compose your individual type of <code>Person</code> (<code>Human</code> or\n<code>Cat</code>) during compile time.</p>\n<pre><code>struct Group&lt;T&gt; {\n   // some fields    \n}\n\n// compile time assembly, \n// then runtime creation of the assembled group of cats\nlet cat_group: Group&lt;Cat&gt; = Group::new();</code></pre>\n<p>Rust now refuses to compile if you use non-cat operations on items in the group,\nThat&#39;s an invariant you now do not need to worry about anymore. This will be\nfamiliar to you with generics in other languages like TypeScript or Python.</p>\n<p>In Rust, when you process your group of cats, there <em>is</em> no individual check\nsomewhere whether an entry is a human or a cat, as it already knows it&#39;s all\ncats before the program even ran. Rust directly dispatches to the cat code, and\nthe human code is not play. You avoid indirect dispatch for every group member,\nwhich can matter in situations where performance is important.</p>\n<p><strong>Rust made me a better programmer as I now better understand the connection\nbetween dispatch and performance.</strong></p>\n<h2 id=\"type-driven-development\">Type driven development</h2>\n<p>When I discovered Python coming from C++ back in the late 1990s, dynamic typing\nwas a revelation. You could so much with so little ceremony. For the last decade\nor so I have been on a long winding road back to types (far more ergonomic\ntypes) and more ceremony. I have the impression many have been on this journey\nalong with me <a href=\"#if_types_anyway\">4</a>.</p>\n<p>Types can statically check your code before it runs. In Rust, they can help the\ncompiler compile stuff down to really high performance code. Both are great. But\ntypes can also have more subtle benefits. Let me get into this by analogy.</p>\n<p>Why create automated tests?</p>\n<p><strong>Obvious</strong>: Automated tests ensure various properties of your code work and\nremain working.</p>\n<p><strong>Subtle</strong>: Writing tests forces you to think about the architecture and APIs\nyou&#39;re implementing more carefully. Making code testable can lead to better\narchitecture. This is the insight of test driven development.</p>\n<p>Why write documentation?</p>\n<p><strong>Obvious</strong>: People (and now machines) can understand <a href=\"#understand\">5</a> the why and\nwhat of your software by reading the documentation.</p>\n<p><strong>Subtle</strong>: The act of writing the documentation can force you think about the\narchitecture and APIs of your software. If you can&#39;t write about it, maybe you\nhaven&#39;t gotten it right yet? That&#39;s documentation driven development.</p>\n<p>Why write types?</p>\n<p><strong>Obvious</strong>: Statically check your code before it runs! Prevent runtime errors!\nPerformance!</p>\n<p><strong>Subtle</strong>: You model the domain model using types, trying to make sure it hangs\ntogether. Enums are really valuable here. You express <a href=\"https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/\" rel=\"nofollow ugc noopener\">parse, don&#39;t\nvalidate</a>\nin them. The types guide the architecture and APIs of your software.</p>\n<p>This perhaps sounds like big design up front processes where people write all\nthe tests, or all the docs, or all the types, in advance, and <em>then</em> do the\nimplementation. <a href=\"#big_design\">6</a> I&#39;m not talking about this -- I&#39;m talking about\niterative development where you keep going back to tests, docs and types as you\nlearn.</p>\n<p>Rust brought into focus how types are yet another tool to help me think while I\ndevelop.</p>\n<p><strong>Rust made me a better programmer as it let me fully embrace type driven\ndevelopment.</strong></p>\n<h2 id=\"the-biggest-surprise\">The Biggest Surprise</h2>\n<p>Here is the biggest surprise I had coming to Rust. Much of the behavior I\nassociated with dynamic interpreted languages with a rich runtime like Python\ncan actually be done statically in Rust using macros.</p>\n<p>Let&#39;s talk about magic.</p>\n<p>Say you want to dump the state of a Python object -- you inspect all its fields,\nlook at their type, turn each into a string, combine all the strings together\ninto a big one. Now you can store it somewhere. Later on you restore that string\nback into an object. You can save and load any objects: magic! Python calls this\n<a href=\"https://docs.python.org/3/library/pickle.html\" rel=\"nofollow ugc noopener\">pickle</a>.</p>\n<p>What if you need to serialize to JSON? Python has a type system, and a library\nlike <a href=\"https://pydantic.dev\" rel=\"nofollow ugc noopener\">Pydantic</a> inspects the type objects during runtime\nand then uses this information to let you automatically serialize a Python\nobject to JSON, or parse it back into Python again. More magic!</p>\n<p>Rust is a compiled language. Types aren&#39;t runtime objects. Without reflection,\nwhich <a href=\"https://facet.rs/\" rel=\"nofollow ugc noopener\">takes special effort</a>, runtime introspection of types\nis not a thing in Rust.</p>\n<p>But Rust can still do what Pickle and Pydantic do, at compile time.</p>\n<p>With <a href=\"https://serde.rs/\" rel=\"nofollow ugc noopener\">serde</a>, Rust&#39;s answer to pickle and Pydantic, you use a\nnormal Rust type, annotate it with a few declarations, and then you can\nserialize it to JSON, or toml config format, and many other formats, and load it\nback again. The annotation looks like this:</p>\n<pre><code>#[derive(Serialize, Deserialize)]\nstruct Human {\n    first_name: String,\n    last_name: String\n}</code></pre>\n<p>With <a href=\"https://docs.rs/clap/latest/clap/\" rel=\"nofollow ugc noopener\">clap</a>, you create the type that\nexpresses exactly what command line arguments you expect (with <code>enum</code>s too!),\ndocument it using the normal way you document any API in Rust, and boom, you\nhave a CLI with built in help. The code that handles the various cases gets\nwell-typed data - at that point it&#39;s been parsed correctly already, using the\nsame type you used to express the CLI.</p>\n<p>Like this:</p>\n<pre><code>/// My first CLI\n#[derive(Parser)]\nstruct MyFirstCli {\n    /// How many cats do you want?\n    #[arg(long, short)]\n    amount_of_cats: usize\n}</code></pre>\n<p>Again declarative <code>#[]</code> stuff going on. It looks a lot like decorators in\nPython. But Python decorators are executed during runtime, and we just said Rust\ndoesn&#39;t normally let you do that.</p>\n<p>How does that work in Rust? Macros! Macros lets you write code that generates\ncode during compile time. With serde, the macro generates a whole bunch of\nserialization code and deserialization code for the types annotated with it.\nThis generated code gets compiled along with the rest of your code. The compiler\ncan optimize it just like any other code.</p>\n<p>Code generation is scary. Macros are scary. Doing introspection in a dynamically\ntyped language is a lot easier than using Rust macros, where code is parsed and\ngenerated. Macros shouldn&#39;t be randomly mixed with application code; macros\nbelong in frameworks. That said, something being easy doesn&#39;t mean it should be\nused casually: in Python you typically want to carefully encapsulate your magic\nin a declarative framework too.</p>\n<p><strong>Rust made me a better programmer as I learned about a new class of framework\npatterns.</strong></p>\n<h2 id=\"ownership-and-architecture\">Ownership and Architecture</h2>\n<p>Rust famously lets you write code without memory leaks that doesn&#39;t use a\ngarbage collector. It also stops you from mutating data you&#39;re also reading\nelsewhere, making it impossible to stumble into whole classes of weird undefined\nbehavior, especially with code that runs in parallel.</p>\n<p>Rust&#39;s ownership system is one of the main things that makes learning Rust hard.\nPython, JavaScript, Java and many other languages have mutable references\neverywhere, and you can just create cyclic data structures. Rust won&#39;t let you\ndo either out of the box.</p>\n<p>The equivalent of this does not compile in Rust:</p>\n<pre><code>class Item:\n    def __init__(self, value):\n        self.value = value\n      \nclass Container:\n    def __init__(self, items):\n        self.items = items\n\nmy_item = Item()\nmy_container = Container()\nmy_container.items.append(my_item)\nmy_item.value = &quot;I change you!&quot;</code></pre>\n<p>This also doesn&#39;t compile:</p>\n<pre><code>class Node:\n   def __init__(self, parent, value):\n       self.parent = parent\n       self.value = value\n       self.children = []\n\n   def add_child(self, node):\n       node.parent = self\n       self.children.append(node)</code></pre>\n<p>Rust won&#39;t just let you have circular references, in this case both children\n<em>and</em> a parent reference.</p>\n<p>This feels very limiting at first! What do you do instead? For mutating stuff,\nyou learn how to separate mutation (often during construction) from using your\ndata. That is a thing that&#39;s good to do in many contexts -- less invariants\nmakes it&#39;s easier to reason about, but it takes a bit of getting used to Rust\nstrictly enforcing it.</p>\n<p>For circular references it&#39;s trickier. I will go into it next, when I discuss\narenas.</p>\n<p>A weird thing happens: if you lean into this friction it can improve the\narchitecture of your codebase. Code becomes less coupled. It&#39;s hard to create\nweird backchannels with action at a distance that makes code difficult to\nunderstand, test and debug <a href=\"#not_impossible\">7</a>.</p>\n<p>Rust code locally can be difficult to understand. But how the data flows, what\ndoes what, in the larger codebase, tends to be cleaner.</p>\n<p><strong>Rust made me a better programmer as I now think about ownership more\ncarefully, which has a positive impact on architecture.</strong></p>\n<h2 id=\"the-arena-pattern-everywhere\">The arena pattern everywhere</h2>\n<p>A few years ago I analyzed a bunch of XML tree libraries in Rust. The best I\nfound, <a href=\"https://docs.rs/roxmltree\" rel=\"nofollow ugc noopener\">roxmltrree</a>, has an immutable tree. But I\nneeded a mutable tree. I found quite a few libraries that did support\nmutability, but many did not support parent references. You couldn&#39;t walk up the\nancestor chain of a node. This, along with missing support for some XML\nfeatures, is why I created my own in the form of\n<a href=\"https://docs.rs/xot/latest/xot/\" rel=\"nofollow ugc noopener\">Xot</a>.</p>\n<p>The reason for this surprising lack of parent references is the ownership\nlimitation I discussed before: Rust makes circular references difficult. You can\nget around it using reference counted types and internal mutability, but in a\nlot of cases this pattern isn&#39;t really optimal -- it&#39;s verbose, less performant,\nand reference count cycles risk memory leaks. What you do instead is store nodes\nin an array and you use the array indexes to node as your reference. You can\nthen have an index referencing your parent, and use index references to your\nchildren, or any other circular reference.</p>\n<p>A fancy word for this pattern is an &#39;arena&#39; and in Rust they show up everywhere.</p>\n<p>In an arena, you store a lot of objects together in the same region of memory\n(in an array). What does it let you do?</p>\n<ul><li><p>iterate fast over its contents. Objects being in the same memory region means</p><p>the CPU can use its cache effectively. This is <em>much</em> faster than arbitrary\nmain memory access and loops really benefit.</p></li><li><p>fast allocation. The arena is allocated from the heap as a block, and after</p><p>that your allocations may just be a few increments.</p></li><li><p>interning: you store something once in the arena and use it in many places, so</p><p>you don&#39;t duplicate data.</p></li><li><p>the arena owns its stuff. Everything in the arena has the same lifetime.</p><p>Indexes between objects in an arena can be circular without worrying.</p></li></ul>\n<p>Rust pushes you to use arenas. This involves more ceremony than just using a\ndirect reference, but it also means Rust pushes you to write code that computers\ncan execute really efficiently.</p>\n<h2 id=\"performance-has-a-quality-all-its-own\">Performance has a quality all its own</h2>\n<p>I mentioned performance a number of times. But what about <a href=\"https://blog.startifact.com/posts/is-premature-optimization-the-root-of-all-evil/\" rel=\"nofollow ugc noopener\">premature\noptimization</a>? The\ngreat irony of this quote is that it comes from a paper where the author, Knuth,\nargues in favor of keeping the <code>goto</code> statement around, as it&#39;s essential for\nwriting efficient software.</p>\n<p>Rust lets you know what you pay for. Reference counting? Dynamic dispatch? You\ncan do it, but it&#39;s going to be visible in your code. Rust <em>also</em> often lets you\nknow when you <em>don&#39;t</em> want to pay for it: just look at <a href=\"https://docs.rs/tower/\" rel=\"nofollow ugc noopener\">tower\nmiddleware</a> and despair about all the generic types and\ntype constraints that get piled onto a relatively simple abstraction.</p>\n<p>When you have these tools available, need to develop new wisdom about tradeoffs\nthat never seemed to matter. If you write Python code you&#39;re not too worried\nabout hash tables being a performance bottle neck, but in Rust code they\ncertainly can be. You can get lost along the way into hyper optimization land.\nOften you need to just get go <a href=\"#clone_and_own\">8</a>. Many patterns that are just\nplain readable Rust code anyway happen to also be friendly to the CPU executing\nit.</p>\n<p>But Rust overwhelming you with details you may not want to think about is not\nthe whole story, because performance is not just quantitative: if your code can\ntruly be more performance, it can access new qualities. When you can write code\nthat uses no memory and no CPU time <a href=\"#exaggeration\">9</a>, it changes how you\nthink. It changes what&#39;s possible.</p>\n<p>Sometimes the quality of performance is obvious: if you write numerical code, or\na simulation, of course you don&#39;t want to wait for the answer. Being able to do\nmany computations really fast is key to making AI possible.</p>\n<p>But it&#39;s more subtle that that: modern computers are <em>really</em> powerful, and\n<em>ridicously</em> fast, and we generally ignore that and just throw more resources at\nour problems. There are good reasons <a href=\"https://blog.startifact.com/posts/bloat-retrofuturism/\" rel=\"nofollow ugc noopener\">why this\nhappens</a>. But if we open our eyes a little,\nthere are new architectural possibilities we can explore.</p>\n<p>While the power of macros were the biggest language surprise, I think this is\nthe biggest shift in my thinking: access to performance unlocks possibilities I\nhadn&#39;t considered before. Take my experiment\n<a href=\"https://github.com/faassen/colchis\" rel=\"nofollow ugc noopener\">Colchis</a>: a library can store vast amounts\nof JSON in memory, while retaining full access, even indexed access (I still\nhope to add jsonpath one day!), to JSON data. Before Rust, this was a\npossibility that wasn&#39;t even on my radar.</p>\n<p><strong>Rust made me a better programmer because I can make the computer do more with\nless, opening up new areas of opportunity.</strong></p>\n<h2 id=\"conclusion\">Conclusion</h2>\n<p>Rust is one of the most difficult programming languages I&#39;ve learned -- and thus\none of the languages that changed me the most. There&#39;s a simple part of Rust\nthat isn&#39;t much harder to manage than any language, and in some cases may\nactually make your life easier -- <code>enum</code>s, declarative type-driven frameworks,\nand the excellent dev tooling come to mind. Even arenas are fundamentally not\nthat difficult to understand. The complexity is in unlearning some habits and\nlearning new ones. And then there&#39;s a more challenging complex Rust, mostly, but\nnot always under the surface, there when you need it.</p>\n<p>Rust expands the reach of what I can build. That&#39;s what makes me happy I\nwent on this journey. <a href=\"#all_the_tradeoffs\">10</a></p>\n<p>1</p>\n<p>AI agents write a lot of code. They know the programming language, so do\nyou need to know it? Does the language still affect the developer? If you share\nmy belief it&#39;s good <a href=\"https://blog.startifact.com/posts/sigh-coding/\" rel=\"nofollow ugc noopener\">to look at the code</a>, then it helps\nif you understand the code you&#39;re reading. I also think it&#39;s never been more\nimportant to think about how the systems you use affect the way you think and\nbehave.</p>\n<p>2</p>\n<p>If you don&#39;t know what a struct is, just call it a class in your\nhead, and you&#39;re good.</p>\n<p>3</p>\n<p>You have them in many languages but in impoverished forms, like\n<code>true</code>/<code>false</code>, or C&#39;s <code>enum</code>.</p>\n<p>4</p>\n<p>If you&#39;re going to do static type checking anyway for the\nguarantees it brings, perhaps use a language designed around it (enums!) that\nalso gives you performance benefits?</p>\n<p>5</p>\n<p>Does AI truly understand? Do you want to have a philosophical\ndebate? What do we mean by <em>understand</em>? Natural language is <a href=\"https://en.wikipedia.org/wiki/Pragmatics\" rel=\"nofollow ugc noopener\">inherently\nstretchable</a>.</p>\n<p>6</p>\n<p>With AI we&#39;ve seen the return of big design up front. I may be\nwrong, but I&#39;m still skeptical of this approach, and still a fan of iterative\ndevelopment and incremental learning and theory building.</p>\n<p>7</p>\n<p>Not impossible. I&#39;ve seen it. People can do it if they really\ntry, and it still makes life harder; it makes it much harder to test. But at\nleast it&#39;s more obvious and more difficult to do.</p>\n<p>8</p>\n<p>Clone and own all the stuff! Which incidentally can also lead\nto more contiguous memory layouts...</p>\n<p>9</p>\n<p>No memory and no CPU time is an exaggeration, but little Rust\nprograms sometimes feel that way.</p>\n<p>10</p>\n<p>AI development is shifting all the tradeoffs in software\ndevelopment - they&#39;re not gone, but they have shifted. The AI can write Rust,\neven if you don&#39;t know it. But I trust plenty of contexts remain where my Rust\nexperience plus AI leads to a better outcome than AI by itself.</p>","headings":[{"level":1,"text":"How Rust Changed Me As A Developer","id":"how-rust-changed-me-as-a-developer"},{"level":2,"text":"Where were enums all my life?","id":"where-were-enums-all-my-life"},{"level":2,"text":"Enums and abstraction","id":"enums-and-abstraction"},{"level":2,"text":"Dispatch galore","id":"dispatch-galore"},{"level":2,"text":"Type driven development","id":"type-driven-development"},{"level":2,"text":"The Biggest Surprise","id":"the-biggest-surprise"},{"level":2,"text":"Ownership and Architecture","id":"ownership-and-architecture"},{"level":2,"text":"The arena pattern everywhere","id":"the-arena-pattern-everywhere"},{"level":2,"text":"Performance has a quality all its own","id":"performance-has-a-quality-all-its-own"},{"level":2,"text":"Conclusion","id":"conclusion"}]}}