Today, we will introduce some terminology we will be using for the remainder of the semester. Some of these terms will be redefined in more detail later in the semester; however, we need to start somewhere!
- IDE - Integrated Development Environment. For our purposes, Visual Studio - the program we use to write our programs.
- Program (Verb) - To write a series of statements that instruct the computer to perform calculations, make decisions based on values, or perform some action repeatedly.
- Program (Noun) - The end result of programming - a compiled series of statements that a processor can execute.
- Statement - The equivalent of a sentence in the English language, a statement is one complete instruction. Usually, we place one statement per line of our program (although some statements may span multiple lines). Some languages require symbols to indicate the end of a statement (quite often the semi-colon) like English uses a period to indicate the end of a sentence.
- High Level Language - Computers process instructions in binary form - represented by 1's and 0's. However, it is difficult for people to think in that form, so we write in "English-like" form to generate source code. When we want to distribute our program, the program must be compiled by a compiler (built into the IDE in VB's case).
- Syntax - the rules of the language. Defines how to write the program. Some languages have a syntax that require a semi-colon at the end of a statement. Others define case-sensitivity (VB's syntax does not require case-sensitivity, but it is a good thing to try to use!)
- Syntax error - the compiler cannot translate your program to binary because you have misspelled or misused a word.
- Logical error - your syntax is correct, so your program can be compiled; however, your program does not function as expected. The computer did what you asked, but you didn't ask the right thing!
- Computers can report syntax errors (identified by wavy blue underlining in the IDE). However, it can't identify logical errors. Syntax errors are easier to identify and fix. The only way to check for logical errors is to test your program using predicable values. For example - if my program adds 2 numbers, then I should test by entering 2+2, and verifying that the answer it gives me is 4!
- Object - a piece of code that defines something in programming. Object Oriented Programming (OOP) is an idea that says we try to envision and then program mechanisms for storing data in a natural way.
- Property - an adjective that describes an object. Objects tend to have many properties. For example, the button control (object) we drug onto our screen has text on the front. I am allowed to change create multiple buttons, with different text. This text is stored in a property of each button.
- Method - a verb that describes what I can do with an object. For example, I might have a text box on my screen. One of the things it can do is erase all text in the box - this is the Clear method.
- Variable - a name for a piece of memory where we can store a value. Variables store values and represent them when needed - like algebra!
- Literal - a value that is hard coded in your program.
- Pseudocode - Sort of "rough draft" notes for our program, doesn't use real programming instructions
- Keyword, or reserved word - A word that has meaning to the language, and can't be used as a variable name. For example, IF is a word that indicates a decision must be made in our program. We are not allowed to use the word IF to hold a value (i.e. use it as a variable name).
- Comment - code that is ignored in our program - used to leave notes to the programmer (things to do, or an explanation of what a line does for other programmers on your team).
- Event - some activity that the user triggers in your program. An event driven language (like VB) runs code in response to the user doing something (clicking on a button, typing, etc.
)
- In the "Hello world" program, we set up a piece of code that said "Show a box on the screen with the text Hello world". However, this code didn't run until we clicked on our box. To write this program, we wrote a piece of code, and then wrote an Event Handler for the button.
- An event handler says "watch for an interaction with a control on the screen". How many ways can a user interact with a button using a mouse and keyboard? Well, they could click on it, move the cursor over it, or type while the cursor is over it... a button can watch for all of these events.
- The event handler listens for these events, and then runs the code we associated with that event.
- Control - the name for a Graphical User Interface object (GUI) that we can use in our program. The toolbox has a list of controls available for use.
- Object Orientation
- What is Object-Orientation?
Object-Orientation is a paradigm for creating software systems using objects.
Objects are tangible and conceptual things we find in the real world.
Using OO, the code is broken into modular, reusable chunks called classes.
Classes are the "blueprint" for creating instances of objects.
These classes can be used throughout an application again and again - without the programmer needing to understand how the code for that specific object works!
- In older languages, if we wanted to build a car racing game, we might need to create 20 variables that describe a car - it's color, top speed, MPG, and so on. Trying to maintain a list of all these values was confusing - it would be like trying to take notes for all of your classes you take with sticky notes, and having them scattered around the room in no particular order. Finding what you want is a challenge! Instead, in an OOP language, we "wrap" the values that describe one specific car (one instance) into a car object - just like you should have one notebook binder for each class. Your notes for a particular class are arranged together in one binder, and those notes don't get mixed up with other notes from a different class, making it easier for you to find and work with the notes for a specific class!
- Object orientation is a way of building "data-centric" applications. Our program, at the simplest level, simply store data and then processes it; with object oriented programming, storing and organizing the data becomes easier, so we can focus on processing.
- Example - on day 1, we created a "Hello World" application that showed us a box on the screen with our message. I personally don't know how it works - I've never seen the underlying code that draws a box on the screen. However, I have learned it's interface - it's name, how I need to run (call) it from my code, and what values it needs to run (in this case, it needs to know what text you want to show in this box).
- What Are The Benefits Of OO?
OO emphasizes creating reusable, robust software in a way that is easy
to understand. By relating programming to the real world, it becomes much
easier to use. Some of the characteristics of OO are:
- Comprehensible - modeling of data after real-world counterparts
- Reusable - faster, modular development
- Robust - increased quality
- Simple - easy maintenance
- Flexible - easy to modify
- Concepts Overview
There are a lot of concepts involved with OO. But let's just cover the
basics for now and maybe this will help you get a better understanding
of OO:
- Classes - A generic blueprint used to create similar objects. We
can have a Human class for instance. All of these humans would breathe
air, have a head, etc. Specific instances of these objects may be
different, having different heads, but they would all share the same
characteristics.
- Encapsulation - Hides object data and implementation details. Protects
the state of the object from other programs and other programs are
protected from changes in implementation. Encapsulation is the ability
to hide the internal workings of an object's behavior and its data.
For instance, let's say you have a object named Car and this object
has a method (another word for behavior) named start(). When you create
an instance of a car object and call its start() method you are not
worried about what happens to accomplish this, you just want to make
sure the state of the car is changed to 'running' afterwards. This
kind of behavior hiding is encapsulation and it makes programming
much easier. When you want your car object to be in a 'running' state,
instead of calling: fuel.on(), starter.on(), etc., you just call start().
This not only makes it easier to work with, but if the internal workings
of this start() method have to change, the results will be the same.
Encapsulation goes hand in hand with placing your code into a component
and using this component when needed. By placing the logic we need
for similar processes into a component, we eliminate the need to rewrite
that code throughout an application every time the process has to
be modified. When we need to make a change to that process, we simply
modify that component and the change is propagated throughout the
application wherever you used the component.
- Inheritance - Allows code reuse by building on existing classes.
Using inheritance you can create a base class Mammal and then build
on this class, creating a subclass called Human that has all of the
inherent properties of its base class. We don't need to redefine the
characteristics all mammals share (for example, give birth instead
of laying eggs) when defining a subclass of mammals.