Book Notes: The Art of Readable Code by Dustin Boswell

I highlight and take notes when I read nonfiction books. Once I finish a book, I format and edit my notes so that I can easily remind myself of what I learned without having to reread the book. These notes are not a substitute for reading the book, they only serve as a reminder of key concepts.

The fewer lines a variable is in scope, the shorter its name is allowed to be. Variables used in larger scopes must be less ambiguous so they are allowed to have longer names.

Don’t use project specific abbreviations — someone new to the project won’t know what they mean. “So our rule of thumb is: would a new teammate understand what the name means? If so, then it’s probably okay.”

“The clearest way to name a limit is to put max_ or min_ in front of the thing being limited.”

“In general, adding words like is, has, can, or should can make booleans more clear.”

“The best names are ones that can’t be misconstrued — the person reading your code will understand it the way you meant it, and no other way.”

“Everyone prefers to read code that’s aesthetically pleasing. By “formatting” your code in a consistent, meaningful way, you make it easier and faster to read.”

“The purpose of commenting is to help the reader know as much as the writer did.”

More comments aren’t necessarily better — the comments take up valuable screen real estate, so if there is a comment in the code “it better be worth it”.

“Don’t Comment Bad Names — Fix the Names Instead”

“Instead of minimizing the number of lines, a better metric is to minimize the time needed for someone to understand it.”

“The simplest way to break down an expression is to introduce an extra variable that captures a smaller subexpression. This extra variable is sometimes called an “explaining variable” because it helps explain what the subexpression means.”

“One technique [to clean up code] is to see if you can solve the problem the “opposite” way. Depending on the situation you’re in, this could mean iterating through arrays in reverse or filling in some data structure backward rather than forward.”

In general, keep scopes short and finish tasks as quickly as possible.

“The more places a variable is manipulated, the harder it is to reason about its current value.”

“The advice for this chapter is to aggressively identify and extract unrelated subproblems. Here’s what we mean: Look at a given function or block of code, and ask yourself, “What is the high-level goal of this code?” For each line of code, ask, “Is it working directly to that goal? Or is it solving an unrelated subproblem needed to meet it?” If enough lines are solving an unrelated subproblem, extract that code into a separate function.”

“Code that does multiple things at once is harder to understand. A single block of code might be initializing new objects, cleansing data, parsing inputs, and applying business logic, all at the same time.”

Break code up into small, easy to understand fragments. This makes understanding easier and reduces potential for bugs.

“do only one task at a time.”

“When explaining a complex idea to someone, it’s easy to confuse them with all the little details. It’s a valuable skill to be able to explain an idea “in plain English,” so that someone less knowledgeable than you can understand. It requires distilling an idea down to the most important concepts. Doing this not only helps the other person understand but also helps you think about your own ideas more clearly.”

“This chapter discussed the simple technique of describing your program in plain English and using that description to help you write more natural code. This technique is deceptively simple, but very powerful.”

“Knowing when not to code is possibly the most important skill a programmer can learn. Every line of code you write is a line that has to be tested and maintained. By reusing libraries or eliminating features, you can save time and keep your codebase lean and mean.”

“When you start a project, it’s natural to get excited and think of all the cool features you’ll want to implement. But programmers tend to overestimate how many features are truly essential to their project. A lot of features go unfinished or unused or just complicate the application.”

Thanks for reading. You might also enjoy following me on Twitter.

Want to learn even more SQL?

Sign up for my newsletter to receive weekly SQL tips!

My Year in Books 2016

Shocker: they aren’t all self-help or by Stephen King.

My GoodReads Year in Books

This year I read/listened to about 41 books (“about” because I didn’t finish a couple of them and because I still have a week and a half left to finish a couple more). I mostly read non-fiction, self-help, and horror fiction. Below are some of the more memorable reads from this year.

Code by Charles Petzold

Code: The Hidden Language of Computer Hardware and Software — Charles Petzold

If you have ever been interested in how the nuts and bolts (bits and bytes?) of computers work, this is the book to read.

Petzold starts out describing data transfer via tin cans and string and quickly moves you on to telegraphs, relays, binary logic gates, etc.. until the end of the book when you have “built” a model computer with full features like memory and an assembly language.

I think the book is targeted more towards a lay-person with interest in computers, but it is a fun read regardless of your technical ability as long as you are willing to think while you read.

Shenandoah by Sue Eisenfeld

Shenandoah: A Story of Conservation and Betrayal — Sue Eisenfeld

I’m not a huge fan of reading history unless I can directly relate to the subject matter. In this case, I read Eisenfeld’s Shenandoah right before our camping trip to Shenandoah this year.

What’s interesting about Shenandoah National Park is that unlike its cousin parks out in the western United States, Shenandoah became a national landmark long after the land area was already inhabited by people. This means that if you visit the park today, you can find remnants of roads, cabins, cemeteries, and orchards all throughout the park.

This book looks at the history of the people of Shenandoah before the land became a park and the lasting effects that it has had on the United States.

Never Split the Difference by Chris Voss

Never Split The Difference: Negotiating As If Your Life Depended On It — Chris Voss

Never Split the Difference is probably the best “self-help” book I read all year. You can find my notes on it in this previous post.

Voss was a master negotiator with the FBI, often helping negotiate for the lives of hostages. Each chapter provides an exciting story from his tenure with the FBI, along with the techniques he used to help direct the negotiation in his favor. He then goes into additional examples of how he has used these techniques when buying a new car, negotiating salary increases, and even how to get an unresponsive individual to respond to your emails.

Like any self-help book, it’s easy to read but more difficult to put into practice. I’ve already used many of the strategies Voss teaches in his book, and it is one of the most useful self-help books I’ve ever read.

Never Broken by Jewel

Never Broken: Songs Are Only Half The Story — Jewel

I am not a huge fan of Jewel’s music, nor am I a folk music listener in general. Before reading this book, the only things I knew about Jewel was that she’s an Alaskan singer/songwriter that had a few hits in the late 90s.

After reading the book however, I learned that she is a pretty incredible person: she dealt with abuse from her family, lived out of her car for a while, paid her way through music school, is a yodeler, and has spent a lot of time about thinking about life and philosophy (one of my favorite observations from her was that “hardwoods grow slowly”, referencing how growth needs to be a long-term goal).

Overall, Jewel’s Never Broken has many good lessons and interesting stories from her time growing up as a folk singer. After reading it, I have a much better appreciation for her music too.

Priceless by Robert K. Wittman

Priceless: How I Went Undercover to Rescue the World’s Stolen Treasures — Robert K. Wittman

Another book on my list from a former FBI agent (these FBI guys sure do have interesting stories to tell!).

Robert Wittman specialized in art crime during his FBI tenure, helping track down stolen masterpieces. Lots of art crime is difficult to prosecute because details are difficult to verify — a lot of the time Wittman’s stories come down to Ocean’s Eleven style sting operations with lots of planning, false identities, and large SWAT teams storming into hotel rooms to take down the criminal dealers and save the works of art.

Besides the crime thriller aspect of the stories, the book also provides good introductory background on art and the different types of crimes that get committed, from breaking into and stealing from museums to illegally selling Native American bald eagle feather headdresses, making the book both exciting and informative.

The Hidden Life of Trees by Peter Wohlleben

The Hidden Life Of Trees: What They Feel, How They Communicate — Peter Wohlleben

Peter Wohlleben is a German forester who has spent his life in nature, initially as part of the logging industry but more recently as a custodian of natural growing forests. His book The Hidden Life Of Trees discusses the importance of diversified (yet native) flora and how old-growth natural (not planted by humans) forests have amazing ecosystems.

Wohlleben anthropomorphizes trees to the point that you will feel bad the next time you accidentally snap off a twig, however the book is full of amazing information about how trees “communicate” with each other and how trees share some of the same “senses” that we humans have like the senses of sound and touch.

The Hidden Life of Trees is a light read that will make you appreciative of your surroundings the next time you are taking a hike in the woods.

Full Dark, No Stars by Stephen King

Full Dark, No Stars — Stephen King

I read six Stephen King books this year (still have quite the backlog to get through) and Full Dark was by far my favorite.

This book is a collection of four short stories. I only really liked three of the stories, but even so this is one of my favorite Stephen King books of all time.

Although I generally like all of King’s books, I think this one was especially great because it wasn’t focused on the psychic /other-worldly aspects like in many of his other stories — instead this book focuses on real-seeming characters with their real-seeming problems.

I think the relatability to the characters in this book is what makes the stories especially terrifying.

Thanks for reading. You might also enjoy following me on Twitter.

Want to learn even more SQL?

Sign up for my newsletter to receive weekly SQL tips!

Book Notes: Never Split the Difference by Chris Voss

I highlight and take notes when I read nonfiction books. Once I finish a book, I format and edit my notes so that I can easily remind myself of what I learned without having to reread the book. These notes are not a substitute for reading the book, they only serve as a reminder of key concepts.

Regardless of all of these techniques, you always have to stay emotionally cool or none of them will work. Let knee-jerk reactions pass and pause in silence instead.

“Contrary to popular opinion, listening is not a passive activity. It is the most active thing you can do.”

“Good negotiators, going in, know they have to be ready for possible surprises; great negotiators aim to use their skills to reveal the surprises they are certain exist.”

You have to stay open minded about a negotiation — best to “[hold] multiple hypotheses” to better understand where someone is coming from.

“Most people approach a negotiation so preoccupied by the arguments that support their position that they are unable to listen attentively.”

“The goal is to identify what your counterparts actually need…and get them feeling safe enough to talk and talk and talk some more about what they want.”

“There are essentially three voice tones available to negotiators: the late-night FM DJ voice, the positive/playful voice, and the direct or assertive voice.” You should use the positive/playful voice majority of the time. Rarely use the assertive. FM DJ voice is downward inflecting and says you are in control.

“While mirroring is most often associated with forms of nonverbal communication, especially body language, as negotiators a “mirror” focuses on the words and nothing else. Not the body language. Not the accent. Not the tone or delivery. Just the words.”

Paraphrasing what the other person just said is another form of mirroring.

“By repeating back what people say, you trigger this mirroring instinct and your counterpart will inevitably elaborate on what was just said and sustain the process of connecting.”

“The results were stunning: the average tip of the waiters who mirrored was 70 percent more than of those who used positive reinforcement.”

Label how someone is feeling — this will make them feel listened to as well as make them continue to talk — either because you labelled their emotions accurately or you purposefully did not.

“In every negotiation, in every agreement, the result comes from someone else’s decision. And sadly, if we believe that we can control or manage others’ decisions with compromise and logic, we’re leaving millions on the table.”

“Saying “No” gives the speaker the feeling of safety, security, and control. You use a question that prompts a “No” answer, and your counterpart feels that by turning you down he has proved that he’s in the driver’s seat.”

“Gun for a “Yes” straight off the bat, though, and your counterpart gets defensive, wary, and skittish”

“That’s why I tell my students that, if you’re trying to sell something, don’t start with “Do you have a few minutes to talk?” Instead ask, “Is now a bad time to talk?” Either you get “Yes, it is a bad time” followed by a good time or a request to go away, or you get “No, it’s not” and total focus.”

“Sometimes, if you’re talking to somebody who is just not listening, the only way you can crack their cranium is to antagonize them into “No.” One great way to do this is to mislabel one of the other party’s emotions or desires.”

“Another way to force “No” in a negotiation is to ask the other party what they don’t want. “Let’s talk about what you would say ‘No’ to,””

The best way to get a response to an email — send a question that you know the response will be no: “Have you given up on this project?”

Don’t strive for “yes” in negotiations — yes means someone is agreeing with you just to finish negotiating. Strive for “that’s right”, where someone is truly agreeing with you.

Use pauses to encourage people to keep talking. Can also use phrases like “Yes,” “OK,” “Uh-huh,” or “I see”.

Use paraphrasing + labeling to try and get a “that’s right”.

NEVER compromise/split the difference: “To make my point on compromise, let me paint you an example: A woman wants her husband to wear black shoes with his suit. But her husband doesn’t want to; he prefers brown shoes. So what do they do? They compromise, they meet halfway. And, you guessed it, he wears one black and one brown shoe. Is this the best outcome? No! In fact, that’s the worst possible outcome. Either of the two other outcomes — black or brown — would be better than the compromise. Next time you want to compromise, remind yourself of those mismatched shoes.”

“We don’t compromise because it’s right; we compromise because it is easy and because it saves face. We compromise in order to say that at least we got half the pie. Distilled to its essence, we compromise to be safe. Most people in a negotiation are driven by fear or by the desire to avoid pain. Too few are driven by their actual goals.”

Don’t think that any negotiation has a deadline — rarely are deadlines hard set.

Acknowledge the other person’s fears all up front: “”I got a lousy proposition for you,” I said, and paused until each asked me to go on. “By the time we get off the phone, you’re going to think I’m a lousy businessman. You’re going to think I can’t budget or plan. You’re going to think Chris Voss is a big talker. His first big project ever out of the FBI, he screws it up completely. He doesn’t know how to run an operation. And he might even have lied to me.””

Make them feel like they have something to lose: ““Still, I wanted to bring this opportunity to you before I took it to someone else,” I said. Suddenly, their call wasn’t about being cut from $2,000 to $500 but how not to lose $500 to some other guy.”

“Instead of saying, “I’m worth $110,000,” Jerry might have said, “At top places like X Corp., people in this job get between $130,000 and $170,000.””

If you can’t negotiate money, start negotiation other things: vacation, work hours, etc…

When talking numbers, use precise ones — $102,378 instead of $100,000 — it makes it seem like you’ve done a calculation.

If negotiating salary, establish success criteria — next time you will then able to negotiate for an even higher salary when you prove that you did well.

Calibrated questions: “queries that the other side can respond to but that have no fixed answers. It buys you time. It gives your counterpart the illusion of control — they are the one with the answers and power after all — and it does all that without giving them any idea of how constrained they are by it.”

Most of the time, calibrated questions use “how”, “what”, and sometimes “why”.

“Another simple rule is, when you are verbally assaulted, do not counterattack. Instead, disarm your counterpart by asking a calibrated question.”

“When someone’s tone of voice or body language does not align with the meaning of the words they say, use labels to discover the source of the incongruence”

Try to get the other person to commit to you three times. After the first commitment, try summarizing (paraphrase + label) to get the second commitment, and then try calibrated (“how”,”what”) questions about success criteria to get the third commitment.

The first time they agree to something or give you a commitment, that’s №1. For №2 you might label or summarize what they said so they answer, “That’s right.” And №3 could be a calibrated “How” or “What” question about implementation that asks them to explain what will constitute success, something like “What do we do if we get off track?”

“At the front counter the young lady asked me if I wanted to join their frequent buyer program. I asked her if I got a discount for joining and she said, “No.” So I decided to try another angle. I said in a friendly manner, “My name is Chris. What’s the Chris discount?” She looked from the register, met my eyes, and gave a little laugh. “I’ll have to ask my manager, Kathy,” she said and turned to the woman who’d been standing next to her. Kathy, who’d heard the whole exchange, said, “The best I can do is ten percent.””

If you are pushed to go first to name a price, allude to what some other high-end client would pay “Harvard business school would pay $20,000 for my services”.

The Ackerman model of bargaining: 1. Set your goal price 2. Make your first offer 65% of goal 3. use empathy and different ways of saying no until the other side counters and increase your offer each time to 85%, 95%, and eventually 100% of goal 4. make the final amount not-round $23,768 instead of $24,000 — maybe the non-round figure is all you have in the bank! 5. At the final offer, offer a non-monetary item to prove you are at your limit.

“A more subtle technique is to label your negative leverage and thereby make it clear without attacking. Sentences like “It seems like you strongly value the fact that you’ve always paid on time” or “It seems like you don’t care what position you are leaving me in” can really open up the negotiation process.”

“But the moment when we’re most ready to throw our hands up and declare “They’re crazy!” is often the best moment for discovering Black Swans that transform a negotiation. It is when we hear or see something that doesn’t make sense — something “crazy” — that a crucial fork in the road is presented: push forward, even more forcefully, into that which we initially can’t process; or take the other path, the one to guaranteed failure, in which we tell ourselves that negotiating was useless anyway.”

Thanks for reading. You might also enjoy following me on Twitter.

Want to learn even more SQL?

Sign up for my newsletter to receive weekly SQL tips!