Saturday, June 21, 2014

Code Rush Documentary - Netscape / Mozilla / Silicon Valley Ups and Downs

As my son worked on file I/O in Python, I decided to watch Code Rush, a documentary that covers the amazing story of Netscape and its path to open source their core product Navigator as Mozilla.

The Code Rush story is filled with millionaires, epic stories of how people changed the world, intense human bonding, and an amazing legacy.  There was also a high human cost, with strained marriages and emotional suffering. 

The film resonated with me.  I feel that it accurately portrayed the hectic culture of the time, the belief in the Internet to radically change society, and the hope that open source with its implied philosophy of freedom and sharing was about to improve our lives. 
The documentary covers the time period from March 1998 to April 1999, a formative time in my life.  While the team at Netscape was changing the future of the Internet, I was on my own adventure.  During that time, I sold my Internet company, an online community in Tokyo, to PSINet, moved to Silicon Valley to kickstart the US office for Turbolinux, helped the CEO raise a ton of money, and most importantly and magically, had a child.

I started this blog to chronicle my childrens' progress to learn to program and to understand the culture of their home, Silicon Valley.  Part of what I hope to teach them is to find their own balance in a town filled with extremes.  If they are lucky, they will each have at least 10 jobs in their lives, ranging from a baker, a designer, a landscaper, therapist, a commercial fisherman, or even a programmer.  Technology could be an enabler in their future.  Or, they could never use it.

As you watch Code Rush, I encourage you to think about your own strategy to define your goals and find balance.  It's a wonderful window into the past that could help you plan your future.

Saturday, May 31, 2014

Still Keeping to Pygame Despite Great New Kivy O'Reilly Book (for now)

Since I wrote about Kivy six months ago, my son and daughter have continued to make strong progress with Pygame.  For IDEs, they've both moved to PyCharm with its awesome code completion and easy integration with GitHub.  My son is making progress with object oriented programming and recursion.

Kivy is much more powerful than Pygame.  It is also harder to use.  Although the documentation is comprehensive, only the tutorials on Pong and Paint are geared toward beginners.  It also not designed to teach programming concepts to new programmers.  Kivy is geared more toward intermediate to advance programmers that want to get a mobile app up quickly. The new O'Reilly book, Creating Apps in Kivy,  by Dusty Phillips is great.  However, most people new to programming will get stalled around chapter 4.  Although the text is easy to follow and the code examples are clear, the concepts are dense.  Just as an example, in chapter 2 of this thin book, Dusty rips into list comprehensions.  While the example is easy to understand, a new programmer is better off dealing with for loops and list iteration.

There's many other places where Dusty teaches us a valuable concept, but I think it is too much, too soon for young developers.  This said, I've been gearing up for my son''s summer by going through the Kivy book and I plan to introduce him to Kivy later in June.

Kivy makes use of a Python file, which works great in PyCharm, and a kv language file, which does not work great by default.  To get the kv language syntax highlighting and tabs working properly in PyCharm, you need to install the kv settings file.  This makes the development process much easier.  I could never get the kv language settings working properly in Emacs.    After 20 years of using Emacs, I find myself grabbing PyCharm more and more.  It's amazing to me that even at my age, I find myself moving to new tools.  I've even moved off of the Emacs key mappings and am using the default PyCharm keymaps.  JetBrains has done a nice job.

I've also gone through the Packt Publishing book, Kivy: Interactive Applications in Python.  The O'Reilly book is much better, clearer, easier to read, with less errors in grammar.  It's also newer.  The O'Reilly book does focus on Python 3, which I don't think is a good thing since most Kivy development is still done with Python 2.7.  Though, I haven't run into any problems following the Python 3 examples.

Saturday, May 17, 2014

Magic and The 3rd Grade Girl Programmer

Somewhere along our path to adulthood, we stop believing in magic.  What would make us start believing again?

