Archive for the ‘Beginning Ruby’ Category

Time to embrace Linux

April 23, 2010
"Linux in the Park" by Flickr user John Vetterli

"Linux in the Park" by Flickr user John Vetterli

These days you’re either a Mac or a PC. That means you either use OSX or Windows. Unless you use Linux.

From working beside my programmer friend, I had learnt that most programmers didn’t really do any work in Windows. He would do all his work on a virtual machine, running Linux. However, I had thought that this was due to the apparent disdain that all programmers seem to have for all things Microsoft – not for any real practical reason.

I’d also previously thought that the only people that used Macs for any kind of work, were photographers and architects (Steve Jobs kinda looks like an architect to me…). However, having made a brief trip to Mountain View last Summer, I found that when I went in to a local cafe, everyone there was hacking away on Macs. I’ve since realised that the hacker community – at least that in Silicon Valley/Mountain View – predominantly uses Macs.

So when I was getting started with Ruby, I figured I would just do everything in Windows as that’s what I’m used to. It’s going to be difficult enough learning Ruby, why bother with a new operating system?

However, although it is clearly possible to program in Windows, it does seem like you are the exception rather than the rule. Seems that everything is kinda set up better to work from Linux. I’m not sure I could say exactly why – seems like Windows might have too many proprietary forced Microsoft conventions in there which mess things up a bit. The reason so many hackers use Macs is because it gives you convienient access to Linux. Or something like that. Is OSX kinda a version of Linux?

Anyway, Linux, like ice-cream, comes in different flavours. Truth be told, I had actually occasionally worked on a Linux machine before which used Red Hat to run a microscope I used during my PhD. Whilst Linux is essentially Open Source and free, I think Red Hat is a flavour for enterprise tastebuds and for which you have to pay.

So based on recommendation from a couple of people I chose to run Ubuntu.

First I had to install a virtual machine. Now I have to admit that one of the reasons I initially tried to work from Windows is that I presumed that installing a virtual machine and running Linux would be really difficult. Turns out it’s really easy.

I installed VirtualBox from Sun Microsystems. It was easy to install. Then I downloaded Ubuntu…

Ubuntu

Ubuntu

…I started this post a few months ago and I’ve just come back to it. The point I was going to make is that it’s really difficult for a newbie to use Linux when they are used to Windows. Firstly, I can’t really work out how to install programmes most of the time. Everything seems to be “get” then it magically appears! To be fair I did manage to get a few things installed last time (although it took me about a week to get the Java environment working) but I am now installing the same set-up on my laptop and I can’t remember how to do it. I really do want to just double click on a file to get it to work. :/

iirc I managed  last time by Googling “how to install…” and trying the various guides I found. I would like to install Hackety Hack but first I have to install Shoes and I really can’t remember how to do this. I’ve found some “how to” instructions for Shoes but they seem out of date and don’t work. I think the original website is gone. *Sigh*

/edit I found this guide to installing software on Ubuntu Linux and it turns out it’s really easy. I’d still like to understand what’s going on when you do it from the command line though…

Learning concepts and building dungeons

February 1, 2010
dungeon view

'dungeon view' by Flickr user iscari0t

I’ve just got to the end of Chapter 6 in Beginning Ruby – “Classes, Objects, and Modules”. I’d say the complexity has stepped up a gear and that leads me to question how I learn things – and by learn I really mean ‘remember’.

Let me just say again, that Peter Cooper‘s explanatory style throughout what I have read so far is excellent. He explains things very simply without being patronising and regularly reminds you of simpler point which are related and which were shown in previous chapters.

However, I do think he makes it too easy to go through large sections with many concepts without testing what you have learnt. What I would like to see after every sub-section is some kind of small exercise, with the answers at the back. Alternatively, more small tutorials to explain each individual concept with challenges to modify it to do something slightly different.

I’ve found it too easy to just read through the book and whilst I think I understand most things (okay, ‘most’ is maybe an exaggeration!) I’m never sure whether I’ve actually learnt (remembered) the concept such that I could actually use it in anger, so to speak. In fact I’d go as far as to say I’m pretty sure I haven’t in most cases.

Chapter 6 covers, amongst other things, Local/Instance/Global/Class variables, Encapsulation, Polymorphism, Module, Namespace, Mix-in, Enumerable and Comparable. At the end of Chapter 6 is a little exercise to create a text adventure-style ‘dungeon’. I went through the exercise, and yeah, I made the dungeon, but it’s hard not to when all the code is there for you. What I’m wondering is is this the best way to learn? Should I leave this chapter with the ability to go off and make a dungeon from scratch if I wanted to? I know I couldn’t. Or should I treat it as a having been introduced to these concepts and understanding (most of) them if not remembering them all?

Dungeon Master

This is not at all what Peter Cooper looks like. Peter wears glasses.

Peter does actually set a challenge after the dungeon exercise to make it really interactive. Also, he finishes the chapter by saying he’ll assume I have a knowledge of how classes and objects work, and how the different scopes of variables work. Well… I kinda got it when I read it, but I couldn’t tell it back to you now – I don’t remember!

So, should I stop here and go through Chapter 6 a few more times (and maybe Chapter 4) until I’ve cemented it in my brain and then play around with the dungeon a bit more? If I actually could play around with the dungeon I would really know that I’ve got it all so far. This could take a while though! Worth it? I think I’ve probably answered my own question.

I wish I had a photographic memory!

An alternative way to choose a language

January 31, 2010
Serving tea at the community kitchen at Bardon, October 1942

'Serving tea at the community kitchen at Bardon, October 1942' by Flickr user State Library of Queensland, Australia

Whilst browsing through some Ruby blogs via Delicious (after having just added mine), I happened upon a blog post entitled, “4 Wrong Ways and 1 Awesome Way to Choose a Language“. After having just written my own “How to choose a programming language” blog post I felt confident that this chap would cite “because it sounds sexy” as the awesome way.

Surprisingly, that was not his reason!

In fact, his reason for choosing his language of choice (which is Python, so clearly not chosen because it sounds sexy) is the community. When you’re working in a language with a good community, there is a good chance that whatever you want to do has already been done by someone else and is available for you to re-use. To be honest that is one of the reasons I picked Ruby. If you go with the current trendy language there is bound to be lots of support and resources out there for noobs like myself.

I actually left a comment on his blog mentioning my method of choosing a language and I suddenly got over 100 visits to this blog. Considering I had not had one single visitor before that, I was quite happy with the increase in traffic. Unfortunately, I get the feeling that no one agrees with my sentiment as I did not get a single comment on the post. It’s difficult enough being motivated to write a blog with 0 daily visitors, but when you do get an influx it would be nice if someone left a comment…

… even if only to ridicule me! :p

Over my Head, Part I: Encapsulation

January 30, 2010
encapsulation

'encapsulation' by Flickr user Swiv

Of course I fully expect that over the course of reading Part two of Beginning Ruby there will be frequent “Huh?” moments.

I just had one in Chapter 6 “Classes, Objects , and Modules.

Encapuslation.

Encapsulation is the ability for an object to have certain methods and attributes available for use publicly (from any section of code), but for others to be visible only within the class itself or by other objects of the same class.

Ok, I think maybe typing that out helped me understand the concept but the code examples that followed did not make much sense to me.

I could stick around and try and get it or I could move on. I’ll move on for now. If it’s that important I’m sure I’ll encounter it again and its meaning will become clearer.

N.B. The Flickr pic above is one of the first Creative Commons images I found doing a search for ‘encapsulation’. It’s of St. Andrew’s Cathedral, which is near where I’m from. Hurrah!

Ruby’s Building Blocks

January 28, 2010
Building Blocks

'Building Blocks' by Flickr user Artful Magpie

So I’ve just finished Part 1 of Beginning Ruby – “Foundations and Scaffolding”.

Chapter 1 just tells you how to install Ruby. I already had it installed so I was able to skip most of it. The explanations do look fairly idiot-proof so it would have been at my level if I hadn’t already installed it, when I was messing about with some other idiot-proof guide.

Chapter 2 is explaining some of the basic concepts about Ruby and why these make it a great programming language. As I previously had no concepts about any programming language it was not a hard sell. I buy it – Ruby rocks not only because Ruby is a nice word, it also rocks because of “Object orientation“. Basically everything is an Object, and for reasons that are not yet entirely apparent to me, that rocks more than a very rocky thing.

Other concepts that are explained include Class, Variable and Method. I did actually feel like this chapter laid a pretty good foundation for me, and I “got it” better than when I was reading through the other e-book guide.

Chapter 3 started getting deep. It covers the important building blocks of Ruby. I’ve read this one twice as it’s pretty difficult to get it all first time. The concepts it introduces include: Regular Expressions, Arrays, Hashes, Code Blocks, Ranges and Symbols. Even on a second read I’ve probably only got about 20-30% of that stuff locked in my head, but hopefully it will become reinforced as I go in to Part 2.

In Chapter 4 you build a little text analyser application in to which you can plug any passage of text and it tells you number of words, sentences, ‘interesting sentences’ etc. It’s a nice little exercise but I wonder how much I just copied code like a robot and how much I really learnt from it.

Chapter 5 steps back for a minute and takes some time to explain the history of Ruby and introduces you to some of the ecosystem – blogs and forums that are good resources to learn more about Ruby. I joined up to the Rail Forum, because according to the book it is “particularly friendly to beginners”. I’m going to need friendly….

Tin robot

'Tin robot' by Flickr user Glamhag

If I’ve got one criticism of the book so far, it’s probably that it needs to have some small exercises to do to make sure concepts are actually being understood and remembered. It explains things in such a clear way that it’s a shame I can’t go off and try some immediately related challenge with the answer at the back of the book with an explanation. I’m worried that the code that I have created, such as the analyser, I just did robot-style. I know there are various “Ruby exercise” websites, so I’ll maybe try them later and link to them when I do.

On with Part 2. Apparently by the end of part 2, I’ll be able to “develop Ruby applications complete with complex class and object arrangements of my own; know how to test, document, and deploy them; and use databases and external data sources to feed you applications.” Ummm…. I wouldn’t be so sure… GULP!

How to start learning Ruby

January 24, 2010
YouNoob

'You Noob on a shirt' by Flickr user xrrr

The problem with learning to program from a starting point of knowing nothing about anything, is that you are in a fairly unique position. There aren’t many people who just decide one day to “learn to program”. This makes it pretty difficult to find suitable information about how and where to start.

Sure, if you go off and Google for “how to learn Ruby” you will find loads of websites which will try to help you get started. The problem is that most of these websites are written for people who can already programme a bit. There is no need for them to explain some of the most basic ideas, as their audience already knows them. If you’re already a Python whizzkid, it’s fairly unlikely you’re going to need to be told what a text editor is.

I really had a hard time finding a resource that started from the assumption that the reader knew absolutely nothing.

The first place I tried was an e-book I purchased called “Learn to Program” by Chris Pine. It describes itself as “A Place to Start for the Future Programmer”. Well that sounds like me!

It’s quite a decent read. Chris’ style is nice and light-hearted and he does explain things quite well. However, I did feel that I didn’t really get the basics from reading this e-book. It felt to me a little like it assumed that initial tiny bit of knowledge about programming languages that I was missing. I gave it a go, and worked through the basics but didn’t quite “get it”. It was some of the important concepts like classes that I didn’t seem to pick up in this book.

Yes, that’s right, I needed something that assumed the reader was even dumber.

I found a good thread on Hacker News: Learning to Hack for the very first time. Reading this guy’s situation, he sounded exactly like me. He had zero experience of programming and wanted to learn to “make stuff”.

