Skip to content

Instantly share code, notes, and snippets.

@kylelong
Last active February 10, 2019 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylelong/bbdafcdfc543f7faf9d63f43d22d6180 to your computer and use it in GitHub Desktop.
Save kylelong/bbdafcdfc543f7faf9d63f43d22d6180 to your computer and use it in GitHub Desktop.
Functional & Object Oriented Programming
Functional Programming
----------------------
Throughout our daily or weekly lives, we often do several tasks repeatedly. For example, brushing your teeth,
introducing yourself to a stranger, making your bed, etc. It would be very convenient if we could snap our fingers
and say, "Make my bed" after every night’s rest. Unfortunately, this is not (yet) the case. Well, in programming, there are
task that programmers know they will have to do over and over again. Maybe calculating the number of days until Christmas, checking if a number is prime, counting letters in a word, etc. It is often very useful to create functions or blocks of reusable code that a program can invoke to execute a this consistent task instead of writing out the code every single time. Instead of writing code and figuring out the logic everytime, functions can be created. For example, static int numOfLetters(String s) { return s.length();}, calculate how long the word (string) s is. Instead of having to rememver the syntax (s.length()), a programmer can say numOfLetters. This makes reusbale, farily easy to understand, and if there is an error in the code, it is probaly in ONE place (not many), which makes it easier to solve issues.
Object Oriented Programming
---------------------------
An object is essentially any tangible thing. Well, in programming and object is an entity that represents a real world component. Objects in real life have attributes about them. For example, A person's bank account can be an object that has a checking and savings account, with balances for each, account numbers, etc. When a new person wants a bank account, it can be thought of instantiating (creating) a new bank account with the entities of a checkings and savings account, balance, pin number, account numbers, etc. In Computer Science it is often useful to represent these use cases in code with groupings of code called classes and create new representions (instantiate the class) of real world scenarios by manipulating the newly created object's fields with functions. These functions are often referred to as getters (retrieve a object's value) and setters (update or set a object's value). This is a very useful technique to create accurate, real world models with code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment