Me

Derek Morey

2022-11-02 #programming-language-design

Programming Language Design: Private Scopes


Current mainstream programming languages don't provide means of grouping code within a single function or method. Often, a function can end up being quite long even when its only doing a single task. The task itself can be complex requiring several steps and calculations but still logically be a single task. Traditional wisdom states that long functions should be broken up into separate smaller functions, but this scatters logic and becomes hard to follow. We need a facility for grouping and encapsulating code within a function. It should group logic together and be easy to comprehend.

Continue Reading...
2021-05-22 #code-style

Return Early From Functions


In general, I find it preferable to return early from functions whenever possible. What I mean by this is that the code in a function should try to fail as soon as possible and exit the function. The first thing the code should do is check whether or not its possible to continue.

Continue Reading...
2019-04-01 #python #javascript #lodash

Emulating Python's groupby with Lodash


I recently had to move a calculation I was doing on the back-end in Python to the front-end in JavaScript. The calculation involved grouping a list of items based on a property of each item. I needed to iterate over a list, creating a new group of items whenever a specific property on the item changed. The itertools.groupby function in Python's standard library behaved pretty much like I expected it to and gave me the result I needed. After some messing around, I was able get the result I wanted by manipulating the output of groupby with the list comprehension below.

Continue Reading...
2017-12-19 #code-style

Assigning Boolean Expressions to Variables


This is just a design pattern I wanted to share. It makes complicated if/else blocks more readable in my opinion. When writing a conditional you can sometimes end up with several expressions that are being tested. It can look something like this:

Continue Reading...
2017-04-06 #code-style

Functional vs Imperative Programming


A while back I wrote a small JavaScript program that compared the difference between functional and imperative programming styles. I figured it might make an interesting blog post so here it is.

Continue Reading...
2017-03-06 #diy

Cardboard Laptop Stand


This is a laptop stand I made completeley out of carboard. I wanted something to raise my laptop up and I had a bunch of boxes laying around so I decided to see what I could make with them. It turned out pretty well given the materials.

Continue Reading...
2017-01-27 #linux #shell-scripting #bash

Linux Backup Script


Here is the script I use to backup my home directory. Its a simple bash script that uses tar and gzip to archive and compress the files. I run it every few weeks and backup my data to another hard drive in my computer.

Continue Reading...
2016-12-20 #tutorial #javascript

Recursive Descent Parsers


In this tutorial we are going to implement a small programming language using the top-down recursive descent method of parsing. Recursive descent parsing utilizes a set of mutually recursive functions to do the parsing. Each function handles a different production rule in the language's grammar. This makes implementing the parser relatively straightforward as the parser code closely resembles the grammar.

Continue Reading...