Silently taking Abs sounds like a terrible idea for future debugging

We assume that only positive integers should go into “Deposit” function. If a negative integer finds its way in there, it thus means that we definitely have a bug somewhere.
So hiding it by simply taking Abs is the worst thing we can do to the future us that will try to debug why the value in the bank ends up being not what we expect it to be.

There are different approaches to how to not hide it, in this case I personally would opt for “Debug.LogError” whenever we discover a negative integer in that function and immediately returning, so it shows up red in the console. Another thing to do would be to use “uint” as the argument - I think C# doesn’t just silently convert int->uint as C++ would do?
Anyway, anything that will alert us that something is wrong as quickly as possible might save us some annoying debugging in the future.

12 Likes

I agree, this seemed like an incredibly lazy approach to ignoring a clear issue. I amended my code to include an if statement so that a console debug would get written to alert me that a negative value has been passed.

A more robust system might be to fire an event and have a class setup to receiving bugs and logging them. I believe it’s possible to print a log of what’s happened and crash the game so that it’s picked up. Still new to all this.

Would have been a good place to introduce Assert to the course.

1 Like

Privacy & Terms