Ruby and Language

Languages are a weird thing. You’re born with one, work very hard to become proficient in it – regardless of the dialect – and then utterly forget the hard work that you put into learning it. In high school and college, you’ll start learning a foreign language and, inevitably, complain that it’s too hard. Why? Because you’ve forgotten how hard it was to learn English.

Now, consider programming languages. Even one of the most organic – Ruby – takes a lot of hard work to get down. Even the basics. Let’s assume that you, like me, are trying to learn it as your first programming language. (This is ignoring the fact that I used to work with ActionScript in high school. That was nine years ago and I was never able to use it outside of the one programming class I took.) You’ll go through exercises, and you’ll work very hard at them. You’ll work on problems posited by the exercises and, eventually, after working out that yes- it can be that simple, you’ll work on another tutorial. Because that’s how you – like me – learn: Beat it into your head over and over until it sticks.

So, I’m on – what – tutorial number four now? It’s called Ruby in 100 Minutes. So, I’m going through classes and methods – again – and decide that the program they’re asking me to write is too simple. Why? Because it doesn’t take into account the fact that, in English, if you have the article “a” preceding a word beginning with vowel, it becomes “an.” So, easy peasy, work in a quick check in the class to fix the program so that the does just that and move on.

Nope. What I found was that, for whatever reason, I could not figure out what to do. I knew there was a method that did exactly what I needed, and I knew I could check the first letter of the string (by using [0] and appending it to the argument), but something wasn’t clicking.

It was driving me nuts. Surely I could at least do this. Didn’t matter if I was doing it in a circuitous way, but after minute thirty, I was doing separate if/elsif/else checks for each vowel.

And then I stumbled across the problem at StackOverflow: Ruby does not have a “starts_with?” command. It does, however, have “start_with?” This boggled my mind. Why would they do this? Where was the logic? What madness was this?!

Well, the creator of Ruby had been asked that before and gave some answer that made it seem that he thought having the command be “starts_with?” would imply the second-person, third-perspective, or some such nonsense. I thought about how crazy that was, because in what world does that make sense? (Yes, I know. Recursive argument.) Then I thought about two things: 1) Rails has “starts_with?” (I think), so the point is moot if you’re developing in Rails; 2) This isn’t English. This is Ruby. This is a different language altogether, albeit one that happens to share the same characters as English and, in some instances, similarities with English. It is, to use an analogy, like you’re writing in another Romance language. (Albeit one that doesn’t do that whole ‘artistic thought’ thing and instead opts for pure logic.)

Now, has that helped me learn the language? Kinda. I mean, I don’t suddenly know everything about Ruby, and I acknowledge that it’s going to take a lot more work until I’m proficient in it, but I think knowing that – providing myself with a frame of mind, in other words – is helpful.

Anyway, other than having minor freakouts about still being unemployed after a month of being in Portland, and not getting call backs from temp agencies (ohgodamithatunqualifiedforeverythingohgodohgodohgodohgod), that’s what I’ve been up to.

Oh! Also! The internet works at the house now! I can’t do crap with it on my Mac partition, because the Ralink drivers for my usb dongle are garbage, but still!

The Third

Reddit’s one of those things I’m hesitant to talk about. It’s a lot like WoW, in many ways. It’s supremely nerdy, and there’s a lot of good stuff on the site, but, by the same token, there’s a lot that’d fall quite solidly on the Dark Side of things. For every RedditGifts, there seems to be a horde of schmucks screaming racial epithets and shouting “FREE SPEECH” as an excuse.

But one of the best communities on the site is – for a place like Reddit – relatively small. It’s the classical music community. There, you’ll see links to performance videos, announcements of deals ($9.99 for every Bach harpsichord piece), bits and bobs about composers’ lives (apparently Scriabin was beaucoup loco), and infighting about whether Mozart is overrated. But, up at the top left, where many subreddits have some cheesey version of the Reddit mascot – an alien named Snoo – r/classicalmusic has a scowling Beethoven.

After I was turned down by New Relic – once again, I get why, so no hard feelings – I decided that I would immerse myself in Beethoven. I started by listening to the Moonlight sonata, then moving to the Ninth, then watched a three hour set of BBC docudramas about the composer. I’d love to review those, but this isn’t the place to do so. If you get the chance, though, you should check them out. Like any art, in order to truly appreciate a work, you have to know something about the person. And, while everyone knows that Beethoven was deaf, some of his works – the later pieces, especially – don’t really live until you get some sense of what was happening to the guy at the time.

Watching the docudramas, I could finally express what it was about Beethoven’s music that resonates with me more than, say, Bach – or, into the far-flung future, Shostakovich. It’s the personality of it, the connection with the classic idea of form and function being married to creativity, but the emphasis on blending that with the chaos of human nature. Pushing past traditions to extremes, really.

