Posts

Exceptional Exception Handlers

Image
As a budding developer, I quickly discovered that there's nothing quite as satisfying as debugging a frustrating error after hacking away at it for what seems to be an eternity. But sometimes error messages aren't very clear and it can make the debugging process especially difficult. Enter exception handlers ! Before we dive into just what an exception handler is and does, we need to take a look at a key question - what is an error and how are errors raised?  In Ruby, an error is an instance of the predefined class Exception  that is raised (or thrown) when something has gone wrong. By default, Ruby programs terminate when an exception occurs, unless you have an exception handler  - a block of code that is executed when an exception occurs. To handle exceptions, we can enclose the code that could throw an exception in a begin-end block and use one or more rescue clauses to tell Ruby the types of exceptions to handle. Note that the body of a method d

Drag and Drop It Like It's Hot

Image
The ability to drag and drop items and elements was first created by Jef Raskin, best known for starting the Macintosh project for Apple in the 1970's. Originally named the "click-and-drag" paradigm, drag and drop is a cornerstone of the user experience when interfacing with computers and smartphones. I recently discovered how to implement this fundamental aspect of designing and developing a program, using Atlassian's React Beautiful DnD Library . This library helps to simplify and more importantly, beautiful and naturalize the movement of items within an app. There are three main parts to keep in mind when designing a drag and drop feature: 1. The Draggable component, which is the item that will actually be dropped. 2. The Droppable component, which contains the Draggable components. 3. The DragDropContext component where the other components live. To test and see how to utilize the tools provided by the library in a project I'm working on, I went

Websites that Run on Magic and Wizardry, aka Ruby on Rails

Image
As a novice programmer, being introduced to Ruby on Rails (Rails for short), a Ruby-based web application framework, brought me into a whole new world with seemingly limitless possibilities. Created by David Heinemeier Hansson, Rails was brought to into this world with the goal of helping programmers become more productive, and happy . Rails places heavy emphasis "Convention over Configuration", meaning that programmers only have to specify and code out non-standard parts of a program. With Rails, beginner programmers like myself to build large, complex applications. To demonstrate how large, we'll look at 10 tech giants that were built using Rails: Connecting travellers with hosts looking to rent their house space to others, Airbnb has over 3 million listings in 190+ countries and provides services to over 200M people worldwide. CrunchBase serves as the Wikipedia of startups, and is the ultimate go-to website to see which companies are investing the co

Would you like an extra end with that? Curly Braces vs. Do End Blocks

Image
As a new programmer, I developed (get it?) a quick growing affinity towards using curly braces {} in my code, because I just simply find it cleaner to read, and when it comes to coding, I am Mr. Clean. Plus, who really likes seeing 10 ends in a block of code? And if they both function the same way, why not use the one that's more pleasing to the eye? Well, actually, they are in fact not the same, as I have learned. Here's how it works: Let's say we want to iterate through an array of numbers [1, 2, 3, 4, 5, 6, 7] and return a new array of numbers divisible by 3, we could write the method out in two ways. First, the curly braces (clean) way: And then the do..end (ugly) way: Again, both yield the same result here, but there is a difference. With the curly braces, the block in the braces are passed to the rightmost method, while with the do end block, the code within the block is passed to the leftmost method. You'll see that given the following example, th