concept functional codebase in category functional programming

appears as: Functional codebase, functional codebases
Grokking Functional Programming

This is an excerpt from Manning's book Grokking Functional Programming.

Itinerary

  private List<String> plan = new ArrayList<>();   public void replan(String newCity, String beforeCity) {    int newCityIndex = plan.indexOf(beforeCity);    plan.add(newCityIndex, newCity); }   public void add(String city) {    plan.add(city); }   public List<String> getPlan() {    return Collections.unmodifiableList(plan); }

#A  In object-oriented programming data and methods that change this data are coupled together. Data is private, it can be mutated only by methods.

#B  This method returns void, because it mutates data in-place. We lose the previous version of the plan. Additionally, it can’t be trusted, because the result of calling it with the same arguments may be different (depending on the state).

#C  We need to be very careful not to leak the internal data to the users of the class. We need to return a copy or a view to make sure nobody else mutates our state (i.e. it doesn’t become "shared"). The bigger the class, the more taxing and error-prone this becomes.