Download Designing Real Systems ELE 301 Slide Deck 2: Version Control

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Version control wikipedia , lookup

Transcript
Designing Real Systems ELE 301 Slide Deck 2: Version Control, Programming Models, and Basic Apps David Wentzlaff Department of Electrical Engineering Princeton University 1 Outline •  A liKle bit of SoMware Engineering (1) –  Version Control •  Programming Models •  Basic App Programming 2 SoMware Engineering 3 The Joel Test •  Do you use source control? •  Can you make a build in one step? •  Do you make daily builds? •  Do you have a bug database? •  Do you fix bugs before wriWng new code? •  Do you have an up-­‐to-­‐date schedule? •  Do you have a spec? •  Do programmers have quiet working condiWons? •  Do you use the best tools money can buy? •  Do you have testers? •  Do new candidates write code during their interview? •  Do you do hallway usability tesWng? hKp://www.joelonsoMware.com/arWcles/fog0000000043.html 4 The Joel Test •  Do you use source control? •  Can you make a build in one step? •  Do you make daily builds? •  Do you have a bug database? •  Do you fix bugs before wriWng new code? •  Do you have an up-­‐to-­‐date schedule? •  Do you have a spec? •  Do programmers have quiet working condiWons? •  Do you use the best tools money can buy? •  Do you have testers? •  Do new candidates write code during their interview? •  Do you do hallway usability tesWng? hKp://www.joelonsoMware.com/arWcles/fog0000000043.html 5 Version Control •  Every want to undo your changes to soMware/
hardware/documentaWon? •  Ever needed to collaborate with others to develop soMware/hardware/documentaWon? 6 Version Control •  Every want to undo your changes to soMware/
hardware/documentaWon? •  Ever needed to collaborate with others to develop soMware/hardware/documentaWon? cp my_project.doc my_project_9_17_2013.doc 7 Version Control •  Every want to undo your changes to soMware/
hardware/documentaWon? •  Ever needed to collaborate with others to develop soMware/hardware/documentaWon? cp my_project.doc my_project_9_17_2013.doc 8 Conceptual Idea • 
• 
• 
• 
Store a repository of revisions. Each revision is a snapshot of a set of files. Can search by author, date, commit comment. Can revert to previous revisions. 9 Version Control Workflow •  Copy: to start, check out or clone a copy of the project, usually HEAD. •  Modify: do what you have to; test your changes; commit the result. •  Merge: others merge your changes into their working copies. 10 Merging •  Usually works smoothly. •  SomeWmes there’s a merge conflict; must inspect: –  common ancestor; –  your change; –  conflicWng change and figure out what to do. 11 Obsolete AlternaWve Lock-­‐modify-­‐unlock. Not commonly used anymore Example: RCS 12 Centralized vs. Decentralized •  TradiWonally: –  one central repository which all developers work against. Check out from master, commit back to master. –  Examples: SVN, CVS, Perforce •  Modern: –  everyone’s repository could serve as host, has full history. Can exchange code with others, no master needed. –  Examples: git, hg, bzr, BitKeeper 13 Case Study: Subversion (SVN) (hKp://svnbook.red-­‐bean.com) 14 CreaWng a new repository Create one from scratch: –  svnadmin create c:\svn\repos More commonly, check out a repository: –  svn checkout hKp://k9mail.googlecode.com/svn/
k9mail/trunk/k9mail-­‐read-­‐only –  creates a working copy. 15 Adding and Ignoring Files •  GUI: (Team > Add to Version Control). •  command-­‐line: svn add filename –  failure to add files: leading cause of build breakage •  You will see ignored files like R.java. –  Generally, do not commit generated files! –  Instead, tell Subversion to ignore them, e.g. using wildcards. 16 Commiqng Files On SVN, a commit makes your changes available to the world. In decentralized version control, a commit records current version. •  When to commit? –  What you commit must compile! –  Generally, one feature at a Wme, aMer tesWng. (Varies by source control system.) 17 Commit Messages •  Serves as important documentaWon •  Start with a one-­‐line summary. •  Establish the specific context of the change: –  Why is it necessary? –  How does it work? –  What are the effects? •  Meta-­‐commit message 1: Summarize clearly in one line what the commit is about Describe the problem the commit solves or the use case for a new feature. Justify why you chose the particular solution. 1https://github.com/erlang/otp/wiki/Writing-­‐good-­‐commit-­‐
messages 18 UpdaWng your repository •  Pull changes from the repository to your working copy. •  Use svn update to do that. If all goes well, you’ll get output like this: wentzlaf@laptop:~/work/checkout1 svn up D example.tex A studies.tex U introduction.tex A sketch.tex U main.tex 19 Conflicts! •  This is a pain: wentzlaf@laptop:~/work/checkout1 svn up C example.tex •  Why? –  Both the latest version and your version differ from the common ancestor. 20 Example conflict 1.  I wrote: “Here’s a line of text”. 2.  Programmer X changes it to “Here’s a line of text that I modified.” 3.  I change it again to “Here’s a modified line of text.” •  The result: <<<<<<< HEAD Here’s a line of text that I modified. ======= Here’s a modified line of text. >>>>>>> zzz •  You need to fix it and tell SVN that you’ve fixed it. 21 Stepping Back in Time •  Major win of version control: –  can undo sketchy changes. •  Can update to a past revision number or a date/Wme. •  How to know which version to revert to? –  your detailed log messages! •  Note: you can’t commit an update, but you can merge it to your working copy. 22 Diffs •  Basic unit of version control is the diff: –  describes what’s different between two versions. •  Inspect your diffs before commiqng. •  Commit minimal diffs. =================================================================== -­‐-­‐-­‐ Text/abstract.tex (revision 17379) +++ Text/abstract.tex (working copy) @@ -­‐1,10 +1,10 @@ Runtime monitoring enables developers to (1) specify important program properties and (2) dynamically validate that these properties hold. In recent research, we have found that static analysis techniques can, -­‐in many cases, verify that runtime monitors never trigger. In -­‐this paper, we describe a system which enables developers to visualize -­‐the remaining cases-­‐-­‐-­‐potential +in many cases, verify that runtime monitors never trigger. In this +paper, we describe a tool which enables developers to visualize the +remaining cases-­‐-­‐-­‐potential points 23 Basic SVN Workflow Repeat unWl done: •  Update your working copy. (svn update) •  Edit files. Manipulate tracked files. (svn add, svn rm, svn copy, svn move) •  Examine changes. (svn status, svn diff) •  Undo changes, if necessary. (svn revert) •  Commit changes to the server. (svn commit) 24 Programming Models • 
• 
• 
• 
• 
Run to compleWon (Batch) Streaming Polling Event Driven Many more … 25 Run to compleWon (Batch) 1. 
2. 
3. 
4. 
Processes inputs Computes Produces outputs Ends public static void main(String[] args) { int f = 0; int g = 1; for(int i = 1; i <= 10; i++) { System.out.print(f + " "); f = f + g; g = f -­‐ g; } System.out.println(); } 26 Streaming Streaming as a Common Machine Language
• Regular
computation
•  Write code and
for repeating
individual filter blocks • Independent filters
•  Put fiwith
lter explicit
blocks together communication
– Segregated
spaces andset •  Operates on a naddress
ever-­‐ending multiple program counters
of inputs AtoD
FMDemod
Scatter
LPF1
LPF2
LPF3
HPF1
HPF2
HPF3
• Natural expression of Parallelism:
– Producer / Consumer dependencies
– Enables powerful, whole-program
transformations
Gather
Adder
Speaker
6
Image Credit: Michael Gordon 27 Polling •  ConWnually checks set of inputs •  Reacts to those inputs to create outputs public static void main(String[] args) { int lastState = 0; while(true) { int pinValue = readPin(); if(pinValue != lastState) { System.out.print(“change detected”); lastState = pinValue; } } } 28 Event Driven •  Program is reac>ve, not proac>ve 29 Event Driven, An IntroducWon •  What happens when you press this? •  Android sends an event to the event listener. 30 Registering for Events •  An event is a noWficaWon of a change to the state of your system. •  An event listener is code which is run when an event is received. mFalseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ checkAnswer(false); } }); // note the inner class used above! 31 Event PrioriWes Imagine the following situaWon: •  your mom calls; •  supper is burning; •  laundry is done. What do you do? 32 Events and Finite State Machines Events
and Finite-State
Machines
•  Remember: reac>ve, not not
proac>ve Remember:
reactive,
proactive.
How
can
the application
whatit it w
wants?
•  How can the applicaWon do do
what ants? Use
Finite-State
Machines!
•  Use Finite State Machines! 2,3,4
start
n1
1,3,4
1
2
1,2,3,4
n4
n2
3
n3
1,2,4
33 Inversion of Control: Without It Inversion of Control: Without It
•  Non-­‐event driven model Old ECE150 paradigm:
1. program start
Operating
System
Your
Program
4. program exit
2. calls 3. returns
Library
34 10 / 31
Inversion of Control: With It Inversion of Control: With It
•  Event Driven Model ECE155 paradigm:
New event-driven
1. call create
onCreate()
4. return create
Android
3. return
2. register
click listener
35 14 / 31
Inversion of Control: With It Inversion of Control: With It
•  Event New
Driven Model event-driven
ECE155 paradigm:
1. call create
onCreate()
4. return create
Android
3. return
2. register
6. click return
5. click!
click listener
36 16 / 31
Behind the Scenes for Inversion of Control Android is running an event loop for each thread: while (!done) { r <-­‐ fetch Runnable from Queue dispatch r } This is a polling loop: in parWcular, a >ght polling loop, but which goes to sleep waiWng for the next event (in fetch). 37 Components of a Basic Android App •  AndroidManifest.xml (Tells Android OS how to hook up to your App) •  Java files –  Business logic (Controller) –  Storage Objects (Model) •  Resources –  Strings •  Aids in InternaWonalizaWon –  Layout •  Usually in XML –  Constants –  Graphics •  Graphical BuKons •  Icons 38 What is XML? •  eXtensible Markup Language •  Structured Document Format –  Has no intrinsic meaning! (unlike HTML) –  Needs a Schema or Document Type DefiniWon (DTD) to define fields 39 Example XML <?xml version="1.0" encoding="utf-­‐8"?> Root node <manifest xmlns:android="http://schemas.android.com/apk/res/android" package=”edu.princeton.ee.301example" AKribute, name “package”, android:versionCode="1" value “edu.princeton.ee.
android:versionName="1.0" > 301example” <uses-­‐sdk Must quote all values android:minSdkVersion="14" android:targetSdkVersion="17" /> Self-­‐closing tag <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name »
android:theme="@style/AppTheme" > <activity android:name="edu.princeton.ee.301example.MainActivity" android:label="@string/app_name" > <intent-­‐filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-­‐filter> </activity> </application> </manifest> 40 Android Build Process Image Credit: Android Programming The Big Nerd Ranch Guide 41 Lifecycle of an App Image Credit: Google hKp://developer.android.com/images/training/basics/basic-­‐lifecycle.png 42 Eclipse Demo •  Where is everything? •  How to Build & Run? •  Emulator 43 Next Class Preview •  JITs vs Interpreters •  FuncWon Calls •  System Calls 44 Acknowledgements •  These slides contain material developed and copyright by: –  Patrick Lam (University of Waterloo) •  University of Waterloo material derived from course ECE 155 45