July 30th, 2024

Check Maybe Div by Zero for Gleam

check_maybe_div_by_zero is a Gleam tool that detects potential division by zero in code, ensuring expected behavior. It integrates with CI systems and supports multiple targets, enhancing code quality.

Read original articleLink Icon
Check Maybe Div by Zero for Gleam

check_maybe_div_by_zero is a helper tool for the Gleam programming language that checks for potential literal division by zero in code. Unlike many languages, Gleam does not crash on division by zero; instead, it returns zero. This tool is designed to identify instances where division by zero might occur, allowing developers to ensure their code behaves as expected. It does not check for division by zero in Erlang or JavaScript foreign function interface (FFI) calls.

To install the tool, users can run the command `gleam add check_maybe_div_by_zero@1`. For usage, the command `gleam run --module check_maybe_div_by_zero` can be executed to check the codebase for potential issues. The tool integrates with continuous integration (CI) systems, returning an exit code of 0 if no potential division by zero is found and 1 if such a case is detected, which can halt the CI process.

The tool supports various targets, including Erlang, NodeJS, and Deno. It is part of a broader development workflow that includes downloading dependencies, formatting code, and running tests. Further documentation is available at the provided Hex documentation link. This tool is particularly useful for developers looking to maintain code quality and prevent runtime errors related to division by zero in their Gleam applications.

Link Icon 2 comments
By @Fire-Dragon-DoL - 3 months
I find that choice interesting. I know it's not mathematically correct, but every time I used the division in web code, I would like that a division by zero would return 0