Skip to content

Instantly share code, notes, and snippets.

@briandk
Forked from anonymous/babys-first-functions.py
Created November 2, 2016 21:42
Show Gist options
  • Save briandk/67764d61a63dd375b330ee5606a50ac6 to your computer and use it in GitHub Desktop.
Save briandk/67764d61a63dd375b330ee5606a50ac6 to your computer and use it in GitHub Desktop.
Maybe we don't need object-oriented programming (OOP) in a first-semester computational modeling course
# Here's a dictionary literal with data and behavior in one line of code
baby1 = {
"first_function": lambda x: x + 1,
"first_words": "Zoiby want to buy on margin"
}
# Here's a much more complicated OOP solution in 5 lines
class Baby:
def __init__(self, first_function, first_words):
"""
Make a baby
"""
self.first_function = first_function
self.first_words = first_words
baby2 = Baby(lambda x: x + 1, "Zoiby want to buy on margin")
baby1["first_words"] # Zoiby want to buy on margin
baby2.first_words # Zoiby want to buy on margin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment