Let's imagine that before functions came into programming, programmers would have to write everything they wanted to do out in a program. Simple enough. But let's say a programmer wanted to do a particular math computation or problem that was long and tedious, and he wanted to do it more than one time, let's say fifty times in one program. It would get pretty long and tedious writing out all those instructions for the math computation over and over again! In step the purpose of functions!
Functions are like small commands for programs. Actually you can think of a computer program like one giant function. A function, or functions, just provide a way to call a certain set of instructions or a task for the program to execute, such as adding a group of numbers or checking a database for example.
A simple function in a program can look like this,
function addnumbers {
$a=1;
$b=2;
return $a+$b;
}
The function addnumbers in this case will return the number 3. Of course this is a very simple function but it shows the way that functions can work. In a more complex function you would pass parameters to the function (values from outside the function) to give you greater results.
Think of a function as a way to perform a particular task without having to write everything out over and over again. Functions can be simple or complex, but they give programmers a way to write out a particular task they want the program to execute, and store all those steps in tasks in a function with any name that can be called at anytime in the program. Then when the function is called the program will execute the code in the function and be on its merry way! How great!
Monday, June 15, 2009
What are Functions?
What are Variables?
A variable in programming is anything that can be set and changed (hence the name variable, because it can vary throughout the program).
A good example of this is, let's say I wanted to set the variable "a" as the number 1. Then anytime I called this variable "a" in my program, it would return it's value that it is been set with, which is '1'.
A variable doesn't necessarily have to be a number, it can be a letter (referred to as a 'character' or even a group of letters (called a 'string') or an even larger number. Basically it can be anything that we need to store.
A variable can be set anywhere in a program, and then called later and it will retain the value that it has been given for the life of the program (stored in its memory) until the program is run again.
Thursday, May 28, 2009
What is the Best Programming Language?
There is no "best" programming language, there are all sorts of different kinds of programming languages out there, each with it's own strengths and weaknesses (you just have to research each one to find out what this is). Each programming language was created and designed to do a different function, and a lot were created to do something that others could not do, so really you have to explore around to find which is the best one to start out with.
Some of the more popular languages right now are Java, C, C++, etc. but there are always new and up and coming languages every day. Just find one that is right for you.
What is Compiling?
Compiling, is the process by which a program is changed from human readable code (in whatever language the code is being written in) into machine readable code that a computer can execute and understand.
Every programming language has it's own compiler, and is always needed to compile your program before it will run. There are many free and also commercial compilers out there that you can choose from, each with its own features and benefits (the more advanced custom ones costing more and more money). But rest assured, you can always find a free compiler somewhere (99% of the time).
The amount of time it can take to compile a program can vary depending on the size of the program from a couple of seconds to possibly a couple of hours depending on the size of the file/program. Most of your basic ones will compile very quickly, no worries.
A compiled program is usually one that ends in something like .exe (executable).
What is a Program?
A program is a set of instructions that your Computer/PC interprets into machine language to perform a certain task. Programs can be created in a variety of languages such as C, C++, Java, Python, etc. and each language has it's own syntax and way of doing things, but the PC is able to interpret each one the same.
Welcome to Basics of Programming
Whether you are trying to learn Java, Javascript, PHP, C, C++, Python, ASP, Basic, or any other programming language, there are some basics that encompass all programming languages in general. Here we will discuss some of those basics in order to give you a solid foundation in programming in general and also to help you learn any programming language with ease.
So have fun and get ready to learn!
