The document could be more clear on when to and not to use `comptime`

Hello @VoilaNeighbor, welcome to the forum!

I like your question because it forces us to think about what is helpful as an implicit contract and what should be specified.

In general, const has the qualification that comptime can be inferred. There was a recent discussion on this in this thread: Coercions and compile time known numbers - #5 by kristoff

The difficulty we face (in my opinion) is the following question: what can we expect our compiler to know about our code without saying it explicitly?

The value of not having to specify everything is that there are certain optimizations that will be picked up even where we do not intend them (as is the case with compile-time known numbers). However, to be more explicit means that we can accidentally opt-out of many of those same optimizations by simply not saying them out loud.

When you say “The document” do you mean the official documentation? Or do you mean something more general like “the language should require us to be more specific overall”?

1 Like