JavaScript: The Good Parts

July 18, 2010

I’ve been a huge fan of Douglas Crockford and his articles about JavaScript for a long time. I often point people to his The World’s Most Misunderstood Programming Language article when I hear them complaining about the language. It’s taken me a couple of years to get around to reading his book, JavaScript: The Good Parts, but it exceeded all of my expectations.

Being an avid reader of his online stuff, and having watched various talks of his I knew the book would be well written and informative, but I thought it’d probably just repeat much of what I’d already read, without providing much new information or insights. To a certain extent this was true, the book does reiterate what’s said in many of his online articles and talks, but the book is absolutely amazing for a different reason: The code examples.

The book is extremely succinct. There’s no padding, and very little dialog to join one section to the next. There is a common thread thoughout the book though, and that’s the code. Examples of good coding practices are repeated, and functions written in earlier chapters are often reused in later ones. So although the book appears to be presenting one feature at a time with a small code example you’re actually building up more and more complex javascript applications, and the book ends with a full JSON parser!

Crockford’s coding style seems to match his writing style: succinct and to the point. There’s some really great code in the book, that I think even non-JavaScript developers could appreciate. Here’s my favourite, from the chapter on regular expressions:

var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
var url = 'http://www.ora.com:80/goodparts?q#fragment';
 
var result = parse_url.exec(url);
var names = ['url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'];
var blanks = '       ';
var i;
for (i = 0; i < names.length; i += 1) {
    document.writeln(names[i] + ':' + blanks.substring(names[i].length), result[i]);
}

Which outputs:

url:    http://www.ora.com:80/goodparts?q#fragment
scheme: http
slash:  //
host:   www.ora.com
port:   80
path:   goodparts
query:  q
hash:   fragment

I also love the explanations Crockford gives as to why he avoids using certain parts of JavaScript, and limits himself to a “good” subset of the language. He doesn’t simply say “This is bad and you shouldn’t use it”, it’s usually accompanied by a story about a time when Crockford had used that feature and got caught out, which is much more compelling.

I think it’s fair to say that JavaScript: The Good Parts is one of my favourite programming books: It’s succinct, packed full of great code examples and best practices for writing maintainable and bug free code. It’s a fantastic JavaScript reference, but much of what the book talks about is relevant to programming in general. Highly recommended!

Rework Roundup

May 3, 2010

ReWork Cover

37signals are the creators of the popular Ruby on Rails web framework and the people behind successful web applications such as basecamp and campfire. Their previous book Getting Real, about effecitive web application development, really resonated with me.

When I heard that they were writing a new book, ReWork: Change the Way You Work Forever, about “building, running and growing (or not growing) a business” the 37 signals way, I was excited. Especially as it arrived at a time when I’m working on my own startup.

A week has passed since my copy arrived from Amazon, so I’ve had a change to read the book and write up some of my favourite points below.

Planning is guessing

“Working without a plan may seem scary. But blindly following a plan that has no relationship to reality is even scarier”

Don’t make long term plans, or at least don’t obsess over them if you do. I think the key point here is be flexible.

Start making something

“Ideas are cheap and plentiful…the real question is how well you execute.”

Coming up with cool ideas all day won’t get you anywhere. Starting something will. Even if it’s lame, you’ll learn something that’ll make the next attempt better.

Build half a product, not a half-assed product.

“Getting to great starts by chopping out what’s merely good.”

The classic 37 signals do less argument, about less being better, and bloat being bad.

Launch now

“Stop imagining what’s going to work. Find out for real.”

I’m also reminded of the Reid Hoffman principle here:

“If you aren’t embarrassed by what you launch with, you waited too long to launch.”

Good enough is fine

“When good enough get the job done, go for it. It’s way better than wasting resources or, even worse, doing nothing because you can’t afford the complex solution.”

I think the above rule is really a specific version of this one. Get something basic done first – worry about making it great later!

Pick a fight

“Having an enemy gives you a great story to tell customers…They take sides. Passions are ignited.”

This is certainly an approach that 37 Signals employ, and it seems to have worked well for them. OnStartups have a good article on the power of polarization which goes into more detail about this idea.

Don’t confuse enthusiam with priority

“The enthusiasm you have for a new idea is not an accurate indicator of its true worth. What seems like a sure-fire hit right now often gets downgraded to “nice to have” by morning.”

Don’t drop everything to start on your latest idea. You’ll constantly be chasing new ideas, and never finish any of your old ones which might be just as good, if not better.

Take a deep breath

“When people complain, let things simmer for a while. Let them know you’re listening…but explain that you’re going to let it go for a while and see what happens. You’ll probbaly find that people will adjust eventually.”

Every time Facebook change their privacy settings there is a huge uproar. When websites change their design you hear complaints. Changes aren’t always for the best, but there are some people complain no matter what. The advice given here is to wait a while for things to settle down before making any decisions based on the feedback.

