170 karma · joined June 30, 2018
I like your spiral metaphor though, since you learn some things along the way.
That is: they either reiterate what the code does, or would if the code were slightly clearer, or they tell half truths that are more confusing than helpful. Mostly they fail to emphasise the salient things, like the why over the what, that are not obvious from the code.
There are helper libraries to ease this (zod supports branded types, I think?), but I guess my general point is that while typescript might give you the ingredients you need to implement type safety in cases like this if you try really hard and remember all your rules everywhere, it doesn't come naturally so it's hard to maintain at scale.
But I did want to add something the article also touches on: types can be not only about ensuring safety or correctness at runtime, but also about representing knowledge by encoding the theory of how the code is supposed to work as far as is practical, in a way that is durable as contributors come and go from a codebase.
Admittedly this can come at the cost of making it slower to experiment on or evolve the code, so you have to think about how strongly you want to enforce something to avoid the rigidity being more painful than valuable. But it's generally a win for helping someone new to a codebase understand it before they change it.
Edit: another thought I had is that type mistakes do not always causes crashes. Silent corruption can be much more insidious, e.g. from confusing types which mean something different but are the same at the primitive level (e.g. a string, number or uuid)
my experience is that ocaml is more powerful than rust for enforcing this sort of type safety, because you have gadts that give you more expressive power, and polymorphic variants and object types (record row types) that give you more convenience. and the module system and functors of course.
you also avoid some abstraction limitations/difficulties that come from the rust borrow checker for places where garbage collection is just fine
I find some irony in seeing the telltale tropes of conventional LLM writing there
as an adendum, the reason I don't understand the motivation is that the visitor pattern in the way I described it is useful when you have many different operations to perform on your AST. If you have only one operation on tokens - parsing into an AST - I'm not sure why you need dynamic dispatch on a second thing, the first thing being the token type. Maybe the construction is that different operations correspond to different 'grammar rules'?
The visitor pattern is a technique for dynamic dispatch on two values (typically one represents 'which variant of data are we working with' and the other 'which operation are we performing'). You would not generally use that in recursive descent parsing, because when parsing you don't have an AST yet, so 'which variant of data' doesn't make sense, you are just consuming tokens from a stream.
There is an observation that you can use `lambda` inside to delay evaluation of an interpolation, but I think this lambda captures any variables it uses from the context.
V gubhtug vg fbhaqrq fhecevfvat sbe n glcr r gb orunir guvf jnl jura V jebgr zl pbzzrag, ohg abj V ernyvfr gung vg zvtug or pbzzba va nal vzcyrzragngvba bs rdhnyf gung uvqrf vagreany fgngr, n fvzcyr rknzcyr orvat n frg/znc qngnglcr jubfr rdhnyvgl vzcyrzragngvba vtaberf vafregvba beqre ohg jubfr vgrengvba beqre qrcraqf ba vg.
Fb V guvax gur nafjre eribyirf nebhaq gur pbzcbfvgvba ynj. Va bgure jbeqf, vf sznc (sznc frg s) t rdhny gb sznc frg (t . s) sbe nal s naq t?
V guvax guvf ubyqf bayl vs s naq t ner cher (be znlor whfg vs t vf cher?). fb znlor vs lbh vtaber hafnsr bcrengvbaf va unfxryy vg'f gehr? vg'f pregnvayl abg gehr va s#/bpnzy. vzntvar gung s vf sha _ -> 0 naq t vf sha _ -> arkg_vag_sebz_zhgnoyr_pbhagre (). gura sznc frg (t . s) qbrfa'g punatr gur fvmr bs gur frg juvyr sznc (sznc frg s) t cebqhprf n fvatyrgba frg.
That said, I wouldn't compare it to scripting languages. The lack of implicit conversions / traits / ad-hoc polymorphism means it's not that convenient for scripting.
I would disagree with that - I find it easier, more comfortable rather than just faster to read any text in a proportional font because the spacing of characters is, well, proportional to what the form of each letter requires. I think it makes it easier to recognise words. It's true that code has a lot of unusual combinations of characters but still it is mostly ordinary words. A proportional font that makes those unusual combinations of punctutation characters less clear is certainly bad, but there are proportional fonts that don't.