0
Speaking “Development Language”Or, how to get your hands dirtywith technical stuff.GWU Libraries ● 12 June 2012Julie Melon...
Today’s Goal• To increase the number of people who can“work” on technical issues in the library• Technical “work” in the f...
Today’s General Outline• Development Lifecycle & Where You Fit In• Computer Programming Basics• Python in Particular• Wher...
and Where You Fit In…
General Software Development Lifecycle• Define▫ What you want to do• Design▫ How you want to do it• Implement▫ Actually do...
Design Phase Needs Domain Knowledge• Functional requirements define the functionalityof the system, in terms of inputs, be...
Example Functional Requirement• Example functionality: representation and manipulation ofhierarchy• Description: The GUI s...
• An epic is a long story that can be broken into smaller stories.• It is a narrative; it describes interactions between p...
• Stories are the pieces of an epic that begin to get to the heart of thematter.• Still written in non-technical language,...
• Scenario: User attempting to add an object▫ GIVEN I am logged in AND I have selected the “add” form AND I am attemptin...
Now You Do One!• Think of a problem you want to solve (a batchprocess, something displayed in the OPAC, etc)• Think of the...
That Was the Define Phase…• From a set of stories, developers begin toDESIGN a way to bring the stories to life.• At some ...
Why Program?• Express complex logic and performcomputations.▫ We make the computer do what we want it to do.▫ These behavi...
What is a “Programming Language”?• An artificial language with a limited purpose• A means of expressing computations (math...
What Does a Programming LanguageLook Like?• ...a lot like human language, as it has:▫ Syntax (form)▫ Semantics (meaning) ...
A Few Basic Programming Components• Variables & Arrays• Operators• Flow Control• FunctionsPutting together these pieces ad...
Variables & Arrays• A variable is a bucket that holds one piece ofinformation.• Examples:▫ $string_variable = “The Library...
Variables & Arrays• An array is a type of variable (or bucket) thatholds many pieces of information.• Example:▫ $rainbow =...
Operators• Arithmetic▫ +, -, *, / (add, subtract, multiply, divide)• Assignment▫ = (“Assign the value of 4 to the variable...
Operators• Comparison▫ == (“when I compare the value in variable a to thevalue in variable be, that comparison is true”) ...
Operators• Concatenation• + (string + string = stringstring)• Logical• && (and)• || (or)• ! (not)
Flow Control• ifif (something is true) {do something here}• if ... else ... else ifif (something is true) {do something he...
Flow Control• whilewhile (something is true) {do something here}• forfor (something is true) {do something here}
Procedures and Functions• Scripts can contain linear, procedural code.• Scripts can also contain references to reusablebit...
Why Python?• It is a general-purpose language• It has been around for a long time (20+ years)• It has a strong developer c...
Uncluttered Layout• Less punctuation▫ While some languages use $ to indicate variables, orbrackets around logical construc...
Variables in Python• Do not begin with a symbol and do not end withterminating punctuation.• Examples:▫ string_variable = ...
Set and Print Variables# set up the variablesstring_variable = "The Library";numeric_variable = 4;myname = "Julie";# print...
Arrays in Python• …are called lists.• Example:▫ rainbow = [“red”, “orange”, “yellow”, “green”,“blue”, “indigo”, “violet”]...
Operators in Python (are not terribly special)• Arithmetic▫ +, -, *, /• Assignment▫ =▫ +=, -=, *=, /=• Comparison▫ >, <, >...
Flow Control in Python• ifif something is true:INDENT and do something here# here’s an examplepeople = 20space_aliens = 30...
Flow Control• if ... elif ... elseif something is true:INDENT and do something hereelif something is true:INDENT and do so...
Flow Control• EXAMPLEpeople = 30cars = 40if cars > people:print "We should take the cars."elif cars < people:print "We sho...
Flow Control• whilewhile something is true:INDENT and do something here# here’s an examplecount = 0while (count < 9):print...
Flow ControlThe count is: 0The count is: 1The count is: 2The count is: 3The count is: 4The count is: 5The count is: 6The c...
Flow Control• forfor there are things in a sequence:INDENT and do something here#here’s an examplerainbow = ["red", "orang...
Flow Controlredorangeyellowgreenblueindigoviolet
Functions in Python• Start with the keyword def• Accepts parameters• There‟s indentation• You get something in return
Functions in Pythondef fibonacci(n):a, b = 0, 1while a < n:print a,a, b = b, a+bfibonacci(1000)///////////////////////////...
So How Does Your Group Use Python?• As batch scripts, with or without a web interface▫ One-offs, utilities, etc• Using a W...
Sample Utility (pymarc)• For manipulation of MARC records▫ In GitHub at https://github.com/edsu/pymarc/▫ From command-line...
Sample Utility (pymarc)• Example 2:from pymarc import Record, Fieldrecord = Record()record.addField(Field(tag = 245,indica...
Launchpad• Works within a Django framework• Has a directory structure you can follow to findhow things are pieced together...
Launchpad (example from a template){% extends "base.html" %}{% load launchpad_extras %}{% block title %}{{ bib.TITLE }}{% ...
Launchpad (example from a template)def clean_isbn(value):isbn,sep,remainder = value.strip().partition()if len(isbn) < 10:r...
Additional Resources• Learn Python the Hard Way▫ http://learnpythonthehardway.org/book/• The Python Tutorial▫ http://docs....
Speaking 'Development Language' (Or, how to get your hands dirty with technical stuff.)
Speaking 'Development Language' (Or, how to get your hands dirty with technical stuff.)
Speaking 'Development Language' (Or, how to get your hands dirty with technical stuff.)
Upcoming SlideShare
Loading in...5
×

Speaking 'Development Language' (Or, how to get your hands dirty with technical stuff.)

1,881

Published on

Slides from an internal workshop at George Washington University Library on 12 June 2012. The goal of this workshop was to increase the number of people who can “work” on technical issues in the library. Topics were grouped into three main parts: "Development Lifecycle & Where You Fit In", "Computer Programming Basics", and "Python in Particular".

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,881
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Speaking 'Development Language' (Or, how to get your hands dirty with technical stuff.)"

  1. 1. Speaking “Development Language”Or, how to get your hands dirtywith technical stuff.GWU Libraries ● 12 June 2012Julie Meloni // @jcmeloni // jcmeloni@gmail.com
  2. 2. Today’s Goal• To increase the number of people who can“work” on technical issues in the library• Technical “work” in the future come from theneeds of the present: your needs.▫ When you can articulate them to someone whocan do the codework, we all win.▫ If YOU can do the codework, you win even more.
  3. 3. Today’s General Outline• Development Lifecycle & Where You Fit In• Computer Programming Basics• Python in Particular• Where to Learn More
  4. 4. and Where You Fit In…
  5. 5. General Software Development Lifecycle• Define▫ What you want to do• Design▫ How you want to do it• Implement▫ Actually do it• Test▫ Did what you do actually work• Deploy▫ Send it off into the wild• Maintain▫ Don‟t forget about it!
  6. 6. Design Phase Needs Domain Knowledge• Functional requirements define the functionalityof the system, in terms of inputs, behaviors,outputs.▫ What is the system supposed to accomplish?• Functional requirements come fromstakeholders (users), not (necessarily)developers.▫ stakeholder request -> feature -> use case ->business rule
  7. 7. Example Functional Requirement• Example functionality: representation and manipulation ofhierarchy• Description: The GUI should allow users to view and interact withhierarchical structures representing the intellectual arrangementand the original arrangement of files and directories within ingestedaccessions. For each component level in the intellectualarrangement, the user interface should present associated digitalassets and an interface to view and edit descriptive metadataelements.• Specific Components: collapse and expand record nodes forviewing (applies to both the original ingest and the intellectualarrangement), add new child record, add new sibling record, copyall or part of the existing structure to the intellectual arrangement,delete a record in intellectual arrangement.
  8. 8. • An epic is a long story that can be broken into smaller stories.• It is a narrative; it describes interactions between people anda system▫ WHO the actors are▫ WHAT the actors are trying to accomplish▫ The OUTPUT at the end• Narrative should:▫ Be chronological▫ Be complete (the who, what, AND the why)▫ NOT reference specific software or other tools▫ NOT describe a user interfaceWriting Use Cases (or Epics)
  9. 9. • Stories are the pieces of an epic that begin to get to the heart of thematter.• Still written in non-technical language, but move toward a technicalstructure.• Given/When/Then scenarios▫ GIVEN the system is in a known state WHEN an action is performedTHEN these outcomes should exist▫ EXAMPLE: GIVEN one thing AND an other thing AND yet an other thing WHEN I open my eyes THEN I see something But I dont see something elseWriting User Stories
  10. 10. • Scenario: User attempting to add an object▫ GIVEN I am logged in AND I have selected the “add” form AND I am attempting to upload a file▫ WHEN I invoke the file upload button▫ THEN validate file type on client side AND return alert message if not valid AND continue if is valid▫ THEN validate file type on server side AND return alert message if not valid AND finish process if is validActual Story Example
  11. 11. Now You Do One!• Think of a problem you want to solve (a batchprocess, something displayed in the OPAC, etc)• Think of the use case:▫ WHO is doing WHAT to achieve OUTPUT• Break it down into a story:▫ GIVEN something WHEN something happensTHEN do something else
  12. 12. That Was the Define Phase…• From a set of stories, developers begin toDESIGN a way to bring the stories to life.• At some point, programming begins and thestories are IMPLEMENTED in code.• During the coding process, TESTS are writtenand code is TESTED.• When the tests pass, the code is DEPLOYED.• As time goes on, the code is MAINTAINED.
  13. 13. Why Program?• Express complex logic and performcomputations.▫ We make the computer do what we want it to do.▫ These behaviors come from our imaginations.▫ The processes come from our needs and desires.• Do things that take a long time or are difficultfor humans to do (counting, comparing,repeating)
  14. 14. What is a “Programming Language”?• An artificial language with a limited purpose• A means of expressing computations (math) andalgorithms (logic)
  15. 15. What Does a Programming LanguageLook Like?• ...a lot like human language, as it has:▫ Syntax (form)▫ Semantics (meaning) signs/words (variables, symbols, numbers, strings) expressions flow control (decisions, conditions, loops, narrative) complex entities (methods, structures, & objects)
  16. 16. A Few Basic Programming Components• Variables & Arrays• Operators• Flow Control• FunctionsPutting together these pieces adds up toprogramming (or scripting, or in general “writingsome stuff to tell the computer what to do”)
  17. 17. Variables & Arrays• A variable is a bucket that holds one piece ofinformation.• Examples:▫ $string_variable = “The Library”;▫ $numeric_variable= 4;▫ $myname = “Julie”;
  18. 18. Variables & Arrays• An array is a type of variable (or bucket) thatholds many pieces of information.• Example:▫ $rainbow = array(“red”, “orange”, “yellow”,“green”, “blue”, “indigo”, “violet”) $rainbow[0] holds “red” $rainbow[1] holds “orange”
  19. 19. Operators• Arithmetic▫ +, -, *, / (add, subtract, multiply, divide)• Assignment▫ = (“Assign the value of 4 to the variable called a”) $a = 4;▫ += (“Add the value of 5 to the variable that alreadyholds 4”) $a += 5; // $a now holds 9▫ .= (“Attach the value „World‟ to the end of „Hello‟ tomake a new value for the string variable”) $string = “Hello”; $string .= “World”; // would print “HelloWorld” (nospace because we didn‟t add that!)
  20. 20. Operators• Comparison▫ == (“when I compare the value in variable a to thevalue in variable be, that comparison is true”) $a == $b▫ != (“when I compare the value in variable a to thevalue in variable be, that comparison is not true”) $a != $b▫ >, >= (“the value of variable a is greater than (orgreater than or equal to) the value of variable b”) $a > $b▫ <, <= (“the value of variable a is less than (or lessthan or equal to) the value of variable b”) $a < b
  21. 21. Operators• Concatenation• + (string + string = stringstring)• Logical• && (and)• || (or)• ! (not)
  22. 22. Flow Control• ifif (something is true) {do something here}• if ... else ... else ifif (something is true) {do something here} else if (something is true) {do something here} else {do something here}
  23. 23. Flow Control• whilewhile (something is true) {do something here}• forfor (something is true) {do something here}
  24. 24. Procedures and Functions• Scripts can contain linear, procedural code.• Scripts can also contain references to reusablebits of code, called functions.▫ Built-in language functions▫ Functions you write yourself.
  25. 25. Why Python?• It is a general-purpose language• It has been around for a long time (20+ years)• It has a strong developer community• It includes a large built-in library of functionality• It is readable• It is expressive (you can do a lot with a little)
  26. 26. Uncluttered Layout• Less punctuation▫ While some languages use $ to indicate variables, orbrackets around logical constructs, Python does not.• More whitespace▫ Instead of brackets to set off blocks, indentationmeans something in Python.
  27. 27. Variables in Python• Do not begin with a symbol and do not end withterminating punctuation.• Examples:▫ string_variable = “The Library”▫ numeric_variable= 4▫ myname = “Julie”
  28. 28. Set and Print Variables# set up the variablesstring_variable = "The Library";numeric_variable = 4;myname = "Julie";# print the variablesprint string_variableprint numeric_variableprint myname
  29. 29. Arrays in Python• …are called lists.• Example:▫ rainbow = [“red”, “orange”, “yellow”, “green”,“blue”, “indigo”, “violet”] print rainbow[0] shows “red” print rainbow[1] shows “orange”
  30. 30. Operators in Python (are not terribly special)• Arithmetic▫ +, -, *, /• Assignment▫ =▫ +=, -=, *=, /=• Comparison▫ >, <, >=, <=• Logical▫ and, or, not
  31. 31. Flow Control in Python• ifif something is true:INDENT and do something here# here’s an examplepeople = 20space_aliens = 30if people < space_aliens:print "Oh no! The world is doomed"if people > space_aliens:print "Were cool."
  32. 32. Flow Control• if ... elif ... elseif something is true:INDENT and do something hereelif something is true:INDENT and do something hereelse:INDENT and do something here
  33. 33. Flow Control• EXAMPLEpeople = 30cars = 40if cars > people:print "We should take the cars."elif cars < people:print "We should not take the cars."else:print "We cant decide."
  34. 34. Flow Control• whilewhile something is true:INDENT and do something here# here’s an examplecount = 0while (count < 9):print The count is:, countcount = count + 1print "...and were done!"
  35. 35. Flow ControlThe count is: 0The count is: 1The count is: 2The count is: 3The count is: 4The count is: 5The count is: 6The count is: 7The count is: 8...and were done!
  36. 36. Flow Control• forfor there are things in a sequence:INDENT and do something here#here’s an examplerainbow = ["red", "orange", "yellow", "green","blue", "indigo", "violet"]for color in rainbow:print color
  37. 37. Flow Controlredorangeyellowgreenblueindigoviolet
  38. 38. Functions in Python• Start with the keyword def• Accepts parameters• There‟s indentation• You get something in return
  39. 39. Functions in Pythondef fibonacci(n):a, b = 0, 1while a < n:print a,a, b = b, a+bfibonacci(1000)/////////////////////////////////////////////////0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
  40. 40. So How Does Your Group Use Python?• As batch scripts, with or without a web interface▫ One-offs, utilities, etc• Using a Web Framework (Django)▫ Frameworks allow you to write web applicationsquickly because they include, well, a frameworkfor doing so. Reusable libraries common to web applications Coding standards Template and templating processes
  41. 41. Sample Utility (pymarc)• For manipulation of MARC records▫ In GitHub at https://github.com/edsu/pymarc/▫ From command-line or wrapped within an app• Example 1:from pymarc import MARCReaderreader = MARCReader(open(marc.txt))for record in reader:print record[245][a]
  42. 42. Sample Utility (pymarc)• Example 2:from pymarc import Record, Fieldrecord = Record()record.addField(Field(tag = 245,indicators = [0,1],subfields = [a, The pragmatic programmer : ,b, from journeyman to master /,c, Andrew Hunt, David Thomas.]))out = open(file.dat, w)out.write(record.asMARC21())out.close()
  43. 43. Launchpad• Works within a Django framework• Has a directory structure you can follow to findhow things are pieced together• Even in a framework, it is still readable code
  44. 44. Launchpad (example from a template){% extends "base.html" %}{% load launchpad_extras %}{% block title %}{{ bib.TITLE }}{% endblocktitle %}…{% if bib.ISBN|clean_isbn %}ISBN: <a href={% url isbn bib.ISBN|clean_isbn%}>{% url isbn bib.ISBN|clean_isbn %}</a>{% endif %}
  45. 45. Launchpad (example from a template)def clean_isbn(value):isbn,sep,remainder = value.strip().partition()if len(isbn) < 10:return isbn = isbn.replace(-, )isbn = isbn.replace(:, )return isbn
  46. 46. Additional Resources• Learn Python the Hard Way▫ http://learnpythonthehardway.org/book/• The Python Tutorial▫ http://docs.python.org/tutorial/index.html• Django▫ https://www.djangoproject.com/• GWU Libraries GitHub repositories▫ https://github.com/gwu-libraries/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×