Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

MyBuilder Tech Blog:
Insertion, Removal and Inversion Operations on Binary (Search) Trees in PHP
Jul 22, 2015 @ 10:08:21

The MyBuilder.com Tech blog has a tutorial posted showing you how to work with binary trees in PHP, specifically how to perform insertion, removal and inversion operations on their data.

Recently Max Howell (creator of Homebrew) posted an interesting tweet in regard to Google's interview process. In this tweet he mentioned how one of the proposed questions was to white-board a solution to invert a binary tree. Over the past couple of years I have been interested in exploring fundamental Computer Science data-structures and algorithms. As a result, I thought it would be interesting to explore this structure and associated operations in more depth - using immutable and mutable PHP implementations to clearly highlight the benefits garnered from each approach.

He starts with a brief definition of what a binary search tree is just to be sure everyone is on the same page. He then gets into the code to represent a Node, a simple class that has a value and "left" and "right" variables to contain each of the possible two child nodes. He then goes through each of the operations (insertion, removal and inversion) showing code examples for both mutable and immutable methods.

tagged: binarytree insertion removal inversion mutable immutable

Link: http://tech.mybuilder.com/insertion-removal-and-inversion-operations-on-binary-search-trees-in-php/

Nicolas Bérard-Nault's Blog:
The unknown value of Value Objects
Mar 31, 2011 @ 12:12:46

Nicolas Bérard-Nault has put together a new post looking at the role that Value Objects play in application development and, more specifically, how they fit in with domain driven design (DDD). He looks to explain the unknown value of Value Objects to developers that might not know how helpful they really can be.

One of the main rules of DDD is that value objects are immutable. This is often not as self-evident as it seems, as many programmers are not even aware of the state they leak and create. Sadly, state is often positively correlated with entropy. Hence, taking steps to contain and to limit state is one of the keys to taming complexity in an application.

He notes that even outside of DDD Value Objects can be quite useful. He gives an example of a "RationalNumber" class with methods for basic things like addition and subtraction. He shows the more traditional mutable version that most developers would start with and uses it in several examples to show its flaws. He finishes up the post with a look at the "more correct" immutable version of the class and a sample call that would result in the correct output of a simple matematical operation.

tagged: valueobject domaindrivendesign mutable immutable