5 ms·
And if you write f# or Java code?
by tigershark 9y ago
And if you write f# or Java code?
- baud147258 9y agoFor java code, use final so that you have constants.
- _asummers 9y agoNote these are only constant pointers. Your data is still mutable if the underlying data structure is mutable, (e.g. HashMap). Haven't used Java in a few years, but I made religious use of final, even in locals and params.
- baud147258 9y agoGood point regarding mutable data. But since we were talking about loglevels, I don't think it's a problem there.
- Freak_NL 9y agoIn Java you usually use `.equals()` to test equality, or if your argument is a boolean value: if (myVar) { // } Instead of `myVar == true/false`. The accidental assignment is much less common due to the way equality is tested in Java. Also, `null` comparisons being assigned will fail to compile (assuming var is a String here): TestApp.java:6: error: incompatible types: String cannot be converted to boolean if (var = null) {
- tigershark 9y agoBut in Java it’s much easier to do the error of using == instead of equals if you always jump language.
- Freak_NL 9y agoSure, but that is such a common mistake that all Java IDE's warn you when you try to use == for Strings and normal non-number objects.
- bonesss 9y agoThese kinds of issues are excellent commercials for why the strictness of a language like F# (or OCaml, Haskell, etc), is such a powerful tool for correctness: 1) Outside of initialization, assignment is done with the `<-` operator, so you're only potentially confused in the opposite direction (assignments incorrectly being boolean comparisons). 2) Return types and inputs are strictly validated so an accidental assignment (returning a `void`/`unit` type), would not compile as the function expects a bool. 3) Immutable by default, so even if #1 and #2 were somehow compromised the compiler would still halt and complain that you were trying to write to something unwriteable Any of the above would terminally prevent compilation, much less hitting a code review or getting into production... Correctness from the ground up prevents whole categories of bugs at the cost of enforcing coding discipline :)
- tigershark 9y agoThis is why I love F# but if you jump between f# and c# your muscle memory will suffer.