It seems improbable for a 9 year old girl to program.  Yet, I see it.  As she sits in front of a Linux computer slowly typing out code in PyCharm, I think that this tiny 3rd grade girl either represents the future of computer programming or a failed opportunity for everyone.

Adjust the y axis to move the character down the screen with keyboard input, I say.  I do not expect her to succeed.  She does it with the aid of PyCharm's fantastic code completion, happily typing in:

There's a moment of magic.  I imagine every girl in America, daintily typing out our future.  In her face, I see the things that adults would pay a fortune to capture, wonderment, belief, excitement in the aha instant of understanding.  The gears click in her head, she presses the Run button on PyCharm, a Pygame window starts up with a pink girl character in the center of the screen.  Then, the 3rd grade girl coder presses the down arrow key on her Logitech keyboard.  And, the girl on the screen moves down.

  First Hacker in History
She talks about Barbie, My Little Pony, Hello Kitty, and Ada Lovelace, creator of the world's first computer algorithm.  She knows about Ada Lovelace's work on the Babbage Analytical Engine, because girls talk in 3rd grade, letting the boys know that the world's first computer programmer was female.  I hope that their girl power feeling of superiority continues on through high school.

I let her know about the Top Secret Rosies documentary of the heroic women programmers during WW II.  She wasn't surprised.

Leading ENIAC hackers mid to late 1940s

Grace Hopper in 1952 with a UNIVAC 1

More links to great female programmers.

Thursday, May 15, 2014

Windows 8.1 and Pygame Subset for Android (pgs4a)

I recently got asked a question about Windows installation on the PyChildren forum.

Here's the question:

When I touch the icon, the screen turns black, and then it goes back to my apps page in my phone. I then run the logcat to find the problem, but all it gives me is this:

V/python ( 676): Extracting private assets.
I/python ( 676): extracting private.mp3 to /data/data/com.bennybear.fungame/files
The user was not using an mp3 sound file.  When the person extracted the Windows compressed package for pgs4a, the file got added into a sub-directory of the build.    Since I was helping my son to install pgs4a on his Windows 8.1 computer, I was able to replicate the problem.   I think that the process of unzipping or extracting the pgs4a file partially failed.  When I compared the pgs4a files on two different Windows 8.1 computers, I noticed they were different.

I then went to the pgs4a site and downloaded a tar.bz2 archive.  I used tar jxvf on cygwin to extract the files.

A working directory is shown below.

Note that inside of the pgs4a-0.9.6 directory, there is not another sub-directory called pgs4a-0.9.6.  In the failed builds, I noticed that there was a temporary pgs4a-0.9.6 file created in the same directory and all the files from that directory were not properly copied into the main directory.

Once I had the files properly extracted, I noticed that the python installsdk script was giving me error messages.  The script was failing to install android-api-15 and android-api-8.  I used the android.bat program in the android-sdk\tools directory to update the android SDK APIs.  

If you get an error message indicating that ant cannot find the build.xml file, this usually indicates that you don't have the proper Google APIs installed from the Android SDK (not the pgs4a installsdk script).  In almost all cases, I've had to install the Google APIs with the android sdk.  On windows, the android sdk manager is called android.bat

There is another pgs4a tool called  These tools are completely unrelated.

Once I had those installed, the build went fine.  In order to connect the Windows 8.1 laptop to my son's Motorola Moto G Android phone, I had to go to the Motorola site and install the driver.  With driver from Motorola, adb was able to detect the phone and install went smoothly.

I also installed it on my Samsung Galaxy phone from his Windows 8.1 laptop.

This seems like a pain in the rear, but I encourage you to keep going.  Pygame is fun because it makes it easy to bring the creative ideas from your brain into reality very quickly.   By putting these ideas, your works of art, on a phone, you can show your friends and help them to understand a bit more about how you think as a person.

