HNHacker News
TopNewBestAskShowJobs

victorNicollet

656 karma · joined February 18, 2011

submissionscomments
victorNicollet··on Design Guidelines for Domain Specific Languages (2014)
A few strong opinions, a lot stronger than they were in my 2017 talk https://youtu.be/_gmMJwjg0Pk, surely that must be the experience speaking :)

- Creating a DSL is a commitment. It is never done, it's either in development or abandoned. Plan for this, both in terms of team size and knowledge management.

- Don't allow escape hatches or ways to access arbitrary functionality in the host language. When (not if) these are used, they ruin backwards compatibility and make maintenance of DSL code a nightmare.

- Don't use a PEG (parsing expression grammar), they are terrible for backwards compatibility. Hand-written parsers are even worse. Using an LR parser generator is worth the time investment.

- Support static analysis, or at the very least don't make it impossible to implement later. It improves productivity, and every error message is an opportunity to teach the DSL to the users.

- You need a language server. The bare minimum is: highlighting, auto-completion, hints on hover, find references, rename.

- It should be trivial to reproduce a production run on a development machine. This means the language should be deterministic, and the production context should be preserved for later reuse, and the development machine should be safe for accessing production data.

- Thousands of unit tests, thousands of regression tests.

It's fine to break these rules, if you can live with the consequences.

And here's a brand new one from this year: use RAG to have ChatGPT "read" your documentation, and ask it to produce scripts for you. When the script doesn't compile, feed the error message back to ChatGPT and try again until you get a working script. Think deeply about why ChatGPT made some mistakes, as it's often the case that humans would have the same misunderstandings. Improve your documentation, error messages or syntax to eliminate them, and then try again to see if it works. We have been doing this for 6 months now, and there have already been some significant improvements that are only obvious in hindsight. And we've now opened a PhD position to investigate whether we can have a separate "LLM-friendly" syntax for the language, dedicated to making code generation easier.

victorNicollet··on We have used too many levels of abstractions
I think it's wonderful that we have created a tech ecosystem (a techosystem?) that allows people to contribute with only a very narrow knowledge of things—or, in less positive terms, that allows companies to hire cheaper labor because fewer skills are required. I believe there are many cases where a mediocre solution is better than no solution at all.

The internet of 1995-2005 was built on mediocre solutions. It was a blast.

Deep-dive experts are not a dying breed, they're not a limited resource with secret knowledge from a time before abstractions. We have more of them now than ever before. They're not defined by having worked all the way up and down the stack, but by having the curiosity to look into layers that are not their own, because not only are we adding more abstraction layers on top, we're also changing some of the layers down the stack: NVMe, WebGPU, WebAssembly, QUIC, AVX512 !

But deep-dive experts are a luxury that most teams don't need, and one of the most important skills of a technical manager is, I would argue, to know when they absolutely must hire one.

victorNicollet··on Don't use DISTINCT as a "join-fixer"
I agree ! This creates a situation where the SQL query does not represent the domain knowledge, but makes assumptions about it and cannot be understood without it. And while this will always be true for the more unusual parts of the domain, it is quite disappointing to be unable to properly represent as simple a concept as "what is a customer?" in SQL.

It's the same as a language forcing you to use `c & ~0x20` because it doesn't have a `Char.toUpper(c)` function. The code works (under the right assumptions) and produces the same result, but it does not convey the concept of converting a letter to uppercase.

What makes it so frustrating is that the DDL portion of SQL spends significant effort on representing such concepts in the database schema ! I can create a Customers table, with its primary key, and its foreign keys into and from other tables, and so on. I can represent "these are all the customers" in DDL, I can represent "every sale must be associated to a customer", and so on. But after the first join, I'm no longer using the Customers table, I'm using a new in-memory relation with no primary or foreign keys, and the concept that "this is the customers table, but with extra fields" is something I need to keep track of in my head, instead of in the language.

victorNicollet··on Don't use DISTINCT as a "join-fixer"
I've gone into more detail about this a few years ago in https://nicollet.net/blog/vanishing-schema-paradox.html but here's a short summary. Suppose you have the following analytics query:

    SELECT Customer.Name, sum(Sales.Quantity) 
    FROM Customer
    INNER JOIN Sales ON Customer.A = Sales.A
    GROUP BY Customer.B
