Python: Functions with Optional & Named Arguments

Python allows functions to have default values for arguments. These are used when the function is called without the argument. But where it gets really interesting is when you realize that in Python it’s also possible to name the arguments and call them in any order, which can be very useful.

def shirt(styleID, size='Medium', color='White'):
    ...

For example, in the ‘shirt’ function above, style is a required argument (since it has no default value) but the other two arguments i.e. size and color are optional (since they do have default values assigned).

There are several ways to call this function:

>>> shirt(1)

styleID gets a value of 1 and size and color are assigned their default values.

>>> shirt(1, "Large")

styleID gets a value of 1 and size gets a value of “Large”, while color gets the default value.

>>> shirt(1, color="Black")

styleID gets a value of 1 and color gets a value of “Black”, while size gets the default value.

>>> shirt(size="Small", styleID=2)

size gets a value of “Small” and styleID gets a value of 2, while color gets the default value.

9 Things to Know About Amazon (Infographic)

This is a great infographic about Amazon produced by FrugalDad:

Amazon Infographic

Source: Frugaldad.com

How To Reverse A String in Python

Unlike other languages such as Ruby, there is no built-in method to reverse a string in Python. Here are two possible ways to accomplish that: 

1) The 'Long' Way

This approach uses a for-loop with the join method to reverse a string:

def rev(s):
    return ''.join([s[i] for i in range(len(s)-1,-1,-1)])

>>> print rev("abcde")
edcba

2) The Simpler Way

This approach uses Python's 'slice notation' to accomplish the same result:

def rev(s):
    return s[::-1]
   
>>> print rev("abcde")
edcba

I think I read somewhere that #1 (for-loop) is faster, but I do love the simplicity of slicing. It looks a little strange at first, if you're not used to Python. But it really is pretty easy to use once you get the hang of it.

Learn Python the Hard Way

Over the last two years, I've spent considerable time learning several programming languages (PHP, C# and Ruby).  I started developing web applications with PHP, moved onto ASP.NET MVC using C# and then decided to experiment with Ruby on Rails.  I really loved the simplicity of Ruby and the 'magic' of Rails, but there was something about the Ruby language that just didn't grok with me — I still can't exactly put my finger on it.

A couple of months ago, I read Dharmesh Shah's post 'Why PHP is Fun and Easy But Python is Marriage Material'.  He made a compelling case for using Python and so a few weeks later I decided to take a closer look at Python myself. As sad as it sounds, I've finally found a programming language that I'm really excited about. It's simple and easy to get started with Python but it's also an extremely powerful language. And after I got over some of the initial 'weirdness' of Python e.g. using tabs for code-blocks, it really started to grow on me.

Learn Python The Hard Way

If you're interested, a great place to start learning Python is Zed Shaw's "Learn Python the Hard Way".  The online version of the book is available for free and there's also an  online class with screencasts at Udemy.com. The course is really designed for people with little or no programming experience. I consider myself to be a novice, but after a few years of programming in other languages, I realized that I actually know more than I thought I did. It was actually a very easy course for me, which I got through relatively quickly. But it was a great way to learn the fundamentals of Python. It might be too basic for a lot of people, but I still think it's worth taking a quick look at.

At the moment, I'm going through Mark Pilgrim's "Dive Into Python" book — which so far has been EXCELLENT. This is a book for experienced programmers and you will find a ton of useful information here. This book is available for free (published under the GNU Free Documentation License) and can be downloaded in a number of formats and languages. Along with this, I'm also reading Ayman Hourieh's 'Django 1.0 Website Development' book (Django is an excellent web framework for Python). I guess you could call it "Python on Django" but that doesn't quite roll off the tongue as "Ruby on Rails" does.

Introduction to Django

Here's a great introduction to Django from PyCon 2010.

Learn Rails the Zombie Way

A fun way to learn the basics of Ruby on Rails:

For more information check out http://railsforzombies.org/

Teach Your Child To Ride a Bike in 5 Simple Steps

Recently, I've been thinking about teaching my 5 year old son to ride a bike without training wheels. We tried to do this a couple of weeks ago and I experienced probably what every parent teaching their child goes through. I spent most of the time holding the bike and running behind him. And by the end of the day, he wanted to put his training wheels back on and I had a sore back.

Yesterday, I watched this video about an organization called Bike New York, a non profit whose mission is "to promote and encourage bicycling and bicycle safety through education, public events, and collaboration with community and government organizations". They run "Teach Your Child to Ride" clinics at parks around New York city and apparently have a very high level of success. After learning about their unconventional training technique, I felt inspired to teach my son to ride again, but this time with a very different approach.

The result — in 24 hours with about 60 minutes of practice, he was riding a bike all by himself. I shot some footage with my iPhone 4 and edited with iMovie 11. Here's the result:


iPhone Photograpy – Who Needs a Digital SLR?

It's amazing what you can do with an iPhone and a $1.99 app. I've been using the Camera+ app on my iPhone 4 for a couple of months. It has a one touch clarity feature that transforms your photos and also provides the capability to add beautiful effects. I've been on a couple of recent trips where I also took my digital SLR with me but never used it once. I managed to get all the shots that I needed with my iPhone.

Here are some shots I took in Lake Wenatchee and Issaquah…