To me – and this is going back to Orks & Poets – Beethoven, while acknowledging the chaos of humanity – doesn’t fall to the level of letting that chaos envelop him. He fights against it – in “Eroica,” we see the progression from almost capitulating to fate (the Fifth symphony, remember) to triumphing over it. Heroism, the symphony says, is triumphing over chaos and bringing forth humanity.

This is something everyone faces. It’s the constant seesaw, balancing act between failure and success, willing to give up and the drive to not just succeed but triumph. Even in something as astronomically trivial, and being rejected by the company that I really wanted to be a part of, the Third is reflected. Does one give up, collapse in on oneself? Not according to Beethoven.

(To try and avoid doing some armchair analysis of the symphony, check out this video on PBS. Puts it much better than I would.)

So, I thought, what to do? Well, keep plugging away, obviously. However, in doing so, you don’t keep doing the same things. Obviously, the same thing wasn’t optimal, or I would not currently be sitting at Seven Virtues, wondering if these two art fans are going to buy anything from the coffee bar, or just keep pawing at the painting that is right near my head and do people seriously not have conceptions of personal space?

But, no. The leads will be chased. The code boot camps will be applied to. Temp jobs will be done. It may seem melodramatic, but, if there’s one thing that unemployment lends itself to, it’s self-inspection. And, through that lens, the challenge of keeping yourself productively busy is often a near-insurmountable obstacle.

But hey, we march on. To, at least, some sort of resolution.

The Importance of Documentation

Hi!

Busy weekend. Wordstock. Reading. I SHOOK TIMOTHY ZAHN’S HAND.

But I’m not going to talk about that. I’m going to save that for another post, for a time when I’m not prepping for a couple of job interviews. No, today I’m going to talk about a lynchpin of coding:

Documentation.

Specifically – and this is going to be brief – the importance of not just screwing around with variables in hashes and arrays in Ruby. See, I’m refreshing my memory on this thing (and learning some new stuff!) by going through the courses on Codecadamy. I’ve been doing this with JavaScript, but I’ve decided that I like Ruby better. Possibly because it’s my birthstone. I think. (That’s what it is for July, right?)

So, I’m going through the lessons, and one of them – sorting the frequencies of inputted words by using a hash – plays pretty fast and loose with variables. Now, it’s made it clear that variables, at least when you’re slapping them between “| |” are just placeholders. I get that. The tricky thing was that, in this particular lesson, we’re forming a hash out of single keys. In this case, words inputted by a user. So, rather than a multidimensional array (i.e., the sort of thing that would require a key and a value in between the |s), we’re just dealing with single things.

Follow me? Hopefully.

Point is, as I’m going through this, I do what I think is correct, and keep being told that I’ve set the hash up incorrectly. Now, I know that’s not right. I know that because I’ve set the variable – “frequencies” – equal to Hash.new(0), just as it should be. So the hash is correct, damn it. And, as I am wont to do in certain situations, I try it a few more times, hoping that at some point, the machine will realize that it’s wrong and I am right.

Of course, that didn’t happen. What was happening, however, was a bit of miscommunication in the form of documentation. See, the author of the course obviously knows his Ruby. In trying to explain this course, however, he’d skipped over the fact that, when you’re sorting a hash, it becomes an array. (I.e., it assigns a value based on the frequency [in this case] of the appearance of a word. So, in this example, the word ‘the’ appeared twice. So, the multidimensional array became “the” => 2. Of course, this was all set up earlier by splitting up the individual words in the input by way of “words = text.split” and then slapping a method to “words” so that the program tallied every appearance of a word. Anyway.)

So, if I haven’t lost you there (WordPress really needs a footnote function), then what we’re at now is that I’m looking at what is clearly a hash, being told that there is no hash, and then being confused. So, after bashing my face against the metaphorical wall a few times, I went to the Q&A forums, where one guy helpfully suggested thinking of the variables as:

|words, frequency|

instead of

|a, b|

as had been displayed in the lesson.

Perhaps you’re thinking, “Well duh. What else would it be?”

Well, for me, who’s still on his first cup of coffee, trying to remember if any of this was covered in my Ruby on Rails course (it was – just very briefly and in one of those “You won’t have to remember this for the test” ways), that made all the difference.

And, further, it made me realize just how important documentation is. It’s so, so important to remember that other people may be looking at your code, so you have to make sure it’s not in your own bizarre mind-language, whatever that may be. And I also think this goes double for editing manuscripts – moreso when you’re doing it by hand. Really, anything where you’re working with other people.

Documentation: Make it like breathing.