Blog Layout

Bomb-proofing your code with robust programming

May 21, 2018

Bugs are a fact of life in software. Sometimes they spring to life because of simple omissions or typos. Those are easy to fix. Sometime bugs arise from mysterious outliers, throwing errors that should never be called. These often come from fragile code.

The solution is what's known as robust programming. Also called defensive programming, robust code anticipates problems, abstracts any values returned to exposed functions, and makes debugging a simple process.

Here's the difference between robust and fragile code.  

Expects Stupid Inputs
Robust code doesn't assume that any caller has read the manual, understands how to produce correct data inputs, or knows how code is supposed to work. That means they may be passing the wrong data types, malformed data, or things that don't make sense. When it catches something like this, it produces understandable error messages and stops this bad data from propagating through the system.

Just because you're working on internal code that will never interact with external users or methods doesn't mean you shouldn't expect the caller to be an misinformed. We forget what we did a week later, neglect internal documentation, and assume function by method names. Everybody can be misinformed sometimes, so make sure every piece of code is ready for that.

Trusts No One
The flip side of this is that robust code does not trust any piece of information that it does not create. Always assume somebody has it out for you and is going to break your code. Always assume that any function that you call could fail or send back unexpected results. If someone throws a bomb at your methods, they should be able to handle it elegantly enough to not blow up the whole shebang.

This is the flip side of the stupid inputs protection. It's not that they don't know what they are doing, it's that they are looking for ways to break your program. A lot of malicious code uses a buffer overflow exploit, where data exceeding the boundaries of a memory buffer are written to nearby memory areas, sometimes executing arbitrary code. But you can prevent it by checking that a data structure is within the bounds that it claims to be. Essentially, you are asking all incoming data for their identification papers to make sure they are what they claim to be.

Hides Your Cards
Public methods and fields and global variables are two great ways to introduce secret bugs into your code. That's because any other method could have access to this data. So those variables could be changed at any time and in a way that doesn't make sense, especially with multi-threading and multiple cores.

Keeping the important stuff private helps you control what happens to any data in your software. Especially if you are relying on that data. If you are creating an API, you will probably need some sort of public get and set routines; that can't be avoided. But by having only one way in and one way out for data, you can control and track data changes and head bugs off.

Expects Things to Change
We all know code within any large project will change. What you may not expect is file structures or standard inputs or output to change. If you assume they stay the same, then you are asking for trouble. What if you or someone like you overrides it or modifies it? Cue explosions.

You should do this for data structures and objects that you create as well. As a secondary benefit, this makes your code easier to maintain and update. For methods where you return data, this means not passing data structures or pointers to objects if you can help. If the structure that you pass has to change, you might have just broken a lot of code.

Making your code robust -- that is, defensive -- ensures your software will have less bugs and less security holes. Trusting things to just work or for static operation will only lead to heartbreak.

By Mimi Petrakis February 28, 2025
As the IT & digital industry continues to evolve, staying informed on salary trends and employment dynamics is crucial for both professionals and businesses. Last month, Peoplebank’s highly anticipated February 2025 Salary Guide was released, offering comprehensive salary insights, job market analysis , and hiring trends to help you navigate the ever-changing landscape of IT & digital employment in Australia. Key Insights from the Peoplebank Salary Guide 2025 Our latest salary guide delivered state-by-state salary benchmarks for various IT & digital roles, providing clarity for job seekers, hiring managers, and industry leaders. It also includes expert insights from Peoplebank specialists, highlighting the latest employment trends shaping the industry. “Our Salary Guide reflects the major challenges and opportunities within the dynamic IT & digital industry. The guide serves as a critical resource for stakeholders, providing insights into commercial realities as the year begins and empowering both talent managers and IT & digital professionals to make informed strategic decisions aligned with the current market.” Tim Moran, Executive General Manager, Peoplebank and Leaders IT What’s Trending in the IT & Digital Job Market? Job Market Stability : The number of professionals changing jobs has continued to decline since 2024, with a rise in job tenure. This suggests a growing emphasis on job security and long-term career planning in the IT sector. Contractor Rates & Permanent Roles : A softening of contractor rates indicates a shift in preference towards permanent employment, reflecting a changing job market dynamic. Talent Development Focus : Companies are prioritising in-house talent development , tailoring skills to meet their specific organisational needs rather than solely relying on external hires. Most In-Demand Roles : Software Engineers are in high demand as businesses invest in AI, automation, and cloud-based solutions to accelerate digital transformation. Solutions Architects are increasingly sought after to design scalable, efficient, and secure IT infrastructures that support evolving business needs. Download the Full Salary Guide Understanding salary trends, hiring patterns, and emerging job market shifts can give you a competitive edge—whether you’re an IT professional planning your next career move or a business seeking top digital talent. Download the full Peoplebank Salary Guide now to access the latest insights and ensure you're staying ahead in the IT & digital industry.
An older woman working in tech faces the camera in the boardroom men are working on tablets in the background
February 2, 2025
As we wrap up the first month of 2025 what have our experts learned? Peoplebank Account Manager Elizabeth Fairweather shares her thoughts and predicts the trends to come
By Mimi Petrakis December 31, 2024
What's ahead for 2025?
By Mimi Petrakis November 7, 2024
Your resume is the first thing a potential employer will see from you. Make sure you take time planning and thinking about your resume.
Blue tile with white text that shows the new Leaders IT and Peoplebank logos and title 'a new look'
By Mimi Petrakis November 1, 2024
Peoplebank and Leaders IT: A fresh look for a new era in recruitment
A poster for navigating the current it job market
September 4, 2024
Read about Navigating the Current IT Job Market: Strategies for Success Amidst Uncertainty from Peoplebank
A group of people are working on a project together.
By Mimi Petrakis July 13, 2024
Read about “How do I Ask for a Reference?” Your Key to Landing the Perfect Role from Peoplebank
A group of people are sitting at a table with laptops.
By Mimi Petrakis June 5, 2024
Read about Career CUSP: Empowering Talent & Employers from Peoplebank
A white background with the words `` ps towards conciliation '' on it
By Mimi Petrakis May 5, 2024
Read about Steps Towards Reconciliation: A Conversation with RGF Staffing's Reconciliation Strategy Manager Jackie Reilly from Peoplebank
A group of people are standing around a light bulb surrounded by pink cubes.
By Mimi Petrakis April 4, 2024
Read about Unlocking the Benefits of Project-Based Employment from Peoplebank
More Posts
Share by: