PDA

View Full Version : Concepts of Programming



xtrapsp
03-19-2013, 12:13 PM
Before we start programming or learning the basics at least, I suppose it would be necessary to read up on how a computer works.
What is a computer?
According to the Von Neumann theory a computer looks something along these lines:

http://i.imgur.com/sUTvMJr.png

It runs in what can be simplified to a basic list of items. Think of this. When you turn on the pc, the CPU is already powered and storing information, it’s just awaiting a signal to boot up and start a line of code. I suppose it could look similar to this:
• Fetch Instruction
• Decode
• Run/Execute
• Fetch Instruction
• Decode
• Run/Execute..
Essentially a program is just a set of instructions which is written in a format the human eye can read, turned into Hexadecimal and Binary and read by the computer. (To simply put it)

What is a compiler/interpreter?

Now we have that out the way, it’s time to start talking about programming itself.
Well, there are two types of script readers, Interpreters and compilers.
Interpreters run code in real time, essentially they take a line of code, run it. Take another line of code. Run it.
Compilers however, read all of the lines of text squeeze it into a format the computer can read and THEN execute it… Clever eh?
Interpreters are used more than before due to being quicker, think of it this way? An old system back in the 50’s – 60’s running on an interpreter? Reading each line individually then progressing? Would have taken a while if the script was over 1000 lines long ;)
There are a few different types of ‘script/code’.
And they are as follows:

http://i.imgur.com/4kMLk6t.png

Decision Statements
If Statement
The ‘If statement’ responds with anything being true or false. For example:

http://i.imgur.com/j6t2Zzv.png

If TimeFromMark is Greater than Time then the result is True.

If else statement
‘if-else statements’ are checking the true and the false. For example, the code here (written in c#) will check if the Boolean flagCheck is true. If it is it will execute the first ‘method’(Blue) if not it will execute the second (Green).

http://img708.imageshack.us/img708/6517/f03975b622d14bb18e25d9e.png

Switch Statements
A switch Statement allows multi-way branching. To sum it up, it allows you to create a complex collection of if-else statements without writing 100’s of lines. In Pascal we call them cases.

http://img33.imageshack.us/img33/9628/e39f7504d5da420a9ebe5ff.png

Recursion

Now we are going to fall a little deeper into Programming with Recursion. I'm not very good at recursion and the only examples I've seen have been poor. But hopefully I can help.

So basically, Recursion is a procedure/function/method which calls itself within itself..

This is the example I have:
http://img51.imageshack.us/img51/9136/ffede7ee047c4cc5b990600.png

As you can see the recursion here is that it is calling itself until the value set in the parentheses. In this example it is defined as n.

I highly suggest for a better tutorial on recursion you click this link:
http://villavu.com/forum/showthread.php?t=98149

Object Orientated Programming
OOP is a programming paradigm that represents concepts or identities as objects. The easiest way to grasp this is to dive in and try it yourself. Objects are used to interact with one another.

So essentially objects are self-contained data structures that consist of 3 things. Properties/Attributes, Methods and events.

Properties are used to specify the data represented by the object
Methods specify an objects behavior.

Classes
These are best seen as blueprints for an object. They define how the object behaves with the methods within.

Method
Methods are the 'important' parts to classes, procedures etc etc.

The bit highlighted below is a method:
http://img.ctrlv.in/514875dc665fa.jpg

So essentially Methods is everything between { and } (In Most Languages).

However, with Pascal we use begin and end.
http://i.imgur.com/nBCxs2n.png

Nesting

Nesting is essentially a method in a method... So in simba you will see it as begin begin end end.

E.g:

http://puu.sh/2sw6j

I've colour coded the nesting, hopefully that will be easier to understand :)

For now I am done. I will probably write a tutorial in the future which gets more and more difficult.

speedster
03-19-2013, 01:59 PM
Nice start mate :) hope this tutorial gets to cover most of OOP programming in time! Good luck with it, looking forward to seeing it expanded!

NKN
03-19-2013, 02:40 PM
Nice job. Will give indepth response when I get home. Class is about to end for this period. (Villavu is unblocked. >: D)

DannyRS
03-19-2013, 03:00 PM
C#!

Interesting read xtrapsp <3 would love to see more

xtrapsp
03-20-2013, 01:15 AM
Will keep adding to it ^^

King
03-20-2013, 03:45 AM
Will keep adding to it ^^

Liked it, we could have a basic programming course here >:) Keep it up!

Valithor
03-20-2013, 05:08 AM
Hey xtrapsp!

Great tutorial! Please keep adding more information! It's good stuff. :D

Spartan 117
01-22-2014, 06:37 PM
Good start. I would also like to see more OOP!