I find myself consistently creating flags within my C++ program, that are later checked to determine if I need to do something, and it honestly feels kind of hack-y despite being a simple solution.For example, Let's say I have a function:update_employee_salary(EmployeeList employees_to_update )update_employee_salary:Connects to the databaseIterates through all employees in the EmployeeList and gets their status (salaried, or hourly) and creates two separate employee list (hourly_emp, salary_emp)Updates my employee_data in cacheWrites that employee data to the databaseIf the employee is an executive, I want to generate notices/logs that Executive salaries were updated.I also want to ensure that if for some reason, after reading from the database, I am unable to write to the database, that I back everything out. For this reason, I don't want to generate the notice until I guarantee it's been written to the database, so I'll create a bool elist_contains_execs flag that is checked after the database has been updated to generate the notice.I find myself doing things like this for all sorts of situations, and it feels gross every time I do it, but often it seems better than iterating through the list a second time to determine if it contains executives after the database update.Question: Is using flags in C++ feel hacky to anyone else? Or do we just accept that it's often a simple solution. What are the cons of using flags. For example, can it make code more difficult to maintain.
Using bool/flags to govern C++ program flow
c++