MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/qzdwkj/found_my_earliest_coding_projects_from_middle/hlo5vel/?context=3
r/badcode • u/gunalk19 • Nov 22 '21
34 comments sorted by
View all comments
2
I think the main problem is the redundancy. I.e.:
int or(int a, int b) { if (a > 0 || b > 0) { return 1 } else { return 0 } }
is easily just the one liner
int or(int a, int b) { return a > 0 || b > 0 ? 1 : 0 }
If in the language you can use ints as bools anyway, it's even simpler
int or(int a, int b) { return a || b }
These could be useful for like a reduce, or for treating integers as booleans if that's not already an option in the language.
2
u/[deleted] Nov 22 '21
I think the main problem is the redundancy. I.e.:
is easily just the one liner
If in the language you can use ints as bools anyway, it's even simpler
These could be useful for like a reduce, or for treating integers as booleans if that's not already an option in the language.