Main paradigms
Various classifications of programming paradigms
- Imperative Programming
- how to execute stuff, defines control flow
- statements change a program state
- Declarative Programming
- what to execute, defines program logic
Programming paradigm is a high-level way to structure and conceptualize the implementation of a computer program.
Some paradigms are about the way code is organized, some about grammar and syntax, and some about implications of program execution.
Originally, their purpose was to classify programming languages.
Various classifications of programming paradigms
my_numbers = [1,2,3,4,5,6,7,8,9,10]
Imperative Style:
Languages like Java, C, C++, Python
Another major classification of programming paradigms
Procedural Style:
Where is functional programming superior to imperative or object-oriented programming and why?
Object Oriented Programming (OOP):
Languages like C++, Java, Python, R
Typically, OOP languages allow inheritance.
Great concept to allow for code reuse and extensibility.
Where is OOP beneficial to use and why?
Scripting languages.
Scripting languages are used to manipulate, customize, and automate facilities of an existing sytem.
Scripting languages are usually interpreted at runtime rather than compiled.
Scripting languages can make your life so much easier!
…automation, remember?
Why AWK is so great… Consider the amazon review dataset:
http://jmcauley.ucsd.edu/data/amazon/index_2014.html
or an updated version
https://nijianmo.github.io/amazon/index.html
The total number of reviews is 233.1 million (142.8 million in 2014).
An excerpt from a book review
marketplace customer_id review_id product_id product_parent product_title product_category star_rating helpful_votes total_votes vine verified_purchase review_headline review_body review_date
US 22480053 R28HBXXO1UEVJT 0843952016 34858117 The Rising Books 5 0 0 N N Great Twist on Zombie Mythos I've known about this one for a long time, but just finally got around to reading it for the first time. I enjoyed it a lot! What I liked the most was how it took a tired premise and breathed new life into it by creating an entirely new twist on the zombie mythos. A definite must read! 2012-05-03
Data Columns of Amazon Review dataset (excerpt):
01 marketplace - 2 letter country code [...]
02 customer_id - Random customer identifier [...]
03 review_id - The unique ID of the review.
04 product_id - The unique Product ID the review pertains to.
05 product_parent - Random product identifier [...]
06 product_title - Title of the product.
07 product_category - Broad product category [...]
08 star_rating - The 1-5 star rating of the review.
09 helpful_votes - Number of helpful votes.
10 total_votes - Number of total votes the review received.
11 vine - Review was written as part of the Vine program.
12 verified_purchase - The review is on a verified purchase.
13 review_headline - The title of the review.
14 review_body - The review text.
15 review_date - The date the review was written.
Obtain all star ratings:
awk '{ print $8 }' reviews.tsv
Obtain the average star rating over the entire dataset:
awk -F '\t' '
{ total = total + $8 }
END { print "Average book review is", total/NR, "stars" }
' reviews.tsv
Is AWK even fast enough? An example with ~1.7GB of data.
Adam Drake reported a 47x speedup compared to a Hadoop cluster using standard awk.
(Drake, n.d.)
Using an optimized version of awk gained a 235x speedup compared to Hadoop on ~1.7GB of data.
(12 seconds vs. 26 minutes)
On a Laptop.
(Drake, n.d.)
Scripting languages can help you with your daily routines or repetetive tasks
rename.py
:
# importing os module
import os
folder = "xyz"
for count, filename in enumerate(os.listdir(folder)):
dst = f"Hostel {str(count)}.jpg"
src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
dst =f"{folder}/{dst}"
os.rename(src, dst)
> python3 rename.py
(Joshi 2022)
Concluding the scripting languages:
You should learn at least one of them.