|
|
|
|
|
by toastking
2642 days ago
|
|
This is why I think debuggers are necessary. Without being able to see a full stack frame of information about variables it can be extremely difficult to debug when using other people's code. So many errors boil down to assumptions about what is in a value. |
|
The first point your code sees uncertain data is the point that it needs to clarify what it has.
The only way you get the errors you're talking about is if you ignore the above practice.
Garbage in. Garbage out.
For code i write, there is usually only one option for what is in a variable, the type of the data i out in there. This is true for dynamic languages as much as static.
In some situations I will also allow a null value. All that means is that there was no data, and no default is wanted. Usually, I want a default.
Closing off all entry points for uncertain data you need to make assumptions about is the first port of call when dealing with other people's or legacy code. It's the way to reason about code without a debugger.
If you can't reason about code without a big question mark above every piece of data you need a debugger.