Can you tell whether this will return exactly one line for each customer ? If INNER JOIN + GROUP BY was the dedicated construct to do so, then the answer would be "yes", because by definition it is the dedicated construct to do so. That's what a dedicated construct does: it is dedicated to doing that thing.

But both INNER JOIN and GROUP BY are much more versatile than that. In order to return exactly one line per customer, the following must be true: 1. column Customers.B must be a unique key of the Customers table (otherwise you'll get duplicate lines), and 2. each value of column Customer.A must also appear in column Sales.A (otherwise you'll have missing lines). Neither of these properties can be ascertained by looking at the query alone.

A dedicated construct would be something like (imaginary syntax):

   SELECT Customer.Name, sum(Sales.Quantity)
   FROM Customer 
   INNER JOIN Sales ON Customer.A = Sales.A
   GROUP INTO Customer
victorNicollet··on Don't use DISTINCT as a "join-fixer"
This is such a pervasive issue with the relational SQL query model ! The fact that joins always create brand new tables is powerful, but it's rarely what is needed.

The example in this article can manage to do without a join because it's only using the other tables to filter the customer table. The proposed solution breaks down as soon as a column needs to be brought in from the other tables (for example, "the total number of products purchased from the Beauty category"). A notion as simple as "I want to return a list of customers with additional properties" does not map to any dedicated SQL construct ! You can JOIN then GROUP BY, but making sure that the result only has exactly one value per customer is not something you can explicitly say in your SQL, it's a consequence of how you set up your JOIN and GROUP BY keys, and it's both easy to make a mistake and hard to understand the intent.

victorNicollet··on Breakelse: When Compiler Developers Get Bored
C# has boolean pattern-matching (and library functions with TryXYZ names) as a solution to this kind of issue. For instance:

    while (Console.ReadLine() is string line && 
           int.TryParse(line.Trim(), out int number)) 
    {
        Console.WriteLine($"{line} is {number}");
    }
