This guide explains what programming is, and gives a short overview of different programming languages. If you want to learn a specific programming language, I'm sure there will be other guides. What is programming? Programming is, in short, the process of developing a computer program by giving instructions to your computer. It is much like making a recipe. This is a good metaphor, because most people are familiar with the process of cooking and don't have a problem imagining how you would make a recipe. The general process of making a program, along with a continuation of our cake metaphor, is: 1. Planning. Thinking about what the program should do, what the program shouldn't do, and how it should do it. This is like thinking about what you want a cake to taste like. 2. Coding. This means writing the actual code (Using a programming language) that implements the idea that you have of how your program should work. A simple idea can be surprisingly difficult to express in code! This is like writing the recipe itself, "Mix the dry ingredients with the milk" etc. to create the cake of your dreams. 3. Compiling. This is the process, done automatically by a separate program called a compiler, that translates your code into something a computer can understand called binary. This does not always apply to some languages like Javascript, PHP, and Python: They are compiled when they are run. This is like following the recipe you just wrote, and then putting the cake in the oven. Just like compiling, baking the cake can take some time. 4. Debugging. There will be bugs. The code may make sense to you, but remember, computers do everything you say, no more, no less. You may have forgotten a character here or there, written faulty code, or just generally done something wrong. Whatever it is, it means that your program isn't doing what you want or worse, doing something you don't want. This means you have to go back to step two and look for the problem and if possible, fix it. This is like finding out that you left out the sugar in said cake of your dreams, so you go back and change the recipe. Debugging can take a long time and be very frustrating. 5. Running the program. Well, this isn't really technically part of programming, but it's almost inevitable that you'll want to run your program once you finished it even if you didn't write it for yourself. It's incredibly satisfying, just like eating the finished cake you just made. It's what makes programming worth it. That's a very basic overview of making a program. In the real world if you program professionally, you will very likely have to document your code to tell people how it works so that they can extend it or fix bugs. So what's a programming language, then? A programming language is a language that a compiler can translate into instructions that a computer's processor can execute. Human languages are full of complexities that are often even difficult for other humans to understand, let alone computers. So various programming languages have been invented that have strict rules and simple syntax and grammar. High and low level programming languages One thing that is often said about programming languages is that one or another is a "High level" or "low level" programming language. A low level programming language is quite close in syntax to the instructions given to a processor, and is therefore often incredibly difficult to learn and understand. A high level programming language is closer to human languages, and 99% of the time requires far less code to express an idea and is therefore more often than not very easy to learn and understand. Why use low level programming languages at all, then? Well, since they are so close in syntax to the instructions given to a processor, it requires less instructions to execute which makes it faster and possibly use less RAM. However, since it requires a lot more thought on the part of the programmer, it is often very impractical to write more than 20 lines of it. High level languages are the other way around; Ideas are expressed easily and you can code almost as fast as you can type but the resulting program is almost always slower. An example of a high level programming language is Javascript or PHP (Which are both usually compiled every time they are run), and an example of a low level programming language is assembler, which is possible to even compile by hand. Languages like Java, C, and C++ are somewhere in between, giving a balance between speed and how fast they can be coded. Just to compare, take a look at an example of a very low-level language (ARM assembly language): BUILD MOV R0, R1 ; Move numbers into R0
SUB R2, R2, #1 ; Decrement R4
ADD R1, R1, #1 ; Increment R3
STR R0, [R3] ; Store the value from R0 into memory (only stores a 1)
ADD R3, R3, #4 ; Increment the pointer by four bytes (definitely works)
CMP R2, #0 ; Is this number in R0 equal to 32 (stopping point)?
BNE BUILD ; Start all over again if they're still not equal.
MOVEQ R11, R3 ; Hey, we have the end of the array, let's keep that.
SUB R11, R11, #4 ; //Offset by 4, ran into this bug earlier.
MOVEQ PC, R14 ; Return to main when finished. No, I don't know what it does either. :lol: And now look at a higher level language, any of the examples of programming languages below should show you the difference in readability. Basic programming terminology: Variables Just like in math class, a variable is a number usually represented by letters because the actual value can change. Variables are the nouns of programming languages. Functions Arguments Return variables Conditionals Loops Data types Major programming languages I plan to put up some examples of each major programming language, more elaborate than just "Hello world", here. Contributions welcome. :) Major programming languages, listed alphabetically: [spoiler=C] Used for: Just about everything. Operating systems and programs alike are written in C. A simple language, but very powerful and flexible. Been around since: Forever. Like 1972. Pros: Very simple syntax, there are all kinds of libraries for it. Probably the fastest higher-level language. A good skill to have. Cons: Parts of the language like pointers can be confusing. Alternatives: C++, Java, C# #include <stdio.h>
int somefunction(void);
int main()
{
somefunction();
}
int somefunction(void)
{
int i;
float j;
for (i = 1; i <= 10; j = ++i)
{
if ( (j/2) == (i/2) )
{
printf("i is even\n");
}
else
{
printf("i is odd\n");
}
}
}
[spoiler=C++] Used for: Just about everything. Many programs are written in C++. Been around since: 1983 Pros: Like C, but with the additional advantage of object-oriented programming (Like Java). Still makes for fast-running programs. Cons: Parts of the language like pointers and object-oriented design can be confusing. Alternatives: C, Java, C# #include <iostream>
using namespace std;
class cat {
private:
int size;
public:
void set_size(int);
int get_size();
};
void cat::set_size(int newsize) {
size = newsize;
}
int cat::get_size() {
return size;
}
int main() {
cat Garfield;
Garfield.set_size(20);
cout << "The size of Garfield is: " << Garfield.get_size() << endl;
return 0;
}
[spoiler=Java] Used for: Similar to C, it can be used for just about anything. It's commonly one of the first programming languages taught to programming students. It has a reputation for not being as fast as C but over the years it has been fine tuned to be of comparable speed. Been around since: 1995. Pros: Simple syntax like C, huge support and libraries. Easy to learn (the basics at least). Portable by nature. (You can almost always compile it on any operating system that has a Java compiler without changing any code) Cons: Not quite as fast as C, generally not ported to consoles as well. Alternatives: C++, C, C#
public class Example{
public static void main(String[] args){
someFunction();
}
public static void someFunction(){
int i;
float j;
for(i = 0; i < 10; i++){
j = i;
if((j/2) == (i/2)){
System.out.println("i is even");
} else {
System.out.println("i is odd");
}
}
}
} [spoiler=PHP] Used for: Web programming, especially with databases such as MySQL. Tip.it uses it, this forum is written in it, and several huge sites use it too for example facebook. Been around since: 1995 Pros: Very easy syntax, eventually you can write code almost as fast as you can type. At the same time though, it has some incredibly powerful features like object oriented programming. Very wide usage, many job openings for PHP programmers. Cons: A scripted language that is compiled every time you run it, so compared to languages like C, C++ or Java, it is quite slow. (There is a compiler for it, but it's not in widespread use and right now you have to compile the compiler yourself in order to use it) Alternatives: Python, Perl <?php
$array = array( "Lorem" => "ipsum", "dolor" => "sit", "amet" => "consectetur" );
foreach ( $array as $key => $value )
{
echo $key . " " . $value;
}
echo "<br>";
for ( $i = 1; $i <= 10; $i++ )
{
if ( $odd = $number % 2 )
{
echo "\$i is odd<br>";
}
else
{
echo "\$i is even<br>";
}
} [spoiler=Python] Used for: General scripting, scripting using APIs of programs such as Blender 3D and the GIMP, web programming. Been around since: 1991 Pros: Very easy to learn. An excellent language to learn as a first language. Easy syntax, incredibly powerful. Lots of programs have APIs for python, plenty of extensions and libraries. Can be compiled. Cons: Can't be optimized that much, not as fast as languages like C/C++ and Java. Alternatives: PHP, Perl, C++ def somefunction():
for i in range(1, 11):
j = i + 1
if j/2 == i/2:
print "i is even"
else:
print "i is odd"
def main():
somefunction()
if __name__ == '__main__': main() [spoiler=Javascript] Used for: Browser scripting, such as all the fancy animations and features on facebook, some general scripting like python Been around since: 1995 Pros: Quite easy to learn, lots of great libraries like jQuery for animation, which makes it a pleasure to work with. Can be compiled, technically. Cons: Not at all useful for making real programs, has a lot of quirks especially between different browsers. Alternatives: No real alternative when it comes to browser scripting, but for more general scripting, Python and maybe PHP. function somefunction()
{
for (i = 0; i < 10; i++)
{
if ((%i)/2 == 0)
{
document.write("i is even<br>");
}
else
{
document.write("i is odd<br>");
}
}
}
[spoiler=C#] Used for: Similar to C, it can be used for just about anything. Microsoft's primary programming language for its flagship development platform, .NET. Been around since: 2001 Pros: Simple syntax like C, huge support and libraries. Easy to learn (the basics at least). Portable by nature. (You can almost always compile it on any operating system that has a .NET or Mono compiler without changing any code) Cons: Not quite as fast as C, but probably faster than Java and GUI doesn't look that good on non-Windows OSs, even with GUI toolkits other than Windows Forms. Alternatives: C++, C, Java public class example
{
public static void Main()
{
SomeFunction();
}
public static void SomeFunction()
{
for (int i = 0; i < 10; i++)
{
if (i % 2 == 0)
{
System.Console.WriteLine(i + " is even");
}
else
{
System.Console.WriteLine(i + " is odd");
}
}
}
} Some tips on learning programming languages If you want to get a strong handle on a new language, or even to gauge how well you know your current languages, it is best to tackle problem solving problems, instead of trying to design a program with a purpose. With problem solving you need to understand the syntax and the semantics. Not just copy and paste code and hope it all works out. Figuring out the following problems, or how to write programs that can solve the below programs will definitely increase your understanding of the language or even help you further in becoming a programmer. The following are the basic problem solving tasks I've been told to complete through-out the online tutorials and in-class conditions. This is a list of those problems that I think bring the best outcome in the understanding of the language. Try to mentally figure out how to solve these problems first however: Loops: 1. Write out 1 to 10 using a loop only. 2. Retrieve two numbers as input, and loop from the smaller number to the highest number, then stop. 3. Using only loops write out a multiplication table for the number entered by the user (If they enter 10, do the multiplication table up to 100 - this is a full 10x10 'grid' of numbers, if the number entered was 10, if it is 8, it would be an 8x8 'grid'). Strings: 1. Enter a string as input to the program, and have the program find any occurrences of any character entered by the user. 2. For each letter in a string, increase it so it changes to the next letter ahead of it in the alphabet. Do not increase punctuation symbols or spaces. 3. Read from a file, and for each LINE in the text file, write that line backwards (including punctuation symbols). Not the entire document backwards, but line by line backwards. 4. In a text file, find any 'scattered occurrences' of the word entered by the user. If the word was 'pie', then your program would go through the text file to find the straight scattered occurrences of the letters 'p', 'i', and 'e'. At the end it would output the number of occurrences found and where the occurrences are by line number. Arrays: 1. Swap every two index values in an array, using a loop. 2. Create a multiplication table using an array. 3. Create a 4x4 Sudoku puzzle using an array, without any graphical support, all text based. --- Doing these basic problem solving tasks, you should gain a higher understanding of whatever language you're trying to learn, or get a handle on. This is also very basic in terms of where problem solving can get to in computer programming. Most universities are or should be handing out this level of problem solving questions to first years. Credits: y_guy_4_life (Wrote most of the part about data types, Java example) Tiigon (Python and C++ examples) Jard_Y_Dooku (C# description and example) Makoto_the_Phoenix (ARM assembly language example) skatedog111 ("Programming tips" section)