Matthew is a freelance technical writer helping businesses win over developers by creating documentation developers need, to really use their platforms to the full. He's also the editor of Master Zend Framework, where you can learn everything there is to know about Zend Framework.

Matthew's articles

  1. Arrays, Slices and Basic OOP in Go

    Recently I wrote an introduction to using Go, looking at what it is, how to install it, and how to get your environment ready. The article finished up by stepping through a small application covering the Go basics of variables, output, functions and structs.

    In today’s article, we’ll build on that foundation, by looking at a few new concepts; specifically:
    - Arrays & Slices
    - Maps
    - Methods

    Arrays & Slices

    There’s many ways in which you can initialize an array in Go. Let’s have a look through 5 examples:

    var numberList [5]int
    var stringList [10]string
    var float64List [15]float64

    Here, we’ve created three empty arrays, of different types (int, string and float64) and different sizes (5, 10 and 15).

    x := [5]float64{ 98, 93, 77, 82, 83 }

    Here, we’ve created an array, 5 elements in size of type float64, initializing it at the same time.

    y := [...]int{ 98, 93, 77, 82, 83 }

    Here, we’ve created an array of type int, but not specified the size. Instead, we’ve passed in ..., and a range of values. When initializing the array this way, it will determine the size from the number of elements provided.

    If you are familiar with dynamic languages, such as Python, PHP and Ruby, you’ll be used to creating arrays of a fixed size, with elements of a mixed or same type, but also be able to dynamically add and remove elements as you go along. Here’s a PHP example:

  2. Scaffolding an Application with Phalcon

    In this video, produced by SitePoint’s sister company Learnable, you’ll learn how to create a basic, modular, application in Phalcon using the Phalcon command-line tools.

    If you’ve used other frameworks which don’t have this tooling support, you’ll know just how long and sometimes error-prone, setting up so much infrastructure can be. Gladly, Phalcon’s command line tools take all that away, allowing you to concentrate on what you do best: building applications.

  3. Go: Building Web Applications With Beego – Part 2

    This entry is part 2 of 2 in the series Building Web Applications With Beego

    Developing a web application with Beego - Part 2

    Welcome back to part 2 of the series, where we get up to speed with the Beego web development framework for Go. If you missed part 1, I encourage you to read it, as it lays the foundation for this series.

    In part 1, we made a good start, understanding and working with Beego by installing Beego and the command line tool Bee, creating a basic project, adding a controller action, creating a basic view template, adding a custom route and finished up learning how to work with request parameters.

    In part 2, we’ll be getting into more of the fun aspects of building a web application by integrating a database, specifically with SQLite3, as well as looking at models, forms and validation. I hope you are ready to go, as this is going to be a good ride through to the end.

    2-Step Views

    You’ll notice throughout a number of the functions in the manage controller, the following code:

    manage.Layout = "basic-layout.tpl"
    manage.LayoutSections = make(map[string]string)
    manage.LayoutSections["Header"] = "header.tpl"
    manage.LayoutSections["Footer"] = "footer.tpl"

    What this does is set up a 2-step view layout. If you’re not familiar with the term, it’s where you have an outer layout which is always displayed, such as sidebars, navigation, headers and footers and inner content which changes based on the action being executed.

    2 Step View Layout

    The image above illustrates what I mean. The green areas are in the outer, wrapper view and the red is the content which changes, based on the executing action.

  4. Go: Building Web Applications with Beego

    This entry is part 1 of 2 in the series Building Web Applications With Beego

    Developing a web application with Beego - Part 1

    Synopsis

    This 2-part series shows developers with experience in dynamic languages such as PHP, Python and Ruby, how to quickly get up to speed with the Beego web application development framework, for Go.

    It steps them through building a simple application with all of the expected components of forms, validation, routing, database interaction, redirection, filtering and more.

    Introduction

    Are you a web application developer coming to Go from a dynamic language as PHP, Python or Ruby, and wondering how to develop web-based applications using it? Are you wondering how to develop in a manner analogous to your existing frameworks, where you can leverage your existing knowledge?

    If so, then you’ve likely done some searching, whether on Google, StackOverflow or other sites, in search of a framework to help you out; and you may have seen that there are a number of options available, including Beego, Martini and Gorilla; in addition to the net/http package.

    Of these four, the one that I’ve been experimenting quite a lot with is Beego. I’ve found that it’s quite feature rich, yet not overly complicated, so I’ve been able to get up to speed with it relatively quickly.

    Beego is not your average web development toolkit. As well as providing a lot of functionality, it builds on a large number of existing Go packages, which allows it to provide:

    • A full ORM
    • Caching
    • Session support
    • Internationalization (i18n)
    • Live monitoring and reloading
    • Deployment support.

    But whilst there are a number of similarities between Beego and the frameworks from the previously mentioned dynamic languages, there are enough differences between them to require some time to be invested before becoming truly productive and proficient.

    Furthermore, whilst the Beego documentation is quite comprehensive, I feel that it suffers a bit by missing points here and there, so I’ve written this 2-part series to help overcome that and help you learn the basics of Beego.

    In this series you’ll see just what an excellent framework it is and how much it takes care of for us as developers. Specifically, here in part 1 we’ll cover:

    • Installing Beego and the command line tool Bee
    • Creating a project
    • Actions
    • Views / Templates
    • Routing
    • Request Parameters

    If you want to read through the completed code for this series, it’s available on Github. Feel free to browse it online or clone it and experiment with it. Let’s Go!

  5. Email Debugging with MailCatcher

    You use email in your applications, right? Ok, that’s a rhetorical question. Of course you do. Despite email being over 30 years old, it’s still the most popular application on the planet, by far. Here are some stats from Pingdom, for 2012:

    • 2.2 billion – Number of email users worldwide
    • 144 billion – Total email traffic per day worldwide
    • 4.3 billion – Number of email clients worldwide in 2012

    Staggering!

    But why another article on email?

    For one simple reason, one which we’ve likely all been caught by at one point or another. Because we need to test, as close to production as we can, but without emailing our clients accidentally, and them consequently becoming confused or frustrated, or embarrassed that their clients have received test emails.

    I’m sure you know what I mean. You think you’ve set your application in some kind of debug mode. Given that, you start your test, which sends a load of emails from your application. All the while, you feel comfortable in the knowledge that no one but you is ever going to see them.

    Your tests pass, you congratulate yourself, and move on. A short time later, you receive a rather, let’s just say terse, Skype call from your client. She’s rather annoyed as her customers have been ringing up, asking why they’ve been receiving odd emails from her company. She’s not happy and wants answers?

    Been there? Don’t want to be there again? I’m guessing you don’t. Here’s the solution – MailCatcher. If you’re not familiar with it, MailCatcher

    …runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that’s arrived so far.

    Sound like a good solution? No matter if you’re tired, under pressure, new on the team, or just need to run tests – MailCatcher will ensure that no email ever gets sent outside of your network, or even outside of your development virtual machine.

    In this post, I’m going to show you how to set it up and run through the interface when emails have been captured by it.

    A Pre-Prepared Virtual Machine

    To save you a lot of trouble of getting MailCatcher set up, I’ve created a custom Vagrant box which does it all for you. Make sure you have VirtualBox and Vagrant installed, then clone a copy of the article’s repository using the following command:

    git clone git@github.com:sitepoint/mailcatcher-article.git
  6. Unit Testing with GuzzlePHP

    In January, Miguel Romero wrote a great article showing how to get started with Guzzle. If you missed the article, or are unfamiliar with Guzzle:

    Guzzle is a PHP HTTP client & framework for building RESTful web service clients.

    In Miguel’s article, he covered a range of the library’s features, including basic configuration for GET and POST requests, plugins, such as logging using monolog, and finished up with interacting with an OAuth service, specifically GitHub’s API.

    In this tutorial, I want to show you how to use Guzzle from a different perspective, specifically how to do unit testing with it. To do this, we’re going to look at three specific approaches:

    1. Hand Crafting Custom Responses
    2. Using a ServiceClient with Mock Response Files
    3. Enqueueing a Server with Mock Responses

    Getting Set Up

    Like all things, we need to walk before we can run. In this case, we need to set up our test environment and test class. To get everything in place, we’ll be using Composer. If you’re not familiar with Composer, please read Alexander’s article here on SitePoint before continuing.

    Our composer.json file will look as follows:

    {
        "require": {
            "php": ">=5.3.3",
            "phpunit/phpunit": "4.0.*",
            "guzzle/guzzle": "~3.7"
        }
    }

    I’ve stipulated a minimum PHP version of 5.3.3. To be fair, it likely should be higher, but this is a good start. Our only other requirements are PHPUnit and Guzzle. After adding these to composer.json, in your project run composer install and after a short wait, the dependencies will be ready to go.

  7. Politics Often Hold the Community Back

    This entry is part 3 of 3 in the series Can Great Apps Be Written In PHP?

    In this part of the interview series, I’m interviewing this channel’s editor, Bruno Škvorc, along with the feedback from Gary Hockin from Roave. We’ll start with Gary.

    Gary Hockin

    What lead you to PHP?

    Simply, classic ASP. I was working as a general dogsbody in a huge steelworks in Port Talbot, and we were paying thousands of pounds for licenses, to display data from an Oracle database on lots of screens.

    I started looking into ways of displaying that data on multiple screens for free – each machine had IE6 (at the time) so I explored ASP.

    From there I realised that I loved the role of web development and quickly learned PHP in my own time, as I realised then that open source was where the future was.

    What have been the things about PHP that bit you?

    In a positive way, originally it’s the fact that you can create these amazing interactive webpages which you can push to a $10 shared host and point your friends to it to play with.

    When I was a “kid” that was what kept me coming back to messing around with PHP, and ultimately why I shifted my career around it. More recently it’s the community. The community is simply amazing.

    What have been the highlights or redeeming features

    Of my career in PHP? I touched on it early, the community has been truly an epiphany for me. About 5 years ago I was sitting around as a Ghost Developer (http://www.troyhunt.com/2013/02/the-ghost-who-codes-how-anonymity-is.html), working in semi-object-oriented PHP, when I suddenly realised that someone HAD to have created a standard framework for building PHP applications.

    A quick Google led me to a list as long as your arm, but because we were already using Zend Guard on distributed servers I decided to use Zend Framework (1). From there I found the #zftalk IRC channel, and from there I got totally immersed in the ZF community.

  8. Getting Started with Go

    Unless you’ve been living under a rock these last few years, you’ll have heard of Go (sometimes referred to as Golang), a language originating from Google, some years ago.

    Go is slated as:

    …an open source programming language that makes it easy to build simple, reliable, and efficient software.

    Quoting another source, Go

    is a statically-typed language with syntax loosely derived from that of C, adding automatic memory management, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.

    Available for most modern operating systems, including Mac OS X, Linux, BSD and Microsoft Windows, it was conceived and initially created at Google, back in 2007, by Robert Griesemer, Rob Pike, and Ken Thompson. Each of these three developers have quite impressive pedigrees.

    Robert Griesemer was involved in Google’s V8 JavaScript engine and the Java HotSpot virtual machine; Rob Pike and Ken Thompson both worked at Bell Labs implementing the original UNIX operating system.

    Most programming languages, especially one with such a strong C heritage, can be difficult to get started with. Go on the other hand, is quite the opposite. And in today’s tutorial, I’m going to show you how to get started developing with Google Go, right from installation to a running application.

     Installation

    Whether you’re on Mac OS X, Linux and FreeBSD, or Windows, Go is easy to install and configure. I’m assuming in this tutorial that you have a UNIX/Linux operating system. When I first installed Go, being on a Mac, I used the latest package file.

    But you can just as easily install, from source, using the following commands:

    tar -C /usr/local -xzf go1.2.1.linux-amd64.tar.gz
    export PATH=$PATH:/usr/local/go/bin

    If you’re not familiar, these will extract a copy of the go files, from go1.2.1.linux-amd64.tar.gz, to /usr/local/go in your filesystem, and add the bin directory within it to your profile path.

    Alternatively, if you’re on Windows, download and run the MSI Installer.

    When the installer’s complete, you’ll find the installed files under c:\Go; and the installer should have added c:\Go\bin to your PATH environment variable. You may want to check, just to be sure though.

    Configuring Your Environment

    With that done, we have the binaries required to begin. But we need to ensure that our environment’s also ready, which requires one more step and a bit of background.

    Go development uses the concept of a workspace, which contains the source files (src), compiled binary files (bin) and packages (pkg).

    The source file directory structure, generally, models open source code repositories, such as Github. So a typical source directory could look as follows:

        src
            github.com
            settermjd   
            sitepoint
                    hello-world.go

    You can see that under src, I’ve linked to my Github repository, called sitepoint, and in it is one file, hello-world.go.

    I could have multiple repositories, and link to multiple hosts, including Bitbucket and Codebase. By taking this approach, I believe that Go inherently keeps code very well structured and organized.

  9. Interview: Tom Oram and Rob Allen

    This entry is part 2 of 3 in the series Can Great Apps Be Written In PHP?

    In our second interview, we talk to Tom Oram, who works for a small development firm in Wales and Rob Allen, from Nineteen Feet.

    These two developers have a solid wealth of PHP experience and knowledge and have helped me refine my ideas and approaches on many occasions. With that, we’ll start with Tom.

    Tom Oram

    What lead you to PHP?

    A job. I was offered a job using a language I knew nothing about called PHP. It was PHP version 3 at the time, so much less advanced than it is now. Since then, I’ve been using PHP almost every day of my working life.

    What have been the things about PHP that bit you?

    In previous versions I’ve had various things which have caused confusion and frustration, most notably references and object copying in PHP 4.

    However in PHP 5 I don’t really have anything that really catches me out. There are, however, things which I think could be improved or added to make the language easier and more consistent to use.

    What have been the highlights or redeeming features

    I guess the best thing about PHP is the speed in which you can get going. You can have an idea and very quickly try it out while at the same time it’s very well suited to larger and more complex projects as well.

    What are the compelling PHP features for you?

    For me I love interfaces and the fact that static typing is becoming more and more possible while still allowing dynamic typing.

    What do you want to see added to the language?

    • Type hinting for scalar parameter types
    • Type hinting of return values
    • Nested classes

    Why PHP over Ruby, Python, Go, etc?

    Honestly I think they all have their own pros and cons. In many ways I think the other languages are designed better and are more consistent.

    However if you’re used to programming in a statically typed language (especially Java) then PHP might seem easier to relate to than Python or Ruby.

    Do you see yourself moving to another language in the future?

    I use other languages all the time, and if a job is better suited to another language I will use that. However for web-based projects I always reach for PHP first, I currently have no intention of changing that.

    Do you have a custom framework/setup?

  10. Can Great Apps Be Written in PHP – An Interview Series

    This entry is part 1 of 3 in the series Can Great Apps Be Written In PHP?

    I read an old post, circa 2010, on the MailChimp blog a little while ago, about their experience using PHP.

    It struck a chord with me, because the sentiments they shared I’ve felt myself, and heard echoed many times over the years. What are these sentiments, you may ask?

    They’re the ones which infer that PHP, despite all its successes, really isn’t a true programming language. They’re the ones which intimate that, no matter how good you are, no matter what you’ve achieved, if you’re a PHP programmer, well, you’re really not a true developer, yet.

    They’re the ones which suggest, or is that presuppose, that you should really become one of the cool kids developing in Ruby, Python, or Go; basically anything other than PHP. After all, what can you really do with PHP, right?