0% found this document useful (0 votes)
37 views23 pages

Basic Programming Terminology

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views23 pages

Basic Programming Terminology

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Basic Programming Terminology

Presenter: Steve Baskauf


[email protected]
vanderbi.lt/codegraf

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: [email protected]
vanderbi.lt/codegraf

What is CodeGraf?
Terms for programs
a program #data = readDict('vanderbilt_units.csv')
#print(json.dumps(data,indent=2))

while True: # infinite loop


print('Time checked:',
datetime.datetime.utcnow().isoformat())

• a generic term for with open('last_run.txt', 'rt',


encoding='utf-8') as fileObject:
a complete set of date_last_run = fileObject.read()
print('Date last run:', date_last_run)
instructions that date_now_utc = generate_utc_date()
does something 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)
#data = readDict('vanderbilt_units.csv')
#print(json.dumps(data,indent=2))

code while True: # infinite loop


print('Time checked:',
datetime.datetime.utcnow().isoformat())

• instructions with open('last_run.txt', 'rt', encoding='utf-


8') as fileObject:
that make up date_last_run = fileObject.read()
print('Date last run:', date_last_run)
a program 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

R script
in RStudio
Python script
in a Jupyter notebook
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

shell console

• 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

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
Classes are abstract categories
of things.
Objects are particular instances
or individuals of a class.

Class: Car

object: toyotaPrius object: ferrari object: volkswagenBeetle


classes and objects
Classes are abstract categories of data
structures. item[0]
Objects are particular data structures. item[1]
The type of an object is the class to item[2]
item[3]
which it belongs. …
Class: list
There are technical distinctions
between variables and named objects
but we will use them interchangeably.

'apple' 3593 True


'orange' 269 False
'banana' 45801 False
'lemon' 2804
'lime'
object name: fruits object name: ids object name: in_stock
type: list type: list type: list
Executing code
while True: # infinite loop

Statements 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)

• Code is made up of date_now_utc = generate_utc_date()


print('UTC date now is:', date_now_utc)

statements if date_now_utc > date_last_run:


run_all_queries() a statement
• A statement performs a # Update the date last run

particular action. with open('last_run.txt', 'wt', encoding='utf-8') as fileObject:


fileObject.write(generate_utc_date())

• A "line of code" is roughly print('done')


print()

the same as a statement # wait an hour before checking again


sleep(3600)

R code
# 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) a statement
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) Python code
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

Remote
Support for Skype consultations with your
subject librarian
Teaching and
Research Ask a Librarian: an easy way to
Needs submit a question via email

Live chat available from the


Library home page
NEED HELP? ASK A LIBRARIAN!
https://www.library.vanderbilt.edu/ask-librarian.php

You might also like