DEV Community

Discussion on: What is Defensive Coding?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Now, how can I integrate this into my TS/JS projects, because of not-so-true static typing, and any casting...

Collapse
 
acroynon profile image
Adam Roynon

I'm not sure I fully understand what you mean here, but to improve the defensive coding of your program I would suggest breaking stuff down into small to manage functions and then thinking about the edge cases and potential problems those functions may face (e.g. wrong inputs, missing inputs, etc) and add some code to defend against those cases. Similarly to how I show the progression of a normal multiply function and then adding code to handle edge cases.