The Many Constructors of Dart

Last night, as I was writing code in a Flutter app, I came across an interesting dilemma. I wanted to throw a custom exception if I was unable to sign in with Apple on the login screen — nothing too crazy. Naturally, this lead me to creating a custom exception. I tried something along the lines of: class PlatformException extends Exception {} // ^ does not work! However, I found out quickly that this wasn’t valid. In fact, you get an error that looks like this: The generative constructor 'Exception Exception([dynamic message])' expected, but factory found - line 1. This...

Flutter routing inside of the Scaffold

If you’re coming from React Native to Flutter, one of the first things you’ll likely ask is “How do I do routing?” First, I’d ask you to consider if you actually need routing. Instead, could you just have a global state that determines which screen to show? In most cases, probably. But if you want things to feel right when building Flutter for Web (or want decent deep linking support), you’ll probably want to build your flutter app with routing. Routing can easily be accomplished via the MaterialApp widget in Flutter. In fact, the MaterialApp has a routes property for...

TypeScript Tuples

TypeScript offers a plethora of types for developers to leverage, but some of the types may be ones that you’re unfamiliar with. Take the tuple, for example. JavaScript doesn’t have a concept of tuples, so figuring out how and when to use one might feel tricky. Thankfully, Tuples are pretty simple and are used by popular frameworks, like React. What is a tuple? Tuples allow you to express an array with a fixed number of elements of which each element may be of a different type. For example, an array of two elements where the first is a string and...

Arrow Functions in PHP 7.4+

PHP is finally getting arrow functions (also known as Short Closures)! I know, I know. I’m just as excited as you are. Here’s everything you need to know about arrow functions in PHP. First, arrow functions are an approved RFC for PHP 7.4. If you’re using a version of PHP that’s lower than 7.4, you won’t be able to use arrow functions. Second, arrow functions can only contain one single expression. The goal with arrow functions (as stated in the RFC) is to help reduce verbosity and multi-line arrow functions are likely to cause more confusion than classic anonymous functions....

Building a simple URL Shortener in PHP with Laravel

I’ve recorded a quick Youtube video for you! In this video, we walk through building a simple URL shortener (think bit.ly) in PHP with the Laravel framework. This originally started as part of my Laravel foundations course (link coming soon) but I felt that we could quickly get through an example on Youtube, too. In the course, we dive into things and go a bit slower to really get a grasp on how everything works, but this less than 30 minute video should get you started down the right path. If you want to continue building upon this (and adding...

How to read from a file in PHP

Reading from a file in PHP is an extremely common problem to solve. You may keep configuration variables in an environment file, or perhaps you pull in HTML from another file. Either way, you need your PHP code to read the contents of those files. Good news: It’s actually a fairly simple task to perform! What’s interesting is that there’s actually quite a few ways to read from a file in PHP. We’ll cover two common cases here and talk about why you’d use one over the other. Heads up: If performance is a concern, you’ll want to read through...

What is Laravel’s Homestead?

Laravel is, as far as PHP frameworks go, extremely popular. In their guide, the Laravel community recommends you use Homestead as your local development environment. But what is Laravel’s homestead and why use it? Laravel’s Homestead Homestead is Laravel’s suggested development environment for building Laravel applications in PHP. Homestead is packaged as a vagrant box (a virtual machine) and is aimed to simply the initial setup of your Laravel project. Why use Homestead? Laravel actually has a fairly specific set of requirements that need to be met if you are to develop for it. Homestead bundles all of these requirements...