This loop can be interrupted by ReadLine() returning null (failing the pattern-matchi as string line) or by int.TryParse returning false.
victorNicollet··on The Twelve-Factor App (2011)
There's an optional but very helpful sixth step: expose the loaded configuration (by pushing it to the logs, or as a /_config endpoint). For secrets, obviously don't expose the secret value itself, but do expose the vault address, secret identifier, and which version of the secret was loaded. This helps check that an application isn't using an outdated version of a secret.
victorNicollet··on The Twelve-Factor App (2011)
My company enforces this with two rules. One, deployment always builds and deploys exactly what's in the git repository, so there is no way to include anything else (secrets, configuration...) in a deployment. Two, it's obviously forbidden to commit secrets to the git repository (we enforce this through training and reviews, but it's fairly easy to add pre-commit hooks as well).
victorNicollet··on The Twelve-Factor App (2011)
Hard agree. I think it's easy to get stuck on the mental model that "the configuration value is the secret" (which means the configuration itself needs special handling), and the correct mental model should be "the configuration value is the identifier of the secret", with another system (Azure Key Vault, etc) being responsible for converting the secret-identifier into the secret-value.

My company open sourced the .NET library we use for this: https://github.com/Lokad/Secrets

victorNicollet··on Database Migrations
Indeed, the event stream contains the full history of all events that have ever been produced during the lifetime of the application.
victorNicollet··on Strong static typing, a hill I'm willing to die on
For example, with static typing one would define many different complex types over the program, in order to have the compiler enforce the many different constraints (here the value can be null, but not there ; these two values must be provided together ; and so on). Things like structural typing or algebraic data types even allows the creation of unnamed types on the fly. When sum types are used, conditional operators will be used to deconstruct these in a type-safe way, resulting in many branches.

With dynamic typing, one would have only a small number of very different types, because having many types increases the risk of using the wrong one, and having similar types makes it harder to notice that the wrong one is being used. The types must be very simple, because deconstructing complex types requires having branches, and branches should be kept to a minimum because they are hard to cover properly with unit tests.

victorNicollet··on Strong static typing, a hill I'm willing to die on
I think there are at least two ways to write safe and robust code, one being to rely on static types to provide automatic guarantees, and another being to structure the program in a way where tests reveal errors immediately. They are mutually incompatible, and so different from one another that few people can be experts at both, but I don't think one is objectively inferior to the other.

Both styles require code to be disciplined, and undisciplined code cannot be caught by compilers, linters or automatic tools, it has to be through code review (or experience and sheer willpower). It's easy to think of examples where a lack of static types would allow brittle code to be written, but it's important to question whether that brittle code may be considered unacceptable by someone experienced in working without static types, in the same way that code using a Dictionary<string, object> instead of an actual type would be considered unacceptable by a type-safety practitioner despite being (technically) type-safe.

victorNicollet··on Database Migrations
The pain of database migrations is what originally pushed me towards event sourcing. The database is read-only (but immediately mirrors changes applied to the event stream), and I can have multiple databases connected to the same stream, with different schemas.

This makes schema changes easy to perform (just create a new database and let the system populate it from the events), easy to do without downtime (keep the old database available while the new database is building), and easy to roll back (keep the old database available for a while after the migration).

The trade-off is that changing/adding event types now needs to be done carefully (first deploy code able to process the new event types, then deploy the code that can produce the new events), whereas a SQL database supports new UPDATE or INSERT without a schema change.

victorNicollet··on Compile-time and short-circuit evaluation
There are really two reasons one would be analyzing the source code.

One reason is to make sense of how to run it: to determine what instructions to emit. This is the kind of analysis where you want to propagate constants (even if they're not flagged as compile-time), to drop dead code (if it can be can determined that it doesn't need to be executed), and so on. For this analysis, even if && evaluation isn't short-circuit, one can replace false && A with just false as long as you know A doesn't have side-effects, and at the very least one can replace:

    if (CallA() && false)
    {
        CallB();
    }
With just:

    CallA();
The other reason to analyze your source code is to provide some level of static information to the user, such as detecting in advance situations that don't make sense. If there is never a situation where the expression `okeoefkepofke[3.141592]` is acceptable, then it's usually a good idea to report it as such even if the expression is 100% dead code as far as execution goes. I would even go one step further and say that static analysis should also register that expression as a (read-only) use of the variable `okeoefkepofke` for purposes of "find all references" or "rename symbol" tools.
victorNicollet··on Feature Flags: Theory vs. Reality
It's a matter of dev team culture: always leave the code cleaner than you found it. Hire people who understand this, and remind each other through reviews.

As for external pressure from shareholders to skip cleanup: it's better to not describe cleanup as a separate step, but as just another part of feature implementation. It is a fact of software development that work on a feature must be done both before and after that feature is first available in production (whether it's to ensure that all is fine with a finger on the rollback button, to set up relevant production monitoring, or to clean up any scaffolding that was required for the release), and it is possible to have features that are available in production but are not yet _done_. Finishing the work is not optional.

victorNicollet··on Ask HN: Could you share your personal blog here?
https://nicollet.net

Rather than a site to write articles, it's a site where I keep links to things I write (or talks I give) so that I don't lose them.

I used to have a large blog ten years ago, with at least one post per day, because every blog guru on the internet said you needed to post every day to grow an audience. But I'm not smart enough to have something interesting to say every day, so it was rather poor quality. So I started this new iteration from scratch and post once or twice a year, mostly about software design.

victorNicollet··on Companies must stop using Google Analytics
Besides, even if you use the standard tool today, five years from now this will be "the tool that was standard five years ago" unless you actively migrate every so often. There are a few domains where the standard tools remain the same for a long while (Google Analytics being one), but often the standard tooling shifts more frequently than that.
victorNicollet··on How not to write a pipeline
Agreed !

I would add that some queue solutions (such as Azure) implement a lease system where a dequeued message re-appears at the head of the queue after a while, unless its removal is explicitly confirmed.

victorNicollet··on How not to write a pipeline
What kind of situation would have a producer push into a queue but not care about the output ? The only one I could come up with, is doing some computation in advance that would otherwise need to be done just-in-time when the result is requested later.
victorNicollet··on How not to write a pipeline
Most of these issues stem from the fact that queues provide no useful guarantees about how many times each entry will be processed (zero? one? many?), at least not without a large amount of work around the queues, usually enough to make them unrecognizable.

Despite the prose, the article is dripping with actual production experience, and many things I wish I had known earlier. To craft a good design, one must be aware of all the problems that the design should fix in order to be good (and accept that settling early into a design will prevent some problems from ever being fixed).

