Basic Programming Terminology
Presenter: Steve Baskauf
steve.baskauf@vanderbilt.edu
Digital Scholarship and
Communications Office (DiSC)
Unit of the Vanderbilt Libraries
Support for data best practices (DMP tool, repositories), GIS, copyright,
Linked Data (including Wikidata), tools (GitHub, ORCID, Open Science
Framework, etc.), and Open Access publishing.
Offers on-demand educational programming, consultations, web resources
Typically offering lessons on Python, R, and GIS
More online at: vanderbi.lt/disc
Email: disc@vanderbilt.edu
vanderbi.lt/codegraf
What is CodeGraf?
vanderbi.lt/codegraf
Terms for programs
a
program
a generic term for
a complete set of
instructions that
does something
#data = readDict('vanderbilt_units.csv')
#print(json.dumps(data,indent=2))
while True: # infinite loop
print('Time checked:',
datetime.datetime.utcnow().isoformat())
with open('last_run.txt', 'rt',
encoding='utf-8') as fileObject:
date_last_run = fileObject.read()
print('Date last run:', date_last_run)
date_now_utc = generate_utc_date()
print('UTC date now is:', date_now_utc)
if date_now_utc > date_last_run:
run_all_queries()
# Update the date last run
with open('last_run.txt', 'wt',
encoding='utf-8') as fileObject:
fileObject.write(generate_utc_date())
print('done')
print()
# wait an hour before checking again
sleep(3600)
code
instructions
that make up
a program
#data = readDict('vanderbilt_units.csv')
#print(json.dumps(data,indent=2))
while True: # infinite loop
print('Time checked:',
datetime.datetime.utcnow().isoformat())
with open('last_run.txt', 'rt', encoding='utf-
8') as fileObject:
date_last_run = fileObject.read()
print('Date last run:', date_last_run)
date_now_utc = generate_utc_date()
print('UTC date now is:', date_now_utc)
if date_now_utc > date_last_run:
run_all_queries()
# Update the date last run
with open('last_run.txt', 'wt',
encoding='utf-8') as fileObject:
fileObject.write(generate_utc_date())
print('done')
print()
# wait an hour before checking again
sleep(3600)
an
application
(app)
one or several
programs working
together for the end
user
a
script
instructions in a programming language that need to be interpreted
Python script
in a Jupyter notebook
R script
in RStudio
Command-line interfaces (CLI)
consoles
A console is a program that sends text commands and receives text
output
The typical console for Macs is called Terminal
The typical console for Windows is called Command prompt
the
shell
A shell is the program that receives and processes text commands
from a console
bash is a shell that processes commands in the Linux operating
system
Python and R both have shells
shell console
Image from https://www.clipart.email/
CLI vs. GUI
A command-line interface (CLI) is basically synonymous with a shell.
A CLI is in contrast to a graphical user interface (GUI)
command-line interface for Git
graphical user interface for Git
Variables and objects
variables
variables are named locations where we store data
example a variable named "basket" that is a list that can store
multiple alphanumeric strings
classes
and
objects
object: toyotaPrius object: ferrari object: volkswagenBeetle
Class: Car
Classes are abstract categories
of things.
Objects are particular instances
or individuals of a class.
classes
and
objects
object name: fruits
type: list
Class: list
Classes are abstract categories of data
structures.
Objects are particular data structures.
The type of an object is the class to
which it belongs.
There are technical distinctions
between variables and named objects
but we will use them interchangeably.
item[0]
item[1]
item[2]
item[3]
'apple'
'orange'
'banana'
'lemon'
'lime'
object name: ids
type: list
3593
269
45801
2804
object name: in_stock
type: list
True
False
False
Executing code
Statements
Code is made up of
statements
A statement performs a
particular action.
A "line of code" is roughly
the same as a statement
while True: # infinite loop
print('Time checked:', datetime.datetime.utcnow().isoformat())
with open('last_run.txt', 'rt', encoding='utf-8') as fileObject:
date_last_run = fileObject.read()
print('Date last run:', date_last_run)
date_now_utc = generate_utc_date()
print('UTC date now is:', date_now_utc)
if date_now_utc > date_last_run:
run_all_queries()
# Update the date last run
with open('last_run.txt', 'wt', encoding='utf-8') as fileObject:
fileObject.write(generate_utc_date())
print('done')
print()
# wait an hour before checking again
sleep(3600)
# Relationship between age of starting smoking and closeness
# create a factor out of closeness, box and whisker plot, then t-test of means
closeness_factor <- factor(with_maternal$maternal_closeness,
levels = c(0, 1),
labels = c("distant", "close"))
plot(with_maternal$H4TO2 ~ closeness_factor)
t.test(with_maternal$H4TO2 ~ closeness_factor, var.equal=TRUE, conf.level=0.95)
# Relationship between number of days/month smoking and closeness
plot(with_maternal$H4TO5 ~ closeness_factor)
t.test(with_maternal$H4TO5 ~ closeness_factor, var.equal=TRUE, conf.level=0.95)
R code
Python code
a statement
a statement
interactive
vs.
script
mode
In interactive mode, one statement is run at a time in the shell.
Immediate feedback is given after each line.
In script mode, the entire script is run at once. Feedback is only given
when explicitly required by the script.
Both R and Python can be run in either mode.
Writing code with an editor
Code editors
Code editors are text editors on steroids.
They are "aware" of the language in which you are coding.
They generally have syntax checking and highlighting.
They may help with automatic formatting.
Some code editors have capabilities for running the code and are
essentially integrated development environments (IDEs).
Access to digital collections 24/7
Skype consultations with your
subject librarian
Ask a Librarian: an easy way to
submit a question via email
Live chat available from the
Library home page
Remote
Support for
Teaching and
Research
Needs
NEED HELP? ASK A LIBRARIAN!
https://www.library.vanderbilt.edu/ask-librarian.php