How to keep you tests non-flakey

Leave a comment

Something I am always striving to avoid in my unit tests is flakiness. That’s why when I needed to deal with a UINavigation bar in the previous version of iMessage, I ended up writing a method that looked like this:

Screen Shot 2017-09-13 at 10.19.35 AM.png

This method puts the responsibility on the client to figure out the runtime of the device, so this method is relatively straight forward and doesn’t suffer from any of the shenanigans that come with embedding lines of code like this, in classes you want to test.

Screen Shot 2017-09-13 at 10.25.54 AM.png

The power of overriding – or always asking for more

A colleague and I in a code review where debating the merits of this approach. The ugliness of exposing these details versus the desire to keep the code clean and testable. Together we came upon the following solution.

Make a public API that is easy and another one that is testable. Then have the public API call the more testable one

So that’s what we did.

Screen Shot 2017-09-13 at 10.30.17 AM.png

The lesson for me here is to always remember you can do anything with software. Got an interface you don’t like? Create a new one. Software is the one disciple where you can have your cake and eat it to. Just create whatever you need, and implement behind the scenes however your like.

Advertisements

Computer History Museum Tour

Leave a comment

This weekend, being my last in San Francisco, I headed to what is probably one of my favorite museums in the world. The Computer History Museum in Palo Alto California.

Screen Shot 2017-09-09 at 10.55.01 AM.png

The Trillion Dollar Startup

It all started with Fairchild semi-conductor. Robert Noyce’s conceiving of the integrated circuit, and Gordon Moore’s ‘law’ encouraged integrated circuit advancements which spawned not only a whole new industry, but a whole new way of working.

Openness over hierarchy, meritocracy, flat organizational structures, and management by walking around are still very much alive and well, and are still alive and well in the culture of Silicon Valley.

Screen Shot 2017-09-09 at 10.55.09 AM.png

Screen Shot 2017-09-09 at 10.55.16 AM.png

Screen Shot 2017-09-09 at 10.55.23 AM.png

Early computers

The earliest computers where calculators and slide rules.

Screen Shot 2017-09-09 at 11.26.02 AM.png

Here is a slide rule wheel created by Elizur Wright for doing insurance calculations in 1869. He is known as the father of Life Insurance.

Screen Shot 2017-09-09 at 11.26.14 AM.png

This little contraption, known as Napier’s Bones was a multiplication aid Europeans used in 1617.

Mechanical Genius

Something I really love about museums are the stories. The people who built and created incredible things that most of us will probably never hear of.

Take Curt Herzstark for example. Here he is, leading a nice quiet life in 1942 before being sent off to a Nazi concentration camp.

Screen Shot 2017-09-09 at 11.35.56 AM.png

While in the concentration camp, Curt refines he per-war design for a calculator. Only this isn’t an electronic calculator. It’s mechanical. The worlds smallest, four function calculator ever built.

Screen Shot 2017-09-09 at 11.36.06 AM.png

And it was used in the 50s and 60s by sports cars enthusiasts because of it’s durability, simplicity, and ease of use. It is still studied today as a work of art.

Punch cards

No doubt you’ve hard of punch cards and how early computers used cards to input programs and store data. Everything from early loom machines, to concensus machines for US elections. It was all punch cards. And no one dominated that space like IBM.

Screen Shot 2017-09-09 at 11.49.05 AM.png

IBM didn’t just own punch cards. They dominated it and create a new way of life for the computer corporate business man.

Uniforms, rally songs, and it was all lead by Thomas Watson, Sr in 1914. Watson lead IBM for 42 years. Through two World Wars, the depression, and created a culture, life style, and loyalty program never seen before in corporate culture.

He wanted his sales mean to be intelligent, morally fit individuals who dressed a certain way, looked a certain way, and thought a certain way. Rallies, speeches, songs, it was all a part of the culture. And IBM dominated computer for much of the 20th century.

Analog computing

Believe it or not there was a time when not all computers were digital. Early artillery computers solving complicated differential equations were analog.

Analog means instead of discrete 1’s and 0’s being sent around a computer, you used voltages and currents.

For example, in 1930, Vannevar Bush, an electrical engineering professors at MIT, created a device that was hailed as ‘the most important computer in existence in the United States’. Bush’s differential analyzer calculated artillery tables based on 6th order differential equations. Analog computers were really good at this.

And it was innovations like this, along with Bell Labs engineer David Parkinson, who one night in 1940 dreamt of a analog voltage amplifier, that helped destroy 76% of German V-1 Buzz Bombs.

Eniac

Screen Shot 2017-09-09 at 1.55.29 PM.png

In WW2 the U.S. Army was sending a lot of material to England. But the one thing they lacked were accurate artillery tables. Enter the Eniac. Started in 1942, it never was actually used in WW2 (it didn’t finish until 1945). But it, and all it’s tubes (18,000) did help out in the Manhattan project and other projects after the war.

Fun fact: Eniac was not binary. It was base 10. That means instead of story memory as a 1 or 0, it stored it as a 0,1,2,3,4,5,6,7,9. Neat!

Univac

The first computer to really ‘make it’ was the Univac. It was a general purpose computer, created by some of the same people who created the Eniac, and it’s claim to frame was it successfully predicted the result of a US election. And that Eisenhower would win.

Screen Shot 2017-09-09 at 1.55.47 PM.png

Within six years, Univac went on to sell 46 machines. Each costing $1M dollars. With the last going into retirement in 1970.

Hey mom. Remember when I asked for 4MB of memory for my birthday when I was 18? Thank fully I wasnt’ around when the Univac was popular. Here is the memory unit for this computer.

Screen Shot 2017-09-09 at 1.55.55 PM.png

I don’t fully understand how it works, but it uses mercury and received data as mercury waves.

Screen Shot 2017-09-09 at 2.00.25 PM.png

Cray super computers

Not many people have heard of Seymour Cray, but he is hero of mine. The father of super computing, Seymour Cray, revolutionized high speed computing for over 40 years, and he did it in a way any engineer would admire.

Screen Shot 2017-09-09 at 2.32.59 PM.png

When management got in the way, he packed up and moved his small team out into the woods, 100s of miles away from management, and did amazing things.

The biggest break for Cray came in 1976 with the Cray-1. Just look at this machine. All hand wired. Super freon cooled. Each machine costed $1M. Cray need to sell 10 to survive. They sold over 100. It was the fastest computer in the world, designed in a unique circular shape to account for the speed of light with no signal having to travel more than 3″.

Screen Shot 2017-09-09 at 2.33.05 PM.png

A little a head of it’s time

See if you can guess what this is.

Screen Shot 2017-09-09 at 2.48.57 PM.png

This was Honeywell’s answer to the kitchen recipe book. A full on kitchen computer that stored recipes. In 1969, in the Neiman-Marcus catalog, this home kitchen computer could be yours for the cool price of $10,600. Apron and two week programming course included.

Not surprisingly, non of these were sold.

Snatching defeat from the jaws of victory

You probably heard the story where Steve Jobs got his ideas for the Mac from a demo at Xerox. This is the computer that he say. The Alto.

The Alto was light years ahead of it’s time. WSIWIG editing. Object Oriented programming. Network computing. Mouse. The Alto had it all.

Note the orientation of the monitor. It goes up and down length wise, not across like most monitors today. That’s because the designed wanted to replicate the size and orientation of 8.5×11″ paper. It did’t stick. But it sure should how deeply they thought about the computer experience.

Screen Shot 2017-09-09 at 3.27.55 PM.png

The Alto is considered one of the greatest blunders in corporate history. Why invest in a technology that discourages photocopying went the thinking at the time.

Computers in Music

This was an interesting section on music. It showed the evolution gramaphones, to records, to 8-tracks, walkman, early mp3 players, and then ultimately streaming.

Screen Shot 2017-09-09 at 11.08.52 AM.png

Screen Shot 2017-09-09 at 11.08.59 AM.png

Screen Shot 2017-09-09 at 11.09.06 AM.png

And I can tell you having worked at Spotify, the innovation in music has only just begun.

Other notables

This was my first computer. The good’ol Apple ][e.

Screen Shot 2017-09-09 at 3.44.38 PM.png

Here’s the Apple Mac (based on the ideas Steve got from the Alto).

Screen Shot 2017-09-09 at 3.44.50 PM.png

And this was a neat find. An actual Pixar hardware computer.

Screen Shot 2017-09-09 at 3.44.58 PM.png

Not enough time

This museum is awesome. I have only scratched the surface here and there is simply note enough time. There are tours. Demos of mainframews, Spacewares on PDP machines, gaming. And you can talk to actual engineers who worked on this things. It’s a wonderful place.

And if you are at all interested in technology, history, and the some of the genius and work that our world depends on, this is the place to be.

The computer history museum is one of those stars in the lower right hand corner of the map in Palo Alto.

Screen Shot 2017-09-09 at 3.50.07 PM.png

The other dot is Steve Jobs house which I also visited this morning. It looks like this.

Screen Shot 2017-09-09 at 3.52.15 PM.png

Elon Musk Interview Questions

Leave a comment

Found these questions quite good for what Elon Musk looks for when interviewing:

Gut feel when hiring.

  1. Tell me the story of your life
  • what decisions did you made a long the way and why you made them
  1. Tell me about the most difficult problems you worked on and how you solved them.
  • the people that really solved the problem, they know exactly how they solved the problem. They know the little details.
  • and the people who didn’t can only go one level, and then they get stuck

Biggest challenge in life?
– how to spend time…
– making sure you have corrective feedback loop and maintaining over time even when people tell you what you want to hear

You can hear these at the end of this video (~30min mark)

Why I don’t get into arguments the way I used to

Leave a comment

 

  • Everything is opinion
  • I believe if I had the same experiences as others I would most likely share a similar opinion
  • And for every strongly held belief an example or counterexample can often be given
  • Not all advice holds in all scenarios
  • And I also have seen this happen in myself.
  • My own thoughts and beliefs have changed over time. So don’t get too excited or surprised when people think differently than you. We need all opinions. Young and old.
  • So when faced with a hostile of different point of view I don’t get as excited as I used to
  • Instead I think
    • There is probably some merit to what they believe
    • It would be to my advantage to discover what it is
    • And then after I can judge and decide whether I share that belief or not
    • And then, only then, if the other party is interested will I share my thoughts back

 

Setting end date instead of computing

Leave a comment

Instead of doing a lot of date and time comparisons, just set the end date of the thing you want.

For example instead of checking to see if a token expires in an hour like this

- (BOOL)hasExpired
{
    if (self.tokenExpirationDate == nil) {
        return YES;
    }
    return [SPTMessageClockUtils oneHourHasPassedFrom:self.tokenExpirationDate];
}

Just set the expiration date on the object itself, and see if it is later than now like this.

- (BOOL)isValid
{
	return ([(NSDate *)[NSDate date] compare:self.expirationDate] == NSOrderedAscending);
}

This simplifies the computing and requires less coding to account for time checks and such.

%d bloggers like this: