Code "style"
2023-Oct-24, Tuesday 14:38![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
So I did more programming for my Cataclysm mod and I wrote the following statement:
Simple, right? It makes the clear decision hierarchy obvious to the reader. If not A, then B. If not A or B, then C, and so on.
Well, no. It turns out the heads of the project have very particular ways they like things to be done, and they don't want any nested statement where different branches return the same thing--so no having two branches return true or two branches return false. This is set as a warning in the tests, but they deliberately elevated it to an error.
Alright, so I need to change it. And I thought, and I thought, and I said, you want a simplified statement? Alright, I'll give you a simplified statement!
Malicious compliance is a go.
(I did leave a comment explaining the logic, before you ask).
if( in_species( species_PSI_NULL ) ) {
return false;
} else if( has_flag( mon_flag_HAS_MIND ) ) {
return true;
} else if( in_species( species_ZOMBIE ) ) {
return false;
} else if( has_flag( mon_flag_HUMAN ) ) {
return true;
}
else {
return false;
}
Simple, right? It makes the clear decision hierarchy obvious to the reader. If not A, then B. If not A or B, then C, and so on.
Well, no. It turns out the heads of the project have very particular ways they like things to be done, and they don't want any nested statement where different branches return the same thing--so no having two branches return true or two branches return false. This is set as a warning in the tests, but they deliberately elevated it to an error.
Alright, so I need to change it. And I thought, and I thought, and I said, you want a simplified statement? Alright, I'll give you a simplified statement!
return ( ( !in_species( species_PSI_NULL ) && has_flag( mon_flag_HAS_MIND ) ) ||
( !in_species( species_PSI_NULL ) && !in_species( species_ZOMBIE ) && has_flag( mon_flag_HUMAN ) ) )
Malicious compliance is a go.
(I did leave a comment explaining the logic, before you ask).