3 ms·
I'm uncomfortable with programs that rely on complicated compile-time evaluation within the type system. For complicated runtime behavior, we have various tool
by CoastalCoder 3y ago
I'm uncomfortable with programs that rely on complicated compile-time evaluation within the type system.
For complicated runtime behavior, we have various tools for stepping through the evaluations as they unfold. E.g., debuggers, print statements, etc.
But I haven't come across anything similar for these type-based evaluations. Usually the best I get is a compiler warning or error, or even worse, an unexpected successful compilation.
Are there any efforts to help with this, for e.g. C++ compilation?
- nrclark 3y agoZig's comptime feature is really well designed IMO. It uses an interpreter to let you run arbitrary Zig at compile-time, and you can use it to do code generation, custom types, etc. It's pretty cool.
- trealira 3y agoFor Lisp macros, there is a macrostep plugin for Emacs that expands a macro within the text of your source code one step at a time until there's nothing left to be expanded. This is temporary, so after you exit the macrostep mode, the source code viewer goes back to normal. Lisp is dynamically typed, so it's not the same as C++ templates or the Rust type system, but to me, it seems like there isn't a reason in principle why you couldn't make a stepper for pure C++ template metaprogramming, like this Peano arithmetic implementation: https://gist.github.com/vladris/2dc4f5a47d003da002a70f0c0184b0a3 https://gist.github.com/vladris/2dc4f5a47d003da002a70f0c0184... Particularly for "using" declarations, like this (taken from the gist that I linked): // A few numbers... using one = succ<zero>; using two = succ<one>; using three = succ<two>; using four = succ<three>; using five = succ<four>; Also, the clangd language server expands C preprocessor macros, but that's less useful because the C preprocessor doesn't allow recursive macros.
- madsbuch 3y agoI think that behind this sentiment is an assumption that software development is mostly applications and CRUD services. If the target system is a space rocket, medical systems, etc. One really want to have guarantees.