Python Training Part 3 (of 4)

In my ongoing series on EVERY business person should learn a programming language… and that language should be Python…   this is part 3 of 4.   Like prior trainings, this should be done in order.  You should already have python 2.6 installed, and be able to create files and invoke idle from either the shell or the gui.

Today’s lesson is on “classes”… classes are a very important concept in Python (and almost any programming language).   They enable you to write much more readable and useful code…. most importantly they enable you to build complex systems that ‘build on top of each other’ using either member variables of classes or inheritance or both.

A class can be thought of as simply a “container” for one or more “variables” and one or more “methods”.
Those variables are called ‘member variables’ because they belong “in the class”.
Those methods are called ‘class methods’ or sometimes called ‘member functions’ because they (almost always) act on or use the member variables of that class.

An object is an instantiation of a class… e.g. while a class “describes” what are it’s member variables and member functions…   an object is one instance (e.g. one of potentially many) class objects.

Okay, enough mumbo-jumbo, let’s get some hands-on!

1. First, create a file called location_classes.py somewhere in your library include path (C:python26 works)

2. In that file, put the following very simple class:
class Location(object):
    #MemberVariables
    #x    #y    #z
    def __init__(self,x,y,z):
        self.x = x
        self.y = y
        self.z = z

# this is one of the most basic classes possible, it has 3member variables, x, y, z, and one member function called “__init__”.   “__init__” is a special member function that is called when an instance is created.
Now, let’s use it.

3. Next, from within idle, type the following commands

from location_classes import Location
l21 = Location()  #this fails!   In our __init__ we required x,y,z to be set!
l2 = Location(3,4,5)
l1 = Location(0,0,0)
print l2
print l1
print l1.x
print l2.z

#notice the “dot” notation to access your instance member variables (l2 is an instance of class Location)
#notice how l1 is seperate from l2, but both are the same class?
#cool right? 🙂
#you havn’t seen the least of it!

4. Now, change your class code to be as follows:
import math
from datetime import datetime

class Location(object):
    #MemberVariables
    #x    #y    #z
    def __init__(self,x=0,y=0,z=0):
        self.x = x
        self.y = y
        self.z = z
     
    def __str__(self):
        return “X: %f, Y: %f, Z: %f” % (self.x,self.y,self.z)

    def distance(self,destination):
        xDiff = destination.x – self.x
        yDiff = destination.y – self.y
        zDiff = destination.z – self.z
        return math.sqrt(math.pow((xDiff),2) + math.pow((yDiff),2) + math.pow((zDiff),2))

#notice we’ve done 3 things.. we’ve set some ‘default values’ to the __init__ function, we’ve added 2 new member functions __str__ and distance.  __str__ is a special one that defines that classes string representation.   let’s try it!
5. Close Idle, and restart it… (you have to do this, or your classes may not get reloaded correctly).  type the following into the new idle window
from location_classes import Location
l21 = Location()  #this succeeds now!!!
print l21
l2 = Location(3,4,5)
l1 = Location(0,0,0)
print l2
print l1
print l1.x
print l2.z

print l1.distance(l2)  #notice it did the distance math from l1 to l2!  cool right?

#play around with this…
l1.z=55
print l1.distance(l2)

#and try stuff like this
l21 = l2
print l21
print l2

6. Okay, now to learn about including a class into a class… this is NOT inheritance, it is instead, making a class a member variable of another class!   (We’ll learn inheritance later).   For now, update your location_classes.py file to be as follows:

import math
from datetime import datetime

class Location(object):
    #MemberVariables
    #x    #y    #z
    def __init__(self,x=0,y=0,z=0):
        self.x = x
        self.y = y
        self.z = z
     
    def __str__(self):
        return “X: %f, Y: %f, Z: %f” % (self.x,self.y,self.z)

    def distance(self,destination):
        xDiff = destination.x – self.x
        yDiff = destination.y – self.y
        zDiff = destination.z – self.z
        return math.sqrt(math.pow((xDiff),2) + math.pow((yDiff),2) + math.pow((zDiff),2))

