Skip to main content

App Inventor Exercise

App Inventor Team​

Ten people, including Prof. Spertus, standing in front of an Android sculpture at Google. An inset shows the cover of the book App Inventor 2

Sprites​

Animated gif of the 'Frogger' game, in which a frog has to cross a stream and highway to get to safety

ImageSprite​

Blocks showing ImageSprite method calls and a cute graphic of a mole

Think, Pair, Share: Ball​

How would you implement Ball, which is also a type of sprite?

How should the type hierarchy be organized?

What code from ImageSprite can be reused?

One Solution​

What's wrong with this?

My Most Embarrassing Mistakes as a Programmer​

Screenshot of post in the Stack Overflow blog entitled 'My Most Embarrassing Mistakes as a Programmer (so far)`.
Further text: 'As a computer science professor, I encourage students to learn from mistakes, whether their own, mine, or famous examples. I feel it’s time to shine a light on my own mistakes to keep myself humble and in the hope that someone can learn from them.'

Source: The Overflow (Stack Overflow Blog)

A Reasonable Decision​

The main difference between a ball and an image sprite is what is drawn: a filled-in circle or a bitmap. Since I implemented image sprites first, it was natural to make the x- and y-coordinates specify the upper-left corner of where the image was placed on the enclosing canvas.

Image showing (x,y) at the top-left corner of a cute mole graphic

The image sprite's x- and y-coordinates specify its upper left corner. This is a reasonable design decision.

A Terrible Decision​

Once I got sprites working, I realized that it would be simple to implement a ball object with very little code. The problem was that I did so in the simplest way (from the point of view of the implementer): having the x- and y-coordinates specify the upper-left corner of the bounding box containing the ball.

Image showing (x,y) at the top-left corner of a circle

The ball’s x- and y-coordinates specify the upper left corner of its bounding box. This is a terrible design decision.

The Right Decision​

What I should have done is have the x- and y-coordinates specify the center of the circle, as is done in every single math book and everywhere else circles are specified.

Image showing (x,y) at the corner of a circle

The ball’s x- and y-coordinates specify its center. This is the right design decision.

Aftermath​

Millions of users had to do extra work in every app they created that used the Ball component.

I patched the problem 10 years later (2019).

I couldn't fully fix it because APIs are forever (Josh Bloch).

We had to add a property OriginAtCenter, which defaults to false in old programs and to true going forward.

Users will be right to wonder why on earth the origin would ever be anywhere but the center.

Answer: Back in 2009, one programmer was lazy and didn't create the obvious API.

What is the Moral of the Story?​

Poll Everywhere QR Code or Logo

Some Morals​

Put some thought into design and implementation.

Try programming to the API before implementing/freezing it.

Do what's best for the users, not the programmer.

Meta-Morals​

Programmers make mistakes every day, big and little.

Follow processes to minimize mistakes.

Learn to recognize and laugh about your mistakes.

Further Reading​

Tweet by Wouter Witvoet @wwitvoet:
Overheard at SFO.
Man 1: 'Can I order an API?',
Man 2: 'Do you mean an IPA?'
Yes.
This just happened.
5:53 PM Oct 18, 2019

Bonus Slide​

Four-panel cartoon. Panel 1: 'Code red: the website is down!!'
Panel 2: Embarrassed sweaty programmer says: 'Ummm...I...I...accidentally
pushed some code to production instead of testing.'
Panel 3: 'You what?' 'I'm sorry...I...I'm new to this...I won't do it again...I...I...'
Panel 4: Celebratory teammates say 'Finally! Welcome to the club!'