An unofficial, read-only Hacker News reader.

The need for a formally verifiable mainstream programming language (opens external site)

338 points by todsacerdoti 1 day ago | blainehansen.me | 312 comments on HN

View full thread · View on Hacker News

Comment thread (10)

  1. We don't really have a verification crisis, we have a validation crisis.

    Ever more cycles spent checking we're building the thing right doesn't address the issue of whether we're building the right thing.

    The debate has always been whether running cycles on "compile" which is checking against a largely fixed set of rules is better than "testing" which is checking against a largely dynamic set of rules. "Testing" tends to be able to do validation better than "compile".

    That's been the running debate between dynamic typed and static typed computer languages for the last half century or so. It swings backwards and forwards.

    Like centralised vs distributed I don't see there being "a" answer other than "it depends".

    Replies (1)
    1. > the running debate between dynamic typed and static typed computer languages

      Actually, I haven't seen a good dynamic vs static types debate for a long long time. Some of these fundamental debates have become tired and people don't debate them anymore, which is understandable.

      But, in the age of LLMs, maybe it's time to have that debate again.

      The major disadvantage of typed languages is they're harder to write at times, the type checker gets in your hair. But if LLMs write the code, what argument remains against static types?

      Replies (2)
      1. > But if LLMs write the code, what argument remains against static types?

        If by static types you mean where the verification language and the implementation language are intertwined, one has to ask: If LLMs write the code, what advantage is there to that intertwinement? That was a convenience function for human authors. LLMs don't care and can just as easily keep track of them as separate concerns.

        Replies (2)
        1. LLMs don't care and can just as easily keep track of them as separate concerns.

          Only if they have the context of every part of the code though. If you put type hints in your code then the LLM can understand the shape of what some code is supposed to send/receive without having to trace back through the code to the source of that data. That means a model with a much context window can successfully change it. That's both cheaper and faster.

          Also, we can still do things without LLMs. You can compile and test code as a part of CICD, and having something doing a static type check is a good quality gate.

          Maybe in a future where we run models locally that's not an issue, but if Anthropic 100x their prices tomorrow I'll be glad I left some aspects of development working without LLM input.

          Replies (1)
          1. > Only if they have the context of every part of the code though.

            Why?

            > You can compile and test code as a part of CICD, and having something doing a static type check is a good quality gate.

            Nothing about separating concerns precludes that, of course. Most serious validation languages already avoid the intertwinement. It's not exactly a new concept. The trouble is that humans often find it hard to keep track of both at the same time, so we trick them into thinking it is one language to get around that (typically at the cost of lesser validation). But LLMs do not have the same trouble.

            Replies (2)
            1. Why?

              A type hint says "only accept things that look like this" and a compiling or a type checker can statically analyse the code to make sure that's valid everywhere. If you don't have that then the LLM would need to track back through the call tree to the originating point that defines the shape of the thing being passed to understand if it's valid all the way through the app in order to know that the data is correct. As it can't know where the originating call starts, it needs context of everything. It might only read the code it needs to read, and that can be done easily with an agent driving a small model, but it still needs complete access to every part of the app in order to trace what it needs to. With type hints it can just run the type checker to validate the code is OK and then trust the type hints.

              Continue this thread (1 replies) →

            2. LLMs have a limited context window. They also have trouble keeping track of what's going on "elsewhere", at least if there's enough of it.
        2. > LLMs don't care and can just as easily keep track of them as separate concerns.

          I agree. In fact I'd argue adding more representations (esp generative ones) just increase the chance of drift[^1].

          Where types are useful is cross-cutting concerns. That is, interfaces between components/systems/whatever. I suspect the size of that boundary will grow with the capability of AI though.

          1: https://jonathannen.com/views-of-the-same-thing/

      2. Ruby and python were my introductions to programming. I picked up C and found the type system to just be annoying. Then I picked up a TS Node project that used Zod and it changed my perspective.

        One of the primary structures that the project concerned itself with was written as a big fat z.object with all optional keys. In the logic, there were all kinds of runtime checks as nested if/else ifs looking for the presence of the keys and branching on their value if they existed. I discovered z.discriminatedUnions and realized that this could be checked once at compile time by defining the possible states of this structure, which progressed monotonically from one state to the next, never backwards

        The logic then became a single comprehensive switch statement with an assert never default. Vastly simplified the rest of the application and obviated the nullish guards that were interspersed throughout the front- and backend logic. Life changing.

        Now, I only use dynamic languages for trivial scripting or where the type system would be unneeded overhead. I am finding this to be rarer as my ambitions grow.

        Also, the benefits of a good LSP provided by strongly typed languages with a robust ecosystem are huge. Makes reasoning about code so much simpler for me when I can peek any object's type in my IDE and go to definition. Ruby LSP is awful at this, you can't rename a variable globally nor can you go to a function's implementation if it cannot be determined. Not so with out-of-the-box tooling in strongly typed languages.