Four-letter words

“Need, must, can’t, easy, just, only and fast. There words get in the way of healthy communication. They are red flags that introduce animosity, torpedo good discussions, and cause projects to be late.”

This is one of my favourite points in the book. I’ll certainly be making an effort to avoid these assumption-ridden words in the future!

Inspiration is perishable

“Inspiration is a magical thing, a productivity multiplier, a motivator. But it won’t wait for you. Inspiration is a now thing. If it grabs you, grab it right back and put it to work.”

So true. A great reason why you should start making something the second you feel inspired to do so.

They were my favourite points, but the book is filled with many more. If you’ve also read the book I’d love to know what you though and what your favourite parts were, either in the comments section or on twitter.

Recommended reading from Coders at Work

January 24, 2010

I really enjoyed reading Peter Siebel’s Coders at Work, in which he interviews many prominent developers including Donald Knuth, Ken Thompson and Peter Norvig. A question that gets asked to the majority of the developers is what programming books do they recommend. I’ve complied some of their suggestions into the following list:

The Art of Computer Programming
TAOCP is mentioned throughout Coders at Work. Some of the developers had read it all the way through, and really got stuck into the maths. Others, such as Doug Crockford had only used the book as a reference. Almost everybody agreed that this book should be on your shelf though.

Programming Pearls
A book about good programming practice with examples in C, this classic has stood the test of time.

Beautiful Code
The tagline for this book is “Leading Programmers Explain How They Think”. The book contains lots of example code, and descriptions and commentary from the code’s author. While this book is only recommended once in Coders at Work, almost all of the interviewees stress the importance of reading code, and this book can help with that.

Structure and Interpretation of Computer Programs
SICP is recommended several times in the book. It’s supposed to be a very in depth book, it looks at programming from a functional perspective, using Scheme. Zawinski says despite being “Lispy”, it provides a great introduction to programming without teaching a language.

Purely Functional Data Structures
Describes data structures from a functional programming point of view, rather than the more common imperative perspective (such as Java and C++ data structure books).

Higher Order Perl
Brad Fitzpatrick recommends this book, which is about functional programming techniques in Perl. The reviews on Amazon seem to suggest this this is an excellent programming book, and should even be interesting for non-Perl developers.

Code Complete
Jamie Zawinski describes this as “the book you wish your idiot coworker had read”. It goes through the whole development lifecyle, including design, desbugging, testing and refactoring.

The Practice of Programming
Co-authored by one of the creators of the C programming language, this book aims to teach you good programming practices to help you write faster and more maintainable code.

The list above is just a sample of some of the books recommended in Coders at Work. The Joshua Block interview also mentions lots of interesting Computer Science papers.

The interviews are really great. Most aren’t particularly technical, but it is interesting to read about how these well-known programmers work, and to get some insight into some of the projects they’ve worked on. Coders at Work is well worth a read.

25 Free Computer Science Books

December 20, 2008

As a computer scientist I’m always looking to improve my knowledge of the subject. There are lots of great sources of information available online, but nothing really beats the depth of knowledge that you can find in a book. It is possible to get the best of both worlds though, as many books are now available online in full, and free of charge!

Below is a selection of 25 of the best free computer science books that I’ve found online, with a brief description of each one. Where the book is also available in printed form I’ve included a link to Amazon, using my affiliate link. If you’d like to buy one of the books but would rather not help towards the cost of running this blog then you can search for the books directly on the Amazon site.

Become An X coder
A guide to MacOSX development with Cocoa using Objective-C. The book contains lots of examples and detailed screenshots.

The Cathedral and the Bazaar
Eric Raymond’s brilliant book about Open Source software, and its impact on software development projects.
View on Amazon

Data Structures and Algorithms with Object-Oriented Design Patterns in Java
Also available in C#, Python, Perl, Ruby, Lua, C++ and PHP versions.
View on Amazon

Dive Into Accessibility
Another Mark Pilgrim guide, on creating accessible websites.

Dive Into Greasemonkey
Greasemonkey is a Firefox extension that allows you to write scripts that alter the web pages you visit. Mark Pilgrim presents lots of example code and case studies in this book.

Getting Real
The influential book from 37 Signals which describes a smaller, faster, and better way to build web based software.

Getting Started with awk
Awk is the perfect tool for many system admin tasks. This book contains loads of great examples, and will turn you into an awk master in no time!

Git Magic
A complete guide to the popular distributed version control software Git, from Linus Torvolds.

GPU Gems
NVidia’s book on GPU graphics programming covers topics such as lighting, shadows, modelling materials, and performance issues.
View on Amazon

How to Design Programs
An introduction to computer programming and designing programs with the Scheme programming language.
View on Amazon

Introduction to Design Patterns in
C++ with Qt 4

From the book itself: C++ is taught “The Qt way”, with an emphasis on design patterns, and re-use of open source libraries and tools. By the end of the book, the reader should have a deep understanding of both the language and libraries, as well the design patterns used in developing software with them.
View on Amazon

Learn You a Haskell for Great Good!
A funny title, but a serious book about the purely functional programming language Haskell.

Linux Device Drivers
An O’Reilly guide on how Linux device drivers work, and developing your own.
View on Amazon


Linux Network Administrator’s Guide
An O’Reilly guide to to network administration on Linux, covering topics such as configuration, firewalls, and DNS.
View on Amazon


Logic, Programming and Prolog (PDF)
Broken up into three parts: Foundations, Programming in Logic, and Alternative Logic Programming Schemes. This books covers both the theory and practice of logic programming with Prolog in detail.
View on Amazon

The OpenGL Programming Guide
Also known as “The Red Book”, this guide tells you all you need to know about the 3D graphics programming library.
View on Amazon

PHPUnit Pocket Guide
The official documentation of the PHP unit testing framework. Contains everything you need to know to start writing automated tests for your PHP code.

Practical Common Lisp
An introduction to Common Lisp. Covers the language in detail, and goes on to describe lots of real life software projects such as spam filters and an network enabled MP3 player.
View on Amazon

Programming in Lua
A complete guide to the popular lightweight scripting language, written by its chief architect.
View on Amazon

Programming Ruby: The Pragmatic Programmer’s Guide
A guide to the popular programming language Ruby from the Pragmatic Programmers.
View on Amazon

The Scheme Programming Language
A complete guide to the Scheme programming language.
View on Amazon

Software Engineering for Internet Applications
The textbook for an MIT course with the same name. This book discusses issues related to building online application, including user registration, content management, and scaling.

View on Amazon

SQL for Web Nerds
Written by MIT professor Philip Greenspun, this book aims to teach SQL from a real world perspective rather than from a theoretical standpoint.

Structure and Interpretation of Computer Programs
A classic computer science text that teaches some advanced programming concepts using Lisp.
View on Amazon

A Tutorial on Pointers and Arrays in C
An extremely detailed tutorial (10 chapters) on pointers and arrays in C. It starts with a description of a pointer and ends with function pointers.

That is just a selection of some of the great books that are available for free online. If you don’t know where to look for more a good place to start looking try my top 10 free python books post. I’m sure I’ll be posting about more in the future too, so be sure to subscribe!

10 Free Python Programming Books

August 23, 2008

Below is a collection of 10 great Python programming books that are available online in full, completely free of charge:

Dive into Python

This is a fantastic book that is also available in print. It covers everything, from installing Python and the language’s syntax, right up to web services and unit testing. This is a good book to learn from, but it’s also excellent to use a reference. I frequently find myself visiting the site! If you only read one book on this list make it this one.

An Introduction to Tkinter

Tkinter is a popular cross-platform Python GUI toolkit, and this book provides a good introduction with lots of examples. If you want to learn GUI development with Python then this book is a great place to start.

How to think like a Computer Scientist

This book uses Python to explain some Computer Science principals. It is full of examples, and each chapter has a collection of exercises for the reader to perform.

The Standard Python Library


This book provides a detailed description and usage examples for all of the modules in Python’s standard library. This fantastic reference is available in print.

Invent Your Own Computer Games with Python

This book is aimed at novice programmers who are interested in writing simple computer games. Each chapter describes a different game and goes through the stages of design and development. A great book for beginners, but the book lacks more advanced content and doesn’t include any information about Python game development libraries such as PyGame.

The Django Book



Django is a Python web framework (similar to Ruby’s Rails) which “encourages rapid development and clean, pragmatic design”. This book covers the framework in detail, and is a great place to start if you’re thinking about creating a dynamic website using Python. This book is also available in print

The Pylons Book

Pylons is another Python web framework. The book is structured in a very similar way to the Django book, and is worth reading if you’re looking for an alternative framework. This book is available in print too.

Data Structures and Algorithms with Object-Oriented Design Patterns in Python

This book provides a thorough introduction to data structures and algorithms using Python. This is definitely not a book for those wishing to learn Python. However, if you want to learn about data structures and algorithms, or you just wish to learn about their implementation in Python, I can’t recommend this book enough.

Building Skills in Python

This book consists of 42 chapters, each packed full of exercises designed to help you build Python programming skills. The book “includes six projects from straight-forward to sophisticated that will help solidify your Python skills”. A great book for those that already know Python, but would like to become more proficient.

Building Skills in OO Design

Written by the same author as the book above, this book follows the same format. This book focuses on object-oriented application design (using Python, of course) to help you to develop better programs.

More free books…

Above are just some examples of the books that you can find online. Back in January I posted a list of free computer science books, and I’ve managed to find lots more since then! I’ll post about them soon, so be sure to subscribe to my RSS feed.

Older Posts »