victorNicollet··on My thoughts on OCaml
Today you can install the .NET runtime, as well as the .NET development tools, on both Windows and Linux. They handle F# as well as C# out of the box.

You can `dotnet publish MyApp.fsproj` on either Windows or Linux, copy the resulting `publish/` folder to another machine with a different OS, and use `dotnet MyApp.dll` to run it. There are also ways to create containers, though I have never tried them for lack of an actual use case.

As for libraries, .NET comes with a huge standard library, much larger than what you would find on a different language. Off the top of my head, here are a few things that come with .NET that would have been a third party library in other languages: text encodings, protocols (HTTP client, TLS, QUIC, SMTP), mainstream hashes (MD5/SHA1/SHA256), mainstream crypto (AES/DES/RSA/EC/ChaCha), serialization (JSON/ XML), weird formats (X509/ASN.1/tar/MIME), mainstream compression (deflate/brotli/zip), binary data manipulation (e.g. endianness conversion, AVX intrinsics, memory-mapping), runtime code generation, in-assembly resources, interoperability (COM, JavaScript, Objective C, SQL), concurrent collections, async...

Besides, since C# is popular, many tools have .NET-compatible clients or libraries which can then be accessed from F#.

victorNicollet··on How to explain the Monty Hall problem to a disbeliever
From my experience, the issue is that the 50% intuition is hard to overcome (and it takes an overwhelming amount of evidence for the 33%/66% reality in order to overcome that intuition). Here's an alternate version of the game which aims to dismantle the 50% intuition directly, instead of trying to argue for 33%/66%.

You pick a box, and another empty box is revealed. Then, the two remaining boxes are shuffled so that you no longer can tell which is which (but the game host still knows). You then choose one of four options:

- take box A,

- take box B,

- ask the host to give you the box you picked initially, or

- ask the host to give you the box you didn't pick initially.

victorNicollet··on Stochastic gradient descent written in SQL
We've been doing this type of gradient descent in production for a couple of years now, and we've been very happy with it. A few insights from my experience:

One of the main benefits of doing differentiable programming over a relational database is that you can use joins to traverse the normalized data schema, and this acts as a very effective prior for your model. For example, you can learn parameters associated to shirt colors by having a parameter in the color table, and joining it with the shirt sales table (through the shirts table). And knowledge of the table structure also lets you improve convergence, for example by adding a factor to compensate for the fact that not all colors have the same number of sales (and therefore have been updated fewer times during each epoch). Here's a paper from last year: https://arxiv.org/abs/2209.03771v1

Automatic differentiation is an absolute must-have. Once you start having a few complex joins and aggregations, it's too hard to derive the gradient by hand. Doing automatic differentiation on relational queries requires some adjustments (in particular, because you cannot use a tape), so you end up having to define a subset of relational algebra that is closed by automatic differentiation. The general ideas were presented in https://ceur-ws.org/Vol-2971/paper07.pdf

On the other hand, while it's possible to do SQL-to-SQL automatic differentiation, the resulting queries have poor performance, so it's better to go one step lower (at the level of the executor for an already-planned query) and perform the automatic differentiation there. And we had an excellent intern work with us on dedicated parallelization for gradient descent queries: https://blog.lokad.com/pdf/reproducible-parallel-sgd-ziyad-b...

Finally, in practice, it usually doesn't matter if the gradient descent is stochastic, so long as you run several passes over the data.

I'm very interested in differentiable programming on relational languages, as the mainstream research concentrates on unstructured, low-information-density data (images/sound/text) when there are many domains where the data is more dense and structured, and (because of that structure) is stored in a database.

victorNicollet··on PHP bug: Password_verify() always return true with some hash
Indeed, '$' is a just bit flip away from '4' or 'd', and we end up with a user account that can be accessed by any password.
victorNicollet··on Big data is dead
Azure has the LS series of VMS [1] which can have up to ten 1.92TB disks attached directly to the CPU using NVMe. We use these for spilling big data to disk during high-performance computation, rather than single-machine persistence, so we also don't bother with RAID replication in the first place.

Though it is a bit disappointing that while Microsoft advertises this as "good for distributed persistent stores", there are no obvious SLAs that I could rely on for actually trusting such a cluster with my data persistence.

[1]: https://learn.microsoft.com/en-us/azure/virtual-machines/las...

victorNicollet··on Ask HN: Why Is Everything Declining?
As for the declining quality of products and services, we are leaving a decade where start-ups were burning VC money to provide a service that was both superior and cheaper, in order to starve their competitors. Now that the competitors are dead, prices/monetization will increase and quality will drop in many areas.

This will hit twice as hard if you were an early adopter, because you also stop being the target audience for most of these products.

And on a smaller scale (restaurants, corner shops, small businesses), the default state of being for most companies has always been to slowly decay over long periods of time. The brand new business that earned your loyalty a decade ago may be worse today, but there's certainly another new business today that you can be impressed with. You just need to find it.

victorNicollet··on Work queues when using messaging
From my experience, if you're fine with pushing a few dozen tasks into a queue, then you're likely fine pushing a few tens of thousands into the queue as well. You won't be able to go faster than the max throughput of whatever lies downstream of the queue, but you won't break anything either.

If the tasks in the queue are not important, then it's fine if they are dropped.

If the tasks in the queue are really important (to the point where dropping one will require remediation) then you would already have set up the necessary tools for introspection and control, even for a few dozen tasks. In particular:

- Detecting that a task has been lost, so it can be re-inserted later.

- Detecting that a task has stalled, so it can be removed and investigated.

- Reordering the queue based on the relative priority of the tasks.

In any case, I would argue that if an upstream system needs the ability to hold some tasks back when the queue is too full, then the queue is in a bad middle ground where it's not completely solving the problem (since "holding back tasks" means a separate queue-like feature in the upstream system) but still consuming a chunk of the infrastructure simplicity budget.

From there, one should either eliminate the queue (replacing it with the "holding back tasks" feature in the upstream system, combined with backpressure from the downstream system) or improve it until it can accept everything the upstream system throws at it.

victorNicollet··on Ask HN: Is TypeScript worth it?
Having worked with OCaml and F#, I find that TypeScript requires fewer changes to non-type code in response to changes to the types.

For instance, given `type T = { a: string; b: string; c: string }`, if I want to make `b` and `c` nullable but always provided together:

    // OCaml
    type TOpt = { a: string; bc: (string * string) option } 

    // TypeScript 
    type TOpt = T | { a: string; b: undefined; c: undefined }
With the TypeScript approach, code which worked with T still works with TOpt (only requiring an `if(x.b)` guard). With the OCaml approach, any code that accessed b or c needs to be rewritten.

The same applies to cases where an object can be in several different modes, but some properties are present in all modes. For example, an AST node can be a literal, identifier, binary operation, etc. but it always has a source location and an inferred type. In OCaml this has to be represented by either separating a "common properties" type from a "kind of node" union type:

    type node = { loc: location ; inferred_type: exprtype option ; kind: nodekind }
    and nodekind = Lit of string | Id of string | Unary of op * node
Or by repeating the common properties in all union type constructors:

    type node = Lit of location * exprtype option * string
              | Id of location * exprtype option * string
              | Unary of location * exprtype option * op * node
Both are tedious (although F# makes the second one slightly less tedious by allowing one to define computed properties on union types). By contrast, TypeScript allows you to have only one type:

    type NodeCommon = { loc: location; inferred_type: exprtype|undefined }
    type Lit = NodeCommon & { kind: "lit"; value: string }
    type Id = NodeCommon & { kind: "id"; value: string }
    type Unary = NodeCommon & { kind: "unary"; op: op; node: Node }
    type Node = Lit | Id | Unary
victorNicollet··on Ask HN: What are you working on this year?
I reached the bottom of the page without getting a good understanding of what Unleash is. Is it something that deploys applications ? Something that pushes settings to applications ? Something that applications pull settings from ? An agent that runs on servers ? A load balancer (or API gateway) ?
victorNicollet··on Ask HN: What are you working on this year?
My old video game from 2004 [1] is now older than I was when I wrote it, and I recently found the C++ source and sprites in one of my archives, so I'm rewriting it in TypeScript as a personal challenge.

The C++ code no longer builds (it's missing proprietary dependencies), and I no longer have the binaries or even the hardware needed to run them (it's a PocketPC game).

If I manage to finish the rewrite, I'll get in touch with the rest of the team, to ask if they'll let me upload it somewhere public.

So far, I'm surprised by how readable my C++ code is. :-)

[1]: https://nicollet.net/blog/darklaga.html

← PreviousPage 2 of 9Next →