💾 Archived View for tilde.cafe › ~stack › gemlog › 2022-10-20.dynamic1.gmi captured on 2024-08-31 at 13:05:55. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-07-22)

-=-=-=-=-=-=-

Statically-Typed languages Are Just Not Good Engineering

gemini://gemini.rlamacraft.uk/techGuides/dynamicallyTypedCodeIsJustNotGoodEngineering.gmi

I have a contrarian view to the above thesis.

Over the past 40 years I've used (and disliked) many languages. To provide some context, I've written a bunch of compilers and code-generating thingamajigs, and have not seen anything better than Common Lisp as high-level languages go.

And so I take an exception to including Common Lisp into the broad category of badly-engineered dynamic-typing languages, because I don't think that any part of that description fits.

Common Lisp has a pretty good type system, which you may choose to completely ignore. Modern CL compilers _infer_ type all by themselves, and if you care about types, you can provide declarations at a _per-scope level_, specifying with any degree of precision, the types you expect certain things to be, including combinations of types with a variety of logic operators.

Strongly-typed languages are really annoying to write code for, unless you know exactly what the problem space is. And you don't know that until you've written the code. Talk about poor engineering!

I can't tell you how many times I've been stuck, cursing, casting pointers in C, because WTF. Or grepping for all the files that call some function whose parameter type I needed to change to avoid such casting, and still not finding all of them because some preprocessor macro is hiding it. It takes days to undo some stupid decision early on in a project!

CL allows you to ignore typing while you interactively prototype your ideas. When you get past the basics, if you care to -- and more often than not, you dont, because either your code is never used or the compiler did a good-enough job that you don't even need to think about limiting types -- ... You can provide type information.

SBCL, the leading Common Lisp compiler, lets you set different levels of enforcement of types. You can get warnings, or you can strictly enforce types.

Personally, the only time I bothered with types in CL in the ten years or so I've been hacking Lisp code, is for optimization. Letting the compiler know that certain variables are integers that fit into a register and such, makes the code a lot faster, competing with the speed of C code. All while enjoying the wild interactivity and incredible metaprogrammability of Lisp.

So as far as I am concerned, types are something that the compiler should worry about, not the human. Unless and until you need to deal with it, in which case, the compiler should let you do so. Because _manually_ setting the type for _every_ variable is kind of insane if you think about it.

So Common Lisp provides the ideal solution for typing, for me.

index

home