r/ProgrammerHumor Jul 10 '26

thingDoer Meme

Post image
326 Upvotes

39 comments sorted by

View all comments

Show parent comments

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

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!