Hacker News new | comments | show | ask | jobs | submit login
The Bastards Book of Ruby (bastardsbook.com)
227 points by J3L2404 2013 days ago | hide | past | web | 36 comments | favorite

Thanks for who posted this, I'm ashamed to say that it is in need of an update/typo-fixing that hasn't been done yet (as you can tell by the winter seasonal photo).

The main complaint I've heard from people who go through Codecademy/Khan any of the other "easy-to-interactively-learn" options out there is that they don't know what to do with their knowledge of loops/conditionals/variables beyond passing the tests. I wanted something focused on applied tasks, whether it be web scraping/API-fetching or even something as simple as batch concatenating/editing text files.

That's how I myself learned, anyway, so just wanted to point out to other authors the value of simple real-world-data projects as a way to keep readers interested.

This is an excellent initiative. Believe me I know exactly what you are talking about. I have gone over countless numbers of exercises In the past where I put my name and then do some selection statements but beyond that I don't know where to go. Working with APIs can provide a needed sense of practicality. I had few ideas just reading some lines of your first chapter. Keep up the good work.

Your's is a fantastic book. Downloading Wikipedia pages, counting the images on the NYT homepage, reading xml files, all within a few hours represented some extremely good learning.

It's a very refreshing approach to loops and if statements as you say.

This tutorial really got me going with programming. Learning through examples is probably the best way of being motivated while acquiring knowledge.

I've been able to apply this knowledge through a fully functionnal Rails App that scraped 5 job websites.


This looks fantastic. I'm currently writing my first practical Rails app and using APIs for the first time (the Tumblr API specifically). The app works, but I need to move the API calls to a background process and I haven't been able to get that to work yet. Does your book cover background processes?

Also, I wanted to let you know about my detailed and thorough tutorial for installing Xcode, Homebrew, Git, RVM and Ruby on a Mac. I think your readers will find it helpful. It covers a lot of steps that are missing from your instructions. http://moncefbelyamani.com/how-to-install-xcode-homebrew-git...

if you put the book's source in github you can get typo fixes etc as pull requests.

I'm a CIS major about to enter my junior year, I still have the same problem that many of codeacademy's students do. I've done a couple of programming classes (which I aced) and dozens of tutorials but I don't have a clue where to begin when it comes to actually designing a useful program.

So think of something simple but fun and useful that you'd like to put together.

For example...this isn't a "first project" for me but it showed me how something simple, to a coder, could be very popular to others; this list of free museums/attractions and their free hours:


The data-gathering part, I did it in the painful old-fashioned visit-every-webpage fashion...but only because I needed to figure out the domain of the issue.

If I were to do this again, I would start with the list of Facebook pages, throw that into Google Spreadsheets.

Then, I'd write the script that would read the spreadsheet for the Facebook IDs, use the Facebook Graph API to scrape the address/hours/summary info, and from there, move to batch geocoding (the Google Geocoder API exercise) and maybe some simple text-processing to auto-figure out if a museum has listed free hours (i.e. search for the div that contains a day/hours listing and the word "free")

And you could also use the Facebook API to get a list of events from each place, though that varies widely by organization and if they have a social media maintainer.

As you get better at coding, you'll find that the hardest step is the first step, collecting the Facebook ID (or whatever piece of data that you start out with)

You just dive in head first and have to realize that a handful of your early projects will be garbage/useless.

If you've built a program/app in another language, try and rebuild it in the language you're learning or one you've never used before.

I agree with what envex said, but would add that if you don't start doing something withing a few weeks of going through these courses, you'll forget almost everything. As they say "use it or lose it".

Perfect timing for me, I'm helping a friend learn to program (in Ruby) with the goal of using his new found knowledge for data collection/analysis. It's like you wrote the book just for us. :)

This is great, especially the screen-scraping stuff. This will really take me from Ruby beginner and level me up. Where's the donate button?

Although I prefer Python to Ruby, this is a very good online source for people to learn how to program.

Well done.

I don't suppose you have a link to something similar for python with lots of real world examples?

Not really unfortunately.

I've learned Python since the 1.5.x days, mostly on the job and following pydev discussions, so never had the need to look up for such tutorials.

But as I said, I find this one quite good.

For those interested, the Bastard's Book of Ruby is written by Dan Nguyen, a journalist and developer who works at ProPublica (http://www.propublica.org/site/author/dan_nguyen ), and the dude responsible for SOPA Opera (http://projects.propublica.org/sopa/ ).

