|
You have a fairly good understanding already, although you have not realised it. Being able to see that there are a set of core principles (Meta principles, if you will) at work behind every language is a big (and hard) step for beginners to take. Alas, you already surpassed that point. Yet, you should not waste any time learning how to code. Invest your time learning about patterns. Every program out there is a pattern. From the moment you start to think about how it may work, to the moment you ship it, all you are doing is thinking up patterns that aim to solve a problem. Let's take for example the following problem: You have to get some data from the user through
a webpage. The pattern to do that is to include a
form in the webpage where the user types in the
data we want. Then the user submits the data by
clicking on a button. Following that we receive
the data and store it in a variable or
array (like a bucket, but for data). From that point
forward we process it with things called functions
,which are nothing more than little bits of code that
only have one task to complete. We then test to see
if that data is in a condition that we can use it.
Thus we include in the pattern a set of conditionals
to test if the data is good to go. If its not good to
go, then we either fix it or trash it. Our pattern
might include some functionality to tell the user that
the data typed in is good, and conforms to what we
need. We may also need to return the data in modified
form to the user. Maybe the user wanted to know
what is the meaning of the word *perro* in English
, so we send back the answer to the user. Perro is
dog in spanish.
Now, let's write a simple program that follows that
same pattern.
<!-- the form where the user submits the data-->
<form action="/submit" method="post">
<input type="text" name="search">
<input type="submit" value="search">
</form>
<!-- /of form -->
<?php
//the following code is not secure at all.
$input = $_POST['search']; //look up there where it says name="search".
function translate ($input)
{
if($input == "perro") //does the user want to translate the word "perro"?
{
return "dog"; //if he/she does then give him the translation.
}
else
{
return "I don't know.";
}
}
//let's use the function to test the data.
$output = translate($input);
echo $output; //this displays the information back to the user.
?>
But wait, we can also do it in python. Let's use a simple python program to show you how. #Python 2.7.X
input = raw_input("What do you wish to translate?") #get the data from the user.
def translate(input): #the translate function.
if input == "perro":
return "dog"
else:
return "I don't know"
output = translate(input) #use the function on the data gotten from the user
print output #display the results back to the user.
See the similarities in the programs? Notice the pattern? Even though they are two different languages (three if we include HTML), they both follow the same basic pattern to solve the problem at hand.You must now focus of learning new patterns of how given problems are solved. For example, getting data from a website, processing it, etc. Patterns do get more
complicated as you advance, even to the point of not being able to understand them. But dont feel bad, most problems are solved using the simple stuff. From here on, I would focus on learning every possible language I could get my hands on. But learn by doing, and not by reading (read -> test and repeat). If you need any assitance, feel free to email me. Best wishes. |