The suggestions in the thread are really useful. The guy already had a site running on Rails, hence he was going to learn Ruby.

Among the many recommendations, was: Beginning Ruby: From Novice to Professional, 2nd Edition (Expert’s Voice in Open Source)
*. I bought this book and I’ve found it excellent so far. When the author says “novice”, he really means it. The book starts out assuming you know nothing and explains all the necessary concepts so that doofuses like me can get it. Inevitably the learning curve is steep, but it definitely starts at the right level for someone like me. I’m sure it would also be a good book for people who want to learn Ruby and aren’t complete noobs.

So my recommendation if you’re a complete noob like me is to buy that book above and start from there. I’ll talk more about the book as I work through it. I’ve already gone through a few chapters but I’ll try and write a couple of quick posts to catch up.

*that’s an affiliate link. i.e. if you click on it and buy something from Amazon.co.uk I get a few pennies. I actually logged in to my affiliate account for the first time in 4 years to make that link. Turns out I’ve got £4.25 waiting for me. What annoys me about Amazon affiliate scheme is that if I put a link for .co.uk, I wouldn’t earn any money if someone from the US clicked on the link, then decided to buy the book from .com. How daft is that? What’s the point in having a .co.uk affiliate account then?

How to choose a programming language

January 23, 2010

Ruby under lens

I’m pretty sure I always knew that ‘C’ was some kind of programming language. I didn’t really do any computing classes at school other than what was obligatory in the 1st year, but I suspect I must have been told about ‘C’ then. I also had some suspicion that it must, therefore, be really old and hence not used anymore.

When I was working along side a programmer a couple of years ago, he did everything in ‘Perl’. My layman’s interpretation of Perl, was that of a badass language for real hardcore programmers. Wishy-washy rubbish programmers who wanted to make crap insecure code, would use PHP. There is no reason for this anti-PHP stance really, but I can’t get it out of my head. It just sounds too…easy.

I do remember him saying one day, “I really like the sound of this ‘Rubionrails‘”. Of course he was talking about “Ruby on Rails” but I heard it as “Rubionrails” – one word instead of three. (I think this must have been in 2006, when Ruby on Rails was really talking off – I’ve been reading up about Ruby history and how Rails really gave it the mainstream attention).

The name kind of stuck with me. “Ruby on Rails” sounded new, shiny sexy and exciting.

So when it came to choosing a programming language to learn from scratch, it was only natural that I should choose Ruby. To be honest, after some reading around about various languages it seemed to me that Ruby really is the best language for a beginner to learn.

I’ve read that learning Ruby is like learning to play the guitar: it’s easy to pick-up but difficult to master. That’s fine by me. I’m not planning on becoming a master, but good enough to busk would be nice!

So in a nutshell, I chose Ruby to learn because I like the sound of the words “Ruby on Rails”. Wonder if they knew how cool it would sound to noobs like me when they named it?

Learning to programme from scratch

January 12, 2010

I’ve decided to try and learn to programme and I’ve started this blog to track my progress (or lack thereof).

Why is this interesting? Well, I’m 30 years old and I have absolutely no programming experience. I don’t mean I’m a designer who’s dabbled in coding, or I learnt some programming a few years ago and I’m picking it up again – I mean I have *no* experience. Zero.

I’m doing this for a few reasons (that I’ll expand upon in a later post), but one of the reasons is just to see if it’s possible. Most programmers live and breathe programming, and they start early – most start around the age of 13. It’s not the sort of thing you just wake up one morning and decide to do.

I’ll start with a few posts to put this is context – why, how, what have I done so far etc.. Thereafter, my posts will probably be fairly irregular ramblings about what I’ve learnt or what I’m stuck on. Maybe this blog will even become a useful resource for others who are starting from scratch.

On the other hand, what is much more likely is that I’ll drift away from this idea, never learn to programme and this blog will remain an online testimony to my lack of commitment. Only time will tell!