Use a Struct Instead of a Long Argument List

Use a Struct Instead of a Long Argument List

Functions having a long list of arguments such as:

 void retrieve(const string& title, const string& author, int ISBN,  int year, bool&  inStore); 

can become a maintenance problem, since their argument list is likely to be changed in the future. For example, a URL with a book cover image may be added or other arguments may be omitted. Consequently, every occurrence of a function call has to be modified appropriately. A better solution is to pack the entire argument list in a single struct and pass it by reference (or by address in C) to the function:

 struct Item{string title;string author; int ISBN;  int year, bool  inStore };void retrieve(Item& book);

The advantages of this technique are obvious:

1. Maintenance. Every modification will be localized to the definition of the struct, but no other code modifications will be required.
2. Performance. Since a reference is all that has to be passed to the called function, you may gain a slight performance boost.
3. Future extensibility. A struct can serve as a base for other classes. It may be extended to have member functions as well.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved