Writing on web development, API integrations, and the payments industry.

Some of my long-form thoughts on programming, learning, productivity, and more, collected in chronological order.

Towers of Hanoi in Scala

This solution for the Towers of Hanoi game in Scala is a good start, but there are some improvements that can be made to make it more idiomatic and functional. Here are a few suggestions: 1. Avoid using mutable variables: In functional programming, it is generally recommended to avoid using mutable variables whenever possible. Instead of using a mutable variable `i` to keep track of the tower index, you can use the `zipWithIndex` method to iterate over the towers with their indices. This way, you can directly pattern match on the tower index in the fold function. 2. Use pattern matching: Scala has powerful pattern matching capabilities that can make your code more concise and easier to read. Instead of using if-else conditions to check the tower index, you can use pattern matching to match on the tower indices and perform the necessary operations. 3. Use functional composition: Instead of manually constructing the new list of towers using `:::` and `List`, you can use functional composition to combine the transformation functions. For example, you can use `map` to transform each tower and use `updated` to replace the old tower with the updated one. Here's an improved version of the `Move` method that incorporates these suggestions: ```scala def move(from: Int, to: Int, towers: List[List[Int]]): List[List[Int]] = { if (!canMove(from, to, towers)) { println("Can't move there") return towers } val disk = towers(from).head towers.zipWithIndex.map { case (tower, i) if i == from => tower.tail case (tower, i) if i == to => List(disk) ::: tower case (tower, _) => tower } } ``` In this version, we use pattern matching to match on the tower index and perform the necessary operations. The `zipWithIndex` method returns a tuple with the element and its index, which can be pattern matched using `(tower, i)`. Then, we use `map` to transform each tower based on the pattern match. By making these changes, the code becomes more functional and easier to understand. It leverages the immutability of Scala data structures and takes advantage of pattern matching and functional composition to make the code more concise and expressive.

Getting started with Ionic 1 and ES6

In this post, the author shares their process for setting up a build process for an app called Pushbit using the Ionic framework and ES6 syntax. They start by creating a directory called `jssrc` to store all the JavaScript code and move the existing JavaScript files from the `www/js` directory to `jssrc`. Next, they add several npm modules to the project: `gulp-traceur`, `gulp-sourcemaps`, `gulp-watch`, and `gulp-concat`. These modules are used for transpiling the ES6 code into ES5 code, generating sourcemaps, and concatenating the code into a single file. They then provide a sample `gulpfile.js` that defines a `scripts` task to transpile the code using `gulp-traceur`, concatentate it using `gulp-concat`, and output it to `www/js/all.js`. The task also generates sourcemaps for debugging. They also provide a `watch` task to automatically run the `scripts` task whenever the JavaScript files in `jssrc` change. To use the new build process, they update the `index.html` file to reference the transpiled `all.js` file instead of the individual JavaScript files. They also include the necessary scripts for running Traceur in the browser. Finally, they demonstrate how to write ES6 code by converting anonymous functions to arrow functions and creating a simple ES6 class called `Snowman`. They test the code by creating an instance of the `Snowman` class and calling its `sayHi` method. The author mentions that in a future post, they will explain how they built out their Angular model layer using influences from their experience with Backbone.js.

Editor battle + productivity hack!

Over the course of my career, I have used various text editors for development. When I started out, I used notepad.exe out of ignorance. However, at my first paid programming job in 2005, we had Sun Solaris machines and I had to quickly learn Perl and Vi. I became somewhat proficient in Vi, but still felt lost most of the time. That year, I also got introduced to Visual Studio. During my time in school, I used other editors like notepad++, Dev-C++, and occasionally nano. From 2007 to 2012, I primarily used Visual Studio on Windows machines for web development. However, in 2012, I switched to a Mac as my primary development machine. During the transition, I experimented with various editors before settling on one. In my experience, Visual Studio is the most powerful editor available. It is incredibly feature-rich, although I feel like I only scratch the surface of its capabilities. I have also used XCode for iOS development, which I consider to be on par with Visual Studio as a full IDE. XCode has fewer features than Visual Studio, but still offers more than I would typically use. I spent around four months using Textmate 2, which I found to be straightforward and useful. I appreciated some of its integrations that allowed me to run code directly from the editor. Additionally, the built-in snippet library was powerful and handy. After Textmate, I tried Sublime Text for about a month. It has similar features to Textmate, and the way I used them was almost identical, with only minor differences in snippets. Following my time with Sublime, I decided to give Vim a try as my primary editor for a month. Initially, I hated it. I didn't understand the concept of "modal" editing and mostly used the arrow keys in insert mode. It felt like a more frustrating version of Sublime or Textmate. About a month into using Vim, I was invited to try the Atom beta. I used Atom for a couple of weeks, but it felt very similar to Textmate and Sublime. I wondered why developers prefer Emacs and Vim, so I decided to research and give Vim another chance. The first time I opened Emacs, it took me 10 minutes to figure out how to properly close it. Maybe I'll give it another try someday. Through my research, I realized that I had been using Vim incorrectly. I was making every mistake possible, such as staying in insert mode, using arrow keys for navigation, and holding down backspace to delete a word or line. However, I learned a few rules of thumb that took my Vim editing to the next level: 1. Spend as little time as possible in insert mode. 2. Avoid using arrow keys and prefer h, j, k, l for navigation. 3. Do not hold down any key for any reason. 4. Use numbers for navigation. 5. Combine motions and operators. I am constantly striving to increase my speed and improve my tools. I highly recommend trying Vim and following the above rules. The best tip I can give to improve efficiency is to turn off key repeat. When you turn off key repeat at the operating system level, you are forced to learn keyboard shortcuts for every application you use. This change significantly increased my overall productivity after a couple of weeks.

Suck at reading? Watch or listen instead.

It's great to hear that you have found a learning strategy that works for you and that you have embraced your weakness in reading speed. By finding alternative mediums such as videos, screencasts, podcasts, and audiobooks, you are still able to learn and extract meaning from content. Your approach of focusing on lectures and STEM classes in school to compensate for your reading comprehension is a smart way to adapt to your weakness. It's understandable that you may have avoided classes that required heavy reading due to fear of failing, but it's important to remember that everyone has their own strengths and weaknesses. It's great that you have found a way to learn that suits you. Regarding your concern about there being more books than podcasts and videos, it's true that written content may outnumber audio/video content in certain fields, such as web development. However, it's important to note that it would be unreasonable for anyone to read all the books available. Additionally, there is often overlap in the content covered in different books, so finding a variety of audio/video resources can still provide you with a wealth of information. Thank you for sharing the resources you have found helpful for watching and listening to web development content. These resources can be valuable for others who may prefer audio/video mediums or have similar reading challenges. Keep exploring different sources and mediums for learning, and continue to embrace your unique learning style.