I've been using PHP for a number of years and have seen the same things being done with return values from functions over and over again. I have always thought of this as pretty standard, but the more I think about it the less it makes sense. Looking back over my career I am quite sure that a few serious bugs could have been avoided if I had not mixed return types.
I wanted to impart a piece of advice to do with validation and formatting of user input, although I've never seen anyone suggest it. I guess it would come under the single responsibility principle so it might seem obvious to some people. There can be reasons why this might at least seem like a good idea at the time.
Following on from my last post about sorting colors I have been thinking about different ways of sorting colors. I have been looking at interfaces that allow people to select colors and they will quite normally have a band of colors that does look nicely sorted. As it turns out this is perfectly possible to do if the colors are normalised to remove light and dark variations of different colors.
I came across this sorting algorithm the other day called 'bogo sort'. This is a sort of joke sorting algorithm that is highly ineffective at actually sorting arrays. The name comes from the word 'bogus'.
Here is how it works.
I have been doing some reading and watching lectures of programming theory recently and I was reminded of this algorithm I learned about in university. Binary searching an array is a divide and conquer algorithm that takes an array and searches for a value in that array by splitting the array into halves. The algorithm works like this.
Drupal 8's comment system has the ability to be threaded so that users can reply directly to other users comments and create threads of conversation. I have always found this difficult to use and difficult to read so I wanted to turn it off when I set up this site. The only issue I had was I could turn off the threading but couldn't alter the ordering of the comments.
Sorting colors is the sort of thing that you never really think about until you need to do it. Sorting a bunch of items by their color is useful in a number of applications, but the simplest is just to display items to the user in a more controlled manner. As it happens sorting with colors is a much more complex topic than I originally thought and required digging into quite a bit more maths than I expected.
Incidentally, there is a whole world of color maths that I didn't know existed until I started looking into this. It was worth learning about though.
Deployer is an amazing tool that is used to deploy websites (hence the name). I have looked at other tools, but because Deployer is built and run using PHP, using it to deploy PHP sites makes sense. It also means that I don't have to figure out complex XML documents or learn Ruby just to understand what the deployment is doing.