Category: Industry Thursday

Talking through tech industry news from the week.

Ruby Programming Exercise: Mapping Array Data in Ruby Using Zip and Splat

In this coding exercise, we walk through how to map array data in Ruby, and specifically how we can build a method that takes in an unlimited number of arrays by leveraging the splat operator. Summary Build a method that takes in a set of headers as an array and maps the data from an unlimited number of other arrays to those headers. Exercise File Code File Exercise Description Given the following arrays: headers = [ ‘1B’, ‘2B’, ‘3B’, ‘SS’, ‘C’, ‘P’, ‘LF’, ‘CF’, ‘RF’ ] astros = [ ‘Gurriel’, ‘Altuve’, ‘Bregman’, ‘Correa’, ‘Gattis’, ‘Keuchel’, […]

Guide for Integrating Omniauth in Rails 5 for Facebook Login Feature

In this classroom lecture, I teach how to integrate Facebook authentication into a Ruby on Rails 5 application. Build out the basic application Scaffold a basic application: rails new app_name -T –database=postgresql Create a set of pages Implement devise Setup a Facebook developer account Link to create the account Make sure to list your site URL in the setting’s page, if only in development use something like http://localhost:3000 Integrate Omniauth Add to your Gemfile # Gemfile gem ‘omniauth-facebook’ Update the User Table with the params needed rails g migration AddOmniauthToUsers provider:string uid:string name:string image:text rails […]

Live Coding Lecture: Ruby Debugging + Inject Deep Dive

In this live lecture I lead one of the devCamp classes in how to perform debugging in Ruby with the byebug gem and also go through a detailed examination of how Ruby’s Inject method works.

Comprehensive List of HTML Style Tags

This guide is an excerpt from devCamp’s new HTML/CSS Bootcamp course. In this guide we are going to review the comprehensive list of HTML style tags. Comprehensive List of HTML Style Tags Mark Style The first style is going to be the marked text tag, you can use this tag to highlight a particular word, phrase or value. The tag for this style will be <mark>. <ul> <li>The <mark>marked</mark> text tag</li> </ul> Small Style The next style is the small text tag, <small>, this style will make a particular word smaller in size. <li>The <small>small</small> […]

The Problem with Procrastination for Developers

Libraries could be filled to overflowing with books filled on procrastination. Through my life and career I have gone through self help books that attempt to explain why people procrastinate along with supplying strategies to help curb procrastination. And as great as all of those books are, no one has been able to describe the true problem with procrastination better in my mind than Steven Pressfield in his book The War of Art. The Problem with Procrastination In his book Pressfield compares procrastination with being an alcoholic. If you’re like me when I first heard this comparison I was […]

Development Study Tips: Reverse Note Taking

In this guide we’re going to go back in time and walk through when I developed the system of reverse note taking. A quick Google search will show that I have coined the term, however I did not invent the process. Back when I started computer science grad school at Texas Tech I was struggling with one of my classes. It had been about a decade since I had been in a classroom environment and I was having a difficult time paying attention to the 1.5 hour lectures. The Problem with Traditional Note Taking During this […]

Learn How to Code: Guide to Memorization

During a recent bootcamp teaching session where I was walking through a number of front end development techniques, a student asked a great question. Referencing the CSS styles, she asked: “What is the best way to remember all of the specific style names and properties?” This is a vital question to answer, especially for new students. For example, if you look at the CSS documentation you’ll find thousands of potential style options. If you’re learning these styles for the first time that list can be pretty intimidating. And that doesn’t even bring in the idea of […]

Should I Comment My Code? The Case Against Code Comments

A question asked by aspiring and experienced developers alike is: should I comment my code? This discussion typically stirs up a lively debate with developers. However I don’t think the question has a right or wrong answer. Instead I think the answer is: it depends.

In this guide I want to take a practical look at when code comments can be beneficial along with when comments cause issues.

Should I Comment My Code?

When code comments go bad

I remember back when I learned how to code. A common theme I heard was that all of my code should be commented. This seemed like a good idea at first. And in a perfect world comments would be beneficial. However we do not live in a perfect world.

Let’s jump into a time machine and look back at how I might have commented a method years ago.

should I comment my code

If you run this code you’ll see that it all works properly.

should I comment my code

So what’s the problem?

Since the one constant rule of software development is that requirements change, let’s imagine that our program needs to be updated to also print out the player’s position.

should I comment my code

In this code I’ve updated the method so that it takes in a key/value hash and prints out the player, lineup number, and position. This works properly when I pass in a hash argument.

should I comment my code

But did you notice something? I didn’t update my comments and the instructions still are calling for an array. If I need to work with the method in the future and I reference my comments and pass in an array, the program no longer works properly.

should I comment my code

So what’s the main problem with code comments? The issue comes down to the fact that they are fragile and can’t be trusted. Comments, by their nature, are static. This means that you could completely change the behavior of a method, and if you don’t update the comments they will be rendered useless.

When I take on a legacy application and look at the comments it’s rare that they’re still applicable to the current system.

Code that Explains Itself

Through the years I’ve slowly stopped commenting my behavior based code, such as classes or methods. Instead I’ve focused on improving the names that I give parts of my programs. I’ve discovered that if I name a code component properly, comments are no longer needed.

David Heinemeier Hansson, the creator of the Rails framework, had this to say about the importance of naming:

“One of the real delights of programming is picking great variable, method, and class names. But an even greater treat is when you can name pairs, or even whole narratives, that fit just right.”

In this guide he gives a great narrative on a specific time he was intentional in regard to naming a method.

When Code Comments are Beneficial

With all of the bashing that I’ve done in regard to code comments, you may be wondering: is there ever a time when commenting is beneficial? The answer is: yes.

I don’t like add comments to code in order to explain functionality, because behavior constantly changes. However I have found two ways to incorporate comments that have proven to be helpful.

Code Organization

First and foremost, I will utilize code comments for code organization. I have discovered that comments can be helpful for large code files such as CSS style files. I’ll add comments such as: /* Nav header styles */. These types of comments let me quickly know where a specific set of styles can be found. And because these types of comments don’t give instructions or describe behavior, they’re far less likely to get outdated.

Automated Comments

Next I’ve discovered that automated comments can be helpful for reference purposes. For example, the Annotate Ruby gem will automatically create and update comments in code files that supply database information. When I work on a Rails application I’m constantly referencing the database schema file to ensure I’m selecting the correct column names. The Annotate gem automates this process by commenting model files with the table information.

When it comes to working with code comments, automated tools that will also update the comments can be beneficial to a developer’s workflow.

Should I Comment My Code Summary

In summary, code comments can lead to a number of negative issues for programs. Comments are fragile, can be misleading, and perform a poor job of explaining application behavior. A better choice is to improve at method naming, so that your code explains itself.

After publishing this guide, developer Kiss György pointed out a great quote from Robert ‘Uncle Bob’ Martin who said:

“Every comment you write is a failure to express yourself well in code.”

Causation vs Correlation for Data Scientists

When it comes to learning about data science there are countless factors that come into play. As data scientists (or developers) it’s vital to have a clear understanding of skills such as cleaning data ranging to mathematical algorithms. However one factor that has a tendency to be overlooked is the concept of causation vs correlation. A Causation vs Correlation Example How many times have you seen “studies” that claim to have discovered that some type of behavior is the cause of another type of result. Take going to the gym as an example. You may hear […]

Developer Soft Skills – Learn How to Gain an Edge in the Marketplace

I talk quite a bit about improving as a developer. Most of the time I focus on how you can learn new technical skills, such as becoming more proficient in a programming language or framework. However if you limit your knowledge to technical talent you will be decreasing your chances for success in the marketplace. In this guide I’m going to walk through five key developer soft skills that you can utilize to become a well rounded coder. Developer Soft Skills This list is by no means comprehensive. Instead it represents the skills that I’ve personally used and […]

By Daniele Zedda • 18 February


By Daniele Zedda • 18 February

Share on