| Hash maps also don't (usually) have external effects. There arent many hash map methods that will actually modify the data. Standard OOP, on the other hand, seems to encourage such behavior. So, for example, a Company object could contain a bunch of Department objects, each of which contained a bunch of Employee objects. These people objects could also be referenced in areas outside of the company object. If I called a company.giveFinanceDepartmentARaiseInDollars(10000) function on the Company object, it would have an unpredictable impact on the Department/Employee objects. It may also have cascading effects in other parts of the application that may not be clear. On the other hand, if you represented this as a company hashmap, with the keys the department structs, you would have to do something like the following instead: company["finance"].employees.forEach(x => x.salary = x.salary + 10000);
company["finance"].base_salary = company["finance"].base_salary 10000 This contrived example shows some of the pros/cons. OOP allows us to hide a lot of behavior/changes, which may mean less repetitive code. OTOH, it hides a lot of behavior/changes. |
More generally the issue of global mutable state and keeping your own sanity as a developer is a problem across paradigms.