Book Review: Object Oriented Javascript by Stoyan Stefanov

Why am I Writing This?

A few weeks ago I was contacted by Packt Publishing and asked to review Object Oriented Javascript by Stoyan Stefanov. I love the language and there aren't very many books that discuss how to use javascript as a full blown real language that is it's own language. I've read some books that try to tell you how to right javascript that works like C# (yes I'm looking at you Asp.NET Ajax). That's the wrong way to go. The best method, the author's method, is to learn as much as you can about what the benefits of this language are and how to leverage them.

Where has this Book Been?

When I first started javascript it was almost too simple. So simple I felt utterly constrained. What can you really do in a weakly typed language that only has functions? As I learned through experience and as this books shows, there is SO much possible in this beautifully simple language.

This is the book I wish I had when I was starting out with javascript.

Who should read this book?

If you don't really use javascript on a day to day basis and you're about to this book is perfect. This book gives you a grounding in fundamentals to help you completely grasp the language. If you've never programmed seriously before, this book probably won't cut it. The first couple chapters would work well for an absolute beginner but the rest of book moves to targeting more seasoned developers by targeting on prototype based inheritance and design patterns in javascript.

So about this book

So like I said before the first four or so chapters are the standard fare you find in every programming language book. The history of the language, the different data types, loops, conditionals, objects, etc. The beginning chapters even introduce us to closures and the author walks through how they are used and how they are constructed step by step. It's great really. When you're trying to prepare a team to start developing utilizing Ajax this is the kind of thorough explanation you want to guide your team into a brave new world of web development.

One of the best things about this book is that it introduces FireBug, the javascript debugger for FireFox, right in the first chapter. This is extremely important for anyone who wants to follow along with the examples in the book. By introducing the debugger first and explaining how to use it, people new to javascript now have some tools to better help them get control of a language that is sure to be a massive paradigm shift for those new to the language.

Once you get to chapter 5 you start getting into the thick of things. Unlike the approach Mircosoft uses, which is to make javascript look as much like some other language (such as C#) as possible, the author lets javascript's prototype feature stand on it's own. He's never trying to make excuses for it and he's very confident in the power of this feature, as he should be.

Concepts such as chaining and singletons are covered as well as how to namespace your code appropriately (so important is this that it's included in the next version of Javascript natively). The author describes the factory, decorator, and observer patterns and also he hits on JSON and how to use configuration objects. I had to discover all of this for myself when I learned. Being that I spent probably a full two weeks just exploring javascript before I really started to become productive I can easily say that this book will save you more than enough time to justify the cost of admission.

Like a Sore Thumb, But Just Right

So then you get to chapter 7 and Stoyan gives just this one chapter to DOM/BOM interactions. Now admittedly, this is a book on OOP in Javascript so maybe the idea of using the DOM/BOM just doesn't fit in at all... but then why leave the chapter in at all? It seems as though the only reason to leave this chapter here is to discuss XMLHttpRequest. I think that's a great thing to include but the discussion of the DOM is a bit superfluous. If we're assuming someone really needs a chapter on it then they probably need a lot more than just one chapter.

The same goes for the information regarding XMLHttpRequest. If you need to have a book which discusses this information you really need a whole book on the subject.

As negative as that sounds, it's really kind perfect. The author introduces you to just enough of the subject that you know what you'll need to read about next. He doesn't waste time trying to make you an expert he just invests your time in introducing you to these concepts so that you can revisit them in another book and round out your knowledge. Once again, this book is about building your knowledge about the core of the language. This chapter kind of sticks out like a sore thumb but the book is better for it.

Final Thoughts

I really did ask myself where this book was when I started learning javascript. I avoided the language for so long simply because such a well thought out and thorough discussion was nowhere to be found. When I was very new to javascript it looked like all you could do was call simple functions. Really, that is all you can do, but this book shows you just how powerful a function and its scope really can be and how limiting other languages can be regarding this power.

Being that the publisher provided me with a free copy of this book to review, I was bit concerned about the possibility of needing to post a negative review. Luckily, that's not a concern. The biggest downside I can see is that this book doesn't stand alone. If you are a developer currently or about to start working with Javascript then you will want to use this book to augment your knowledge of the technology and learn how to develop maintainable code. If you're new to programming in general you'll need this book in addition to another book that focuses on the kind of development you want to do (Flex, JQuery, Rhino, etc).

N00b Writing a Parser Part 1: The Scanner & Reader

I'd like to share some of my learning about this stuff as I'm going through it. I've been meaning to write something for a while but since I am actually writing a parser now I figured what better a time to show what I'm up to?

So first and foremost I want to send up the signal flares: I am perpetually learning. I wouldn't call anything you see here an example of best practices. My main reason for wanting to share this is to help people wrap their heads around parsing. It seems so big the first time to try to tackle it. If you try to learn about it by seeing a finished parser it's pretty complicated looking and intimidating if it's designed well. If it isn't designed well, it's just a mind fuck.

By showing you my steps on building one from scratch from my limited perspective, I'm hoping it will serve as a kind of halfway understanding, a bridge if you will, between not understanding and understanding completely.

BaseCamp.NET

Just a quick status update. Tonight, I added the entities for all of the BaseCamp items to the project and got the test framework up as well. Given that a lot of the code is network dependent, I wouldn't call these unit tests per-say. The test framework will be making network calls and this is by design. That's all I have to say for now, stay tuned for more.

Python and C# BaseCamp API Wrapper

I'm really just posting this as a bookmark for myself. I found some guy who had written just enough C# code for BaseCamp that it helped me figure out HTTP Basic Authentication so I plan on taking the work I do on the Python BaseCamp API and porting it to C#. Here is the very basic C# wrapper that the other guy wrote: http://www.basecamphq.com/forum-archive/viewtopic.php?id=3291

Be looking for a beta of the Python implementation by the end of this week. I'll complete the C# port once the Python code is pretty solid.

as3fbp Released under MIT License

This is just a quickie. A while back I posted an article exploring how a flow based programming framework would work in ActionScript 3 (refer to http://aboutjustin.com/blog/?p=90). In my opinion, flow based programming isn't just about concurrency, it's actually about any asynchronous tasks you need done.

Well I went ahead and released the software. It's very small in terms of lines of code but does work as an example of what goes into flow based programming and how programming in it should be. The project is having a bit of an identity crisis it has two names right now, as3fbp and ActionFlowScript... Meh. I'll let time sort that out. Here's a link to the project on Google Code: http://code.google.com/p/actionflowscript/

There is at least one outstanding bug that would be an issue if you actually were going to try to use this in a production environment. I would recommend using it more as a learning tool than anything else. Hopefully I'll have some news on some more open source goodness by the end of the week.

Google Gears: The future of the web?

Yes. This kind of technology should be in every browser, but, is this the revolution we've been waiting for?

I've been reading about this concept for a bit. It might have been at Google I/O actually. Essentially you could cache every response you get back into gears' db an then query it quickly before going back to the web server. Realistically, I'm not sure if that is really the next big thing that people are going to want. I can see Ajax changing things significantly and even Comet having a large impact (it allows web apps to communicate asynchronously with the server wherein the server can push unrequested data to the client). Right now, Gears seems to be mostly a caching solution or useful for the more obvious use of offline pages.