Tutorial: Basic Programming Concepts

DeletedUser

Guest
This will be a series of very basic concepts, if you have questions or want clarifications just ask, likewise if there's one you've heard of and want explained.

Also... if these are boring and you all know it all already, let me know, we'll go onto some more advanced stuff?
 
Last edited by a moderator:

DeletedUser

Guest
Variable Assignment

Just like algebra at school (you were listening right?), except it's an ongoing process, not just words on paper...

Code:
x = 5

the variable 'x' represents 5 to your program. Note that in most languages x is different from X, and you should always program to accomodate this. Never rely on 'tEsT' to be the same as 'TeST'

Code:
x = x + 5

This is fine to do, hopefully self-explanatory.
 
Last edited by a moderator:

DeletedUser

Guest
Data Types

All languages use datatypes. Some hide them from you (PHP, Javascript) while others force you to abide by types.

Char - A character. Bear in mind that this includes 0-9, and punctuation etc. If you're really interested you can find out what your language can take (for the most part, the ASCII character set, just google it) in a character variable

String - a list of 'character' variables. See? easy this.

Int - an integer, a whole number without a decimal point. Memory allocation decides how big this number can be, but for your immediate purposes I would suggest that this is not necessary to know.

Float - a floating point, used to represent massive numbers, and seriously interesting to your inner geek. You'll find yourself boring someone in the future - may deserve a future longer post.

Boolean - contains the values true/false.

These are the major datatypes. There are others, and when you program in an object orientated language (which PHP is, now) you'll create your own datastructures.

When I say some languages hide them, I mean that in Javascript (for instance) you assign a variable thus:

var junk = 5times3

Javascript itself (the compiler that interprets JS) decides which datatype you're using and does what it feels like - in this case a String.
 

DeletedUser

Guest
Logic Tests

Code:
if (something){
 do something
}else{
 do something else
}

fairly self explanatory? the if/else command is going to come up everywhere. The important things is the way to use it, logic gates are necessary:

OR (usually || in programming (next to z))

Code:
if (x == 5 || x == 6)

AND (&&)

Code:
if (x == 5 && x == 6)

you can see that you have to be careful (this is a sesamy street example I agree, you'll come up against others)

If you care about other operators, you're probably an electrical engineer...
 

DeletedUser

Guest
Object Orientated core concept

We discussed Chars and Strings further up.

If you can understand the concept that Strings are groups of chars, you've got the basic idea behind OO.

Imagine further that I can create my own objects, and so I'll create one called Dog.

I'll also create one called Kennel (Pound in America?). Kennel might contain a list of the dog objects it knows about and wants to do something with. But it's important to understand the Kennel doesn't contain the ID for Dog (it can, but that's stupid), it contains the actual Dog object.

Everything is an object. Objects ONLY have properties and methods. Here's an example in PHP for simplicities' sake:

Code:
class Dog{
 private $hair_colour;
 private $gender;

 function bark(){
   //do a bark
   echo "bark";
 }
}

Ok, a couple of things above - most people have a standard for naming things, I've used a capitol D, never normally would, don't worry about it for now, it'll change.

// represents comments (in most langauges. /* */ for blocks of comments). use them OFTEN. your code isn't going to make sense in 5 minutes from now, let alone a week.

private (also public, protected, other keywords like static etc) not important at this moment. In PHP in particular you don't have to declare whether things are private or public.

Now I want to use this object:

Code:
$barney = new Dog();
$barney->gender = "not sure";

I've used the 'new' keyword to create a new dog who's a bit confused. '->' is the keyword in PHP to use or to access a property or function of the class we're discussing.
 

DeletedUser2795

Guest
could you do this in a specific Programming Language?
And you forgot arrays and pointers...
 

DeletedUser5

Guest
could you do this in a specific Programming Language?
And you forgot arrays and pointers...

It's not necessary to do it in a specific programming language, they are all very much the same. The all have the same data structures, it is just the syntax for declaring these data structures that is different.

There are many things that are missing from this tutorial, but I am assuming that it is not finished yet. However, the content covered so far is great.
 
Top