In continuation to a previous blog post Test Driven Development, we would like to discuss the Defensive Coding approach in this blog post.
What?
Defensive programming is an approach to improve software quality by “Making the software behave in a predictable manner despite unexpected input or user actions". The software's behavior should be consistent even in undesirable conditions.
When?
Defensive programming techniques are used especially when a piece of software could be misused mischievously, or inadvertently, to cause a catastrophic effect, which is likely to be the case.
Why?
One of the compelling reasons to perform defensive coding is that catching exceptions is computationally expensive. It is useful to follow techniques that allow the program to continue by gracefully handling the exceptional conditions, without throwing an exception.
Defensive coding also reduces the number of bugs and ensures code correctness.
How?
The most widespread practice is to use guard statements like:
Null Checks
Pre-conditions
Assertions
- Do not repeat the guard statements. We often tend to repeat code to perform validations. This repeated guard usage can lead to primitive obsession and wasted computational cycles.
- In such cases, it is always better to either include abstractions to perform the validations or extract the duplicates into separate and reusable checks.
- Since these validations are very crucial and spread across the code base, they should be kept intact. It also helps us to adhere to the DRY (Don’t Repeat Yourself) principle.
- Always wrap a third party library usage with our own gateways or proxies.
nsquared solutions
Showing posts with label #development. Show all posts
Showing posts with label #development. Show all posts
Sunday, August 12, 2018
Tuesday, May 2, 2017
Microsoft Build 2017 Conference In Seattle, Washington State
Only a few more sleeps
till the exciting (well we find it exciting) Microsoft Build 2017 conference in
Seattle, Washington State, to kick off on May 10th to 12th.
Dr
Neil Roodyn will be attending deep technical sessions, learning new
technologies and getting advance notice of Microsoft’s new plans.
He
will be meeting and learning, from more than 5,000 developers in the
industry, from all over the World and yes, the place will be a buzz with
it’s own tech speak.
The Build up is underway. Announcements are thick and fast. You can feel
the excitement. We’ve had updates to Cognitive Services that help
developers build apps that understand people and the world around us. The
current SDK for the Windows Creators Update feature was shipped. Also
announced Azure Managed Disks and VM scale sets, for ease of use and scale
benefits to PaaS to IaaS developers.
Microsoft Build 2017, May 10-12 in Seattle, in person or Live Streamed
will teach you as developers, how to put these latest and coming innovations to
create:
·
AI-powered
apps we have yet to imagine
·
Apps
that make your customers more productive
·
Cutting
edge, intelligent cloud apps
·
Mixed-reality
experiences
·
Mobile
experiences for nearly any device
·
Simplified
end-to-end development ops experiences
There
will be keynotes, deep technical sessions, hackathons and opportunities to
collaborate and code with your fellow technologists and engineers.
There’s never been a more exciting time to be a
developer.
Click here to watch the conference via live stream
Subscribe to:
Posts (Atom)


