Posts Tagged: programming

Throwing in the towel on becoming a programmer

Man learn Javascript, c. 1900.

Man learn Javascript, c. 1900.

I think ready to hang up my programmer skates. In fact, it seems more likely that I never had skates to begin with. In the past 5-10 years, I’ve attempted to learn to code in virtually all of the major web languages and environments, using all of the latest tools and and classes and tutorials—and I’ve failed miserably every single time.

I just stumbled across Dawn Casey’s omg! I’m a n00b and too afraid to start. It is unbelievably good. Go read it, I’ll wait. Some parts are sad, some parts are laugh-out-loud funny, and I’m sure there are some parts in the middle there that are encouraging to beginners, but I can see right through the whole thing.  The whole ebb and flow from “holy man, I’m completely lost” to “humm…I think I’m starting to finally get this!” is something I know very, very well. I’ve felt this addictive, though ultimately disappointing feeling many times.

We’ll have some fun reliving the agony in a moment, but first a word of background for the folks at home: although I can’t program I can definitely code. The distinction needs to be made there. I’ve been coding for years and have actually gotten pretty good at it. WordPress is my main tool of choice and I’ve gotten quite handy with it — I maintain my own starter theme (a fork / amalgamation of several projects),  I write all of my projects from scratch, I write (modify) all kinds of custom functions to make different parts work, and I generally know the ins and outs of building reasonably complex sites with WordPress. On top of that, I’m extremely comfortable in the command line and I use Git for almost everything I work on. All that is to say that  A) I’m not a beginner, and B) I’m not non-technical. But, as we’ll now learn, I’m absolutely not a programmer.

A Sense of an Endpoint or, The Trouble with Programming

Over the years I have tried to learn all the big players: PHP, Javascript, Ruby, Python, Perl, Java and Objective C. I have failed to learn all of these. It’s almost staggering to even write/realize this. Seven languages. Seven! And I completely and utterly failed at learning all of them. What’s the issue then? After all these years, I think I’ve finally come up with the answer: although the road to starting to learn all of these languages is manageable, they all have a brick wall at the end. Let’s look at the four I spent the most time with:

PHP

PHP is my “best” language, though that’s a dubious honour. It’s the one I’ve been playing with the longest, and the one I’m most comfortable in, given all my time spent with WordPress. PHP is (should be?) a great language to learn with because all of the environment stuff is taken care of for you—just download MAMP, stick some PHP tags into a document and off you go. This is the language I’ve definitely spent the most time with — I’ve done several courses, read several thick books, read literally zillions of tutorials. I’ve gone through lengthy tutorials where I create an object that has a PDO or something to access my fake eCommerce store in my fake database. Things have actually gone fairly well a few times with PHP, in that I’ve gotten fairly far along with the material, but it never lasts long. Pretty soon it’s midnight on a Tuesday and I’m trying to access a query string that was sent via $_POST and I get thinking, “You know? Life is waaaaaay too short for this”.

php-codes

I’m sorry…..what?

So, while starting with PHP is great, going beyond the basics has felt like solving a Rubik’s Cube with my toes. In the end, every single time, I’ve decided that there’s no way I’d ever want to build anything with PHP that I couldn’t already do much faster/easier/better with WordPress. And hence, I’ve given up.

Javascript

This is the real fun one! I’ve spent almost as much time with Javascript as I have with PHP. I started with jQuery (which I can use reasonably capably) and eventually worked backwards into plain Javascript. It’s actually a lot of fun, at first. The thing with Javascript is you have control over when things happen. This control is given to you by funny things called “callbacks”. Essentially, you use a function to call (or “callback”) another function. Let’s say for some reason you wanted to hide every image in on page for 10 seconds on page load. All you need to do is create a timer function that counts for 10 seconds and then call the image loading function as a callback to that. See? Fun!

The not fun part about Javascript is that brick wall I was talking about earlier. After spending a lot of time going through tutorials and courses and reading books and building little projects, I really felt like I was ready to take on the Javascript world. After you’ve got the basics down pat, the logical next step is browsing through the 500 TodoJS apps and spending a month trying to decide which MVC framework will suit you best. After you decide, it will take you another month to try and figure out what an MVC framework even does. I still don’t really know.

So, when people tell you that Javascript is the wave of the future, this is what they’re talking about. If you’re feeling pretty good about all the JS you know, just have a look at this:

js-codes

I’m sorry, ({ what })?

At first I thought, “Hummm, I’m really catching onto this Javascript stuff!” Everything’s an object, callbacks, hell, I even understood what the module pattern was and why it made sense to use it (to avoid this “spaghetti” business people talk about)! But turning all that knowledge into a working Backbone app? That felt like swimming in cement. The funny thing about Javascript is that I still can’t see a way for me bridge those two worlds. I simply can’t see how I can take all these fundamentals that I know about Javascript now, and scaffold it up enough so that something like Backbone even makes sense to me. Despite hours and hours and hours of work, getting to that “next level” with Javascript feels literally impossible.

Python

I don’t have a lot to say about Python, except that I know the promise from xkcd is an empty one. I tried it a few times, and worked through the course at Codecademy, but it never felt very natural. I didn’t spend too long with it, but it never really clicked. On top of that, there’s a constant din of “Python’s not for you, it’s for them ({scientists, academics, hackers, statisticians, someone else})” out there if you look up stuff about Python. The language has always been really appealing for me, but for better or worse it’s never felt like something I should invest my time in. That, combined with the fact that I discovered Ruby meant the end for Python.

Ruby

If you’ve never touched a single language, this is the one for you. It really is beautiful, like so many say. It’s short, concise, fun, productive, and a lot of it really, truly reads like English. Of all the languages, Ruby was by far the most natural and fun. In the months I spent learning Ruby the hard way, I’d run home from work to get back to it. I really loved working on new things in Ruby — they all just made sense so quickly. By the end, I was feeling so happy and comfortable with Ruby that I even tackled some problems in Project Euler with it.

But as I look back at it now, I could have easily used PHP or Javascript for those same problems. I still like the syntax of Ruby better than all the others, but I wasn’t doing anything with Ruby that I couldn’t do with PHP or JS. I’d write a clunky function that did something with x and y and returned some value at the end. Doing it with Ruby was fun, but I wasn’t doing anything beyond playing with the primitives. Well, what’s beyond the privatives you ask? In short: Rails. Just like all the others, Ruby has a brick wall as well. It’s called Rails. The only thing is, Rails isn’t just a brick wall, it’s a brick mountain.

A few years back, I spent about a month getting comfortable with Ruby. It was actually really nice, and as I’ve said, fun. Actual, legitimate fun. After I was happy with where I was with Ruby the language, I started in ernest with Michael Hartl’s famous Rails Tutorial. I probably lasted another 6 weeks after that, but I knew pretty early on that it really wasn’t going to happen for me. In the tutorial, Hartl introduces Ruby, Rails, Git, Heroku, Test Driven Development and just about everything else you can think of, right from the start. By the end of the first month, I had literally no idea what was going on. I’d rake something and then route something else, and then I’d try and migrate up to (or down from) somewhere and absolutely none of it made any sense. By quittin’ time (around week 6) I was 100% convinced that anything I’d end up building with Rails could be build in a fraction of the time in WordPress.

Sure, but what about Sinatra? I actually did a few projects with Sinatra as well, and really liked using it. It felt pretty fun too. Way less behind the scenes magic, and you could actually see what was going on. But what was the point? Rails is still the big endpoint, and playing around with Sinatra really doesn’t get you too far down the road to learning Rails.

A light at the beginning of the tunnel

The whole business of programming is extremely complex. There are so many moving parts to anything these days, and one could easily spend a year just learning the tools available for a given language/environment. Javascript is a perfect example of this—it’s completely and utterly obsessed with tools. Not that these tools aren’t useful, there’s just a million of them.

I’ll end with two excerpts. First, a quote from the omg I’m a noob piece that I mentioned at the top, that sums all of this up nicely for me:

incomprehensible

Second, probably the true impetus for writing this post, is a few lines from David DeSandro‘s ImagesLoaded Javascript plugin. While en route down a winding rabbit hole the other day, I stumbled across this plugin and took a second to look through the code to see if any of it made sense to me. By about line 20, I was actually laughing out loud. I have no clue whatsoever what the code is doing, despite all of my courses and books and hours spent at the screen. Here’s the selection that made me spit coffee onto my keyboard:

desandro-what

Really though, just what is happening here?

It’s not that I’m done trying to learn any of this, or certainly not that I don’t find any of it enjoyable. I suspect that in years to come, I’ll go pick up a fresh copy of Ruby again and spend a month or two using it to figure out some Project Euler problems, but I think that my ambitions to become a programmer have finally extinguished. And I think I’m actually relieved by this.

Here’s to spending more time outside!

Learn to make, don’t learn to code

The agony of learning:

You sign up for Codecademy. You spend 3 months deciding between Python and Ruby, because you heard Django was more powerful or something but Rails had better community support or something. You in fact have no idea what that means. You maybe do a tutorial or two. Oh wait, I should be learning Node.js. It’s the future. Then… hey what’s that shiny thing over there?

Jake Levine

Boy-o-boy does this ever ring true. My experience was precisely like that—learning to code is simply that—learning to code. Until you actually learn to build something, you’ll never get anywhere. I went from Ruby to Python to Javascript back to Ruby back to Javascript—it never ended.

But I remember the moment when some of it finally clicked: I was learning PHP a few years back, I kept falling asleep during the Lynda.com videos, so I bought a book. The book put me to sleep too. I followed tutorials that mostly didn’t work or were outdated, and tried everything else out there to help beat it into my head.

One day, I was trying to dynamically create a menu in WordPress using a query—I had to create a function to get the page id, hand that off to another function to get that page’s children, and then to another to get the last item in an array to determine the page’s ancestors. It was all there—strings, numbers, arrays, functions, passing values around. No doubt it was a Frankenstein of code, but it worked, and did it ever feel good!

Until you actually start making something, you’re just going through the motions—you’re not learning.

On Programming

Programming is much closer to a craft than a science or engineering discipline. It’s a combination of skill and experience expressed through tools. The craftsman chooses specific tools (and sometimes makes their own) and learns to use them to create.

—From John Graham Cumming.

This is the best description of programming that I’ve ever read. It’s never felt like an art or a science to me, and it hasn’t gotten easier with more time, reading, or research. The only modest strides I’ve made in the past few years with becoming a better programmer have involved building actual things, solving actual problems.

My brother, a craftsman — an industrial electrician— spends his days fixing million dollar undersea pumps, huge diesel generators,  and motors of all shapes and sizes. In the past few years, I’ve noticed a trend in how he talks about the things that he works on — he compares them. This pump works like that pump, but has this kind of motor in it, for example. Things like that. Every problem he runs into is thought of in the context of a similar problem that he’s already encountered.

As I’ve learned more and more these past few years about PHP and Javascript, I’m finding myself do the same. I first look at a problem not in terms of exactly how I get started or what steps are involved, but instead I try and find a previous solution to compare it to. I’m sure as time goes on this will become automatic and not conscious, but it’s really become my first step now.

Thinking about this as a craft — a combination of skill and experience — instead of just as a pure you-have-it-or-you-don’t skill has been extremely helpful to me.

(Finally) Learning Ruby on Rails: Month 1

I’m trying to make 2012 the year I finally learn to code. Not HTML/CSS/jQuery, but actual code—you know, if statements, and things like that.

So just a few days after Christmas, I chained myself to my desk and cracked open my worn copy of PHP/MySQL Development and a Lynda.com essential training course, and started in. I don’t think I lasted more than a few hours that first afternoon. Its not that I don’t get PHP, I think I just can’t stand it. I distinctly remember where it all went off the rails. See the screenshot below.

What a complete mess. Sure, I can read it, and for the most part I know what it says, but it does require some mental energy to just process and decode the structure of it. It just isn’t welcoming. My first instinct when I look at code like this is to sigh at the pain of having to mentally organize it before I can figure out what its doing. That’s aside from the fact that all you can really see are < and > signs, question marks, brackets and semicolons.

I’ve known this about PHP for a long time. I’ve struggled with getting beyond the beginner’s stage with it at least a half-dozen times in the past few years. I always get fatigued, normally stop at the same place, and then get too busy  and move on to something else after a few days. I’ve just never been able to find any traction, never been able to really dig in.

Enter Ruby, Again

I say again, because this certainly isn’t my first brush with Ruby either. I’d done a few tutorials and done the magical TryRuby thing, and thought it was really cool. But I’ve gotten hung up on the complexity of Rails more than once. And don’t let anyone tell you it isn’t complex. When you dive into Ruby and Rails you get it all thrown at you at the same time: object oriented programming, an MVC framework, Ruby gems and their dependencies, Rails ‘magic’, etc etc.

It’s quite a lot to get your head around—and until you have at least a tiny, tiny amount of knowledge about each, you’ll never get anywhere. Ruby is 100% object oriented (still figuring that out), Rails lives and breathes MVC (a paradigm I’d never used before), and figuring out gem bundle install errors and dependencies will make you old long before your time. In short: its tough.

But this time, Ruby’s simplicity, elegance and readability was always there, pulling me along the whole time.  Just have a look at this excerpt from a program that fetches and downloads webpages from Wikipedia, from the fantastic Bastards Book of Ruby:

require "open-uri"

remote_base_url = "http://en.wikipedia.org/wiki"
remote_page_name = "Ada_Lovelace"
remote_full_url = remote_base_url + "/" + remote_page_name

puts "Downloading from: " + remote_full_url

remote_data = open(remote_full_url).read

my_local_filename = "my_copy_of-" + remote_page_name + ".html"

puts "Writing to: " + my_local_filename

my_local_file = open(my_local_filename, "w")
my_local_file.write(remote_data)
my_local_file.close

It is long, and probably doesn’t make sense to you, but just try reading it line by line. It basically sets a base url (the base Wikipedia url), adds the name of the page we want to fetch (the entry for Ada Lovelace), downloads the file and then pastes it into a file on our harddrive. Again, its a bit dense, but you can probably get the gist of what its trying to do, even if the syntax doesn’t make sense.

After running through a few more of the tutorials from the Bastards Book of Ruby, I was hooked. The code was readable, none of it seemed impenetrable, and I seemed to be able to write code myself (or at least predict how it was going to be written) fairly quickly—within a day or so. I was far from functional without a tutorial to follow, but I was able to get a basic understanding of what the code was doing, without getting frustrated by the syntax.

It’s about Momentum

After a good, solid Saturday and Sunday running through tutorials and watching screencasts, I was really starting to get interested. That was the strange part for me: in numerous attempts to try and learn PHP, I never once felt that urge to go home and open up a new tutorial. I always had that nagging feeling like it was going to be an onerous, complicated chore. I always ploughed on with a no-pain-no-gain mentality, but I never, ever felt excited about learning—and within a week or so, I’d just give up. With Ruby, I already feel like I have some actual basics to work with now, and more importantly, I’m still excited about learning after four weeks. I actually feel like I have some momentum to keep going with—that mixture of excitement, interest and slow-and-steady accumulation of actual knowledge.

Goals for the first month

My goal for the first month was simple: just watch and read as much as I possibly could.

Instead of learning nuts and bolts, and trying to actually write and memorize a lot of code and syntax, my goal was to just see as much as I could. I hoped that if I kept looking at new material, I’d keep seeing similar things over and over.

This worked out quite well. In the 25+ tutorials and articles I read, for example, almost all of them used loops in some way. After all this reading, I was able to pick out which part was the loop, and really see how it worked and how to write the syntax for it.  Same with if statements (known as part of ‘flow control’). Just reading and re-reading if statements really ingrained them in my head. After the first week or two, when I actually started to write some code of my own, I already felt a bit more comfortable.

Resources from Month 1:

  1. Lynda.com Ruby Essential Training-> got through about 50%
  2. Lynda.com Ruby on Rails Essential Training -> got through about 60%
  3. Bastards Book of Ruby -> Maybe 30% of this, but I also ran through lots of the code samples
  4. Rails Tutorial -> About 50% done, still working on this one
  5. Rails for Zombies -> This one seemed silly, but is actually very, very good
  6. Several short Sinatra tutorials

