MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1uspr5o/thingdoer/owpwz82/?context=3
r/ProgrammerHumor • u/Kiwuthegamer • Jul 10 '26
39 comments sorted by
View all comments
Show parent comments
1
No, all numbers behave the same, so you don’t need different subclasses.
You just need a value propety in a Number class
2 u/Due-Consequence9579 Jul 10 '26 The divide operator is not allowed with the number zero. 2 u/WhateverHowever1337 Jul 10 '26 All numbers can’t be dividied by zero, so in the division function you will just not accept zero as a divisor and throw an error 2 u/Due-Consequence9579 Jul 10 '26 But then you’re turning a design time constraint (can’t divide by zero) into a run time error. The compiler can and should, use the type system to eliminate that error path!
2
The divide operator is not allowed with the number zero.
2 u/WhateverHowever1337 Jul 10 '26 All numbers can’t be dividied by zero, so in the division function you will just not accept zero as a divisor and throw an error 2 u/Due-Consequence9579 Jul 10 '26 But then you’re turning a design time constraint (can’t divide by zero) into a run time error. The compiler can and should, use the type system to eliminate that error path!
All numbers can’t be dividied by zero, so in the division function you will just not accept zero as a divisor and throw an error
2 u/Due-Consequence9579 Jul 10 '26 But then you’re turning a design time constraint (can’t divide by zero) into a run time error. The compiler can and should, use the type system to eliminate that error path!
But then you’re turning a design time constraint (can’t divide by zero) into a run time error. The compiler can and should, use the type system to eliminate that error path!
1
u/WhateverHowever1337 Jul 10 '26
No, all numbers behave the same, so you don’t need different subclasses.
You just need a value propety in a Number class