The Art Of Readable Code

The Art Of Readable Code by Dustin Boswell and Trevor Foucher

art-of-readable-codeI didn’t know much about this book. I knew that it was written by two Googlers. It was under 200 pages. And the title was intriguing. Sounded great, let’s see how good it is.

After reading it I have to say that it’s really good. Again, an incredible book for beginners something everybody should read between their first and second year programming. Really well written, no clutter, funny cartoons. Really good book.

Code should be easy to understand. AND
Code should be written to minimize the time it would take for someone else to understand it.

These are the two main mantras in the book. I would even say one mantra. The idea that you write code for some other person to read is great. They also say: “Maybe that person is you in 6 months”. And I agree. I noticed this in the beginning of my ‘career’ (for a lack of a better word). I looked at code I’ve written 6 months before and had problems understanding it. Today, I can look at code I’ve written 3 years ago and have not many problems understanding it.

Use a thesaurus

Because English is my second language I often do this while searching for better names. But I think even for native speakers there’s a payoff. I try not to make it too non-obvious, though.

Append important information to variable names. e.g. delay_ms, unsafe_user_comment, textfield_utf8, etc.

I like this idea and it’s extremely valuable in non-static typed languages. Which makes me think whether you should, for example, define two types of input. Save and Unsafe text. You write all your ‘internal’ function only using save text and therefore have to check your unsafe text you’re getting from the user / input.

Names should be non-ambigious

n.c.

Comments as “director commentary”

Love this. If there’s something non-obvious describe it. If you tried a few things describe it. Really good advice.

Examples in the comments / docstring

I love when library writers do this. Python has a great implementation which allows you to define examples and tests in the docstring. But nonetheless, something worthwhile.
All in all, really good! I knew most of the stuff thanks to

  • functional programming (bottom up, dreaming about what you want to do, no side-effects, )
  • edw519 who said that naming is one of the most undervalued activities in programming. His comments got me started to use clean and consistent naming.
  • my own laziness (writing as little code as possible)

I would recommend it to new comers, i.e. with about 2 years of experience. They will probably get the highest payoff. Absolute recommendation!

Breakthrough advertising

Breakthrough advertising by Eugene Schwartz

breakthrough-advertisingThere’s a lot written about this book. I won’t go into detail. But one of the most stark things about this book is its high price (used hardcover costs $396.00):

breakthrough-advertising-amazon.jpg

Some say this book made the most millionaires. Some say it made their career. So what it is about?

the copy writer does not create the desire of millions of women all over America to lose weight; but he can channel that desire onto a particular product, and make its owner a millionaire

This is probably one of the main points in this book. Creating trends is incredible hard, riding them not so much.

All in all, I think it’s an incredible book. It’s truly a manual to make money. That doesn’t mean that you can just grab the book and money is pouring out but the books describes in depth each step in writing copy and explains strategies in detail.

Analysis is the art of asking the right questions and letting the problem dictate the right answers.

Mass desire

  • copy channels desire onto a particular product but doesn’t create it
  • Mass desires are the pubic spread of private wants
  • Using these trends allows for leverage
  • a) permanent forces: health, -technical problems => differentiates of the product + freshness
  • b) forces of change: detect & chart possible trends

Stage I: Choose the most powerful desire that can possibly apply to your product

Each desire has three dimensions:
a) urgency, intensity, degree of demand to be satisfied aka. pain level
b) staying power, degree of repetition, the inability to become satiated aka. frequency of pain
c) scope aka. how many people have this problem

Stage II: Acknowledge the desire (reinforce it / offer means to satisfy) in the headline

Stage III: Show how your product performances satisfy the desire

a) Start by listing all different performances it contains and group them against the mass desires each satisfies

Your prospect’s state of awareness

You copy connects the market with the product. Your headline is the first step.

The headlines is based on three questions:

a) What is the mass desire that creates this market?
b) How much do these people know about the way your product satisfies this desire?
c) How many other products have been presented to them before yours?

