How do I make protocol methods optional in Objective-C?

Imagine you have a protocol in Obective-C.

@protocol ABCRocket

- (void)start;


What if you want to make some properties or methods optional? You can use the optional keyword.

@protocol ABCRocket

- (void)start; // Required


- (double)speed; // Optional


Not all objects to implement the protocol will have the -speed method. Trying to call -speed on those objects will crash the program, so we should check if the object implements -speed first.

if ([foo respondsToSelector:@selector(speed)]) {
      // Foo has the -speed method. Do something awesome!

It’s simple and easy.

Posted in Software | Tagged , | Leave a comment

A Quiz to Practice Big O for a Software Interview

Estimating big O is a crucial part of software engineering interviews. If you can write decent code, but can’t analyze big O, interviewers will mentally subtract points from your score.

Tips for analyzing Big O

  • Consider the worst case
  • Think about when n is very large. 2^n dwarfs O(n^2)
  • Drop constants (e.g. O(2n) -> O(n))

Quick Test

Here’s a quick test (answers at the bottom). For each question, write down the big O runtime of run(…).

Question 1

public int run(int[] input) {
  if (input.length < 1000) {
    return -1;
  for (i = 0; i < 1000; ++i) {
    input[i] = input[i] + 1;
  return 0;

Question 2

public void run(int[] input) {
  for (i = 0; i < input.length; ++i) {
    input[i] = input[i] + 1;

Question 3

public void run(int[] input) {
  for (i = 0; i < input.length; i += 2) {
    input[i] = input[i] + 2;

Question 4

public int run(int[][] input) {
  int sum = 0;
  for (i = 0; i < input.length; ++i) {
    for (j = 0; j < input[i].length; ++j) {
      sum += input[i][j];
  return sum;

Question 5

// Return a random number between 0 and m-1
public int random(int m); // O(1)

public int run(int[] input, int k) {
  int index = random(input.length);
  input[index] = input[0];
  if (k < 0) {
    return 1;
  return run(input, k - 1) + 1;

Question 6

// Return a random number between 0 and m-1
public int random(int m); // O(1)

public int run(int[] input) {
  return inner(input, input.length - 1);

public int inner(int[] input, int i) {
  int foo = random(10);
  input[i] += foo;
  if (i < 0) {
    return 1;
  return inner(input, i - 1) + inner(input, i - 2) + 1;

Question 7

// Return a random number between 0 and m-1
public int random(int m); // O(1)

public int run(int n) {
  int[] input = new int[n]; // Initialized to all 0s
  return inner(input, n - 1);

public int inner(int[] input, int i) {
  if (i < 0) {
    return 0;
  } else if (input[i] > 0) {
    return input[i];
  input[i] = random(10);
  return inner(input, i - 1) + inner(input, i - 2);

The answers are below this photo of young Alan Turing.

Photo of Alan Turing


  1. O(1). When n is large, the runtime is the same as when n is small (max 1000 iterations).
  2. O(n). Directly based on input.length
  3. O(n). Based on input.length. O(n/2) is equivalent to O(n)
  4. O(n^2). The outer loop is executed n times. What does each iteration of the outer loop do? It executes the inner loop n times.
  5. O(k). You could also say “O(n), where n is k”. The important thing is that the number of times the function is called is based on k. Executing one stack frame of run(…) is constant time.
  6. O(2^n). The runtime is like the number of nodes in a binary tree with n levels. The recursive function causes big O to grow exponentially. The branching factor is 2 because each stack frame calls inner(…) twice.
  7. O(n). input acts as a cache that limits the number of calls to inner(…). The recursive function only branches when input[i] <= 0. Therefore, the number of function calls is proportional to input’s length.

How many did you get right?

0-4 – I recommend brushing up on the basics of big O.

5-6 – You’re on a solid path. Keep practicing so you don’t trip up in an interview.

7 – Perfect score! Now’s the time to level up your practice with other data structures like trees and graphs.

Posted in Software | Tagged , | Leave a comment

A Small Note After George Floyd

On May 25, an African American man named George Floyd was murdered by police officers. It was a tragedy, and not the first.

I haven’t focused on this blog in recent months. After George Floyd, I wasn’t sure what to write. Bragging about how “woke” you are feels off-putting to me, and I still have much to learn. So I’ll say this:

To the African Americans reading this: I stand with you.

To the other people reading this: Read about the experiences of African Americans, both historically and in recent years. If you find yourself dismissing their stories, ask yourself why.

At this moment, I feel like the best thing I can do is to continually listen, learn, support my friends and colleagues, and translate these ideas into long-term action. Posting to social media feels like virtue signaling. The real heroes were the people working towards justice before it was “popular”. And while talking about race is often uncomfortable, that’s OK. Being uncomfortable is necessary for growth.

Posted in Other | Tagged | Leave a comment

The Battle of the Burgers: Food Chain Magnate

In the spring of 1955, the county government gave me a small loan so that I could open a diner in our little town. But I wasn’t the only one—three other aspiring food chain magnates also started restaurants, and the battle of the burgers ensued.

I started off by hiring a recruiting girl and an errand boy from the local high school. Together, we slowly built a team, collected bottled drinks from wholesalers, and ran a small marketing campaign to attract our first customers. In the early days, we didn’t have a burger cook, so we could only sell beer, cola, and lemonade! But it was enough to scrape by.

In the second month, I decided to make bigger investments in the business. I reorganized the management trainees and sent some of the staff to take classes and improve their skills—while in class, they weren’t earning money for the restaurant.

Then, we launched a bigger marketing campaign enticing residents of the town to buy lots of juicy burgers. Little did we know that this would be our first battle.

On the day after the marketing campaign, we expected to take in a boatload of money. If we didn’t, I would have to fire some of the staff because our cash on hand was approaching zero. We were selling burgers for 10 bucks each—a healthy margin—and there were three big neighborhoods right next to the diner. I was confident that they would all come to the closest restaurant–ours.

Instead, we watched resident after resident drive past our little diner. Where were they going? Turns out, a competing restaurant was selling burgers for only seven dollars! I was thrown into a state of panic and began to think about how I would break the news to the staff. Our restaurant would soon be closed.

But in the last hour of the dinner rush, a group of customers appeared on the horizon. The rival restaurant had run out of burgers, and the last group of customers had come to our diner. We were saved and scraped through the month with just five dollars standing between our existence and bankruptcy.

Sensing the big burger opportunity, another restaurant owner opened a new location right across the street. I learned from the competition and reduced *our* prices to $7 per burger. So our diner drew all the customers from the area, but we were making less profit than before.

After that, the competition grew dirty. We degenerated into a price war. Every month, we did another reorg and lowered our prices by one or two dollars, until we were selling burgers for only three dollars each. The diner was getting customers, yes, but we could barely stay afloat. Our only saving grace during this time was that we hired our first CFO. He found several accounting errors and raised our net profits by 50%.

Suddenly, a lemonade craze swept through the town, fueled by the singer John Lemon, whose music played nonstop on the radio. Almost everyone wanted lemonade with their orders. The three restaurants that sold lemonade at $10 or less instantly ran out of stock. My dear errand boy, who I hired early on, couldn’t keep up with demand.

It was nice that we got to sell our current stock for a small profit, but the biggest winner had hoarded lemonade earlier. When our supply ran out, he began selling lemonade at $20, and the customers drank it up. He was rich! And we were barely profitable.
After that last crazy month, I decided to retire from the restaurant business.

The final scores:

$900 Lemonade Baron

$230 Opened multiple locations

$190 Me

$90 Priced out of business

In short, Food Chain Magnate is a harsh and unforgiving game. If you want a heavyweight game with no randomness, it gives you that exceptionally well.

Posted in Other | Tagged , | Leave a comment

How to Structure Your Presentation to be Clear and Convincing

Have you ever sat in a meeting where you felt bored?

You had to endure a presentation where the speaker read several paragraphs per slide, all in monotone.

Some rando in the room kept asking useless questions, prolonging the presentation.

You felt like you didn’t need to be there after the first 5 minutes.

This article is about how you can give awesome presentations, not awful ones. When you implement the tactics in this article, your will not feel like they want to leave. You’re going to learn how to craft an exceptional presentation that makes people remember you in a good way.

You’re going to learn how to engage the audience. You’ll learn how to make your message stick. And you’ll learn how to make your presentation clear and convincing.

Begin with the End in Mind

Ok, so you’re going to give a presentation. First, think about the why you’re giving this presentation.

  • Are you trying to get approval for an engineering design?
  • Are you gathering support from non-technical people for a new project?
  • Are you looking to get promoted or get a raise?
  • Are you speaking publicly, perhaps at a conference, and want to inform other engineers and increase your notoriety?
  • Are you pitching to investors for your startup?

Of course, you should also consider who your audience is. You’ll have different material for engineers at your company versus a general audience at a TED talk.

When you begin with the end in mind [1], you realize the stuff you can cut out. You see the people you need to invite (and the ones you don’t).

Sometimes, you might realize you don’t need a presentation or meeting at all. And that’s OK! Congratulations, you just saved your company $500.

No matter what your goal is, your job will be easier if you create a friendly environment. Give the audience a reason to listen to you, present your information clearly, and highlight how your ideas benefit them. Then they will be happy to make a decision that benefits everyone.

Your Main Message

Now that you have a goal, decide 1-3 main messages you want the audience to remember. The fewer, the better.

For example, imagine Steve is a software engineer responsible for his company’s iPhone app. He wants other engineers and UX designers to remember his app when creating new designs.

He decides on two main messages of his presentation:

  • “Design with iOS users in mind”
  • “Test end to end on an iOS device before launching”

As Steve crafts his presentation, the content will be focused around these two messages. He won’t spend time going off onto tangents, and he can remind others if their questions are sufficiently off-topic. As he repeats his messages, he also reminds the audience how these ideas will benefit everyone. Better designs, fewer problems, happier users–everyone wins.

By the way, if you’re doing a design review, it’s best to provide the design as a separate document and circulate it beforehand. If your slides are more like an essay, and all you do is read from them, skip the presentation and write a document instead.

Structure for Clarity

Now that you have your main messages, it’s time to design your presentation.

Most engineers use Google Slides, Microsoft PowerPoint, or another piece of software for creating slides.

Slides should be a complement to your presentation, not the focus.

You want the attention to be on you, not the screen. As soon as people concentrate on the screen, you lose their attention.

Less attention -> more dumb questions

Now that that’s out of the way, there’s no single right way to structure a presentation. One possibility is:

  • Intro
  • Section 1
  • Section 2
  • Section 3
  • Conclusion

Sounds pretty simple, right? “Chunking” your information into sections helps people remember it. Better than slapping some random info on your slides and meandering through your topic in no apparent order.

Another powerful structure follows a story. You can talk about a problem, and how your design solves it at each step, resulting in happy users. Just like the Hero’s Journey.

  • Intro
  • Background and problem begins (Act 1)
  • Problem gets more challenging (Act 2)
  • Solution (your awesome proposal, Act 2-3)
  • Conclusion

People love stories. Stories are memorable and give meaning to otherwise meaningless events.

If you structure your presentation like a story, make sure it has:

  • Characters (Engineers, customers, components of a system)
  • A challenge (a customer problem, a technical challenge)
  • A climax (how you solved or will solve the problem, often dramatic)
  • A resolution (how the characters improved after solving the problem)


The intro section should be short. Maybe 1-3 slides.

The first slide has the presentation’s title and your name. Super simple. You can create a crazy, memorable design, but that’s not necessary for more informal talks.

The next 1-2 slides are optional. They might have the objectives and key messages. But maybe not. Why?

If you’re goal is to persuade people, don’t explicitly state that. Your job is to create a friendly atmosphere where they can willingly understand your information. By showing them how they’ll benefit from your proposal, they will happily make the decision on their own. Your objective in this case is to provide information, and you can have a single-slide intro.

You can also do a longer intro where you provide background information about your topic. For Steve the software engineer, he might start with a few slides explaining how the company’s iOS app is used. Of course, that might be enough content for a longer section.

Main Sections

This is the meat of your presentation (sorry, vegans).

At the start of every section, you can optionally put a slide that has nothing except a title for the section. Sections don’t need to be formal, but you as the presenter know the key points you want to make in each part.

As you create your slides, keep hinting or explicitly stating your main messages. Use images to highlight key points. It’s OK to have slides that have 1 sentence on them. In fact, this is an excellent way to emphasize your main messages.

Make things easy to understand. I like to keep slides simple, almost minimalist. The clearer and concise you can be, the easier your info is to understand.

If you’re telling a story (or multiple stories), let your voice take the lead. Tie the story back to your main messages. Use your body to emphasize the story, and point to the slides as a supplement. The audience should not be reading the story. They should be listening to it, and watching it.

In the main sections, you can add things like AutoCAD drawings and flowcharts. Depending on your purpose and audience, you might go deeper into the technical details. Keep relating why your info matters to the audience.

When there are non-technical people in the room, try to take as little time as possible on the highly technical details. People in sales and marketing don’t care how you solved a problem. They care about the results. They care about why your solution will help get more customers. Talk about that and they will gladly listen.

For example, Steve the software engineer is talking to a group of UX designers. The UX designers don’t write code, but they do want to help create a great product. Steve takes screenshots of the app and puts them in the slides. Some slides have nothing but a screenshot. He talks about design problems that the team had, and briefly how he helped solved them. Steve uses the pictures and diagrams to answer questions. He avoids posting code snippets, since they wouldn’t help get his message across.

Also, make sure your graphs are easy to interpret. Good graphs make objectively show how fantastic you are. Bad ones confuse the audience.

Should I add jokes?

Humor is great! Get your audience in a good mood and they’ll like you more for it. They’ll pay more attention. They’ll remember your message.

People make decisions with their heart, then justify it with their brain. If you can get someone to like you, you can get them to agree with you. No matter how logical someone acts, they’re still human.

If you can add a joke into your presentation and it sounds natural, do it! Most (but not all) environments would welcome a little humor. Don’t worry about seeming immature.

And finally, don’t overdo your humor, and don’t force it. This is a presentation, not a standup routine.

Making Slides Not Suck

Creating slides is a topic worthy of a whole other article. The main idea is don’t distract the audience.

Remember what I said about slides earlier? Slides are a compliment to your presentation. Your physical body and voice should drive the meeting, not your slides.

First, put as few words as possible on each slide. One sentence per slide is enough. Have a bulleted list, and make it quick to scan. Eyes are drawn to text, and you don’t want the audience reading more than listening.

Second, use images. Images can be used to highlight key points. don’t use animated gifs, or anything that would be too distracting. Having 0 or 1 image per slide is usually enough.

Your slides don’t need to look perfect, but they should be easy to understand. Don’t clutter your slides with tons of information. Break your information into multiple slides. And like I said, try to get down to one sentence per slide.


In your conclusion, remind your audience about your main messages. This is a very short section–3 slides is usually enough.

Recap your main messages. Remind the audience how they can benefit by remembering your info or following your recommendation.

If you have a call to action, put it here. Include your contact information if necessary. Finally, open the meeting up for questions.


Additionally, you can add an appendix to your slides after the conclusion. This is where you would put material that would answer common questions following your main presentation. For example, Steve the software engineer might add a graph about customer behaviors.

You can also add material that doesn’t fit elsewhere the presentation.

As you create your slides, practice speaking your presentation and time yourself. Make sure you don’t go over your allotted time. Give your voice energy–don’t speak in monotone–and use hand gestures. I’ll say it one more time: slides are a compliment to your presentation, not the focus.

Putting effort into your presentation will make the audience much more engaged. Soon, you’ll be having people come up to you afterwards complimenting you on what a great presentation you gave.

To learn more secrets of giving awesome presentations, subscribe to the blog. Stay tuned for more articles about:

  • How to speak to keep their attention
  • How to make slides not suck
  • How to stay on track (and within your time limit)

If you see “You are following this blog” — great! You’re already subscribed.

Emily Williams helped inspire some of the material.

[1] For more on this idea, see Stephen Covey’s book, The 7 Habits of Highly Effective People

Posted in Uncategorized | Tagged , , | 1 Comment