What Do Microsoft Program Managers Do?

For most of my 10+ year's career at Microsoft, I've been in program management roles — from being a program manager responsible for a specific product feature to becoming a group program manager leading a team of program managers. It's a role that I really enjoy doing and over the years I have learned a lot about the program management discipline from a lot of smart people at Microsoft. This post focuses on the 'what' i.e. what do program managers do.

The first thing to note about the program manager role is that it's an unfortunate job title. As Steven Sinofsky wrote in his blog post PM at Microsoft back in 2005 "program managers do not program, nor do they manage". Well that isn't completely true – there are some PMs that write code (although that's not usually part of a PM's job) and there are PMs that manage other PMs (but not development and test teams). Also PMs play an important role in not only defining the software product, but also doing the project management.

I like to describe the PM role at Microsoft using the '3 Ds' – discover, design and deliver:

 

 

 

1) Discover (Framing the Landscape)

In order to understand and frame the landscape, the PM needs to gather as much data as possible about the market, customers, competitors, technology trends etc. There are lots of ways to accomplish this – market research reports, customer feedback, user surveys, usability studies, competitor product reviews, industry reports etc. The goal at this stage is to just gather data and start making some sense of the landscape.

The next step is to analyze this data and identify opportunities, gaps, trends in the market. One useful tool for distilling this data into key information is a SWOT analysis (strengths, weaknesses, opportunities & threats). In simplest terms you identify the strengths and weaknesses of your business/product (internal) and then identify the opportunities and threats in the market (external). Whatever tool you use, the goal at this stage is to develop a deeper understanding of the landscape.

Once the PM understands the landscape, it's time to clearly define the opportunity. Usually this doesn't just emerge once you've understood the landscape – it takes a little more work. One useful way to develop those ideas is to start discussing your findings with other members of the team i.e. other PMs, developers, testers, product planners, marketing, partners etc. This will eventually get you to a point where you feel good about a particular opportunity and are ready to tell a story.

Telling the story is really about answering the what, who & why questions i.e. what problem are you going to solve, who are you going to solve it for, why does this problem need to be solved etc. By now the PM can clearly describe the landscape and use data to backup key points. You'll know when you're onto something when people clearly understand what you're proposing and why. And when your story not only resonates with them but starts to get people excited.  

 

2) Design (Defining What to Build)

Once the landscape has been framed, the PM must help define what to build.  A good place to start is by clarifying the value proposition i.e. what problems will you solve for your customers.  The PM will then work with the team to establish SMART goals including the non-goals i.e. what you will not try to do (in order to manage the project scope).  And then work with key stakeholders to define and prioritize the requirements — which will eventually get translated into scenarios.

There's no silver-bullet for figuring out what to build — as they say, the best way to have great ideas is to have lots of ideas (good or bad).  The PM must help foster the right environment for idea generation e.g. establishing brainstorming 'ground rules', involving the right people etc.  Then these ideas need to be validated using relevant data, evaluating the trade-offs and by continuously asking 'will this solve our customers' problem?'.  And then the PM must help the team get closure by selecting a concept or idea.

Getting to the right design takes multiple iterations and feedback loops. The PM needs to clearly communicate the early ideas (whiteboards, sketches, emails etc.) and gather lots of feedback on the proposed design. Both functionality and user experience (UX) need to be considered at this stage, so it's critical to involve UX designers early in the process. After several iterations, the PM should have enough information to start producing the detailed specifications (spec).

The spec is typically a document that provides very detailed information on how the final product should look and function. But in an agile world, it's sometimes more effective to write a shorter spec and communicate the details of the design with a prototype. In some cases, this could be a set of design comps and in other cases it could be a working mockup of the final product. There are lots of great prototyping tools available — a couple of my favorites are Balsamiq and iMockups for iPad

 

3) Deliver (Shipping the Right Product On Time) 

In this phase, the PM's job is to ensure that the product team ships the right product on time. This means working with the rest of the product team (development and test) to understand work item estimates, develop a schedule and make the right trade-offs e.g. cutting features if necessary. The PM must take on a leadership role in developing a solid plan with the rest of the product team and effectively anticipating and identifying potential issues.

The PM also spends a lot of time refining the plan during this phase e.g. clarifying requirements, working with developers to resolve feature design challenges etc. And with so much focus at this stage on how to build the product, it can be easy to sometimes forget why you're building it. So ensuring that everyone keeps the big picture in mind is critical. The PM needs to continuously remind the rest of the team about the value proposition and ensure that the final product will actually solve the customer's problems.

 

As early versions of the product become available, the PM can start to get real user feedback e.g. is the product intuitive to use, does it address the real world scenarios, do customers actually like what they see etc. This provides the product team with incredibly value information about the product they're building and it's an opportunity to refine the design and make additional improvements to ensure that the team ships the right product. It can also help to identify major customer issues that may require the team to go back to the drawing board.

And finally, the PM needs to provide effective communication across the board. There are always a lot of moving parts on any software development project and the PM is the key person to ensure that everyone on the team knows what's going on i.e. status of the project, issues, risks, dependencies, early customer feedback etc.

First Look at Windows 8

Here’s a demo of Windows 8 that was previewed at the D9 Conference earlier this month.