How aware is your prospect?

I) Customer knows your product and what it does and knows he wants it
II) Customer knows the product but doesn’t want it yet

Your headline should focus on one of these tasks:

a) reinforce desire
b) sharpen / extend the image of the product
c) introduce new proof / details
d) announce new mechanism for better satisfaction / elements former  limitations
e) completely change the image (USP)

You use the brand name / logo and point out the product’s superiority

III) Customer knows that the wants the product but he doesn’t know yet that there’s a product

IV) Customer has a need but doesn’t understand the connection between him and the product

Start with the need / solution in the headline. Dramatize the need and present the product as the inevitable solution

V) Prospect isn’t aware of his need or he won’t admit it // need is very general

a) Price means nothing yet
b) The name means nothing
c) Function and desire mean nothing

You are echoing your market (emotional, attitude). You are defining them for themselves. The reader has to own the headline: his headline, his problem, his state of mind.
You’re not selling the product, you are selling the ad. Your goal is that they keep on reading to that they can get through each awareness phase.

THE UNIVERSITY OF THE NIGHT

The young Lincoln, poring over borrowed school-books far into the night – seeking in the dim light of his log fire the transforming light of knowledge – eager to grow – eager to do . . . here is an example which has inspired the man who strives against the odds of circumstances to make his place in the world.
To-night, in cities and towns and villages . . . thousands of men will drop their daily labors to fight, beneath the lamp, the battle that Lincoln fought. . .
Up from the mines, down from the masts of ships . . . from all the places where men work, they will go home and take up their books because they yearn to grow, because they seek higher training, greater skill, more responsibility. . .
Some of them are men who work in one field whereas their talents and desires are in another. Some . . . are halted in their progress because they do not understand the higher principles of their business or profession. Some left school in boyhood because poverty made it necessary. . .
Fifty years ago these men . . . would have had no place to turn for the courses of study and for the personal guidance that they need.
Thirty years ago there was founded a school to help them – a school created for their needs and circumstances – a school that goes to them no matter where they are – a school . . .
Created in response to a need, the International Correspondence Schools have developed their scope and usefulness to the growth of that need . . .

How many products have been there before you?

I: First to market

If prospects learn about your product, they become more interested, more enthusiastic and believe more

Be simple, be direct, don’t be fancy; dramatize the claim, bring your product and prove that it works

II: You’re second

If the direct claim (I) still works
copy it and enlarge on it; drive it to a limit

III: People already bought products and (II) is at its limit

People accept their fate but still have the desire; they are looking for something new
Introduce a new mechanism; shift from what the product does to how it works; reduce the claim from (II) down and integrate it; e.g. „I am 60 pounds lighter“ => „lose fat“; integrate the claim into your first paragraph

IV: Elaboration on the new mechanism

Make it easier, quicker, surer, solve more problems, overcome old limitations, promise extra benefits (like II)

V: Dead market

Use the technique of fifth awareness phase

38 ways to strengthen your headline

I. Verbalization

Reinforcing a claim by binding other images to it

  • Measure the size of the claim
  • Measure the speed
  • Compare it
  • Metaphorize it
  • Make the prospect feel, seek, touch, see or hear it
  • Show prime examples
  • Dramatize the claim / results
  • Use paradoxes
  • Remove limitations
  • Use people / values the prospect wished to be identified (celebs, professionals, etc.)
  • Show how much the claim does in detail
  • Use a question
  • How to
  • Use authority
  • Before – After
  • New, Now, announcing
  • Stress exclusivity
  • Turn the claim into a challenge for the reader (Does she or doesn’t she? Which?)
  • Use quotations
  • Symbolize the claim / find parallels
  • Use contradictions to common sense
  • Offer information
  • Give the problem / need a name
  • Warn about possible pitfalls if the reader doesn’t use the product
  • Break the claim into two sentences or repeat (part of) it
  • Compare your product to other usages (if you can count to …)
  • State the difference
  • Surprise the reader that former limitations that have now been overcome
  • Address people who can’t buy your product (If you already…)
  • Address the prospect directly
  • Dramatize how hard it was to produce the claim (When X did A we had to …)
  • Accuse the claim of being too good
  • Challenge the prospects present limiting beliefs
  • Turn the claim into a Q&A

The Art of Creative Planning

I: Word-Substitute technique: Use headline substitute words
II: Use formulas
III: Analytical approach (see above)

A man will not visualize future disasters occurring to himself, but he is perfectly capable of visualizing, and buying preventative from, the image of such future problems affecting others around him.

Inside your prospect’s mind — what makes people read, want, believe

I. Desires

expand, sharpen, channel them and give them a goal
Your prospect must want

II. Identifications

roles or traits the prospect wants
your product must represent

III. Beliefs

opinions, attitudes, prejudices, etc your prospect lives by
your product must fit

Intensification

  • fill out vaguest desires with concrete images
  • your writing the scripts of your prospect’s dreams (xI000)

When limited space:

  • Compression: boiling down into key words
  • The campaign: Repetition of key words with progression

I. Present the product / result directly by a thorough, completely detailed description of its effect

II. Put the product in action / describe what will happen to him

  • Let your reader visualize himself proving the performance of your product (provide a test) in the most specific and dramatic way

  • Extend the vision over a longer time horizon

  • Viewpoint from someone your reader can identify with (ordinary people, experts, celebs)

  • Use the disadvantages of the old product as compare it to the new one

Using SQLite

Using SQLite by Jay A. Kreibich

using-sqliteI’ve used SQLite in multiple projects and loved it. It’s fast enough for my applications: Appropriate Uses for SQLite.

Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound. SQLite has been demonstrated to work with 10 times that amount of traffic.

I first started using SQLite with Python because I thought there must be a better alternative to writing/reading a file for storage. That was SQLite which comes included with Python. Also I use SQLite basically for every web project I start – just because normally the project doesn’t scale over 50-100k hits, so I don’t really care about my DB as long as it works and is easy to set up.

I noticed in the last few months that I never really dove into databases. I want to change that and finally read a book from cover to cover about a database. I decided to choose SQLite just because I use it mainly. However, I still have one book in my reading list which goes into more depth regarding database design.

In-memory databases are often used to cache results pulled from a more traditional RDBMS server. An application may pull a subset of data from the remote database, place it into a temporary database, and then process multiple detailed searches and refinements against the local copy. This is particularly useful when processing type- ahead suggestions, or any other interactive element that requires very quick response times.

I never thought about doing this but I think it’s a nifty idea. You can easily create in-memory databases with SQLite and the interface can remain the same.

SQLite offers automatic indexing if you define a explicit primary key. You can still define other indexes for yourself.

I also learned that you can do the following:

Which allows you to copy a database or create a new one on the fly.

Also I learned a bit more about transactions. I only read about it especially in regarding to Clojure and STM funnily enough. But it was interesting to see that you can use savepoints, releases and different locking mechanism with SQLite.

There’s one chapter about nested structures in SQL. The author presents two possible approaches:
* Parent – Child relationship, basically [node_id, some attributes, parent_id] – easier to maintain, harder to traverse
* Otherwise using enumeration of depth-first traversal, basically [lower and upper bounds for each tree, which gets smaller in sub trees] – harder to maintain, easier to traverse

Plugins / Virtual table

The ability to write plugins rather easily is also one of SQLite special attributes. It allows you to write custom scalar and aggregate functions which can then be used in SELECT queries.

The idea of virtual tables are pretty cool. You can use SQLite with any format you want without importing the underlying data directly. For example, you could write a virtual table to handle logs or csv files.

The only problem I have is that it takes a while to write these and then you could either just dump them into the database or you would use a faster DB for bigger files. So I’m not quite sure when there’s a good application for that.

All in all, the book was an interesting read. I think the biggest payoff is for people working with SQLite and C.

Smalltalk, Objects, and Design

Smalltalk, Objects, and Design by Chamond Liu (1999)

smalltalk-objects-designAfter reading Extreme Programming explained I wanted to learn more about Smalltalk. You may ask why but the whole Agile / XP / OOP stuff grew out of Smalltalk. I heard of it before and knew that it works with a complete integrated development environment which can be saved as images. I think a great concept.

So I looked up some books and this one was recommended. Also I want to learn about some pure OOP. I know most of the basics but most of the time it felt clumsy. However, like often, great concepts get bend over time and you can really see their true nature. That also why I like older books on some topics.

I have a bit of a feeling that Smalltalk is to ‘enterprise’ software as lisp is to AI & co.

I will use Squeak which is a modern implementation of Smalltalk and backwards compatible. Also Squeak by Example is a pretty useful reference for figuring out how Squeak works – it’s also free.

Objects

  Humans as a metaphor for objects, e.g. ‘this account should be clever enough to check the balance’

I’m astonished by how good the book is written so far. Wow. Somehow I feel like I found some ancient tome which was hidden and I can learn from the ancient masters. Or I watched too much Skyrim the last week.

  • ‘Objects promote a common vocabulary’
  • ‘It is more important to concentrate on clear objects than on the side effects; unless the objects are clearly understood, they will be neither produce nor resuable.’
  • ‘class’ as a factory (not really a collection)
  • Subclasses have more qualities than the superclass

Smalltalk implementations work with a image, there’s an build-in object browser, a debugger, source control and a testing suite. Incredible if you think about how modern it was years ago. It really feels like the equivalent to lisp but in the enterprise field.

  • ‘no one can expect to produce resuable designs without considerable trial and error.’
  • Sarkela: ‘Not until you try to reuse do you discover what’s wrong.’

  • abstract class = class without any instances

  • abstract classes are a repository for expectations
  • pure virtual function (C++) / abstract method (Java) / subclassResponsibility (Smalltalk)

CRC Cards

  • Class-Responsibility-Collaboration Cards
  • Responsibility: What should instances of the class ought to be able to do?
  • collaboration: What class uses other classes?
  • ‘Better to have accomplish something than nothing at all’ – regarding over-engineering

When (not) to inherit

  • Example: Face has a Mouth has a Tongue
  • Face inherits from Mouth inherits from Tongue – can do more
  • Alternative: mix-ins, e.g. Face inherits from both Mouth and Tongue. Looks like inheritance but is a composition
  • ‘Inheriting, thereby tightly coupling two classes, is a long-term commitment’

Tradeoffs

  1. Code reduction
  2. Subversive superclass message
  3. Maintainance
  • ‘If in doubt, consider buying’
  • ‘In short, multiple inheritance adds power to a programming langauge, but at a cost of complexity.’

Use cases and dynamic relationship

  • ‘Testers test what software does’
  • ‘for many diagrams the chief benefit comes through the human exchange in which they were created’

Designing the UI

  • Designing UIs for games are easier because the underlying metaphor is clear
  • Designer has to have a (coherent) conceptual model

Polymorphism

  • Polymorphism = several classes with the same method evaluated at runtime
  • Substitutability = if it works  for a class it has to work for its subclass

Design patterns

I won’t list the pattern but rather my experience about them. I noticed that I could do a lot of these things easier using functional programming.

‘In the years to following publication of Alexander’s books on patterns [the originator of design patterns in architecture], he realized that patterns alone did not ensure that the results would have “the quality without name.”‘
So I decided to reread Norvig’s presentation about Design patterns. It’s mind-boggling how we ended up with C++ and Java.

Conclusion

Incredible book. I love it. I didn’t want to learn Smalltalk to write Smalltalk but to understand OOP better and especially the paradigm of ‘everything is an object’. This book worked great for that. The author writes superbly and is extremely humble. A great book.