Software: Machine Code and Programming Languages
- A large program like Firefox.exe is a big block of machine code
- It's very rare for a person to write machine code directly
- Instead, we write code in one of many "programming languages"
- e.g. Java, Javascript, Python, C, C++
Programming Languages - In Translation
- CPU machine code is the "native" language of the CPU
- CPU machine code instructions are extremely simple
- Hard to get much done with such simple instructions
- Programming languages have "high level" features, like print
- There is no single machine code instruction that prints
- So how do programming languages work?
- Programming languages work in translation to machine code
- In Javascript, the print statement is translated to, say, 10 machine code instructions
- These 10 instructions, when run, perform the print command
![source code translated to machine code](software-translation.png)
Source Code Translation
Two worlds...
- Source Code
- 1. The "source code" of the program, written in a programming language (e.g. Javascript for CS101)
- The source code defines the behavior of the program
- A human can read and edit the source code
- But source code does not "run" on the CPU directly
- Machine Code
- The CPU understands machine code
- Only machine code can actually run on the CPU
- The source code is translated to machine code, and that translation runs on the CPU
- Extra for the curious:
- 1. The translation can be done ahead of time by a "compiler"
-e.g. Firefox source code compiled to yield Firefox.exe - 2. The translation can be done on-the-fly
-This is how CS101 works
-You type Javascript source code into the browser
-It is translated at the moment you click Run
Source Code = Control
- Having the .exe allows one to run the program but not change it
- How to change a program? (feature or bug-fix)
- Make a change in the source code (human readable)
- Now the program (in translation) runs the changed way
- The source code is the real definition of the program
- The machine code is the way it runs
- Source Code = control, the ability to change the program
- Machine code .exe file = you can run it, but that's it
Traditional Proprietary Software - e.g. Microsoft Word
- e.g. Microsoft Word
- Microsoft owns and controls the source code
- Microsoft sells you Word.exe and permission to run it
- You just have the machine code! - Word has lots of valuable features, and you pay Microsoft for the right to use it
- The classic vendor-customer market which we all use all the time
- Control: Microsoft has all the control, customer can just buy or not
Competition is what keeps companies in check in a market
The Open Source Software Miracle
- Open Source Software is incredibly widespread
- Computers, phones, the internet .. built with tons of open source software
- Open source software is free; no vendor is paid
- No $$$ -> how does this ever get written?
- Aside: capitalism has many frustrating qualities
-Study open source software
-Counter to capitalism and yet super popular - Examples of open source software:
- Linux operating system
- The Android operating system (95% of it)
- Parts of Mac OS X (50%?)
- The Chrome Browser (!!!)
- The Firefox Browser
- The MySQL database system
- The GCC compiler
- Computer languages: C, C++, Python, Java, Javascript
- Any computer/phone/site you use, there's lots of open-source software in the "stack"
Open Source Software
- Free Software Foundation
-1985 Richard Stallman
-A revolutionary who believed users should have the right to see/edit their software
-"Freedom" driven (more philosopher, less economist)
-(slowly) turned out to be a great model in and out of the for-profit world
How Open Source Works
- Open Source software - a legal structure
- (there are many variants, so this is a high-level view)
- 1. source code - The source code is freely available
-Typically the software does not cost anything
-It can be used in profit-making enterprises
-How does it come to exist? (see below) - 2. right to modify The software includes a legal right to make modifications
-And the right to use and distribute these modifications - 3. contribute back changes
-If someone adds a feature or fixes a bug in the source code
-There are incentives to contribute that change back to the shared source code
-In some licenses, conribute-back is obligatory
-There is some sort of board that decides to accept code contributions - Basically the opposite of the Proprietary-Fine-Print!
- Open Source Social Contract:
-Here is great software and you are free to use and change it
-If you add a great feature, contribute it back so others may use it
Beat Cal Example
- The Chrome browser is open source, therefore you could...
- 1. Download the chrome source code ("chromium")
- 2. Modify the source code so every page it displays says "Beat Cal" at the top
- 3. Distribute your new version of "Chrome"
-You'd have to call it something else ... Chrome is trademarked - 4. For a real feature, you might contribute the change back to the main Chrome source code
- Key: you have control, not the vendor
Open Source Example: GCC
- GCC is a widely used "compiler"
- An important and very complicated piece of software infrastructure
Aside: a compiler translates source code into runnable machine code - GCC is open source under the GPL open source license
- 1. Free GCC costs no money to use, just download it
- 2. Source code The source code of GCC is available
- fix a bug or add a feature you want to GCC - 3. Contribute there are incentives to contribute changes back to the main GCC source code
Central question: Who Builds Something That Is Distributed For Free?
- i.e. How does open source software come to exist?
- Apple, Google, Facebook, Redhat, Oracle, Twitter all use GCC
- Some of these companies are competitors
- Many of them contribute bug fixes, features back to GCC
-They fix the bug because they want it fixed for themselves first
-But the contributions then flow to all, including their competitors
So what is the result...
- How open source gets picked up by Apple, Google, ...
- They need something like GCC infrastructure to exist
- They all use GCC
- They all contribute to GCC
- The benefits of the contributions will flow to all (competitors)
- Therefore
- 1. We all get the benefit of free, high quality infrastructure piece
- 2. BUT nobody is going to have competitive advantage from GCC
- Result:
-GCC is a free infrastructure piece
-Maintained and used by all
-Not a source of competitive advantage ("cudgel")
Open Source Conclusion
- Software has many layers where you want something to work reliably
- Open source provides
-free
-widely used, high quality
-maintained collectively
-provides no advantage vs. competitors - Conclusion: for many niches, free + high-quality is an appealing tradeoff
- Proprietary software is not dead, but open source dominates many areas
- Ultimately we all benefit: avoid work duplication
- That's how your computer systems work today!