def vectorTo(origin,destination,speed):
    if speed==0:
        return origin
    dist = origin.distance(destination)
 
    dx = (destination.x – origin.x) / dist
    dy = (destination.y – origin.y) / dist
    dz = (destination.z – origin.z) / dist

    x = origin.x + dx * speed
    y = origin.y + dy * speed
    z = origin.z + dz * speed
 
    return Location( x, y, z )

#a boat is defined by its length, width, height, type-code and position and heading (point boat is moving towards)
class Boat(object):
    #Member Variables
    #length = 0    #width = 0    #height = 0    #boat_type = 0    #position = Location(0,0,0)    #heading = Location(0,0,0)

    def __init__(self,boat_type):  #makes boat_type required
        self.length = 0
        self.width = 0
        self.height = 0
        self.position = Location(0,0,0)
        self.heading = Location(0,0,0)
        self.boat_type = boat_type

    def move_towards_heading(self, speed):
        if (self.position.distance(self.heading) <= speed):
            print “Will arrive”
            self.position = self.heading
            return True
        else:
            #move towards goal
            self.position = vectorTo(self.position, self.heading, speed)
        return False

## Notice We’ve made a function (vectorTo) which is used in a new member function of class Boat… (move_towards_heading)…
### Notice that the Boat class has 2 member variables that are a Location type!  And that the move_towards_heading updates the position vectors of the Boat class!  Cool right?

7. Let’s play with our new boat! 🙂  From python idle command line type:
from location_classes import Boat
ab = Boat(1)  #a boat of type 1
ab.heading = Location(5,5,5)
print ab.position
print ab.position.distance(ab.heading)
ab.move_towards_heading(1)
print ab.position
print ab.position.distance(ab.heading)

ab.move_towards_heading(speed = 1) #note that i said speed=1 here, but i didn’t have to, I could have just said 1, but I wanted to show you how in a function call you can specify which parameters are what…

print ab.position
print ab.position.distance(ab.heading)

ab.move_towards_heading(1)
print ab.position
print ab.position.distance(ab.heading)

#can you see our boat moving?  I can!   It’s moving!!!!

8. Okay, time to learn about inheritance!   We need TIME!  Time, I say, time! Make your location_classes.py file look like this:

import math
from datetime import datetime

class Location(object):
    def __init__(self,x=0,y=0,z=0):
        self.x = x
        self.y = y
        self.z = z
     
    def __str__(self):
        return “X: %f, Y: %f, Z: %f” % (self.x,self.y,self.z)

    def distance(self,destination):
        xDiff = destination.x – self.x
        yDiff = destination.y – self.y
        zDiff = destination.z – self.z
        return math.sqrt(math.pow((xDiff),2) + math.pow((yDiff),2) + math.pow((zDiff),2))

def vectorTo(origin,destination,speed):
    if speed==0:
        return origin
    dist = origin.distance(destination)
 
    dx = (destination.x – origin.x) / dist
    dy = (destination.y – origin.y) / dist
    dz = (destination.z – origin.z) / dist

    x = origin.x + dx * speed
    y = origin.y + dy * speed
    z = origin.z + dz * speed
 
    return Location( x, y, z )

#a boat is defined by its length, width, height, type-code and position and heading (point boat is moving towards)
class Boat(object):
    #Member Variables
    #length = 0    #width = 0    #height = 0    #boat_type = 0    #position = Location(0,0,0)    #heading = Location(0,0,0)

    def __init__(self,boat_type):  #makes boat_type required
        self.length = 0
        self.width = 0
        self.height = 0
        self.position = Location(0,0,0)
        self.heading = Location(0,0,0)
        self.boat_type = boat_type

    def move_towards_heading(self, speed):
        if (self.position.distance(self.heading) <= speed):
            print “will arrive”
            self.position = self.heading
        else:
            #move towards goal
            self.position = vectorTo(self.position, self.heading, speed)
        return self.position
 
