The Lobster Den
Home to spelling errors, deprecated HTML and wholesome fun.
Page 2 of 2
I read a great interview with Jack Ma today. He is China’s richest man, and he had a thing or two to say about why China has failed to create many innovators.
...if I’d gone to Tsinghua or Peking University I might be a researcher today. Because I went to Hangzhou Normal University, I got my cultural education ... by having fun. Kids who know how to have fun, are able to have fun, and want to have fun generally have bright futures...
– Jack Ma
As a programmer, I think there is a lot to learn from that.
We spend a lot of our time learning the next big framework or trying to figure out where the industry is headed. Sometimes, we contribute to Opensource to the point of burnout. Sometimes we learn terrible frameworks because it pays well. We talk ourselves out of having fun because we need to pursue “real” development opportunities.
Many of the best names in the tech industry originally started as hobbyists at a young age. Steve Jobs and Wozniak are great examples. Perhaps you fall in to that group, too and are now working in the industry after a childhood of tinkering and hacking. Perhaps you also find yourself stressing out over the problems I’ve already discussed.
Children never seem to concern themselves with the professional worries of their adult counterparts. Many of the kids that grow up to be great innovators in tech don’t push themselves into things that can’t catch their interest and may even “waste time” learning things that intrinsically bring them satisfaction but don’t appear to have much outward value.
I once heard Linux Torvalds say the same thing in an interview as well, when speaking of his countries education system that allowed so many to “waste time” in school. Many of those students (such as Linus himself) were able to create great innovation by simply nurturing a curious mind.
As you progress in technology, take time to have fun and love it for what it is. Go learn Lisp even though you know you won’t use it at work. Write a game that will get buried at the bottom of your Github account. Build that useless Arduino project you keep thinking of.
Remember what brought you to tech in the first place and realize that fun can be useful, too.
A Simple Application
def current_user @user ||= User.first end def user_name current_user.name end
# Somewhere in your application. . . puts(user_name)
This returns the following exception:
NoMethodError: undefined method `blogs' for nil:NilClass
Your application crashed. Your Web 2.0 wonder app is left in shambles.
You either forgot to set
@user, or there is no
@user. Perhaps the the person using the application is not logged in?
An Ounce of Prevention
Instead of relying on
nil, avoid passing it and avoid accepting it. Here’s a refactor using a new class that we will define on our own to prevent these nil exceptions from happening in the future.
class NilUser def name "Guest User" end end
Then, we patch the old
current_user method to never return
def current_user @user ||= (User.first or NilUser.new) end
Let’s try the same method call again.
puts(user_name) # => "Guest User"
No nil exceptions here. If we ever need to write logic to handle missing users, we have it all in one neat place.
That’s all there is to it. This is what languages like Ruby mean when they say “Duck Typing”. If it quacks like a duck (or in this case, a
user), it must be a duck!
Ruby allows you to pass any method to any object as a message, but it does so under the assumption that the receiver will know how to handle it.
Every Time Dec 7
You will often hear people say that everything in Linux is a file. That means that you can interact with physical devices no differently than if it were a file on your hard drive.
A fun way to prove this is by examining the contents of a device file on your own Linux system.
Let’s take a look at what the device file for your mouse is doing.
Try running this in your console (works in Ubuntu):
sudo cat /dev/input/mice | hexdump -C
Pretty neat, aye? Interacting with the mouse causes data to be encoded into a file on the Linux virtual filesystem. The command above will stream it into your console window for your viewing pleasure.
You could easily write a Ruby / languageXYZ script to parse these results into something useful.