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

Category: Book Reviews Page 2 of 4

“Learned Optimism” by Martin Seligman

Learned Optimism: How to Change Your Mind and Your Life is an interesting mix of a psychological treatise and a self-help book. Unlike many self-help books, this book is written by somebody with clear qualifications in the area. The author, Martin Seligman, is a professor of psychology at the University of Pennsylvania and a past president of the American Psychological Association. The concepts in the book were derived from well-designed studies of people and animals and were written up in reputable journals including Science.

The first part of the book focuses on the recent history of psychology and explains Seligman’s research into learned helplessness and his later shift into researching optimism. He describes multiple studies performed and the results, and how they were disputed by proponents of other theories. The most memorable study he describes was designed to show learned helplessness using dogs. The experiment used three dogs. The first was placed in a box that continued to give the dog electric shocks until it pressed a bar. The second dog was placed in a box that continued to give it electric shocks until the first dog pressed the bar in the other box. The third dog sat in a box with no electric shocks. In the final stage of the experiment, all three dogs were placed in boxes which gave electric shocks until the dogs jumped over to the other side of a partition. Across a large number of repetitions, the common behaviour was that the first dog quickly jumped over the partition and escaped the shock. The second dog (with learned helplessness) just lay on the bottom of the box being shocked. The third dog (the control) jumped over the partition and escaped as well. Similar experiments were performed with people and annoying sounds with similar results. Seligman also found that a small proportion of people and dogs did not give up and seemed immune to learned hopelessness. This later became the focus of his research into optimism.

An interesting observation made in the book is that previously, people used to have faith and trust in their community, church, country and government and this provided support in times of personal failure. However, in recent times, these supports are no longer present or as strong for many people. With rising work hours etc, community and neighbours are much less important than they were previously. Religion has declined and many people do not go to church in the western world. Governments have been caught out in lies and corruption (eg, Nixon, Howard). Faith in country has been eroded by globalisation and wars like Vietnam and Iraq. Simultaneously, marketing and consumer culture has focussed on elevating the importance of the self, personal choice and success. In this environment, where self is all important, and the supports of previous generations no longer apply, personal failure is far more debilitating and depressing than it has ever been before.

Later in the book, Seligman explains that everyone, when they have a set back or failure, are stopped in their tracks at least briefly. However, optimists recover faster and are able to act again sooner due to the way they explain the failure to themselves. When something bad happens to an optimist, they expect that the bad thing will be short lived (temporary), was caused by someone else (external) and only affects a partial area of their life (specific). Pessimists are the opposite. They expect bad things to go on for ever (permanent), were caused by them (personal) and will affect their whole life (pervasive). The opposite applies for each cognitive style as well – optimists see good things as permanent, personal and pervasive. Pessimists see good things as temporary, external and specific. Seligman also mentions that turning a thought over and over in one’s mind (rumination), with a pessimistic explanatory style leads to a magnification of the negative impact of the thought (often a factor in depression).

There are also a number of psychological tests in the book that aim to measure optimism. Variations on these were used successfully for selection of sales people who had to make cold calls at a large insurance company (MET Life). A high level of optimism meant that the sales people were able to keep on going despite multiple rejections.

In the last section of the book, Seligman talks about ways to dispute one’s internal dialogue and explain the set backs in life in less self-damaging ways (ie, temporary, external and specific). He suggests that your internal voice should not necessarily be given any more credence than an external voice as it can often be biased. He recommends disputing internal dialog with evidence, offering alternate explanations and analysing the implications. His other suggestion is to postpone thinking about the problem by distraction or writing it down and setting a time to think on it further.

Seligman finishes by discussing when optimism or pessimism is most appropriate. His theory is that optimism is generally a beneficial outlook as it allows one to be proactive and productive in the face of failure, to lead and to inspire and encourage others. However, his studies showed that mild pessimists had a more realistic world view than optimists. Hence in life critical situations, certain types of advisory and assurance roles, mild pessimism and the resulting realism was a better mindset to employ.

Overall, there are a lot of interesting ideas in the book. After reading it, I now think a lot more about my internal dialogue and pay more attention to the way I explain good and bad events to myself. I did find that the last part of the book about “Changing from Pessimism to Optimism” was a bit repetitive as it covers the same ground multiple times with emphasis on different areas such as relationships, work and teaching children. Although I found the historical information and descriptions of studies well written, convincing and interesting, I would have preferred a few less in the interests of concision. These small complaints aside, I would highly recommend reading this book, especially if you find yourself ruminating often on the difficulties in your life rather than enjoying the good parts and taking action.

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.

Page 2 of 4

Powered by WordPress & Theme by Anders Norén