<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title></title>
    <link rel="self" type="application/atom+xml" href="https://prydt.xyz/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://prydt.xyz"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-05-10T00:00:00+00:00</updated>
    <id>https://prydt.xyz/atom.xml</id>
    <entry xml:lang="en">
        <title>A Few Good Ideas in Programming Languages</title>
        <published>2026-05-10T00:00:00+00:00</published>
        <updated>2026-05-10T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/a-few-good-ideas-in-pl/"/>
        <id>https://prydt.xyz/blog/a-few-good-ideas-in-pl/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/a-few-good-ideas-in-pl/">&lt;p&gt;Here are just a few programming language features I love:&lt;&#x2F;p&gt;
&lt;h1 id=&quot;1-flow-typing&quot;&gt;1. Flow Typing&lt;&#x2F;h1&gt;
&lt;p&gt;A great idea that I first encountered in &lt;a href=&quot;https:&#x2F;&#x2F;crystal-lang.org&quot;&gt;Crystal&lt;&#x2F;a&gt;, is the idea of &lt;em&gt;flow typing&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Crystal is a compiled programming langauge with static type-checking with syntax very similar to the &lt;a href=&quot;https:&#x2F;&#x2F;www.ruby-lang.org&#x2F;en&#x2F;&quot;&gt;Ruby programming language&lt;&#x2F;a&gt;. Something that keeps Crystal feeling like a dynamically typed language is how a variable can be assigned to multiple types throughout the course of its lifetime, unlike most statically typed languages I&#x27;ve used. Here is an example:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;Crystal&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-Crystal &quot;&gt;&lt;code class=&quot;language-Crystal&quot; data-lang=&quot;Crystal&quot;&gt;&lt;span&gt;my_var &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;5
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# my_var&amp;#39;s type here is Int32
&lt;&#x2F;span&gt;&lt;span&gt;assert(my_var.is_a?(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;Int32&lt;&#x2F;span&gt;&lt;span&gt;))
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; some_complex_condition()
&lt;&#x2F;span&gt;&lt;span&gt;  my_var &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;hello!&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;  # my_var&amp;#39;s type here is String
&lt;&#x2F;span&gt;&lt;span&gt;  assert(my_var.is_a?(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;))
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;end
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# What is my_var&amp;#39;s type here?
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;#
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# It&amp;#39;s Int32 | String
&lt;&#x2F;span&gt;&lt;span&gt;assert(my_var.is_a?(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;Int32 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;| &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;))
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;What&#x27;s most interesting about this is that there is some time when &lt;code&gt;my_var&lt;&#x2F;code&gt; is just a &lt;code&gt;Int32&lt;&#x2F;code&gt;, there is a region where it is guaranteed to be a &lt;code&gt;String&lt;&#x2F;code&gt; and then there is a region where the compiler cannot actually guarantee one or the other... so its type is the union of all the possibilities. Now if you try to run a &lt;code&gt;String&lt;&#x2F;code&gt; method on &lt;code&gt;my_var&lt;&#x2F;code&gt;, it&#x27;ll fail because its not a &lt;code&gt;String&lt;&#x2F;code&gt;, its a &lt;code&gt;Int32 | String&lt;&#x2F;code&gt; and the compiler will force you to add a check like &lt;code&gt;if my_var.is_a?(String)&lt;&#x2F;code&gt; which &lt;em&gt;narrows&lt;&#x2F;em&gt; the possible types to just a &lt;code&gt;String&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This is a great example of using fancy type inference to make a compiled language &lt;em&gt;feel&lt;&#x2F;em&gt; dynamic without paying much of a runtime penalty.&lt;&#x2F;p&gt;
&lt;p&gt;Typescript also has &lt;a href=&quot;https:&#x2F;&#x2F;www.typescriptlang.org&#x2F;docs&#x2F;handbook&#x2F;2&#x2F;narrowing.html#control-flow-analysis&quot;&gt;flow typing&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;www.typescriptlang.org&#x2F;docs&#x2F;handbook&#x2F;2&#x2F;narrowing.html&quot;&gt;type narrowing&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;2-borrow-checking&quot;&gt;2. Borrow Checking&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;rust-lang.org&#x2F;&quot;&gt;Rust&lt;&#x2F;a&gt; is a systems programming language which guarantees memory safety without a garbage collector.&lt;&#x2F;p&gt;
&lt;p&gt;One large class of memory safety bugs in concurrent programs is the loathsome data race: when multiple threads read and write the same memory location simultaneously without synchronization.&lt;&#x2F;p&gt;
&lt;p&gt;The borrow checker is how Rust is able to statically prevent data races at compile-time. It enforces the following &lt;a href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;1.8.0&#x2F;book&#x2F;references-and-borrowing.html&quot;&gt;rules&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Any borrow must not out-live the scope of the owner&lt;&#x2F;li&gt;
&lt;li&gt;You can EITHER have:
&lt;ul&gt;
&lt;li&gt;exactly 1 mutable reference (&lt;code&gt;&amp;amp;mut T&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;OR 1 or more immutable references (&lt;code&gt;&amp;amp;T&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This might remind you of a &lt;a href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Readers%E2%80%93writer_lock&quot;&gt;readers-writer lock&lt;&#x2F;a&gt; which is a lock which allows many readers OR a singular writer. This is because to prevent data races, we only need to synchronize reads with respect to writes. The point of concurrent synchronization is to serialize the writes to a given memory location.&lt;&#x2F;p&gt;
&lt;p&gt;I love the borrow checker because it is such an elegant solution to the problem of data races and are a zero-cost abstraction which only comes at the cost of compile-time checks and added complexity. Added complexity is a real tradeoff but if you are writing concurrent programs, this complexity is inherent to the subject matter.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;3-contract-programming&quot;&gt;3. Contract Programming&lt;&#x2F;h1&gt;
&lt;p&gt;If you&#x27;ve programmed much, you&#x27;ve probably come across the humble assert statement, which is used to error &#x2F; report if a given invariant isn&#x27;t upheld. Every program has invariants that it needs to uphold. Things like &quot;this date is always past this other date&quot; or &quot;this tree is always balanced.&quot;&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;a href=&quot;https:&#x2F;&#x2F;dlang.org&#x2F;&quot;&gt;D programming language&lt;&#x2F;a&gt; (such an underrated language) supports &lt;a href=&quot;https:&#x2F;&#x2F;dlang.org&#x2F;spec&#x2F;contracts.html&quot;&gt;contract programming&lt;&#x2F;a&gt; where it provides syntactic support for describing more complex invariants which can be at the function-level or object-level.&lt;&#x2F;p&gt;
&lt;p&gt;D has standard assert statements:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;D&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-D &quot;&gt;&lt;code class=&quot;language-D&quot; data-lang=&quot;D&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;double &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;always_positive &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;assert&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;always_positive &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But D also has &lt;code&gt;enforce&lt;&#x2F;code&gt; which is used to mark a difference in semantics. Asserts are used for program invariant violations. If an assert is triggered, this should indicate a correctness bug in our program. &lt;code&gt;enforce&lt;&#x2F;code&gt; instead throws an exception due to some external issue: something like a user input out of bounds or environment issue.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;D&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-D &quot;&gt;&lt;code class=&quot;language-D&quot; data-lang=&quot;D&quot;&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;enforce&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;length &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Must be at least 7.&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Additionally, D has syntactic support for pre- and post-conditions for functions.  Here&#x27;s an example taken from &lt;a href=&quot;https:&#x2F;&#x2F;ddili.org&#x2F;ders&#x2F;d.en&#x2F;contracts.html&quot;&gt;Programming in D&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;D&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-D &quot;&gt;&lt;code class=&quot;language-D&quot; data-lang=&quot;D&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;daysInFebruary&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;year&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;out &lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;result&lt;&#x2F;span&gt;&lt;span&gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;assert&lt;&#x2F;span&gt;&lt;span&gt;((&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;result &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;== &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;28&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;|| &lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;result &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;== &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;29&lt;&#x2F;span&gt;&lt;span&gt;));
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;do &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;isLeapYear&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;year&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;? &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;29 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;28&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here the &lt;code&gt;daysInFebruary&lt;&#x2F;code&gt; function has a post-condition which is that it should only ever return 28 or 29; everything else is definitely a logical error in the function.&lt;&#x2F;p&gt;
&lt;p&gt;And finally, D has class-level invariants which are used to guarantee that object data is is always consistent. Here is a slightly more complex example tying everything together:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;D&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-D &quot;&gt;&lt;code class=&quot;language-D&quot; data-lang=&quot;D&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;class &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;BankAccount {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;private double &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;invariant&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;() {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;&#x2F;&#x2F; object-level invariant, always checked
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;this&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;double &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;initialBalance&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;in &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;initialBalance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Initial balance cannot be negative&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;initialBalance&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;void &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;deposit&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;double &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;in  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Deposit amount must be positive&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;out &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;== &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;&#x2F;&#x2F; checked after method returns
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;void &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;withdraw&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;double &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;in  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0,           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Withdrawal amount must be positive&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;in  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;lt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;,    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Insufficient funds&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;out &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0,       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Balance must remain non-negative&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;-= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;amount&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;double &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;getBalance&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;()
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;out &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;result&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;result &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Balance returned must be non-negative&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;balance&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This &lt;code&gt;invariant()&lt;&#x2F;code&gt; block is far cleaner and easier to maintain than having some consistency check function run at the beginning and end of every class method, and it has idomatic meaning.&lt;&#x2F;p&gt;
&lt;p&gt;-- Pranoy&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>AI Fear and Uncertainty</title>
        <published>2026-04-12T00:00:00+00:00</published>
        <updated>2026-04-12T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/ai-fear-and-uncertainty/"/>
        <id>https://prydt.xyz/blog/ai-fear-and-uncertainty/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/ai-fear-and-uncertainty/">&lt;blockquote&gt;
&lt;p&gt;&quot;We mustn&#x27;t be caught by surprise by our own advancing technology.&quot; -- Aldous Huxley&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;But we often are. Technologies like the printing press, the radio, the television, the internet, and the smartphone have all outpaced any sort of institutional understanding or regulation.
In many ways this has to be the case. At least in the US, this is how our governing institions were designed. And how do you go about regulating a technology you don&#x27;t understand?&lt;&#x2F;p&gt;
&lt;p&gt;This latest wave of AI is the next such technology which will outpace us, and we are not ready. I see disaster in the future. It&#x27;s not hard to see.&lt;&#x2F;p&gt;
&lt;p&gt;While the most vocal proponents of AI promise that it will be a technology which will revolutionize all work, automating away grudgery while at the same time curing all ailments, I fear that most people do not see it this way.
If you see AI as a gift to humanity, we should take a step back and think about how AI has affected the majority of people.&lt;&#x2F;p&gt;
&lt;p&gt;Say you are the average person:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that the internet you once knew is gone. That social media sites you visit are flooded with slop and bots. AI scrapers lead to sites you visit needing to put up migitations.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that you have to be more on guard when viewing images and videos. Sure photoshop has been around for a while but you realize that AI has dropped the skill required to generate realistic looking media. You worry about how this will affect our politics.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that almost every piece of software you use has annoying AI features shoved in your face. Maybe you&#x27;ve noticed that only a few of these features are actually any good.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that the S&amp;amp;P 500 is more than 7% just NVIDIA. Maybe you worry about this so called &quot;AI bubble.&quot; You worry about it popping.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that our schools and universities aren&#x27;t equipped to deal with ChatGPT powered cheating. Maybe you yourself are gen-AI-ing your way through school. Everyone else is doing it.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that you are more worried at work. You worry that your boss thinks that AI can automate you away. Maybe you worry that your boss expects double the output because AI will magically make you much more productive. Your boss probably doesn&#x27;t understand Amdahl&#x27;s law.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that you are worried about layoffs. Everyone&#x27;s doing them now because of AI, right? If it&#x27;s not AI, its probably AI spending.&lt;&#x2F;li&gt;
&lt;li&gt;Maybe you&#x27;ve noticed that deepfakes are a huge problem that we haven&#x27;t addressed yet. Maybe you realize that AI has automated revenge porn.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Oh and yeah I guess it&#x27;s nice that AI makes it easy to generate an email or something.&lt;&#x2F;p&gt;
&lt;p&gt;People are not stupid. They realize that AI can lead to a great bifurcation. Even in tech circles people meme about &quot;a permanent underclass.&quot; People worry that if AI succeeds, it will take away their jobs... and if it doesn&#x27;t? If this &quot;AI bubble&quot; pops... They except to lose their jobs to a great recession. They expect to have their savings wiped out.
People feel that our current configuration of society will lead to them not getting to really taste the fruits of AI. And when you fill a populous with fear, resentment, anger, uncertainty, and desperation... I wonder what happens.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m not saying that all of this is true. I&#x27;m saying that it doesn&#x27;t take much to read the room and see that this is the general sentiment. And these feelings matter. If you want AI to be successful, if you really think it will do all these great things, we&#x27;ll have to change the configuration of society to assure people that they will benefit. What this means, I&#x27;m not sure. I think a stronger welfare state is necessary.&lt;&#x2F;p&gt;
&lt;p&gt;-- Pranoy&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>On Tony Hoare</title>
        <published>2026-03-12T00:00:00+00:00</published>
        <updated>2026-03-12T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/tony-hoare/"/>
        <id>https://prydt.xyz/blog/tony-hoare/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/tony-hoare/">&lt;p&gt;Every so often something happens that makes me remember that computer programming is a new thing.&lt;&#x2F;p&gt;
&lt;p&gt;Something that makes me remember that we are still in the infancy of computing. That we don&#x27;t really know what we are doing and we are still figuring it out. We can&#x27;t boast the long histories of fields like math, medicine, or mechanics.&lt;&#x2F;p&gt;
&lt;p&gt;Sir Tony Hoare&#x27;s recent passing made me remember that.&lt;&#x2F;p&gt;
&lt;p&gt;Computing is such a young field that many of our pioneers are still around.[^2] Hoare is an inspiration to me and I thought it would be nice to write a little about his many contributions to our young field.&lt;&#x2F;p&gt;
&lt;p&gt;While Hoare was most known for &lt;strong&gt;Quicksort&lt;&#x2F;strong&gt;[^1], I want to cover some of his other work:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Record Handling (structs, enums, null)&lt;&#x2F;li&gt;
&lt;li&gt;Monitor Synchronization&lt;&#x2F;li&gt;
&lt;li&gt;Floyd-Hoare Logic&lt;&#x2F;li&gt;
&lt;li&gt;Communicating Sequential Processes&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;record-handling-1966&quot;&gt;Record Handling (1966)&lt;&#x2F;h1&gt;
&lt;p&gt;Hoare introduced the idea of &quot;record structures&quot; which are now just called structs. In this same essay, he introduces &quot;record subclasses&quot; which are akin to discriminated unions (think Rust enums). Finally, if that wasn&#x27;t enough, he introduces the notion of a &quot;null reference&quot; which he calls his &quot;billion dollar mistake.&quot; Anytime you get a NullPointerException? That&#x27;s him too.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;monitor-synchronization&quot;&gt;Monitor Synchronization&lt;&#x2F;h1&gt;
&lt;p&gt;Hoare elaborated and popularized the Monitor concurrency primitive invented by Per Brinch Hansen. Monitors solve a common issue in concurrent programs: making threads (efficiently) wait for a condition to become true before continuing.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;floyd-hoare-logic&quot;&gt;Floyd-Hoare Logic&lt;&#x2F;h1&gt;
&lt;p&gt;In &quot;An Axiomatic Basis for Computer Programming&quot; (1969), Hoare develops a systematic method for reasoning about the meaning of computer programs. One of the key ideas of this logic is what is now known as a &quot;Hoare triple&quot;: &lt;code&gt;P {Q} R&lt;&#x2F;code&gt; where &lt;code&gt;P&lt;&#x2F;code&gt; is a precondition, &lt;code&gt;Q&lt;&#x2F;code&gt; is a program, and &lt;code&gt;R&lt;&#x2F;code&gt; is a postcondition. If &lt;code&gt;P&lt;&#x2F;code&gt; holds, then running &lt;code&gt;Q&lt;&#x2F;code&gt; will lead to &lt;code&gt;R&lt;&#x2F;code&gt; being true. With axioms and inference rules for imperative programming, you can write a proof about the behavior of programs which is exactly what modern verification languages like &lt;a href=&quot;https:&#x2F;&#x2F;dafny.org&#x2F;&quot;&gt;Dafny&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;verus-lang&#x2F;verus&quot;&gt;Verus&lt;&#x2F;a&gt; do!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;communicating-sequential-processes-csp&quot;&gt;Communicating Sequential Processes (CSP)&lt;&#x2F;h1&gt;
&lt;p&gt;The core idea of CSP is modeling concurrent systems as a set of independent processes which do not share memory but instead communicate through &quot;channels.&quot; Processes can send messages cross these channels, and other processes can recieve messages through them.&lt;&#x2F;p&gt;
&lt;p&gt;You can see the echos of CSP&#x27;s influence in languages like Erlang and Go.&lt;&#x2F;p&gt;
&lt;p&gt;These are just some of Tony Hoare&#x27;s most influencial ideas but I need to stop somewhere (and it&#x27;s 1:40AM here so I should logoff...).&lt;&#x2F;p&gt;
&lt;p&gt;Rest in peace.&lt;&#x2F;p&gt;
&lt;p&gt;[^1] &lt;a href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;primitive.slice.html#method.sort_unstable&quot;&gt;Rust&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;algorithm&#x2F;sort.html#Notes&quot;&gt;C++&lt;&#x2F;a&gt; both include a &quot;sort&quot; algorithm which is a hybrid sorting algorithm which uses Quicksort for large arrays, and fallsback to heapsort and insertion sort for smaller arrays. The details vary from language to language but Quicksort is still state of the art!&lt;&#x2F;p&gt;
&lt;p&gt;[^2] Alan Turing could&#x27;ve probably made it to the 1990s if the Brits weren&#x27;t as homophobic. He would be 114 today.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Configuration Languages Should be Strongly Typed</title>
        <published>2026-03-05T00:00:00+00:00</published>
        <updated>2026-03-05T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/config-languages-strong-typing/"/>
        <id>https://prydt.xyz/blog/config-languages-strong-typing/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/config-languages-strong-typing/">&lt;p&gt;Nothing in an undergraduate education in computer science prepared me for the amount of YAML I would have to stare at as a software engineer. Whether its to configure k8s, docker, CI, my eyes start to glaze over. The indentation guides on my favorite hipster IDE blend together as I try to figure out whether the snippet of config I copy-and-pasted from another codebase is correctly aligned.&lt;&#x2F;p&gt;
&lt;p&gt;This sucks.&lt;&#x2F;p&gt;
&lt;p&gt;Much of the infastructure that powers our world is build on a foundation of oceans of JSON and mountains of YAML.&lt;&#x2F;p&gt;
&lt;p&gt;I think the configuration languages we use should be more like programming languages. In specific, they should have a strong type system with the ability to effectively convey constraints, and require schemas.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s an example.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;yaml&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-yaml &quot;&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;server&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;port&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;8080&amp;quot;         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# string or int?
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;timeout&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;30          &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# seconds? milliseconds?
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;ssl&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;yes&amp;quot;           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# bool? string? &amp;quot;yes&amp;quot;&#x2F;&amp;quot;true&amp;quot;&#x2F;1?
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;max_connections&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;-1  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# valid? sentinel for &amp;quot;unlimited&amp;quot;?
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;log_level&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;verbose&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# what are the valid options?
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;retries&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;3.7         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;# fractional retries make no sense
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now while this is just a random bit of YAML I produced, we can already start to see the limitations of YAMLs types and how it is conveyed to the programmer.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s see how we can do better using something like Zod, a TypeScript schema validation library.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;typescript&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-typescript &quot;&gt;&lt;code class=&quot;language-typescript&quot; data-lang=&quot;typescript&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;ServerConfig &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;({
&lt;&#x2F;span&gt;&lt;span&gt;  port: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;number&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;min&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;max&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;65535&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;  timeout: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;number&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;positive&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;describe&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;Timeout in milliseconds&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;  ssl: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;boolean&lt;&#x2F;span&gt;&lt;span&gt;(),
&lt;&#x2F;span&gt;&lt;span&gt;  maxConnections: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;number&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;positive&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;literal&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;Infinity&lt;&#x2F;span&gt;&lt;span&gt;)),
&lt;&#x2F;span&gt;&lt;span&gt;  logLevel: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span&gt;([&lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;debug&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;info&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;warn&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;error&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]),
&lt;&#x2F;span&gt;&lt;span&gt;  retries: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;z&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;number&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;nonnegative&lt;&#x2F;span&gt;&lt;span&gt;(),
&lt;&#x2F;span&gt;&lt;span&gt;});
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is an example of the sorts of constraints which would be really great to be able to express in a configuration language. Here, we can tell that:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;port must be within the range [1, 65535]&lt;&#x2F;li&gt;
&lt;li&gt;logLevel must be one of the options instead of an arbitrary string&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;and so on.&lt;&#x2F;p&gt;
&lt;p&gt;Strong types let us convey constraints clearly and regardless of whether we convey it to the user, all of our programs have constraints. This is why a schema is also important. Regardless of whether we provide a schema to the user, there is always an &lt;em&gt;implicit schema&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This schema-on-read is built in to the way that our program parses (and validates... we are validating user-provided data, right?) the config file.&lt;&#x2F;p&gt;
&lt;p&gt;Now take a look at this config file:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;dhall&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-dhall &quot;&gt;&lt;code class=&quot;language-dhall&quot; data-lang=&quot;dhall&quot;&gt;&lt;span&gt;let LogLevel = &amp;lt; Debug | Info | Warn | Error &amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;let MaxConnections = &amp;lt; Unlimited | Limit : Natural &amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;let ServerConfig =
&lt;&#x2F;span&gt;&lt;span&gt;  { port : Natural
&lt;&#x2F;span&gt;&lt;span&gt;  , timeout_ms : Natural
&lt;&#x2F;span&gt;&lt;span&gt;  , ssl : Bool
&lt;&#x2F;span&gt;&lt;span&gt;  , log_level : LogLevel
&lt;&#x2F;span&gt;&lt;span&gt;  , max_connections : MaxConnections
&lt;&#x2F;span&gt;&lt;span&gt;  , retries : Natural
&lt;&#x2F;span&gt;&lt;span&gt;  }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;let config : ServerConfig =
&lt;&#x2F;span&gt;&lt;span&gt;  { port = 8080
&lt;&#x2F;span&gt;&lt;span&gt;  , timeout_ms = 5000
&lt;&#x2F;span&gt;&lt;span&gt;  , ssl = True
&lt;&#x2F;span&gt;&lt;span&gt;  , log_level = LogLevel.Info
&lt;&#x2F;span&gt;&lt;span&gt;  , max_connections = MaxConnections.Limit 100
&lt;&#x2F;span&gt;&lt;span&gt;  , retries = 3
&lt;&#x2F;span&gt;&lt;span&gt;  }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;in { server = config }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a configuration language called &lt;a href=&quot;https:&#x2F;&#x2F;dhall-lang.org&#x2F;&quot;&gt;Dhall&lt;&#x2F;a&gt;. You can think of it like &quot;JSON + functions + types + imports.&quot; This Dhall file actually compiles into&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;yaml&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-yaml &quot;&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;server&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;log_level&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;Info
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;max_connections&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;100
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;port&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;8080
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;retries&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;3
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;ssl&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;true
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;timeout_ms&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;5000
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;but it is so much clearer.&lt;&#x2F;p&gt;
&lt;p&gt;To conclude, types and schemas are really our best friends for dealing with all sorts of problems we can run into when writing configuration state in brittle formats such as JSON or YAML.&lt;&#x2F;p&gt;
&lt;p&gt;There are many other interesting higher level configuration languages to try like Dhall, Apple&#x27;s &lt;a href=&quot;https:&#x2F;&#x2F;pkl-lang.org&#x2F;index.html&quot;&gt;Pkl&lt;&#x2F;a&gt;, and Google&#x27;s &lt;a href=&quot;https:&#x2F;&#x2F;starlark-lang.org&#x2F;&quot;&gt;Starlark&lt;&#x2F;a&gt;. If jumping in the deep end is impractical, even just combining an existing JSON config file with a &lt;a href=&quot;https:&#x2F;&#x2F;json-schema.org&#x2F;learn&#x2F;getting-started-step-by-step&quot;&gt;JSON Schema&lt;&#x2F;a&gt; is a great first step, and provides real benefits.&lt;&#x2F;p&gt;
&lt;p&gt;-- prydt&lt;&#x2F;p&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;beza1e1.tuxen.de&#x2F;config_levels.html&quot;&gt;https:&#x2F;&#x2F;beza1e1.tuxen.de&#x2F;config_levels.html&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lexi-lambda.github.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;05&#x2F;parse-don-t-validate&#x2F;&quot;&gt;https:&#x2F;&#x2F;lexi-lambda.github.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;05&#x2F;parse-don-t-validate&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Albums I Listened to in College</title>
        <published>2026-01-08T00:00:00+00:00</published>
        <updated>2026-01-08T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/albums-in-college/"/>
        <id>https://prydt.xyz/blog/albums-in-college/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/albums-in-college/">&lt;p&gt;&lt;img src=&quot;&#x2F;album-collage.jpg&quot; alt=&quot;A collage featuring the album covers described in this article&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Music has the uncanny ability to always remind me of certain people or certain times. Last year I graduated college, and I wanted to share some of the albums that stuck with me the most. You&#x27;ll definitely realize that these are mostly in the vein of hyperpop or indie rock adjacent stuff.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ll include a few songs from each album that I think are standout so you can give each a quick taste but each and every one of these albums has been picked for being pretty cohesive and consistent in quality.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s a brief set of &quot;tasting notes&quot; from some of my favorite albums of recent years:&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-100-gecs-1000-gecs&quot;&gt;1. 100 gecs - 1000 gecs&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;(okayyyy... this album might not be the best to start off with. many others on this list are way more approachable. if this isn&#x27;t your cup of matcha soy milk latte , i very much get it.  but for the freaks like me... this will change your life
)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;got me into hyperpop&lt;&#x2F;li&gt;
&lt;li&gt;shrill, harsh&lt;&#x2F;li&gt;
&lt;li&gt;bombastic&lt;&#x2F;li&gt;
&lt;li&gt;autotune, catchy as hell&lt;&#x2F;li&gt;
&lt;li&gt;doesn&#x27;t take itself too seriously. very fun&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: 745 sticky, money machine, ringtone&lt;&#x2F;p&gt;
&lt;h2 id=&quot;2-underscores-fishmonger-fearmonger&quot;&gt;2. underscores - fishmonger &#x2F; fearmonger&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The goddess of fortune was smiling on me when by chance, i attended a 100 gecs concert where the opener was none other than Underscores. She quickly became my favorite favorite favorite hyperpop musician of all time.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;extremely approachable hyperpop&lt;&#x2F;li&gt;
&lt;li&gt;very catchy, very tasteful&lt;&#x2F;li&gt;
&lt;li&gt;some of the best production ever&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: second hand embarrassment, bozo bozo bozo, spoiled little brat, your favorite sidekick&lt;&#x2F;p&gt;
&lt;p&gt;if you like this album, go listen to Fearmonger and &lt;a href=&quot;https:&#x2F;&#x2F;soundcloud.com&#x2F;underscores&#x2F;snny&quot;&gt;story of s*nny&lt;&#x2F;a&gt; (on soundcloud only???? WHY)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;3-glass-beach-the-first-glass-beach-album&quot;&gt;3. glass beach - the first glass beach album&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;lowkey emo&lt;&#x2F;li&gt;
&lt;li&gt;thoughtful lyrics&lt;&#x2F;li&gt;
&lt;li&gt;energetic&lt;&#x2F;li&gt;
&lt;li&gt;really raw vocals&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: cold weather, bedroom community, classic j dies and goes to hell part 1, glass beach&lt;&#x2F;p&gt;
&lt;h2 id=&quot;4-wild-party-phantom-pop&quot;&gt;4. wild party - phantom pop&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;no skip album&lt;&#x2F;li&gt;
&lt;li&gt;just really really good indie pop.&lt;&#x2F;li&gt;
&lt;li&gt;nothing more to really say&lt;&#x2F;li&gt;
&lt;li&gt;if there was any justice, it would&#x27;ve been far more successful when it came out. (like Tally Hall)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: OutRight, Life&#x27;s Too Short, Take My Advice, Violet, Chasin&#x27; Honey, Lo-Fi Children&lt;&#x2F;p&gt;
&lt;h2 id=&quot;5-jhariah-a-beginners-guide-to-faking-your-death&quot;&gt;5. jhariah - a beginners guide to faking your death&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;One of the most cohesive albums on this list. Tells a very fun story.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;jazzy&lt;&#x2F;li&gt;
&lt;li&gt;musicial&lt;&#x2F;li&gt;
&lt;li&gt;genre bending&lt;&#x2F;li&gt;
&lt;li&gt;incredible vocal range&lt;&#x2F;li&gt;
&lt;li&gt;villainous&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: ENTER: A BEGINNERS GUIDE TO FAKING YOUR DEATH, PRESSURE BOMB 3?!?!, DEBT COLLECTOR, Flight of the Crows&lt;&#x2F;p&gt;
&lt;h2 id=&quot;6-good-kid-good-kid&quot;&gt;6. good kid - good kid&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;really solid indie rock&lt;&#x2F;li&gt;
&lt;li&gt;songs are similar, but in a good way&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: Alchemist, Tell Me You Know, Witches&lt;&#x2F;p&gt;
&lt;h2 id=&quot;7-vampire-weekend-vampire-weekend&quot;&gt;7. vampire weekend - vampire weekend&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;saw them live, one of the best concerts I&#x27;ve been to. oldest album on this list which has a very recent skew&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;fancy indie rock&lt;&#x2F;li&gt;
&lt;li&gt;ivy league vibes&lt;&#x2F;li&gt;
&lt;li&gt;aristocracy&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: Campus, Mansard Roof, Oxford Comma, M79&lt;&#x2F;p&gt;
&lt;h2 id=&quot;8-friday-pilots-club-nowhere&quot;&gt;8. friday pilots club - nowhere&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Honestly just go listen to everything made by them. Lots of great singles not on this album.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;dark&lt;&#x2F;li&gt;
&lt;li&gt;haunting vocals&lt;&#x2F;li&gt;
&lt;li&gt;high energy&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: Vampire Disco, Nowhere, Spectator&lt;&#x2F;p&gt;
&lt;h2 id=&quot;9-happy-fits-concentrate&quot;&gt;9. happy fits - Concentrate&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;happy&lt;&#x2F;li&gt;
&lt;li&gt;a tinge of melancholy, the right amount&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;top songs: Best Tears, &quot;Alright, Cool, Whatever&quot;, Achey Bones&lt;&#x2F;p&gt;
&lt;p&gt;Please go listen to these and tell me what you think!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Fuzzing Binary Search</title>
        <published>2025-11-10T00:00:00+00:00</published>
        <updated>2025-11-10T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/fuzzing-binary-search/"/>
        <id>https://prydt.xyz/blog/fuzzing-binary-search/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/fuzzing-binary-search/">&lt;p&gt;Something close to a holy grail for me in programming is an automated test generator.&lt;&#x2F;p&gt;
&lt;p&gt;Given some function, I would love to be able to throw my code at another program which probes my function and tries all the weird edge cases that I am sure to forget when writing unit tests or defensive asserts. Writing tests manually? That&#x27;s boring! And oftentimes when something is boring, getting a computer to do it is a solution.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;symbolic-execution-klee&quot;&gt;Symbolic Execution (Klee)&lt;&#x2F;h2&gt;
&lt;p&gt;At first, I wanted to try out symbolic execution with &lt;a href=&quot;https:&#x2F;&#x2F;klee-se.org&quot;&gt;Klee&lt;&#x2F;a&gt;. Klee is a symbolic execution engine for LLVM which runs programs with symbolic values for the variables, which allows it to effectively simulate running the program on all possible inputs at once! This is extremely cool, although you can probably already guess that this can be quite computationally expensive, even with Klee being extremely clever. But for constrained enough tasks, this absolutely fits my defintiion of a holy grail. The issue is that I wanted to try this with Rust, and it looks like &lt;a href=&quot;https:&#x2F;&#x2F;www.unwoundstack.com&#x2F;blog&#x2F;klee-and-rust.html&quot;&gt;using Klee with Rust is not currently well supported&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Alright... well maybe I&#x27;ll try to get that working sometime later, but for now let&#x27;s try something else. Fuzzing!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;fuzzing&quot;&gt;Fuzzing&lt;&#x2F;h2&gt;
&lt;p&gt;Fuzzing is a technique for finding interesting test cases using randomized inputs. While this by itself is not too ground-breaking, more sophisticated fuzzers like American Fuzzy Lop (AFL) use techniques for directing the random input to maximize code coverage of the test cases. This allows fuzzers to try to take every path within your code and weasel their way into control-flow states you might not have expected.&lt;&#x2F;p&gt;
&lt;p&gt;For my very basic trial of fuzzing, I will be using two libraries: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;proptest-rs&#x2F;proptest&quot;&gt;proptest&lt;&#x2F;a&gt;&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-fuzz&#x2F;cargo-fuzz&quot;&gt;cargo-fuzz (libfuzzer)&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;&#x2F;h2&gt;
&lt;p&gt;I want to test these libraries on a small but important well-known bug: &lt;a href=&quot;https:&#x2F;&#x2F;research.google&#x2F;blog&#x2F;extra-extra-read-all-about-it-nearly-all-binary-searches-and-mergesorts-are-broken&#x2F;&quot;&gt;integer overflow in binary search&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;Java&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-Java &quot;&gt;&lt;code class=&quot;language-Java&quot; data-lang=&quot;Java&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;public static int &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;binarySearch&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int[]&lt;&#x2F;span&gt;&lt;span&gt; a, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; key) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; high &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; a.length &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;while &lt;&#x2F;span&gt;&lt;span&gt;(low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;lt;=&lt;&#x2F;span&gt;&lt;span&gt; high) {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; mid &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;(low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; high) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;&#x2F;&#x2F; BUG: low + high can overflow
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; midVal &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; a[mid];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;(midVal &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; key)
&lt;&#x2F;span&gt;&lt;span&gt;                low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; mid &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;else if &lt;&#x2F;span&gt;&lt;span&gt;(midVal &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; key)
&lt;&#x2F;span&gt;&lt;span&gt;                high &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; mid &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;else
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span&gt; mid; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;&#x2F;&#x2F; key found
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;return -&lt;&#x2F;span&gt;&lt;span&gt;(low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;);  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a0a1a7;&quot;&gt;&#x2F;&#x2F; key not found.
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here the code is in its original Java from the article. I&#x27;ve rewritten it in Rust because I wanted to try fuzzing &#x2F; property testing in Rust&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#2&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;Rust&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-Rust &quot;&gt;&lt;code class=&quot;language-Rust&quot; data-lang=&quot;Rust&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;pub fn &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;binary_search&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;needle&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;haystack&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;Vec&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) -&amp;gt; Option&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; high &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; haystack.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;while&lt;&#x2F;span&gt;&lt;span&gt; low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;lt;=&lt;&#x2F;span&gt;&lt;span&gt; high {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; mid &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;(low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; high) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; mid_val &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; haystack[mid];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; mid_val &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; needle {
&lt;&#x2F;span&gt;&lt;span&gt;            low &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; mid &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        } &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;else if&lt;&#x2F;span&gt;&lt;span&gt; mid_val &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; needle {
&lt;&#x2F;span&gt;&lt;span&gt;            high &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; mid &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        } &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;else &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;Some(mid);
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;None;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I&#x27;ve modified the signature for simplicity. In the original Java &lt;code&gt;binarySearch&lt;&#x2F;code&gt;, a failure to find the item returns a negative insertion index, the index where the item would be inserted into the list. I&#x27;ve replaced that with an &lt;code&gt;Option&lt;&#x2F;code&gt; type which makes the failure clearer, although it removes some information. In the Rust standard library, they return the insertion index with a &lt;code&gt;Result&lt;&#x2F;code&gt; type.&lt;&#x2F;p&gt;
&lt;p&gt;Now something I didn&#x27;t realize immediately while translating this code manually: in the Java code, low and high are &lt;code&gt;int&lt;&#x2F;code&gt;s (32-bit), while in Rust, they are &lt;code&gt;usize&lt;&#x2F;code&gt; (pointer-sized unsigned int). This leads to some issues since the implementation assumes that high can be negative in the case of an empty list. -- This is where proptest and cargo-fuzz come in!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;proptest&quot;&gt;proptest&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;Rust&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-Rust &quot;&gt;&lt;code class=&quot;language-Rust&quot; data-lang=&quot;Rust&quot;&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;proptest::prelude::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;allow&lt;&#x2F;span&gt;&lt;span&gt;(dead_code)]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;needle_and_haystack&lt;&#x2F;span&gt;&lt;span&gt;() -&amp;gt; impl Strategy&amp;lt;Value = (&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;, Vec&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&amp;gt; {
&lt;&#x2F;span&gt;&lt;span&gt;    (
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        proptest::collection::vec(prop::num::i32::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;ANY&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c18401;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;    )
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;proptest! {
&lt;&#x2F;span&gt;&lt;span&gt;    #[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;test&lt;&#x2F;span&gt;&lt;span&gt;]
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;proptest_binary_search&lt;&#x2F;span&gt;&lt;span&gt;((&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;needle&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;mut haystack&lt;&#x2F;span&gt;&lt;span&gt;) in needle_and_haystack()) {
&lt;&#x2F;span&gt;&lt;span&gt;        haystack.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;sort_unstable&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; result &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;binary_search&lt;&#x2F;span&gt;&lt;span&gt;(needle, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;haystack);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; result {
&lt;&#x2F;span&gt;&lt;span&gt;            Some(index) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;                prop_assert_eq!(haystack[index], needle);
&lt;&#x2F;span&gt;&lt;span&gt;            },
&lt;&#x2F;span&gt;&lt;span&gt;            None &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;                prop_assert!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;haystack.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;needle));
&lt;&#x2F;span&gt;&lt;span&gt;            }
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;proptest is a property-testing framework for Rust which automatically shrinks failing test cases.&lt;&#x2F;p&gt;
&lt;p&gt;Here is the result of running the proptest:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#fafafa;color:#383a42;&quot;&gt;&lt;code&gt;&lt;span&gt;thread &amp;#39;proptest_binary_search&amp;#39; (95480) panicked at src&#x2F;main.rs:36:1:
&lt;&#x2F;span&gt;&lt;span&gt;Test failed: attempt to subtract with overflow.
&lt;&#x2F;span&gt;&lt;span&gt;minimal failing input: (needle, mut haystack) = (
&lt;&#x2F;span&gt;&lt;span&gt;    0,
&lt;&#x2F;span&gt;&lt;span&gt;    [],
&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It correctly found that an empty list is an error since high is now a usize!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;cargo-fuzz&quot;&gt;cargo-fuzz&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;Rust&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-Rust &quot;&gt;&lt;code class=&quot;language-Rust&quot; data-lang=&quot;Rust&quot;&gt;&lt;span&gt;#![&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;no_main&lt;&#x2F;span&gt;&lt;span&gt;]
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;fuzz_binary_search::binary_search;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;libfuzzer_sys::fuzz_target;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;fuzz_target!(|&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;input&lt;&#x2F;span&gt;&lt;span&gt;: (&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;, Vec&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)| {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let &lt;&#x2F;span&gt;&lt;span&gt;(needle, haystack) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; input;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; result &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;binary_search&lt;&#x2F;span&gt;&lt;span&gt;(needle, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;haystack);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; result {
&lt;&#x2F;span&gt;&lt;span&gt;        Some(idx) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;assert_eq!(haystack[idx], needle),
&lt;&#x2F;span&gt;&lt;span&gt;        None &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;assert!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;haystack.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0184bc;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a626a4;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;needle)),
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;});
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;cargo-fuzz, which uses LLVM&#x27;s libfuzzer under the hood, is also able to find several errors with this implementation which has been shoddily translated.&lt;&#x2F;p&gt;
&lt;p&gt;P.S. wanna get your LSP to work in the &lt;code&gt;fuzz&#x2F;&lt;&#x2F;code&gt; directory that cargo-fuzz uses? You need to add this to your Cargo.toml.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#fafafa;color:#383a42;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span&gt;[workspace]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e45649;&quot;&gt;members &lt;&#x2F;span&gt;&lt;span&gt;= [
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;.&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#50a14f;&quot;&gt;&amp;quot;fuzz&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;some-remarks&quot;&gt;Some remarks&lt;&#x2F;h2&gt;
&lt;p&gt;Although proptest felt a little more clunky when defining input constraints, this does help speed up the search through guidance.&lt;&#x2F;p&gt;
&lt;p&gt;Something that I didn&#x27;t expect but had fun learning was that actually reproducing this bug from 2006 in Rust would have led me to write some quite awkward Rust&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#3&quot;&gt;3&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;! This is exactly what I want from a programming language. I want to be nudged in the correct direction. Rust makes it difficult to &quot;hold it wrong.&quot; Modern programming languages really ought to be &lt;a href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Poka-yoke&quot;&gt;poka-yoke&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This was just an excuse to play around with fuzz testing and it works remarkably well for the amount of effort it takes. I think that if you are writing some data structure or some non-trivial transformation, there&#x27;s really no reason not to fuzz your program. Fuzzing is of course no cure-all, but it is easy enough to setup that you don&#x27;t really have an excuse not to try it!&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve made a git repo for these little experiments so if you want to see the complete code for any of these examples, here: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;prydt&#x2F;etudes&#x2F;tree&#x2F;main&#x2F;fuzz-binary-search&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;prydt&#x2F;etudes&#x2F;tree&#x2F;main&#x2F;fuzz-binary-search&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;proptest-rs.github.io&#x2F;proptest&#x2F;&quot;&gt;The Proptest Book&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;rust-fuzz.github.io&#x2F;book&#x2F;introduction.html&quot;&gt;The Rust Fuzz Book&lt;&#x2F;a&gt;, covering cargo-fuzz and AFL&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;lcamtuf.blogspot.com&#x2F;2014&#x2F;11&#x2F;pulling-jpegs-out-of-thin-air.html&quot;&gt;Pulling JPEGs out of thin air&lt;&#x2F;a&gt;, a really neat example of the powers of fuzzing&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;&#x2F;h3&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;1&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;1&lt;&#x2F;sup&gt;
&lt;p&gt;proptest is actually a library for property testing which is slightly different from fuzzing. Property testing has more guidance from the programmer for how the inputs are generated, while fuzzing tends to be more black-box.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;2&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;2&lt;&#x2F;sup&gt;
&lt;p&gt;Why for real? -- For fun!&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;3&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;3&lt;&#x2F;sup&gt;
&lt;p&gt;I would have needed to intentionally cast low, high into &lt;code&gt;i32&lt;&#x2F;code&gt; and then cast back into &lt;code&gt;usize&lt;&#x2F;code&gt; for indexing.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>another day, another blog</title>
        <published>2025-09-17T00:00:00+00:00</published>
        <updated>2025-10-19T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Pranoy Dutta
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://prydt.xyz/blog/first-post/"/>
        <id>https://prydt.xyz/blog/first-post/</id>
        
        <content type="html" xml:base="https://prydt.xyz/blog/first-post/">&lt;blockquote&gt;
&lt;p&gt;Writing is nature&#x27;s way of telling us how lousy our thinking is. - (This quote is sometimes attributed to Leslie Lamport, but he is actually quoting &lt;a href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20120121030813&#x2F;http:&#x2F;&#x2F;www.budiu.info&#x2F;blog&#x2F;2007&#x2F;05&#x2F;03&#x2F;an-interview-with-leslie-lamport&#x2F;&quot;&gt;Dick Guindon&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Although I&#x27;ve had a blog in one form or another since &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;prydt&#x2F;algorithms&#x2F;commit&#x2F;c790175d077dc93b6dbb8ef59ea8f849db940245&quot;&gt;2017&lt;&#x2F;a&gt;, blogging never became a habit for me. I&#x27;d always have ideas but either never written them down. Whenever I did write something, I tried to do something too big or too polished.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s how I plan to change this.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-quantity-has-a-quality-all-its-own&quot;&gt;1. Quantity has a quality all its own.&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It&#x27;s unintuitive, but I believe that lowering my standards to some degree will actually improve my writing quality in the long run.&lt;&#x2F;p&gt;
&lt;p&gt;The desire to have a blog with only the highest quality posts is actually hampering my ability to become a better writer. While I don&#x27;t think you throw out all quality control, loosening standards in favor of consistency will hopefully result in increased quality.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;2-don-t-futz-with-it&quot;&gt;2. Don&#x27;t futz with it.&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#2&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Like so many aspirational bloggers, I fell into the trap of spending more time on my blogging setup than actually writing. I started on &lt;a href=&quot;https:&#x2F;&#x2F;jekyllrb.com&quot;&gt;Jekyll&lt;&#x2F;a&gt;, switched to &lt;a href=&quot;https:&#x2F;&#x2F;gohugo.io&#x2F;&quot;&gt;Hugo&lt;&#x2F;a&gt;, and now I&#x27;m on &lt;a href=&quot;https:&#x2F;&#x2F;www.getzola.org&#x2F;&quot;&gt;Zola&lt;&#x2F;a&gt;. None of this matters to me or to readers.&lt;&#x2F;p&gt;
&lt;p&gt;While it&#x27;s nice to have a cool custom theme, etc, etc, nothing matters more than just writing.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve settled on a setup and I&#x27;m not going to futz with it anymore.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;3-make-it-social&quot;&gt;3. Make it social!&lt;&#x2F;h2&gt;
&lt;p&gt;I&#x27;ve enlisted a group of friends to join a &quot;blogging circle&quot; where we all share our writing and keep each other encouraged to continue to be consistent with it.&lt;&#x2F;p&gt;
&lt;p&gt;I will link my friend&#x27;s posts here from time to time and I can&#x27;t wait to do this more.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;blog-trailer&quot;&gt;Blog Trailer&lt;&#x2F;h2&gt;
&lt;p&gt;Here are some topics that interest me and I hope to cover in no particular order:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Distributed Systems&lt;&#x2F;li&gt;
&lt;li&gt;Programming languages&lt;&#x2F;li&gt;
&lt;li&gt;Concurrency&lt;&#x2F;li&gt;
&lt;li&gt;Hashtables&lt;&#x2F;li&gt;
&lt;li&gt;Politics&lt;&#x2F;li&gt;
&lt;li&gt;Music&lt;&#x2F;li&gt;
&lt;li&gt;Anything I&#x27;m reading&lt;&#x2F;li&gt;
&lt;li&gt;... really anything, we&#x27;ll see.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Here&#x27;s to consistency!
-- Pranoy&lt;&#x2F;p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;&#x2F;h3&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;1&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;1&lt;&#x2F;sup&gt;
&lt;p&gt;Attributed to &lt;a href=&quot;https:&#x2F;&#x2F;en.wikiquote.org&#x2F;wiki&#x2F;Quantity&quot;&gt;Karl Marx&lt;&#x2F;a&gt;, often misattributed to Stalin.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;2&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;2&lt;&#x2F;sup&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;IrIb7RSJL2I?t=615&quot;&gt;Don&#x27;t futz around with these hashbrowns&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
</content>
        
    </entry>
</feed>
