3 ms·
> fn add() { ... }: mispleading name or incorrect implementation `a - b` Advice like this is frustratingly non-general: you might be doing addition over GF
by woodruffw 5y ago
> fn add() { ... }: mispleading name or incorrect implementation `a - b`
Advice like this is frustratingly non-general: you might be doing addition over GF2[1] in which case `fn add(a, b) { a ^ b }` is a perfectly sound function. I've worked on a codebase, in Rust, where that's the case[2]!
[1]: https://en.wikipedia.org/wiki/Finite_field_arithmetic#Effective_polynomial_representation https://en.wikipedia.org/wiki/Finite_field_arithmetic#Effect...
[2]: https://github.com/trailofbits/reverie/blob/master/src/algebra/gf2/batch.rs#L49 https://github.com/trailofbits/reverie/blob/master/src/algeb...
- deleted 5y ago[deleted]
- xanathar 5y agoLinters should be frustatingly non-general. They should alert for the common case and special cases should have a "#[allow(xxx)]" or "#pragma warning disable xxx" (or whatever does that in your language) and, possibly, a comment. This, incidentally, also helps fellow humans reading the code who'll see that it's all intentional and won't flip with "wtf why does it XOR in an add method?" even if just for a second.
- marcosdumay 5y agoOnly up to a certain point. If you add a few pragmas before each line of code, your code is not completely illegible. As an example, those linters that have a message for each programing style and a rule to convert between them are stupid. They might be useful as some other kind of code, but as linters they are not just useless, they are actively harmful.
- zild3d 5y ago> you might be doing addition over GF2 Then the function name, class, and/or comments should be making that clear! In this case, the BatchGF2 class does so. Maybe somewhere else a Fourier class has `fn add() { a * b } // a and b are in time domain` but a standalone add() function with no comments or class should probably not be doing a ^ b, a - b, or a * b. some github copilot like linter can then draw from other GF2, Fourier, etc code references vs vanilla add functions
- catlifeonmars 5y agoThat’s abstraction breaking. The code calling add should generally not need to be aware of the implementation details of add. The users of the add API should generally not need to be aware of the implementation details of add.
- couchand 5y agoIn the case of a Galois field I think you're always intentionally reaching for the tool, you use it because of those implementation details. Making sure the struct's name clarifies that that's how the arithmetic works is appropriate. In that case you definitely want to implement the standard Add trait, so the user can naturally write their maths. They've already opted in to the behavior with a call to Gf2::from.