class Location4d(Location):
    t = datetime.now()
    def __init__(self,x,y,z,t):
        super(Location4d, self).__init__(x,y,z)
        if t > 0:
            self.t = t

    def __str__(self):
        return “X: %f, Y: %f, Z: %f, T: %s” % (self.x,self.y,self.z,self.t)

## notice we added a new class Location4d, and it inherited Location!   up till now, we’ve been inheriting “object” which is actually a very base class that gives us ability to call super  ( we didn’t have to do this, we could have called  class Location()  but then we wouldn’t have had access to the super function, which can be really helpful. )

### Also notice that since we inherited from Location class, that we actually have an x, y, z already as member variables, and we added t  (time!).

### We’ve over-ridden the __str__ function (by having defined ou own) and added to the __init__ function (using super)

#### let’s play with it.

9. In your command shell  (idle) type the following:

from location_classes import Location4d
l4 = Location4d(0,0,0,0)
print l4
l3 = Location4d(4,5,6,0)
l4.distance(l3)
l3.distance(l4)
#  notice we called the distance function?   how you say?  simple, we inherited not only the member variables, but also the member functions!   Cool right?

10. What else can you do with classes?
Turns out you can do a lot just with these few things I’ve showed you… but there is so much more too!  Creating classes of classes of classes, you could model the universe!
Most libraries you use will start with a class as well!  So knowing how to ‘instantiate’ a class instance is key  * you did this many times when you said l4=Location4d(0,0,0,0) for example!

So, here’s your homework!!!

Create a new class called Rectangle…  make sure it inherits from Location or Location4d  (your choice… yes, deep inheritance is possible, as is multiple inheritance..e.g. a location and a location 4d… although that makes no sense here).

Now, write a member function to return the area of the rectangle.

Now, write a member function to ‘move’ the rectangle from one position to another position at a given speed.

Now, write a program that asks for length and width and prints the area of the rectangle.

That’ll do it!  Enjoy!

Business Use of Patents and Provisional Patents

The raging debate about Patent Trolls and what can and should be patented might lead one to consider, what is the business purpose of a patent?  Particularly if you are a startup (very early stage, perhaps pre-funded) with little cash, little time, and a need for focus, the question of patents, to patent or not, seems to be somewhat common.  This post is a summary of my advice and knowledge on the topic, as I recently provided to a new company called Basedrive who are working on their business plan as part of The University of Texas Longhorn Startup class and program.

Here is my advice…

1. First, don’t be a Patent Troll:

A Patent Troll is someone who patents something with no real intention of building it, so that later they can ‘claim royalties’ or sue big companies for ‘stealing their idea’.  This approach is not something upon which to build a true entrepreneurial business; and such loopholes should be looked on with great skepticism.

2. Don’t do patent searches…

If you are thinking of writing a patent, and are worried if your patent is truly novel or not, you may be tempted to ‘search prior patents’.  DO NOT DO THIS!   You will be required to list all the patents you looked at, and this could taint you or your ideas… further, you WILL likely find something similar.. but it’s not your job to know this, or if yours is “different enough”.

IF YOU THINK IT MIGHT BE UNIQUE, do not search… just move to step 3, below.

3. Decide if $130 (or so) is worth spending or not…
For $130, all in total amount, you can file a provisional patent.  (See Patent Fee Schedule)

So, what would a $130 Provisional Patent buy you for your business?
a.) You can put the words “Patent Pending” on your product.
b.) Investors will see you as ‘better’ than companies without a patent pending.
c.) It can lead to a real patent in the future, with a priority date equal to the date you submitted the patent (or earlier).

The downside?  None.  In order to claim the priority date by means of your provisional patent, you need to file the final patent within 12-months of submitting the provisional; but this is not a bad thing… even if you don’t write the final patent in the 12-months, you can still write the final patent later with no penalty. (just no claim on the provisional).

If you need to buy food, don’t spend the $130… but otherwise, I say do it.. at least for 1 thing!

4. What is Patent-able/What to write?
So, what do you patent?  My best advice is to focus on some implementation detail that you do that helps your product/service be unique.  Got no technology?  Don’t bother writing a Patent (IMHO).

