Software dev, tech, mind hacks and the occasional personal bit

Category: Book Reviews Page 2 of 3

Review: “Deploying Rails Applications” by Ezra Zygmuntowicz et al.

Deploying Rails Applications: A Step-by-Step Guide by Ezra Zygmuntowicz, Bruce Tate and Clinton Begin is a good read, if a little dated. It was published in May 2008, and you can see that things have moved on a little in the Rails world since then. None the less, quite a lot of the information is still relevant and useful.

The book covers some basic Rails and version control concerns at the start, then rapidly launches into chapters devoted to Rails hosting options available from shared hosts to virtual and dedicated servers. The advice given is good and is in line with my experiences. Unix configuration is given in depth which would be very handy if you had not set up a server before. Next is a good discussion of Capistrano and automating deployments. The examples all use subversion. However, these days I expect the majority of Rails source code is pulled with Git. There is also a chapter on managing mongrels and setting up monitoring solutions. This is still relevant if you want to use mongrels, however these days Passenger is probably the best choice, and it does not have such complex management and configuration requirements. The scaling out chapter is useful and pulls together handy information including details on MySql replication/clustering. There’s a chapter on deploying on Windows and also some suggestions around performance and profiling.

I haven’t come across another book that brings together a structured collection of useful information to help you move from running rails locally to having a cluster of scalable production servers and the automated deployment process required to support it. Despite being too old to cover Git and Passenger, I’d still recommend having a read of this book if you’re at the stage of planning to launch a Rails site or looking to scale your VPS up to a cluster.

An Island to Oneself by Tom Neale

While in the Cook Islands, we went to the National Museum and it was there that I first heard about Tom Neale and saw reference to him on a census of island populations from the 1950s (“Suvarov: population 1” with a footnote saying “Tom Neale”!). He was the only inhabitant of Suvarov, an atoll in the Cook Islands, having done what many people only dream of. He left civilisation and moved to a beautiful, deserted island in the Pacific, replete with coconut trees, jungle, and an azure lagoon. Not only that, but he survived and prospered there and wrote an amazing autobiography of the time, called “An Island to Oneself”.

I tried to borrow “An Island to Oneself” from the National Library on Rarotonga (there is only one library on Rarotonga!) but unfortunately all copies were out. So, I turned to Amazon (the long tail poster child), and was very happy to find they could source me a copy. I don’t want to spoil the tale, but recommend you have a read if you have ever thought about what life would be like on a desert island, surviving only by your own wit and skills, hundreds of miles from civilisation!

UPDATE (6 Jul 2016): Thanks to Don Hirst for this link to the full book online.

Review: RESTful PHP Web Services by Samisa Abeysinghe

Packt Publishing kindly sent me a copy of RESTful PHP Web Services by Samisa Abeysinghe to review. The book’s cover claims that it will help you “Learn the basic architectural concepts and steps through examples of consuming and creating RESTful web services in PHP”. The book succeeds in providing simple steps and examples of creating and consuming web services, but falls short on REST architectural concepts and design principles.

The book starts with a very brief introduction to the principles of REST, and rapidly moves on to a discussion of PHP tools frameworks. The introduction misses some important REST / RESTful web service concepts such as hypermedia, application vs resource state and the relevance of utilising HTTP headers and status codes. Some of the information in the introduction is confusing. For example, on page 12, it says “Resources can have multiple representations that reflect different application states”. This does sound a little odd – resources can have multiple representations, for example, for different requested content types. Representations should reflect resource state, not application state. Also, the coverage of HTTP verbs is misleading, especially when POST and PUT are discussed.

The next couple of chapters discuss PHP support for HTTP, using libraries such as CURL, and XML parsing strategies. The author chooses realistic examples for code samples, such as Flickr and Yahoo Maps clients. The last example given is quite cool – using earthquake latitudes and longitudes from an Australian government site to plot points on Yahoo maps. The example code is generally simple and easy to follow. However, it would have been nice to see some sort of separation between view and data access logic.

The following chapter is a worked example of building RESTful services for a library lending books. It is a good example, and becomes the basis for most future chapters. The resource design and URLs are reasonable, although it may have been nice to have “loans” as resources in their own right. Using links between resources, rather than just relying on known URLs would also benefit the design.

Later chapters cover alternative frameworks such as Zend and WSO2 using the library lending system as an example for code samples. These chapters are useful as they give an idea how the frameworks look when put in practice. It does look as though PHP and frameworks still have significant limitations around routing flexibility from the examples (eg, the .php extension seems to mandatory in URLs). There is also a chapter on debugging with tips around tools and troubleshooting XML parsing issues.

