it should have comments • Document each method your write, and intersperse comments describing why you are doing something • Clearly define what inputs you expect and what outputs you will provide • You will be reading and revising your own code, and after 6 months you won’t remember what you did and why! 2 def __resize__(self): """ Resizes the array by creating doubling the storage_length, creating a new list and re-hashing all stored items """ new_storage_length = self.storage_length * 2 # initialize a new list and pre-fill it with empty lists new_items = [[] for i in range(new_storage_length)] for item_list in self.items: ....
your code does what you believe it does: • Write unit tests • Pray • Writing units tests is the only way to “guarantee” that your code does what it is supposed to do • Unit tests are a form of software testing that validates code logic • They aren’t the only type of testing you need to do! • Unit tests are best at testing the outputs of a method for a variety of inputs • They must be thorough! 3
complete understanding of problem and solution • Write code that anyone can understand • Keep methods as short as possible (easier to test) • Refactor on a regular basis • Use variable names that are descriptive! • Test your code, even against unlikely circumstances • Read other people’s code as much as possible • This is the only way to become a good developer • Read about developing software • Challenge yourself • This is the only way to become a good developer • Most important: Have fun! 5
Your laptop! (Mac OS X is Unix), Sun, HP, IBM... • Provides all resources • Networking • Web server • Logging • File system • Multi-user • Home directory (~) • “Cloud” is really just servers in a data center • AWS - Amazon Web Services (free micro instance) • Heroku (free web dyno) • Rackspace • Google AppEngine 6
csh, bash, zsh, ksh are variants; all have differences • Most basic tool for getting work done on a *nix server • Shell is your UI for your server • Commands are interpreted when pressing the <return> key • File streams: stdin, stdout, stderr • A command output can be piped to another command’s input • Shell scripts are programs too! • Some hints: • <ctrl-c> or q: quit or kill current program (usually) • ls: list files • cd: change directory • less: print the file contents to the terminal • grep: find text in a file 7
attached server shell • Provides interactive shell access, safely • Proves line-based encryption • Usually requires username and password • Can use certificate-based login • Secure FTP: same as FTP, but securely • Most graphical FTP clients offer SFTP connection • Built in on *nix, Mac OS X • Putty on Windows 8 ssh <user>@<host>
Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-30-virtual x86_64) * Documentation: https://help.ubuntu.com/ System information as of Sun Oct 14 04:09:12 UTC 2012 System load: 0.0 Processes: 63 Usage of /: 15.2% of 7.87GB Users logged in: 0 Memory usage: 37% IP address for eth0: 10.80.238.210 Swap usage: 0% 43 packages can be updated. 27 updates are security updates. Last login: Mon Sep 17 02:24:51 2012 from xxx.verizon.net ubuntu@dev:~$
between developers • In a shell, you’ve got basically 2 choices: • Emacs • vi • Both are good, but very different • We’re going to use emacs, because that’s what I use • Pay attention to the minibuffer • Ctrl-key commands • Open file: <ctrl-x><ctrl-f> • Save file: <ctrl-x><ctrl-s> • Exit: <ctrl-x><ctrl-c> • Cancel command: <ctrl-g> 11
of on a server’s local disk • Like FTP, but provides easier security and web serving • Usually much safer • Distributed • Guaranteed uptime • Automatically backed up • Can be connected to a CDN • Provide a URL for a stored file so anyone can retrieve it • Common services: • Amazon S3 • Rackspace CloudFiles 12
least 1 IP address • DNS maps names to numbers • How your most people find things on the Internet • Different types of records: • CNAME • A • MX • Tools • dig • host 13
yahoo.com has address 72.30.38.140 yahoo.com has address 98.139.183.24 yahoo.com mail is handled by 1 mta6.am0.yahoodns.net. yahoo.com mail is handled by 1 mta7.am0.yahoodns.net. yahoo.com mail is handled by 1 mta5.am0.yahoodns.net.
to keep and access the changes made to (text) files • Beyond the editor, this is the second most important tool you will use • Lots of different ones, but we are going to use Git (vs. Mercurial/Hg) • Git • Invented by Linux Torvalds (yes, the Linux guy) to help manage changes in the Linux kernel • Add new files: git add <file> • Save versions of files: git commit -a • Everything is a changeset with a unique ID • Push your local changes to remote: git push • Get remote changes: git pull • Github • Hosted Git, with lots of nice features 16
an id, like: • 8357dea69d8b3a4bd6448c1d86fa4250dfffa830 • Commands • Make a local copy of a repo: git clone <url> • Add a file to a repo: git add <file(s)> • Save changes to files into repo: git commit [-a|<files>] • Publish your changes: git push • Pull down the most recent changes from remote: git pull • Show uncommited changes: git show • Show recently commited changes: git log • Lots more! • Learn more git: http://try.github.com/levels/1/challenges/4 • Use Github for code reviews! 17
• Play with tools: • shell • python • git • Homework: • Write a file in your home directory with the name “hw2” and the file contents “Hello World” • Read file “hw2” in my (in directory /home/Users/ubuntu) • Get a Github account and email me ([email protected]) your username • Email me your Github username and the text in my hw2 file • Read and follow Github getting started doc: https://help.github.com/ categories/54/articles 19