http://en.wikipedia.org/wiki/Computer_science
Every computer scientist is a programmer, every programmer write recipes that is interpretaded by computer to do some action. You build process or systems with recipes that make what you want.
The first concept to learn is an algorithm, look in the Wikipedia:
http://en.wikipedia.org/wiki/Algorithm
Every algorithm is a recipe, you can create a recipe to make a cake, you need input stuff, like milk, chocolate, etc... and create a system using a sequence of actions, the output is the cake.
The algorithm receives input data that pass through some conditions(sequence of actions) to create output data, you can display the outputdata in the monitor screen.
Every mathematical function is an algorithm.
When you solve a mathematical problem, it is an algorithm too, because you define a sequence of actions or steps, that you need to do to solve an algorithm.
You can encapsulate a recipe in a method, it is call black box function, for example, a black box function, is a system that you don´t see, for example when the cooker make the cake with a recipe, if you dont look to him making the cake, it is a black box function, what happens is:
Cake chocolateCake = makeCake(milk, chocolater, butter, etc...);
makeCake is the blackBox function that hide what happens from your eyes, chocolateCake is the food produced, the output data, and the type of the food is Cake. makeCake is called procedure in Computer Science.
To make a procedure, you need to learn logic first, the basis of logic is cause and consequence.
Logic
First thing you need to learn is Logic, the World we live (Earth) is a logical place, there is no magic, it is cause and consequence, The plants grow, because they have the necessary input data: land, water, CO2, the procedure is called photosynthesis, the output data is a bigger plant or a surviving plant, more O2, fruits.
Boolean Logic
The boolean logic is based in true and false, you check if a condition is valid (cause) and produces a consequence.
You probabilly have heard, that computers is all about binary code, binary code is a sequence of 0 or 1. Binary code is the basis of Boolean Logic,
because zero represents false and one represents true.
http://en.wikipedia.org/wiki/Boolean_logic
When you work with boolean Logic there is a table called Truth Table, that represents the axiom of an boolean operation, for example, when you say: "a line is a sequence of dots", it is an axiom, an axiom is something basic that is truth by definition and you cannot prove, it is used to build systems.
boolean variables: a, b
operation: and
Truth table
a | b | result | what happens |
0 | 0 | 0 | if a is false and b is false, so the result (intersection) between them is false. |
0 | 1 | 0 | if a is false and b is true, so the result (intersection) between then is false, if they are not equal, there is no intersection. |
1 | 0 | 0 | if a is true and b is false, so the result (intersection) between then is false, if they are not equal, there is no intersection. |
1 | 1 | 1 | if a is true and b is true, so the result (intersection between them is true). |
Now i will program what it means for example:
for comparition we use the == signal for equal, we use != for not equal, to give a value for a variable, we use =, the type of variable is in the left side, Comment is /////
//// Begin of Code //////
////// Declaration of variables //////
boolean beautifulFace = false;
boolean beautifulBody = true;
boolean beautifulPerson;
////// Block of Code One ///////
///////// Cause///////////////////////////////////////////////////// ////////////// Consequence ///////
if( beautifulFace == true and beautifulBody ==true) { beautifulPerson = true; }
else if( beautifulFace == false and beatifulBody == true) { beautifulPerson = false; }
else if(beautifulFace == true and beatifulBody == false) { beautifulPerson = false; }
else if(beautifulFace == false and beatifulBody == false) { beautifulPerson = false; }
////// End of Block of Code One ///////
/// Now we will write the same block in a smaller way, the negative of (1,1,1) in the table, is the rest of the table {(1,0,0), (0,1,0), (1,1,0)}, this is represented by the else alone symbol:
if( beautifulFace == true and beautifulBody ==true) { beautifulPerson = true; }
else {beautifulPerson = false;}
////////// End of Code ////////////
input data of the recipe is beautifulFace, beautifulBody.
output data of the recipe is beautifulPerson.
Nenhum comentário:
Postar um comentário