What kind of technology?  Hardware?  Yes.   Software?  Yes.  Both?  Ideal!

Even if your use of the technology is in software, I suggest writing the patent as though the software could be implemented “into a device”… (thus covering both hardware and software).  This might require creative thinking, but it might also get you the patent later!

What do you write for a provisional?  SIMPLE:  Just write in plain English how your technology works, and how it might work in software or hardware.  Simple, plain, English.

You will also need 1 drawing.  1.  not 2.  1.  Simple block diagram is ideal, showing the system.

Now, go to uspto.gov and SUBMIT IT YOURSELF!   No need to pay a lawyer to submit or review a provisional patent.  JUST DO IT!

5. Should you file a final, full patent?

Maybe.  But not yet.  Not until either: a.) you can easily afford the $8,000-10,000 for a lawyer to do it right… or  b.) your business really needs it for some reason [e.g. to increase your stock’s value even more by having full issued patents ].

When you do a final patent… simply get a lawyer to do it.  Simple.   A real patent lawyer.  You don’t want to do a final by yourself.  Just give the lawyer your provisional as a starting place, and off you go!

6. So business value?
Yep.  Provisional = Obvious.  It’ll help you stand out and raise money and look good. (that’s it really).
Final full patents… = Less Obvious.  It MIGHT help you raise more money at a better price, it MIGHT protect you from getting sued [because you could counter-sue], it MIGHT help you go after someone who is infringing on your patent (doubtful)…

So, Provisional = Yes.  Final = Doubtful (IMHO).

So, get to it!

What Martial Arts can teach you about Business.

I love martial arts.  I’ve practiced some form since I was 10 years old.  Martial Arts can teach you may things about business… some very interesting concepts from the business of martial arts, and some from the philosophy of martial arts.  Read on for the scoop.

The Business of Martial Arts:

  1. At it’s core, the business of Martial Arts is a franchising operation.  The difference is that you must EARN the right to franchise.  That’s just good business sense.  Don’t let anyone with a buck sell your product, make them earn the right.
  2. Bill monthly, encourage use.  By billing monthly, martial arts keep you “captive” to your pocketbook (a tactic known to 24-hour gyms).
  3. Make me feel special.  As a consumer of martial arts, I love it that you make me feel special, unique, and desired.  It’s a club that not just anybody can join: e.g. the best kind… and a kind that breeds long-term customers.
  4. Don’t be what you are not.  You don’t have weights, snacks, movie nights, or popcorn.   You don’t offer massage, swimming lessons, or dance…. you are martial arts.  You are what you are, and you never break your contract with me about what you are. Good for you; this too keeps me loyal, not overly demanding, and keeps your costs down too!
The Philosophy of Martial Arts:
  1. Only for Defense, never for Offense.  This may not be all martial arts philosophy, but it is most of their core principles.  How does this relate to business?  Simple.  DO NOT abuse your customers.  If they are your customers, you don’t need to FIGHT them for goodness sakes.  Also, don’t go after your competition… it’s better to find your NICHE and defend from a position you own, then to go on OFFENSE and try to take their position.
  2. Goals.  This is a core tenant of Tae Kwan Do (my current marital art of choice)… and for business it is essential.  If you have no goals, you are going nowhere.  If you don’t set “Practical goals” you can “Actually measure”.. you are drinking your own Kool-Aid or setting yourself for failure.  No matter what you do in business, set goals… try to reach them.. analyze if you fail… celebrate if you win. Then set another goal now that you are wiser of your limitations (for more or less).
So you see, Martial Arts can teach you much about business.. and keep you healthytoo!  Get to it!  We can spar any time (the image at top is of me sparring a partner during black belt testing…  I’m the bug guy leaning forward.. perhaps a tad too aggressively).  I need to work on #1 of the martial arts philosophy… I attack too much!

7 reasons to Fail Early & Cheaply

Since everyone knows 19 out of 20 start-ups will fail… why not fail as soon as you can and as cheaply as you can?  In fact, recent evidence suggests that the #1 reason start-ups fail is trying to scale up too quickly/too soon.  Here are 7 reasons to FAIL as quickly as possible, and as cheaply as possible:

  1. Whenever you fail, you almost always learn more than if you succeed… especially if you start out with the goal of learning/deciding if a hypothesis will work.
  2. If you can fail quickly, you will likely have time and energy enough to try again!  (not necessarily a ‘new’ start-up, but instead another “hypothesis”/product variation to test in the current one).
  3. If you fail cheaply, you may have money enough to try again!
  4. If you fail early, you avoid spending too much time on a bad idea.
  5. If you fail cheaply, you haven’t invested too much “sunk costs” into the idea, and can let it die more quickly.
  6. If you can fail quickly, it means you have wisely set criteria for failure (a rare thing indeed!)!
  7. If and when you succeed, you KNOW you have something, because you have defined (wisely) what success is, and your past failures prove that the current situation is “Worth” scaling up!
Final word of warning: Scaling up itself is a difficult challenge, so use the term literally, and slowly increase the rate of growth, rather than step function.

Engineers should NOT start a business.

I’ll say it again, Engineers should NOT start a business… unless they are prepared to run a business. So many people I meet are hungry to “have no boss” and “work on what they want”, that they forget that to start a business is to run a business. If you are not willing to “work on stuff that needs doing”, then starting a business is probably a very bad idea.

Consider the ideal case. You are an engineer. You love doing engineering. You start a business that is just consulting your engineering skills.

  1. Do you think you will always be able to pick and choose your contracts? -Wrong. You work on what the client wants… and if jobs are scare, you take work where you can get it.
  2. Do you really think you have no boss?  -Wrong. The client is the boss.
  3. No accounting? -Wrong. You now track hours, expenses, invoices, etc.
  4. No sales? -Wrong. You have to sell yourself for every bid.
  5. No marketing? -Wrong. Every client is a Word-of-mouth marketer for you.
So… by “starting even the simplest business”, you’ve just made a bunch of work that you probably don’t like doing.  You’ve just created a bunch of bosses where you used to have only 1.  And now you are working harder than ever.  So why do it?
1 word: Profit.
The reason you work harder, you do the extra yicky work, etc. is because you can charge WAY MORE than you were before.  As a variable resource, people will pay more for your services. You just have to keep the pipeline of work filled and you will rake in the extra 25-50% due a contractor/consultant.
If you are starting a business for more “freedom”, you might get some… but Profit is a far better reason.

Video: Engineers Make Better Business People, because they MEASURE!

I have a strong core belief that (if they wanted to) Engineers (and other mathematically trained professionals) would make better business people than “business graduates” or MBAs.  An Engineer-MBA is the best combination, because they learn the MBA lingo, but not the bad habits.

Watch the video to see WHY I think Engineers make better business people, and what you can do about it.

Video Blog 6/14/11: Magic Marketing Formula for Engineers

Discover the “magic” of Marketing in an Engineering Formula.  The Dominant Coeffecient might surprise you… it’s what makes a product/service SUCCESSFUL vs. UNSUCCESSFUL.

In case you missed it, the Formula is:
       SALES = REVIEW_SCORE * (SUM_OF_OTHER_MARKETING_STUFF_YOU_DO)

This is a true statement for at least the Killer NIC and various iPhone games I’ve worked on.

Is it true for you?

The “Tree of Business”

To so many people, business is confusing.  It’s hard to understand, and we fear the unknown.  To the most “daring” among us, we embark on starting and running our own companies (I’m on Startup #2).  When people begin to think about starting this insane ride that is “self-employed”… it may be helpful to think of business as a tree.

First, the most important question:
What kind of business do you want to build?
1. A Tree that grows large and bears regular fruit.  (a for-profit business, but limited in size)
2. A Tree that stays small, and has just enough fruit to feed yourself & family.  (a for-profit business, often called a lifestyle business).
3. A Tree that sprouts many other trees and grows into an orchard or a forest (a huge corporation that someday may IPO – Initial Public Offering).
4. A Tree that gives any excess fruit away to charity (a non-profit)
5. A Tree that you plan to grow quickly, by feeding the tree its own fruit, and then someday sell the tree to someone that is building and orchard or wants to keep the fruit for themself.  (a for-profit business, designed for acquisition).

Knowing what you want out of your business can be extremely helpful in deciding A.) What to do.  and B.) When to feel successful. and C.) How to get your starting soil (investment).

Enjoy your fruit!

Learn when to call…

If you are like me, you hate sales calls: doing them, almost as much as getting them.  If you have a small business, you probably get them and do them a lot.  The trick to making (and receiving) sales calls, is doing them when they will be best received… here is a few tips.

  1. Never call after 4pm, or before 8:30am… period.  
  2. Try calling no more than 2x per day.
  3. Call first in the morning, leave a message saying when you’ll call back later that day, and do it.  
    • (10am and then later at 2pm are good times).
  4. After 2 or 3 days of call attempts, email to ask to set up an appointment.  (email the admin if you can), then switch to once per week.
  5. Figure out their “slow day”… here is a hint, its probably NOT Monday.  
    • Often it is Friday at 10am or 2pm.
  6. Don’t call on the weekend, or at lunch.

Engineers fear Lawyers… A Company’s First Steps are Easy

Fear: HOW DO I START A COMPANY? MANY Engineers freeze up with fear right here. They don’t realize just how easy it is to start a business these days. In Texas, everything can even be done online, and the legal part is really really simple. (NOTE: i’m not a lawyer, so do not consider this legal advice… side-note: see, even I’m afraid of lawyers).

Although this link has more detailed information and all the needed links, I’m going to try to make the process super simple in my own words.

1. Pick S-Corp or C-Corp. The only difference I can tell is that S-Corp does not double-tax dividends, but only allows investment by individuals. Most people should choose C-Corp if they plan to be invested in , and S-Corp if they are not. Don’t fret… you CAN change it later by reincorporating.

2. File appropriate form online (in Texas, that is here): http://www.sos.state.tx.us/corp/sosda/index.shtml (costs $300, so make sure your business name is unique, a simple search is available same site!)
a. Choose some amount of stock that is big enough, but not too big. I chose 10,000,000 shares to start at par of $0.001.
b. Must have at least 1 director (can be same person throughout the document).

3. Get EIN from IRS (this is needed to file taxes, which is the ONLY requirement to continue as a company): http://www.irs.gov

4. File for state tax if appropriate. Texas is here: http://www.cpa.state.tx.us/taxpermit/

5. Enjoy being a company.

Its that easy. Now that you are a company, you might want to issue some shares to yourself. If you do, make sure you file an IRS 83-b form within 30 days. http://www.fairmark.com/execcomp/sec83b.htm

As for giving yourself stock, I recommend it! And I recommend you get this stock in exchange for services rendered (such as business plan preparation, time spent in meetings/formation, etc.). A good founder split is NOT EVEN SPLIT! If there are 2 people, it should be at least 51%/49%. In fact, I HIGHLY recommend that one founder (the one who is leading the effort) get 51%. Reasons: this avoids any future problems related to who is in control/direction of company, this prevents any number of founders from ganging up on the others, and this makes good sense if you want to raise money because that founder will have enough power (hopefully) to stay on the Board of Directors and protect the other founders interest.

A simple MOU can make the above reality. If you actually issue the stock (e.g. with a directors approval or other legal mumbo-jumbo), then you will need a lawyer IMHO.

Frankly, beyond this point of a company, having a decent (fairly priced) legal counsel for the company is a good idea. (Yes, my fear of lawyers kicks in now). But you DONT have to have one to form the company, and you SHOULD wait to get a lawyer until you raise money, or start negotiating contracts/earning revenue/making sales.

Best of luck, and sometimes, fear is not a bad thing… but lawyers don’t cost that much. I have found good legal advice as low as $200-$300/hour… don’t pay more email me/message me first, I’ll give you a few referrals.

–photo credits