The writing style is generally clear and easy to read. There are occasionally some odd turns of phrase, such as on page 10: “AJAX makes Web applications to become more interactive, faster, and more user-friendly”.

Overall, I would recommend this book to people wanting to write simple URI template based web services or clients in PHP, and also to people interested in getting an overview of libraries and frameworks currently available in the PHP ecosystem. To gain an understanding of the REST architectural constraints and designing good RESTful systems, I would recommend RESTful Web Services, and if you wanted to take it further, digging into Roy Fielding’s thesis and the HTTP 1.1 Spec.

Review: JavaScript – The Good Parts by Douglas Crockford

“JavaScript: The Good Parts” was kindly lent to me by my friend and colleague Dave Cameron. It was a highly informative read, and a good length at just under 150 pages. The aim of the book is to define an elegant, recommended subset of JavaScript that allows you to do everything you need, and work around problems in the language. The book is aimed at people who already have a good grasp of programming in other languages.

I learnt quite a bit from the book. Here are a few of the most important parts that come to mind:

  • JavaScript has function scope, not block scope so it is best to declare variables at the top of functions.
  • It is important to put { on the same line as the block opening keyword (eg, function, if etc) rather than on the next line. Otherwise, you may run into problems with some JavaScript implementations auto-adding ; in the wrong place.
  • Using the === and !== operators are safer and better than the == and != operators as they do no coerce types.
  • The ‘new’ operator is a bad way to make new objects in JavaScript and should be avoided. Functions starting with a capital letter should always be called with the new operator by convention. Failing to do this will add all the functionality of the object you are trying to create to the global object (thanks to the this references)!
  • You can always pass any number of arguments to a function. Extra arguments are not bound to function parameters, missing arguments will be undefined. Inside the function all arguments are accessible using the ‘arguments’ variable which is an array-like object.
  • Lots of things are false. Eg, 0, NaN, empty string, null, and undefined.
  • hasOwnProperty(name) is great in for(property in object) loops to find members of your object rather inherited members.
  • Object.beget(someOtherObject) allows prototypal inheritance from someOtherObject.
  • JavaScript arrays are really just objects with numerical property names and the length property, so if you use a for in loop, you’ll get indices in random order.
  • It is a good idea to ‘namespace’ your code in a single global variable for your application to avoid conflicts with other libraries. Eg, myApp = {}; myApp.myVariable = 5;
  • If you don’t used var, a global variable is created.
  • Closures let you make information private and give you encapsulation.
  • Inner functions have access to the variables defined in an outer function.

Creating objects with private data:

var incrementer = function() {
  var value = 0;
  
  return {
    increment: function (inc) {
      value += typeof inc === 'number' ? inc : 1;
    },
    getValue: function() {
      return value;
    }
  };
};

var myIncrementer = incrementer();
 

Functional inheritance

var mammal = function(spec) {
  var that = {};
  
  that.getName = function() {
    return spec.name;
  };

  return that;
};

var myMammal = mammal({name: 'Fred'});
myMammal.getName() === 'Fred'

var cat = function(spec) {
  var that = mammal(spec);
  var super_getName = that.superior('getName');

  that.purr = function { /* new catty stuff */ };

  that.getName = function { 
    return super_getName() + ' the Cat!';
  };

  return that;
};

var myCat = cat({name: 'Kitty'});
myCat.getName() === 'Kitty the Cat!'

// Helpers

Object.method('superior', function(name) {
  var that = this, method = that[name];
  return function() { return method.apply(that, arguments); };
});

Function.prototype.method = function(name, func) {
  this.prototype[name] = func;
  return this;
};

There were a few things that I thought could be improved in the book. First of all, although the structure was adequate, it did lend itself to repetition. For example, scope is covered on p36 (in Functions section) and p102 (Awful parts), with very similar words. Secondly, I did not find the frequent syntax diagrams added much to the narrative.

Despite these small blemishes, I’m glad to have read Crockford’s book. I now understand much better which parts of JavaScript to use, and how to build good object oriented code in JavaScript.

The Long Tail by Chris Anderson

Just finished reading “The Long Tail – How Endless Choice is Creating Unlimited Demand” by Chris Anderson. In summary, the long tail is about selling small volumes of a vast variety of items instead of large volumes of a small number of “hits”. This possible when the cost of distribution to geographically distant customers is low and the cost of storage for stock is not a concern (eg, intellectual property in electronic format, JIT manufacture). Popular companies capitalising on the long tail include eBay, Amazon, Google Adwords and Lulu.

The book has a lot of interesting stories and statistics but tends to repeat itself often. The long tail idea is probably not new to most readers these days, and I think if you’re familiar with Amazon, there’s little that comes as a surprise. However, I did find an interesting section in the book about the tyranny of choice. Anderson suggests that choice is good, customers want choice, and choice is only a problem if you don’t know what to choose to suit your taste. Hence, an important part of a long tail business is helping people find what they want (ie, filter out noise) in all the vast array of choices. He suggests using user reviews, rankings, sorting etc as means to help people find the “best” choice for them. I also hadn’t come across Lulu before – looks worth checking out, a site for mini self-publishing.

Thoughts from Process Consulting

Just finished reading “Process Consulting” by Alan Weiss, lent to me by my talented colleague, Darren Smith. The book is concerned more with general consulting, not IT consulting or IT methodologies. I found the bigger picture view in Weiss’s book enlightening and helpful in evaluating and questioning my own consulting practices. Here’s a few thoughts from the book:

  • Remember that you are not the change agent. The client personnel are the change agents. You are the catalyst, but they are accountable for enduring change. Don’t be a hero…
  • Cute phrases and pithy slogans don’t change behaviour. Aligning people’s objectives behind corporate objectives and supporting that behaviour with metrics and rewards will usually gain their attention. Rapidly.
  • Is it really progress if we teach a cannibal to use a knife and fork? (from Stanislaw Lem, quoted by Weiss)
  • At the outset of any change process, immediately after agreement with the buyer, identify and “recruit” these key positions [hierarchical leaders, front line management, respected leaders and experts]. Use the buyer’s clout if you must. The most crucial factor in organizational change occurs prior to implementation: It’s the conceptual agreement and acknowledged self-interest among the few people who actually have their hands on the controls.
  • [Regarding change,] neutral is as bad as negative, since the default position for everyone else will always be the old behaviour.
  • Don’t be anxious to “make change”. If you have a six month window, for example, invest at least the first month or more aligning your support and key sponsors and establishing their accountabilities. The more time you take with critical sponsors, the faster you will ultimately create change.
  • When you find someone micromanaging, it is almost always because of a lack of trust. If you don’t do the job the way he or she would do it, you must be doing it incorrectly. If the leader has trust in subordinates, simply providing the goals should be sufficient.

Practical JRuby on Rails (Web 2.0 Projects) by Ola Bini

The fine folk at Apress sent me a copy of Ola Bini‘s new book to review. The full title is “Practical JRuby on Rails Web 2.0 Projects – Bringing Ruby On Rails to the Java Platform”. Overall, it was a good read, and extremely valuable to anyone who is developing in JRuby. JRuby information and documentation is scarce and most of the time, a Google trawl does not give you good results on a JRuby related query. Ola’s is the first, and currently the only JRuby book available, and in my experience, the most valuable resource available to give you an all-round picture of JRuby capabilities and usage.

Audience
Despite comments on the cover, I would suggest that this book is not ideal for people new to Ruby / Rails. Ola jumps in the deep end quite quickly, and being a talented Ruby programmer, makes use of lots of shorthand, procs, code blocks etc which would likely be hard to follow for someone new to Ruby. Although there is a section at the back called “Ruby for Java programmers”, I think this would not be sufficient for somebody new to Ruby to understand all the code examples.

To get the most value out of the book, it would be good to have at least a basic understanding of Ruby and Rails (eg, having read Agile Web Development with Rails or messed around with Ruby/Rails a bit) and a basic understanding of Java syntax, deployment and Java EE.

What’s Covered?
The book is project based, so as to give context and useful examples of JRuby functionality. There are 4 projects:

  • The Store (Shoplet) – a standard Rails app running under JRuby using Active Record JDBC.
  • Content management system – general Java integration and using Java libraries for content rendering.
  • Administration System – using EJBs, JMX and discussion of JRuby deployment options.
  • Library System – JRuby as the “glue that never sets”. Using Java Web service frameworks and JMS from JRuby.

The Good

  • Teaches you how to do all those tricky bits which are half-Java and half-Ruby and can’t be easily found online, such as converting between Ruby and Java types, including JAR files, implementing Java interfaces, etc
  • Clever and concise Ruby code – I picked up some Ruby tricks reading Ola’s code.
  • Complex code snippets are generally well explained in text.
  • Useful tips on when to use Java libraries and when to use Ruby ones.
  • Generally good and interesting example projects which justified the use of JRuby and the techniques shown in the book.
  • Helpful discussion of JDBC and database connectivity options for JRuby.
  • Nice overview of the many JRuby deployment options.
  • Helpful “sidebars” about Java Enterprise Edition technologies.
  • Covers the strong areas of JRuby well – web applications and system integration.
  • Appendices provide useful reference information.
  • Nice section at the end on how you can get involved in JRuby.

The Less Good

  • Example views often contain table layouts, inline styles and other layout information that would be better done in separate CSS files.
  • Variable names in code could be more descriptive. This would make example code easier to follow.
  • Occasional odd spelling like “sur_name” and use of deprecated Rails features, such as “start_form_tag” (to be fair though, Rails API does change very quickly).
  • The title suggests that the book is about Web 2.0. There is a little token AJAX, and I suppose a content management system is a bit Web 2.0, but overall, buy the book if you want to know about JRuby, not Web 2.0.
  • Although REST is only mentioned briefly in a little sidebar, and not a focus of the book, I found the description of REST and CRUD a bit misleading, especially when considering PUT vs POST.
  • The discussion of JRuby deployment provides a good overview, but more in depth discussion of major options (eg, GoldSpike), and production configurations would be great.

Conclusion
As the best and only JRuby reference, I’d highly recommend you buy a copy if you are working in, or planning to work in JRuby. The book will help you to write JRuby applications which make good use of Ruby, Rails, Java libraries and Java Enterprise Edition features.

Some Murakami Quotes

Recently, I’ve been catching up on my reading. Haruki Murakami is one of my all time favourite authors. His novels are always interesting, and the writing style is generally gorgeous, although it does vary a little between different books. I’m not sure if this is Haruki Murakami changing his style in the original Japanese, or simply results from different translators.

Something I’ve been noticing lately is that in all of the Murakami novels I can recall, the protagonist always has a lot of time. This is so different to most other novels which try to rush from one exciting event to the next. Perhaps this is part of the reason why I really like Murakami’s writing so much. Anyway, here’s some memorable quotes from Murakami novels that I’ve read recently:

From Kafka on the Shore:
“Perhaps most people in the world aren’t trying to be free, Kafka. They just think they are. It’s all an illusion. If they really were set free, most people would be in a real pickle. You’d better remember that. People actually prefer not being free.”

“Pointless thinking is worse than no thinking at all”.

From Hard-Boiled Wonderland and the End of the World:
“Huge organisations and me don’t get along. They’re too inflexible, waste too much time, have too many stupid people.”

“It’s frightening,” she said. “Most of my salary disappears into my stomach.”

From The Wind Up Bird Chronicles: (language warning on this one)
Show quote, although it contains 4-letter words.

Web Design and CSS, how hard can it be?

So, audaciously, I decided to do the theme for my pet Rails project. How hard can CSS and Photoshop really be? Having made basic layouts and modified various themes, I thought my CSS skills were adequate, and Photoshop is, after all, just another Windows application.

With the help of my talented fiancee and flatmate, the Photoshop side of things went fairly well for a banner image. Not too hard, find a good image and apply some layers, effects and text.

When time came to hit the CSS, I felt confident. Based on my vague trial and error understanding of floats etc, I managed to spend a fair bit of time messing around, painfully, slowly getting a good layout in Firefox, only to be frustrated by an awful rendition in Internet Explorer. Then trying to make a compromise layout between the two that looked reasonable in both, only to have a slight change throw everything into disarray. Repeat ad nauseum.

Clearly, I my confidence was misplaced, and my CSS skills sucked. Time to actually learn something. I turned to my yet un-opened copy of “Beginning CSS Web Development – From Novice to Professional” by Simon Collison, recommended by a ThoughtWorks buddy, Warren. I read it pretty much cover to cover on Saturday. It was quite a good read, practical with useful examples and a light tone. Lots of good stuff within:

  • Clear explanation of the basics
  • Coverage of different browsers
  • Some insight into a web designer’s mind
  • A number of useful page layouts
  • Different options for form layouts
  • Some advanced CSS tricks
  • A nice worked example of cutting up a Photoshop mock-up and turning it into image slices, CSS and HTML.

Overall, the book was pretty much exactly what I needed to get back on track and bring my misbehaving CSS under control.

Here’s a few things I learnt that solved some of the most pressing woes I was having with CSS:

  • Margins collapse into each other. Ie, if you have two elements next to each other and each has a 10px margin, the total distance between the two will only be 10px. Adding 1px of padding will mean the borders of the two elements don’t touch and hence won’t collapse
  • Generally avoid padding on fixed width elements. Instead, wrap them in another element such as a div, and put the padding on it. That way, you avoid needing to do any hacks for the broken box model in older versions of IE.
  • You can put an ID on each pages’ BODY, and that way, you can easily target elements on individual pages using their body’s ID.
  • Often a good way of doing layout with floats is to keep the document as much using the normal flow layout, and then put in appropriate margins or padding to make space for floats, rather than floating the whole document.
  • The order of values in short declarations like ‘margin: 1px 2px 3px 4px;’ is top, right, bottom, left.
  • It is a good idea to stick to the limited set of web-safe fonts, and also use a number of fallbacks for font family to cover all viewers.

My app’s theme is not finished yet, but CSS has now become more a pleasure than a frustration.

Naked Economics by Charles Wheelan

Just finished reading ‘Naked Economics: Undressing the dismal science’. It was a present from a friend, and I’ve been meaning to read it for a while. Glad I finally got around to it.

From the title, I assumed the book aimed to point out the failures of economics as a science. Not so at all – it was written by an economist and provides a high level overview of capitalism in layman’s terms.

Here’s some interesting questions and explanations from the book:

  • Why do we have money? So that we can indirectly swap our labour or goods for the things we want, even if the person with the things we want is not interested in our labour or goods. Without money, we would need to barter. That’s fine if you’re swapping chickens for rice. But what happens if you do web design, and you want meat for dinner, and the butcher does not want a website?
  • Money has value only because we all believe it does. We have faith that if we sell something (ie, convert it to the common value unit), we will then be able to swap that money for something we want.
  • Why have markets anyway? Markets produce what people want – ie, what people are willing to pay for (or at least what we are convinced into wanting through advertising etc).
  • Why not set the price of everything rather than letting it get worked out in a market? Well, it would be an enormous job, and things would not reflect the cost of production. Eg, bird flu wipes out half of the chickens in the world. There are now less chickens to go around so chicken becomes more expensive. People who really want chicken can still get it, but it costs them more. People who don’t care as much or can’t afford it eat fish or beef instead. If the cost of chicken was a constant mandated by the state, chicken distribution would need to be mandated in some other way. If there’s not enough chicken for everyone who wants it, who should get it? First come first served? Political clout? Personal connections?
  • Markets destroy. A new way to mechanize weaving may make thousands unemployed and destroy towns and communities. But according to Wheelan, the country as a whole is better off as we are able to produce more for less cost, hence increasing our standard of living. Ie, as a consumer, you may now be able to buy a shirt for half the price.
  • In politics, small motivated groups often drive policy. Eg, the general population does not care much one way or other on a subsidy on growing alfalfa. It might cost each person in Australia 0.01c per year. However, if the subsidy was to be removed, and the alfalfa farmers would care a lot. It may well mean their livelihoods so they would demonstrate, make campaign donations, vote as a block and generally make as much fuss as possible to make sure the subsidy was not removed.
  • Why do people work in sweatshops? According to Wheelan, the pay is generally better than for other jobs available – ie, sweatshops are not the cause of the problem, rather a symptom of the general poverty and lack of opportunity in the area.
  • Why is free trade good? So that everyone can do what they do best – ie, specialise to the max. The idea being that if everyone works on what they are most good at, then productivity overall is higher.
  • Why are tariffs bad? Because they support local industries that are not viable – ie, a poor uses of resources.
  • Why do we need governments? To provide the rails for capitalism. Eg, to enforce laws (so you can’t just kill me and take my stuff), to regulate the excesses of the free market and to provide goods and services that people need but that free markets will never provide. Also, to do things that individuals cannot do alone, but are in the interest of the population as a whole – eg, build infrastructure.
  • Care for the environment is a luxury good – ie, if you and your family are starving, cutting down trees to sell for food seems like a pretty good idea.
  • Companies destroy the environment because the current monetary cost of environmental destruction is usually minimal. If the full cost of environmental destruction was factored into the market (eg, companies have to pay for pollution and destruction), then environmental destruction would slow dramatically.
  • Who can create new money? The reserve bank, and it does it by buying bonds from banks with money that did not previously exist.
  • How can the reserve bank change interest rates? It can sell government bonds at its target rate and it can buy bonds (with brand new money) or sell bonds from/to trading banks to influence the amount of cash the banks have to lend. Eg, lots of cash at a trading bank means they’ll lower the interest rates so as to rent out the money.
  • How come the economy can go into recession for no real reason? If people are worried, they don’t spend. If people don’t spend, then companies can’t afford new/current investment. People get sacked and then can spend even less. People get more worried and the cycle continues.
  • Why is the level of savings in a country important? Money in the bank means it can be lent out to people who want to use it to create new businesses or expand current businesses. Access to capital allows growth.

I wouldn’t take these on face value, and I would certainly question some of the assumptions on which they are based. However, they provide some interesting areas for further thought.

Page 2 of 3

Powered by WordPress & Theme by Anders Norén