What is a “Function” in Programming?, & What is “Object Oriented Programming” (OOP)–Notes
Functions
Function–a block of code packaged together with a name.
- Functions are a core feature of all programming languages.
- aka–sub-routines, methods, or some other name.
- a way to break up your code.
- a key benefit of functions is that they help us avoid writing the same lines of code again & again.
Once you create a function, you can call it by using its name followed by a set of parenthesis( ).
- Functions can change their behavior depending on the parameters and arguments given.
To have a function return a value, use the “return” statement. Ex: ‘return my_value’
Being able to return values from functions is a cornerstone of programming.
Library
Library–a grouping of variables and functions that someone else has written and verified. A standard library contains reusable classes & functions that help programmers create portable programs!
- Best Practice Tip
- Read the documentation for the version of the programming language you are using! Refer to the documentation (freely available online!) frequently to be sure you are aware of the rich collection of features and that you are using them correctly.
- If after reading the documentation, you are still unsure of how a feature works, experiment using a small text program and see what happens. Run the programs and study any errors generated and correct the program to eliminate the message.
Pseudocode is an informal means of expressing program logic.
Object Orientation–a natural way of thinking about the world and writing computer programs. Basic object technology concepts include classes, objects, attributes, behaviors, encapsulation and inheritance.
Object orientation is the key programming methodology used by programmers today. Not until object-oriented programming became widely used in the 1990’s did software developers feel they had the tools to make major strides in the software development process.
Object technology is a packaging scheme that helps us create meaningful software units. With object technology, the software entities created (called ‘classes’), if properly designed, tend to be reusable on future projects.