My long term goal for my children is for technology to serve as a tool for creative expression, not a barrier.  It should be fun and frivolous.  Games are great learning tools.  The work and lessons here should not be viewed through the lens of making money or job-training.  These experiments with children are about developing creative thinking and techniques to express ideas.  Sure, it's a pain to get pgs4a to install sometimes.  I agree.  But, I still think it's the best way to get kids and adults up to speed to be able to take their ideas and prototype them on a mobile phone.  

Have fun!

If you have questions or would like to join the discussion, go to the PyChildren Forum.

Sunday, May 4, 2014

Installing Pygame Subset for Android on Windows 8.1

I documented an epic tale of installing pgs4a on Windows 8.1.

Although it took more time than I anticipated, I successfully installed a Pygame application from Windows 8.1 to my Samsung Galaxy Note 2.

 I previously wrote about Shems Eddine tutorial on pgs4a installation and always assumed that the process was easy on Windows.  Wow, now I realize that there are a few hurdles.  Although several people had asked me about pgs4a installation and configuration, I could never replicate these problems on Linux.

I was able to install a rudimentary version of Asteroids that my son and I are working on.  A big part of the lesson is using sine and cosine to rotate the ship in all 360 degrees.

I've also been encouraging him to move to PyCharm.

The screenshot below shows how to start android.bat from within the pgs4a\android-sdk\tools\ directory.

View of the Android-SDK package manager showing the API 17 packages installed.

Sunday, March 30, 2014

Recursion For Kids

There's a bunch of 9th graders at my son's school talking about recursion.  They're not learning this in class.  It's just something to do.   I'm fascinated by their decision to dig into one of the fundamental ideas of computer science on their own.

For kids, recursion is simply calling a function from itself.  It's an easy concept to understand and can be used to create powerful examples in under 15 minutes.

Some of my son's friends entered into a programming contest as a group and won it.  I'm continually impressed with 9th graders.  They're tough, both mentally and physically.  I can't keep up with the teens.  Just as an example of how far behind I'm lagging, all the 14 year old programmers are also running under 5 minute miles for track.  They're fast!  Where do they get all the energy?  I don't think I could finish a mile in under 9 minutes now day with all my injuries.

Since recursion is a hot topic for kids, I introduced recursion to my son.  Here's a recursion example he wrote today.

More examples:

Monday, March 17, 2014

Python Android App Debugging Tip: adb and python print statements

With the phone connected to the USB cable and in debug mode, open a new terminal window and type:

  $ adb logcat |grep python

You can now view standard python output from applications running on your android phone with python print statements. Output of logcat
I/python  ( 2392): play sounds
I/python  ( 2392): play sounds
I/python  ( 2392): play sounds

The most common problems with Python Subset for Android Apps dying on the Android phone at startup:
  1. you didn't import the sound mixer module properly
  2. your fonts are not in the main program directory
  3. your sound files are not in the main program directory
  4. your graphic files or map files are not in the main program directory
  5. you are using a python module that is not in your main program directory
Note that there's a common theme here of a desktop program working because the assets exist somewhere on your desktop machine, but those assets don't get transferred to your phone.  Look at your sound, graphic, and font files to make sure they are in your main directory.

In the problems above, the adb logcat command will usually show you what asset the program fails to load.

You'll save time in the debugging process if you open up two terminals at once.  In one terminal, run the adb output.  In the other terminal, build and install your program onto your phone.  With the USB cable connected, run your application on your phone.

Check to make sure you are initializing the android library.

Make sure you are importing the mixer module as shown below. In previous versions of pgs4a, I had problems with audio files that weren't in *.wav format. I only use wav files now.

Another common problem is that your application is not named

Make sure you have called the application and that you are building the application with the name of the directory that contains your application.

if you are using the sgc gui toolkit with android, you need to make sure that the fonts are loaded prior to setting up the sgc screen. I've had several occasions when I got the order wrong the my application worked on the desktop and crashed on the phone. This code below is only relevant if you use sgc, which is definitely not needed to make games on android. However, if you do use sgc to make your buttons and sliders, it can be a bit tricky to use on android.