Should case expressions compile to an if for each case? #4521
Replies: 2 comments 1 reply
-
We don't do defensive programming to guard against mistakes from outside of Gleam code as it would have a notable impact on code size and runtime performance. Like with any JS code you must make sure you pass in the correct type of value otherwise anything unexpected can happen. If you wish to have these checks yourself you can add them using the Dynamic data type. |
Beta Was this translation helpful? Give feedback.
-
Since those concerns more relevant to production, then technically we could have a "development" build mode that does defensive programming? Although understandable if this is not a good idea due to the maintenance burden! This suggestion came up because I was encountering a weird behavior in my project, and it took me some time to even realize that it was due to an FFI bug. After the realization it was straightforward to track down the bug. But it's probably a good idea to surface bugs like this as soon as possible in the development. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This Gleam code today:
compiles to the following JS code.
Should it compiles to something like the following instead?
The former is correct for pure Gleam, but with FFI code not strictly typed it can lead to unpredictable behaviors.
The latter can more easily surface FFI bugs, but it is perhaps not clear what should run inside the
else
.Beta Was this translation helpful? Give feedback.
All reactions