Payton.Codes

Musings on life, games, and code

Tag: coding

  • Record Objects to the Rescue

    Record Objects to the Rescue

    Very often, I need to return multiple values from a function in PHP. Maybe I need three different dates or an integer and a string. Perhaps the most common scenario is when returning data from a database query. In each of these situations I have to decide the best way to encapsulate those values. Mostly,…

  • Good coding practices

    Good coding practices

    I recently had to give a talk on “Good coding practices” for some new developers at Automattic. At first I had no idea how to summarize such a vast and dynamic topic, but as I was working on a plan I started to see some ideas come up over and over again and I decided…

  • Writing a diff/PR description to get better reviews

    Writing a diff/PR description to get better reviews

    During a recent work meetup, we had an impromptu exercise where we went over what makes a GitHub PR description most useful to the people reviewing it, particularly when not everyone is working on the same part of the codebase. Better descriptions make for faster reviews! This is my attempt to turn that discussion into…

  • grepdef: a quick way to search for definitions in code

    grepdef: a quick way to search for definitions in code

    I live inside my code editor all day and something that I need to do pretty often is to search for the definition of a symbol (a variable, constant, or function). For example, I might be debugging a problem in a JavaScript file when I come across this code: I need to see translateDataFromRaw to…

  • What I learned writing a game engine

    What I learned writing a game engine

    One of the things I did on my recent sabbatical was to start coding a video game in JavaScript. I learned a lot in the process, and I thought I’d write down some of my experiences. (For the record, while I wrote the game engine myself, I used the excellent Pixi library for graphics.) Classes…

  • Await, there’s more!

    Await, there’s more!

    This week I gave a talk at my local JavaScript meetup on the history, use, and future of Promises and I thought that you, dear reader, might be interested as well. Here’s the blurb: JavaScript is an asynchronous language; it is designed to react to events and to trigger jobs that take an unknown amount…

  • Alternatives to Else

    Alternatives to Else

    One of the first imperative programming concepts I ever learned was if/else. With this relatively simple power tool I could make decisions in my code based on any number of factors. Of course, my early programs were… a little hard to read. I hadn’t yet learned one of the maxims of programming that I try…

  • How do we deal with dependencies in PHP

    How do we deal with dependencies in PHP

    Generally what we want to do when we’re coding something is to call a function. While some of the functions we call could stand alone and some could be methods on an object, they’re all just function calls. So why does most PHP code have so many classes? I don’t think code organization is a…

  • Safely coding with constants

    Safely coding with constants

    In PHP there is a tendency to assume that the code we are working on is the only code that is running. The global and transactional nature of the language’s past has made this easy to do. This tendency naturally leads us to use global state, and while there does seem to be a resistance…

  • Creating Sniffs for a PHPCS Standard

    Creating Sniffs for a PHPCS Standard

    As a follow-up to my summary of using phpcs to lint your PHP code, this post will explain how to create, modify, and test a phpcs standard. As a quick refresher, phpcs organizes its linting messages (warnings and errors) into “sniffs”, then into “categories”, then into a “standard”. The official tutorial for creating a standard…