bcpeinhardt / code_review

A linter for Gleam, written in Gleam
25 stars 1 forks source link

Lint: Disallow non-literal division and non-literal modulo #26

Open inoas opened 5 months ago

inoas commented 5 months ago

What the rule should do:

What problems does it solve:


let a = 0
1 / a

Example of things the rule would not report:

1 / 2
const foo = 2

1 / foo

I am looking for:

lpil commented 5 months ago

What problem does this solve?

inoas commented 5 months ago

It removes divison by zero annomalies during runtime and keeps / and % to work where it is safe by default?

lpil commented 5 months ago

Division is safe by default. It would not be in the language if it was not.

MystPi commented 5 months ago

This doesn't make much sense to me at all. There are many times when the divisor can not be a literal. Even if the divisor does turn out to be 0 Gleam makes it very clear what the expected behavior is.

inoas commented 5 months ago

This doesn't make much sense to me at all. There are many times when the divisor can not be a literal. Even if the divisor does turn out to be 0 Gleam makes it very clear what the expected behavior is.

then just use divide/modulo/remainder functions?

MystPi commented 5 months ago

This doesn't make much sense to me at all. There are many times when the divisor can not be a literal. Even if the divisor does turn out to be 0 Gleam makes it very clear what the expected behavior is.

then just use divide/modulo/remainder functions?

...that's what the operators are for though—the functions should only be used in places where the divisor cannot be 0 for any reason. Probably 99% of the time it doesn't matter whether the divisor is 0.