Protected: Takeaways from “The Storytelling Animal” by Jonathan Gottshall

This content is password protected. To view it please enter your password below:

Advertisements

Whiteboarding C Programming

image11

Today after pivoting from pseudocode on the whiteboard, I had J do FizzBuzz on the whiteboard. I set my timer for 20 minutes. I was surprised when he said he was finished. 3 minutes had passed. Somebody is getting good at this 🙂

Question Posed:

How would you code in C to make the computer fizz when it finds an even number and buzz when it finds an odd number?

But did he get it right? What about checking the input? An hour later I had the code from J after it had been put into Eclipse and tested:


#include <stdio.h>
#include <stdlib.h>

int fizbiz(int num)
{
    if(num%2==0)
    {
        printf("fiz \n");
        return 0;
    }
    else
    {
        printf("biz \n");
        return 1;
    }

}

int main()
{
    int number;
    printf("Type in a number: \n");
    scanf("%d", &number);
    int result = fizbiz(number);
    printf("Remainder is: %d",result);
    return 0;
}

Next we’ll build from this simple little code snippet into a programming adventure that will reveal the importance of pointers and addresses, compiler specific caveats, and data type reveals!

Question Posed:

How would you update the code in C to have the computer take in an array of numbers?

UPDATE: I asked J to update the code to take in an array of numbers and he sent this back to me:


#include <stdio.h>
#include <stdlib.h>

void fizbiz(int num[])
{
  int i = 0;
  while(i<10)
  {
    if(num[i]%2==0)
    {
        printf("fiz \n");
        printf("Remainder is: 0 \n");
        i++;
    }
    else
    {
        printf("biz \n");
        printf("Remainder is: 1 \n");
        i++;
    }
  }
}

int main()
{
    int number[] = {11, 22, 33, 44, 55, 66, 77, 88, 99};
    fizbiz(number);
    return 0;
}

I want the problem of data types in C to reveal itself in the exercise. Just asked him to update the code to fizz on chars and buzz on ints. Very interested to see how he approaches this!

Question Posed:

How would you code in C to have the computer fizz on chars and buzz on ints?

UPDATE: Five minutes after emailing J the new request he emailed me his updated code:


#include <stdio.h>
#include <stdlib.h>

void fizbiz(int num[])
{
  int i = 0;
  while(i<10)
  {
    if(num[i]%2==0)
    {
        printf("fiz \n");
        printf("Remainder is: 0 \n");
        i++;
    }
    else
    {
        printf("biz \n");
        printf("Remainder is: 1 \n");
        i++;
    }
  }
}

int main()
{
    int number[] = {11, 'b', 'd', 55, 77, 'f', 'h', 99, 33};
    fizbiz(number);
    return 0;
}

Reading over the code, the concept started to open itself up. I remember reading somewhere, “In order to recreate you must first break it into pieces.” If you listen closely you can hear the problem cracking. I emailed J the following.

Question Posed:

How would you code in C to have the computer fizz for a char and buzz for an int? We are no longer checking for even or odd. We are checking datatypes.

Very interested in seeing the code that comes from this request. Will he get it?

UPDATE 3: With a single import of ctype.h, J was able to check to see if the current element in the array is an alpha character or a numeric character. Not exactly what I was looking for but who’s at fault when the problem is not clearly defined?


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

void fizbiz(int num[])
{
  int i = 0;
  while(i<10)
  {
    if(isalpha(num[i]))
    {
        printf("Character: fiz \n");
        i++;
    }
    else
    {
        printf("Integer: biz \n");
        i++;
    }
  }
}

int main()
{
    int number[] = {11, 52, 'b', 'd', 51, 23, 'f', 'h', 45, 13};
    fizbiz(number);
    return 0;
}

I decided to be clearer in my instructions. How can I phrase the question without having to indicate how to solve it?

Question Posed:

How would you code in C to make the computer create an array of ints and longs then fizz for ints and buzz for longs?

Interested to see how he updates the code 🙂

Update 4: J sent me the following email:

Hi David,

I just found that the size of an int and long are both 4 bytes. Did you want me to compare another datatype?
Int – 4 bytes
long – 4 bytes
float – 4 bytes
double – 8 bytes
char – 1 byte
J
Exactly what I was looking for! Now I’m interested in showing him the difference between a signed int and an unsigned int. I sent him the following question:
Hi J,

Good going! Please update code to fizz for int and buzz for unsigned int.
David
I’m looking forward to what he discovers along the way!

Swift Pair Programming – Session 6

swift

Last week Nick and I took another run at OAuth2 in Swift. Hawaii isn’t affected (neither fall nor spring) by Daylight Savings Time. I called him an hour early while he was still driving back from work. Once we determined why the scheduling was incorrect, we reconvened and dove back into OAuth with Swift.

Unfortunately we weren’t able to get the application to authenticate. After the first run through, I looked deeper into the actual OAuth process. I have a better understanding of the delineation between Consumer Keys and Consumer Secrets versus the Access Keys and Access Secrets.

I suspect that we are unable to connect because we are using an open source library to connect to Twitter that was actually written to use OAuth to connect to github. The list of attributes necessary for the connection are different from the way we are meant to connect with Twitter.

As our pairing time was winding down, we did two things. We searched for another open source OAuth repo to test with. We also talked about how we both don’t really understand lambdas.

“Wait, have you heard of this fucking website for Swift closures?” Nick asked.

Thinking I hadn’t heard him correctly, I said, “No.”

He was already sharing his screen and opened up Safari. He started typing in the url, “fuckingswiftblocksyntax.com” and I couldn’t help  laughing. Once we finished typing the url I couldn’t hold it in. And laughed for an uncomfortably long time 🙂

To put this in context a few weeks back he shared a JSON parser called Freddy. Their tagline is:

“So, Freddy vs. JSON, who wins? We think it is Freddy.”

You have to add some levity to this profession that sometimes feels like crafting concrete skyscrapers with steam. That’s the thing about the profession. There’s nothing tangible. We’re working with electricity. Making it to magical things. And it could break at any time.

Nick also mentioned a testing framework that was developed to allow debugging inside the simulator but I can’t remember it now. I made a note to myself to ask him tomorrow.

This weekend I successful set up push notification in my app. Hemingway was famous for saying that when he was writing he would always stop at a place where he felt he could easily get back into the groove the next day.

As I get more and more experience developing I find myself forcing myself to stop as soon as I have made some serious project after a full day of working. Knowing when to stop to avoid burn out is a hard lesson to learn, an even harder rule to follow, but a worthwhile lesson in humility, patience, and love of the craft.

Frozone, Mr. Freeze, and the Power of Debugging

Last week I wrote about how J wants to work for the NSA. This weekend, in the middle of the National Cyber League competition, he coded a bubble sort in C in an online IDE called JGrasp. But he ran into an error in his output that he could not figure out.

His array showed extra letters after the sort. I looked through the code and nothing jumped out at me as wrong.

Bing! I had a revelation.

“Do you know what a breakpoint is?” I asked.

He said, “No.”

“Do you know what a debugger is?” I asked.

“No,” he said.

Again, the obstacle becomes the way forever and ever.

I saw this opportunity and jumped on it. At the conclusion of our meeting I had J install Eclipse on his Windows 7 machine. He got a little stuck installing cygwin on his machine – windows 7 does not come with a c compiler. He had even more trouble setting the path in Eclipse to compile and debug from within the Eclipse IDE.

His shift was just about to end as he set the path to cygwin in Windows. We were not going to have enough time to debug in Eclipse. I pivoted and had him write hello world in notepad, he navigated to the directory on the command line and gcc’d the c file to an executable 5 minutes before his shift ended.

“We’re not going to have enough time to debug in Eclipse today.” I said. “Let’s wait until Wednesday to pick this up again. In the meantime, see what you can learn about setting the path to cygwin in Eclipse and let’s start debugging on Wednesday.”

He agreed and I got up and started walking back to my office.

As I walked I thought about how best to describe the process of debugging to someone who has not used a debugger before. I thought of Mr. Freeze in batman. He has a freeze gun right?

Then I thought of Frozone from the Pixar movie, The Incredibles.

Why am I thinking of these frozen characters so much?”

I thought to myself. Then it hit me. Debugging starts with a breakpoint. A breakpoint stops all program execution. Almost like freezing a bad guy, mid-bad. Or Frozone freezing the policeman in the bank to get away.

When we debug we freeze the program. But we’re not freezing to get away from something. We’re freezing the program so it doesn’t run 10,000,000/second. We can’t see the program run if it’s going so fast. So we leverage tools, like a debugger, to see exactly what the computer is thinking at the place in code that we set the breakpoint.

Looking forward to freezing J’s C program to investigate the internals and catch this bug that is ruining his output.

I remember the first time I stepped into a function. The superpower of forcing the computer to stop. I can’t wait to see his reaction when he learns that this is possible. Looking forward to Wednesday 🙂

 

Just started the Hawaii iOS Developer Meetup

Welp, I did it. I put my money where my mouth is. I signed up for meetup.com and created a new group. We’re called the Hawaii iOS Developer Meetup. We’re going to meet once a month at the beautiful hackerspace HICapacity in suite 132 at the Manoa Innovation Center.

I talked to my friend James at HICapacity. “James, I want to do a meetup at HICapacity.” He responded, “Cool!”

I created the meetup on meetup.com. I wasn’t sure exactly how to structure the meetup so I talked to my friend Nick, the host of the iPhone OS Weekly Developer Meetup San Francisco.

I loved the way he structured the meetup in San Francisco. He told me he was fine with me just using his framework. Reading over the manifest I am very happy with the trajectory of this endeavor.

Can’t wait to see what the turn out is like at the first meeting on Dec 1. If you’re in Hawaii and you’re interested in attending, please check out the event and register to attend.

Here’s the manifest for the Hawaii iOS Developer Meetup:

This group was created to provide a regular meetup for iOS developers actively working on projects. The purpose is to work together to support one another in bringing our ideas to life. The goals are also to meet people in the Honolulu, Hawaii area who are doing the same type of work (programming and creating apps for the iphone, ipad, and mac) and to have fun.

This meetup is for:

  • iOS Developers of all levels.
  • People who are interested in getting their hands dirty in code.
  • People just starting to develop for iOS who do not have much experience.
  • Developers on other platforms (Android, etc) who are interested in learning about iOS development.
  • Developers looking for specific help in adding functionality to their app.

This meetup is NOT for:

  • People interested in hiring a developer to work on their idea.
  • Marketers wishing to sell a product / service to iOS developers.

The meeting format will be evolving and dynamic but as a starting point attendees should expect an opportunity to discuss:

  • What he/she is working on
  • What apps they have released
  • What they’re interested in or what their specialty is
  • What they want to get help on.

There may also be a speaker who presents a specific topic. But everyone will have the opportunity to share and ask questions. Afterwards, there will be non-structured time, during which attendees are free to pair off or have discussions in smaller groups. If you have one, bring your laptop and any iOS devices you have. I’m hoping this meetup will serve as a launching point for barn raising groups, where all members of the group in turn have the opportunity to utilize the rest of the group to develop an app. This will most likely be done separately from the formal meetup.

While the primary purpose is to support developers of iOS applications, there will also be events in which the topic of discussion will be other platforms such as android, however they will never be presented by direct stakeholders of the platform (in other words, no pimping allowed).