[Programming Guides] Part 1 • Introduction to programming

Discussion in 'Code Snippets and Tutorials' started by ricky92, Jan 31, 2008.

  1. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Programming Guides • Part 1
    [hr="98%"][/hr]
    Introduction to programming

    Visual Basic, C#, PHP, Python, Perl, C++, Pascal, Java, Delphi, ActionScript... There are too many programming languages to learn them all, at least for now. However, they have many things in common: the concepts. In fact, if you already know a programming language then it's easier to understand another language, even if it's pretty different. First things to understand about it is how a program works. It's not as easy as it looks like: even a simple program which just plays "Tic tac toe" takes time to be made. A program is not smart: it can only be if you make it so. Every single thing a program does has to be explicitly written: you cannot just tell a program to press a button on a webpage and autobuy for you, you have to write every single step. And to do this, programming languages use similar ways: they can execute routines or functions; there is just one big difference between them: the first can only execute the code in it, the second can also return a value. Ok, I understand this is not easy to understand, so I'll make a (really stupid :p ) example:

    Ok, stupid example but that should do the job. First example: John just does something. Second one: John does something to have something else in return. That's basically the same difference between routines and functions! :) However, you might be asking yourself where routines and functions store their values... in variables. They are called like this because they can vary (they can be modified during the runtime, in other words). They can store different types of values, depending on what type of variable they are: Strings (they store text), Integers (they store numbers, without decimals), Singles and Doubles (they store numbers WITH decimal numbers; doubles can store more decimal values), and many other kinds. You can use variables in a lot of ways: to store a value, to return a variable's value, to update another variable's value (or its own value), etc... Of course, you can use numbers as you would do with a simple calculator. However, every programming language has built-in functions and subs to make the programmer's life easier. But, as I already said, you still have to make processes yourself: built-in functions can help, but nothing more. Another way to store values is to store them in costants. However, as the name suggests, they can't be modified during runtime: this means they will have the same value for all the time the program will run.
    Now that most of the basis are explained, we can start analyzing a more difficult topic: conditions and loops. The first is not that hard to understand: if the specified condition is true, then the code below will be executed, if not, the code in the condition will be skipped or another (optional) piece of code will be executed instead of the other. An example to clarify this:

    Example explains all. :p It's not THAT difficult, is it? Another construct in programming languages are loops. They can be of 3 kinds:

    1. Repeat the code X times
    2. Repeat the code for each element in something
    3. Repeat the code until a precise condition is true

    However, this will be explained with next parts of this guide: even though programming languages have similar ways to make loops, it's better to explain them when I can make an example based on code and not events (bye, John :D ) :p

    This is the end of the first part of my programming guide. I hope you have understood everything; if not, just post here your questions.

    Next part will be about how web and http works. I know this is not REAL programming yet, but I can guarantee this is needed. It will be easier to understand anything about internet programs, and how they do and should work.