I'm not sure how many other programming books have come up out of the news apps/NICAR world (the National Institute for Computer Assisted Reporting), but one of the reasons i like the Bastard's Book so much is that it's a really practical bent on learning to program.

Love this quote from the book from the about/why section

Programming languages are more human-friendly.

Early computer languages were optimized for early computers. With today's processors, languages can have far more built-in features that drastically reduce the physical tedium and memorized minutiae needed to write powerful programs. Because programming languages don't need to be as efficient for machines to process, they've become much more efficient for humans to work with.

Thanks, this is the best answer to all the "don't learn to program" arguments.

A really, really good book. My only wish is that there was a Bastards book of PHP. There is no such practical, useful equivalent in the PHP world that I've found—and I've looked.

Maybe I'll ask Dan to write that one next =)

I had said awhile back that I would shoot for a Python version since the code tries to be as Ruby-idiom-free as possible...but I think I need to first focus on moving it to a more painless deploying process, such as github+jekyll...and hopefully make it easy for anyone to port over the lessons/examples in other (high-level) languages

I'd honestly want to help you enable this using http://ruhoh.com. it's jekyll inspired but made to be a lot more streamlined.

The stack is markdown and mustache. This would be a great way for me to see how I need to evolve the ruhoh platform.

Can't honestly say this is the best platform for your book but I am willing to dedicate time to your project to get this done for everyone's benefit. Please contact me and/or point me to the public repo if available. thanks!

Would this help?


Edit: Actually the project looks dead, so I'm not sure you'd want to use it.

I've been planning something along these lines for PHP, but PHP in and of itself has plenty of learning resources. That's not to say they're any good, per se.

The focus thus shifts on to correcting the many mistakes these other learning resources make. That might be poor security (SQL injection, XSS, etc.), use of deprecated functions (mysql_* functions), and maintaining your website as an unholy tangle of intermingled HTML, CSS, JS and PHP. This is what I'm more interested in doing.

I don't personally see much value in writing about much else (like, idiomatic PHP), because the language itself lacks an opinion on what good code and bad code is, or whether it should be procedural or OOP (see DateTime and mysqli for examples where there is an interface for both styles). Trying to establish a 'norm' for these things would be nothing less than Sisyphean in nature.

Compare this to Python and Ruby, where these books flourish because the language itself makes it easier to write about.

Let us know when its done! There's so much junk and old tutorials out there on PHP, it's very hard to know what's right and what's wrong. It's impossible to know where to start.

Starting from practical, useful exercises would be an amazing way to (finally) truly learn PHP.

Back when I was a PHP programmer the "PHP Cookbook" published by O'Reilly was a terrific resource. Unfortunately it looks like that isn't being maintained. Still might be worth picking out of the bargin bin though.

I wouldn't wish PHP on anyone - even a bastard ;)

As someone who is currently trying to learn Ruby, this book is EXACTLY what I need. Oftentimes I burn out reading books where I can't see the direct application of the code I'm learning. THANK YOU!

Great to hear. I definitely need to clean up/supplement the various exercises and chapters but hopefully it gives you some of the basic framework to adapt to other web/data sources that you're interested in. Once you've figured out how to loop through a database/data table/API and save yourself dozens/hundreds of mouse-click-copy-paste operations, you won't need much more incentive to keep coding.

Nice! I haven't read a whole lot of it yet, just the why and FAQ sections, but already it feels unlike your everyday programming book, which I think is refreshing. Also I like the stats next to each of the chapters in the TOC... you seem to be a detailed person.

Just something that caught my eye, being french...

This sentence is not correct: "Je n'ai pas aller au bibliotheque pour manger le fromage."

You should write: "Je ne suis pas allé à la bibliothèque pour manger le fromage."

Which, in case you wonder, means: "I didn't go to the library to eat cheese."

Non-French here, but trying to learn. What's the difference between "manger le fromage" and "manger du fromage"?

non-french speaker here, but i think it's "eat the cheese" vs. "eat cheese / eat some cheese"

Yup, that's it.

This is amazing. Thanks for posting this.

I await the Bastards Book of Haskell with great interest. ;)

Wow, perfect timing, thank you. I just decided to start Michael Hartl's Rails Tutorial, and was looking for something on Ruby because I don't know the language.

I love the practical focus; it's exactly why I want to learn programming. I have a very narrow field, and no one has applied programming + domain knowledge to it.

edit: forgot to add, the design is beautiful. A pleasure to read.

Excellent work! Maybe I overlooked it, but is there a PDF version of this?

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact