How Does Stripe’s 7 Lines of Code Work?

How 7 Lines of Code works

Disclosure: Nothing in this blog should be taken as investment advice. Do your own research. This blog is supported by advertising and affiliate links... Links to products and/or services on this blog may include links to affiliate programs that provide commissions to this blog. All of the content in this blog is 100% my own opinion.


Stripe offers a simple solution to the problem of overly complex, non-user-friendly e-commerce processing.

Specifically, Stripe’s e-commerce solution was created by developers, for developers.

The company is famous for its “seven lines of code” which enable businesses to use its system to process payments from anyone by adding only 7 lines of code to a website.

This elegant solution has made it easy for businesses to accept payments online, and for Stripe to process tens of billions of dollars in transactions.

With its 7 lines of code as a foundation from which to grow, Stripe has expanded to offer useful e-commerce subscription payment services, helpful tools for today’s entrepreneurs and has become one of the most valuable (over $9 billion) Silicon Valley startups in history.

How Does Stripe’s 7 Lines of Code Work?

But how can it be possible to create a business worth billions of dollars that only requires a customer to add 7 lines of code to their website in order to accept payments?

One way this could be possible is through the relationship between coding commands, functions and loops.

A “command” is just a set of instructions to do a single action.

For example, in the context of eating breakfast, some examples of commands could be “open cupboard” or “grab cereal bowl” or “grab cereal box” or “open cereal box” or “pour cereal” or “pour milk”, etc. etc.

A “function” is simply a collection of commands. The function groups commands together and then executes them in a sequence that accomplishes a larger action.

In our eating breakfast example, a function would be a sequence of breakfast commands.

When added together in the proper sequence, you have the “breakfast” function:

  1. “open cupboard”
  2. “grab cereal”
  3. “grab bowl”
  4. “open cereal box”
  5. “pour cereal”
  6. Etc.

Some functions may be ones that are commonly repeated. If a function is often repeated it can be incorporated into a “loop” to make it easier to execute.

An example of a function that you would repeat at breakfast would be putting food in your mouth, chewing, swallowing, etc.

You can define a function that happens only once, like “prepare cereal”. Or you can create a function that happens again and again, like “chew”. Once you define the function, it can be written to happen once or called to repeat as many times as you want.

So, it’s possible that Stripe’s seven lines of code are seven lines of code that are comprised of functions and/or loops that are really comprised of many different commands on many more lines of code than 7.1

Stripe's 7 lines of code (actually 12)
Stripe’s 7 lines of code (actually 12)

Part of pursuing an igrarian lifestyle is embracing the need to understand as much about web technology and code as you possibly can.

Should I Learn to Code?

Yes, if you have time.

If you have an idea for a side-hustle or an application or a website, you may not want to do the coding yourself. But if your idea needs to be built from scratch, the more you know, the better so you can avoid being taken advantage of.

As Antonio García Martínez eloquently observes in “Chaos Monkeys“, a book about his experiences as an entrepreneur and product manager (PM) in Silicon Valley:

“The principal reason for you to be technical is not to help technically design the system under development; if you’re doing that, then you’re PMing wrong. No, you’re technical so you can tell when engineers are bullshitting you, which will be often.”

One of the easiest ways to expose yourself to the basics of code is to learn Swift, the programming language for iOS (iPhone apps, iPad apps, etc.)

Swift Playgrounds is a free app you can download on your iPad that can get you started with fun coding tutorials.

Below is an example of using a function to reduce the number of lines of code needed to execute a task.

You can see the function at the top, starting with “func” and then following 24 lines of code from there.

To solve this Swift coding challenge, I created a function called “getGems()” which is a sequence of commands to move a cartoon character. The character moves around on the floating island and collects gems and turns switches on and off.

Some of the commands are repeated, so by adding them together as a function, I can save time writing the solution to the challenge.

Once the function is defined, in this case as “getGems()” below in red, I can “call” it by invoking the function in a loop in blue.

func getGems() {
collectGem()
turnLeft()
moveForward()
collectGem()
turnRight()
turnRight()
moveForward()
moveForward()
collectGem()
turnLeft()
turnLeft()
moveForward()
turnRight()
moveForward()
collectGem()
turnLeft()
turnLeft()
moveForward()
turnLeft()
moveForward()
moveForward()
moveForward()
}

moveForward()
for i in 1 … 4
{getGems()
}

Executing the blue function “getGems()” is only 4 lines of code, as opposed to the 24 in red. This way, I’ve reduced the code needed to run the program by 600%!

If you have an iPad, you can download the “Swift Playgrounds” iPad app for free and get started playing around with Swift.

It’s a really cool application that will help you to get your feet wet with coding, introduce you to basic coding concepts and provide a foundation in Swift. With over 600,000,000 iPhones and iPads out in the wild, there are many reasons to consider Swift your first coding language.

Once you try Swift, if you like coding, maybe you’ll learn write an elegant 7 lines of code to be the foundation of your own special billion dollar startup company.


Footnotes

  1. According to a Y-Combinator post, it’s actually 12 lines of code and a lot of back end engineering… So my example is just that, an example of how code can be simplified.