3 ms·
For the first example used: public void addBar(Foo foo){ Bar bar = new Bar("baz"); foo.setBar(bar); dao.update(foo); dao.save(bar);
by mcx 12y ago
For the first example used:
public void addBar(Foo foo){
Bar bar = new Bar("baz");
foo.setBar(bar);
dao.update(foo);
dao.save(bar);
}
What would the functional version look like?
- fegu 12y agoThe functional version would chain these statements (either implicitly with temporary variables or explicitly with bind), so it became obvious which depends on which. As it is now, you can't be sure if foo.setBar(bar) changes bar, and you can't be sure if dao.update(foo) changes bar. You also can't be sure if foo is the same before and after addBar. Imagine coming back two years later to add some functionality here. You can either read all the other functions or you can rely on the choice of verbs to guess. In functional code, you won't have to guess (as much).