Sunday, April 7, 2019

Functional Programming Principals in Scala

After a long break (Advanced Algos took a lot out of me), I decided it was time to take another class. When the topic of taking the Scala series of classes from Coursera came up in my programming group, I jumped at the chance. I needed a break from theory, and a chance to do some coding in a new language was just the ticket. This post covers the first course in the series, "Functional Programming Principles in Scala". tl;dr: Take this course, it's great!



I thought about doing a detailed summary... then I thought about doing a condensed summary... then I said fuck it, my time would be better spent writing code and continuing to the next class (and honestly no one reads these posts anyway lol). So I put together this basic outline instead so that I can at least feel like I have something to show...
  • Week 1
    • Intro and Setup (I used IntelliJ)
    • 1.1 - Programming Paradigms
    • 1.2 - Elements of Programming [Scala Substitution Mode]
    • 1.3 - Evaluation Strategies and Termination
    • 1.4 - Conditionals and Value Definitions
    • 1.5 - Example: square roots with Newton's method [code]
    • 1.6 - Blocks and Lexical Scope
    • 1.7 - Tail Recursion
    • Programming Assignment: Recursion [solution]
  • Week 2
    • 2.1 - Higher-Order Functions
    • 2.2 - Currying
    • 2.3 - Example: Finding Fixed Points
    • 2.4 - Scala Syntax Summary
    • 2.5 - Functions and Data
    • 2.6 - More Fun With Rationals
    • 2.7 - Evaluation and Operators
    • Programming Assignment: Functional Sets [solution]
  • Week 3
    • 3.1 - Class Hierarchies
    • 3.2 - How Classes Are Organized
    • 3.3 - Polymorphism
    • Programming Assignment: Object-Oriented Sets [solution]
  • Week 4
    • 4.1 - Objects Everywhere
    • 4.2 - Functions as Objects
    • 4.3 - Subtyping and Generics
    • 4.4 - Variance (Optional)
    • 4.5 - Decomposition
    • 4.6 - Pattern Matching
    • 4.7 - Lists
    • Programming Assignment: Huffman Coding [solution]
  • Week 5
    • 5.1 - More Functions on Lists
    • 5.2 - Pairs and Tuples
    • 5.3 - Implicit Parameters
    • 5.4 - Higher-Order List Functions
    • 5.5 - Reduction of Lists
    • 5.6 - Reasoning About Concat
    • 5.7 - A Larger Equational Proof on Lists
  • Week 6
    • 6.1 - Other Collections
    • 6.2 - Combinatorial Search and For-Expressions
    • 6.3 - Combinatorial Search Example
    • 6.4 - Maps
    • 6.5 - Putting the Pieces Together [code]
    • Programming Assignment: Anagrams [solution]

I was so bored with this post, I amused myself by writing a snippet of JavaScript to extract the bullet points from the Coursera website because I didn't want to type them out myself:

items = document.getElementsByClassName("rc-WeekItemName")
acc = ""
for(var i = 0; i < items.length; i++) {
 item = items[i]
 acc += item.textContent.replace(/^.*(?=[0-9]\.)/,"") + '\n'
}
console.log(acc)


The high level take aways for me were:
  • Tail recursion is good, do that.
  • Avoid mutable state like the plague.
  • Pattern matching is good, do that.



No comments:

Post a Comment