Tag: php

Measuring software coupling

Coupling is about how objects in your application are connected: which objects depend on which, and how does that affect the entire system’s stability?

An application has tight coupling when a lot of components depend on each other. This should usually be avoided because a change in 1 place can cause issues in any of its dependencies.

So what does coupling tell you about your classes?

Measuring software complexity

When asked for estimates, you usually don’t have much more than your gut feeling to go on. You just know that this one thing is going to take longer because it’s more fragile than that other thing. But why is that?

People much smarter than me have researched this subject and there are good ways of measuring how complex a piece of code is.

Time & timezones

If you’ve ever been far away from someone you want to communicate with, you’ll know how annoying daylight saving times & timezones make it to coordinate time across the world.

You don’t want your users to have to have to reason about that, so you’ll have to make your application do the work for them & display them the time at their location.

Dealing with time isn’t necessarily difficult, you just have to be consistent.

How to make your code scale

Building scalable software means that you are prepared to accommodate growth. There are basically 2 things you need to consider as your data grows:

  • Will requests be handled at a faster rate than they come in?
  • Will my hardware be able to store all the data?

Obviously, you will need more infrastructure as you grow. You’ll need more machines. You’ll probably also need/want to introduce additional applications to help lighten the load, like cache servers, load balancers, …

You don't want to build your own minifier

Every developer has likely at least considered writing their own framework or CMS. Until you start to realize just how much work it is and how much of your problems have actually been solved by someone else already. Then you throw in the towel and start using (and hopefully, contributing) to existing open source projects that suit your needs. Writing a minifier is very much alike.

While working on a CMS we had started, we wanted to serve our CSS and JavaScript minified, automatically. We threw some regular expressions at those static files. Eventually, it became more complex, it grew into a project of its own.

Geographic searches within a certain distance

A 2-dimensional location on our earth can be represented via a coordinate system similar to an X & Y-axis. These axes are called latitude (lat) & longitude (lng).

Latitude is the north-south axis with a minimum of -90 (south pole) and maximum of 90 degrees (north pole). The equator is zero degrees latitude.

Longitude is the X-axis equivalent, running around the globe from east to west: from -180 to +180 degrees. The Greenwich meridian is 0 degrees longitude. Everything west and east from it is respectively negative and positive on the longitude scale, up until the middle of the Pacific Ocean, near the International Date Line, where -180° longitude crosses over to 180°.

How to build a MySQL-powered search engine

In content-heavy websites, it becomes increasingly important to provide capable search possibilities to help your users find exactly what they’re looking for. The most obvious solution is searching your MySQL database directly, but implementing a generic MySQL search is not at all trivial. Here’s how to avoid those pitfalls and build a robust MySQL-powered search engine for you website.

This article will solely focus on the most common text-based search (as opposed to e.g. geography- or time-based)

Async processing or multitasking in PHP

In PHP, there are multiple ways to process data asynchronously, although not one will work in every single environment. There is no one true solution, and whichever suits you best will mostly come down to your specific task.

Although both multithreading and multiprocessing can be used to process code in parallel, it probably makes sense to first distinguish between the two.

Regular expressions for pros

Regular expressions are powerful string-manipulation tools, though chances are you probably don’t even know half of what is possible with them. Before touching some of the PCRE awesomeness, make sure you’re quite familiar with regular expressions already.

Though you probably won’t use any of the below on a daily basis, you should definitely be aware of their existence. The exact syntax might’ve slipped your mind by the time you get to use some of these, but I guess you can always come back to refresh your memory once you need it, right?

If you know all about the stuff in the basics tutorial already, dive in!

Introduction to regular expressions

Regular expressions are under-valued and most developers tend to only know the basics. Having a thorough understanding of how regular expressions work, will be incredibly helpful when you need to parse structured data.

In essence, a regular expression – or regex – is an instruction set to parse “certain data” in a “certain string”. A simple example of such regex is /[0-9]+/: instructions to find numeric occurrences in a string.

Regular expressions are most commonly PCRE-based, an instruction set derived from the regular expression implementation in Perl. I’ll be discussing the PCRE implementation in PHP in particular. While in other programming languages the specific implementation may differ, most modern languages have PCRE ( Perl Compatible Regular Expressions) support and the concepts should and will largely be the same in the language of your choice.