If I were starting again, I would probably do them in that order. Learn a little bit of Ruby, get totally mind-boggled with the Ruby on Rails Essential Training, go back to Ruby again briefly (it should make much more sense now), then move on to Rails Tutorial. Rails Tutorial is really the gold standard tutorial out there. Its long, detailed and brings you right from start to finish. You do get lost at times, but its the best resource I’ve seen out there to date.

Next Steps

This month, I’m planning to finish the Rails Tutorial (building a Twitter clone), and I plan to actually try and build something simple from scratch. My plan here is to build something like a recipe catalog or an image gallery or something small like that to get the hang of things. My intention is to ‘scaffold’ (auto-generate) half of it and try actually writing the other half. Maybe I’ll scaffold a Users resource, while actually coding a Recipes resource…something like that.

All in all I think month 1 was reasonably successful. I still can’t really code things without guidance in Ruby, and I only really have a loose handle on just the V part of MVC (Views) in Rails, but things are moving along already.

For completeness, here’s a quick inventory of what I do have some idea about in Rails:

  1. I have some clue now about what the whole REST thing is about
  2. Models are where the database parts go
  3. Controllers usually (?) start with a few basic methods: index, new, show, edit, delete
  4. All of these methods have their own template/view files
  5. URLs get setup in the routes file—each method has its own url, and you can manually define your own, including a “root” route or homepage

And that sounds and feels like progress to me! Stay tuned for next month’s update.

On [not] learning to program

Back when I was desperately trying to learn PHP a few years ago, I would have killed for the resources that are all over the web today. If I had had those Stanford classes, Kahn Academy, Code Academy or Think Vitamin, maybe I would have actually learned to program. Instead, I struggled along with out-dated books, rambling, bug-filled tutorials, and complex theoretical discussions on the MySQL documentation forums. In the end, while I learned an incredible amount, I certainly never did learn to program.

I stumbled across yet another incredible resource yesterday: The Bastards Book of Ruby. Written in plain English, the online book takes you through practical programming projects, while teaching you about variables, loops, and objects as you go. In just a few minutes yesterday, I read about how to create a tweet aggregator and how to read from and parse text files. Both were interesting, engaging and useful examples. Somewhere down the road, I can picture myself going back to this book and putting some time into finally learning/playing with Ruby.

 

But (of course), there’s still a huge fly in the ointment: getting this stuff downloaded, installed, compiled and working. I’d venture to say that the target audience for this book is people like me—people who already build websites, people who already code, people who already make stuff using some combination of technology. Like many other people, I make my stuff with WordPress on my local installation of MAMP. The 10+ times in the past when I’ve tried to get Ruby and Rails working on my local machine, I’ve broken MAMP. Subsequent research and forum postings have even advised against using the MAMP copy of MySQL with Ruby. So how are you supposed to run the two? One forum poster told me to run a separate copy of Mac OS in a virtual machine! Sorry, but that’s just a bit too much for me.

In an interview with Fresh Air in 1996, Steve Jobs argued that computer science was something that we should all be exposed to:

In my perspective … science and computer science is a liberal art, it’s something everyone should know how to use, at least, and harness in their life. It’s not something that should be relegated to 5 percent of the population over in the corner. It’s something that everybody should be exposed to and everyone should have mastery of to some extent, and that’s how we viewed computation and these computation devices.

While I couldn’t agree more, I really don’t know how this can become a reality, given the state that technology is in these days. In order to execute a single line of code, you need to download Xcode to be able to download to Homebrew, to be able to download Ruby, Rails, MySQL, rpm, etc etc etc. This really makes the whole Ruby on Rails framework available only to a select few.

The reality is simple: increasingly few of us know how to actually program in an age where we need exponentially more programmers. Computer science enrollment has leveled-off or dropped in the last decade, and we don’t teach kids to program in school anymore. And finally, in my opinion the most crippling issue, when people actually get motivated enough to learn to program in something new and exciting like Ruby on Rails, they’re extremely likely to fail even getting the software installed.

While this abundance of new learning resources is obviously fantastic, I think considerably more attention needs to be payed making it so that we can actually use them. When writing a single line of code involves an hour of downloads, broken installs and late nights trolling through support forums trying to decode error messages, I really don’t think we’ll reach our end goal: teaching more programmers.