IMG_0914 Scott Bellware on software design principles
Scott Bellware gave a talk on SOLID software design principles at a Women Who Code meeting in March of 2014. If you follow SOLID principles, you might discover that a lot of commonly seen coding practices are wrong -- at least according to Scott Bellware.
For example, the Law of Demeter (each unit should have only limited knowledge about other units) means that you shoud not use another object's associations. So don't traverse an object's field like a tree: order.item.product.supplier. Instead, if your code needs to send email to the supplier, get a Supplier object from a database query -- e.g. Supplier.where(id: supplier_id) -- and call supplier.send_email(). In other words, send command to an object, but avoid pulling data out. This is called "tell, don't ask" principle.
Scott talked about about several similarly "counterintuitive" (at least at the first glance) coding practices that emerge from the goal to keep classes as loosely coupled as possible.