You are viewing our Forum Archives. To view or take place in current topics click here.
Programming Basics
Posted:

Programming BasicsPosted:

Kyle93
  • Winter 2021
Status: Offline
Joined: Jun 25, 201013Year Member
Posts: 4,078
Reputation Power: 2628
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Status: Offline
Joined: Jun 25, 201013Year Member
Posts: 4,078
Reputation Power: 2628
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html

Stickied by iPatobo

Programming Basics


Welcome, if you are reading this you wish to learn some of the basics of programming. Now, this does not apply to every language and will not be the same for each langage as many languages have a different syntax. However, with that being said it can be applied to most if not all language as this fundamentals are used in each language I know.

What this includes


  • What is programming
  • What is a "language" and some examples
  • Commonly used terms
  • Sequence
  • Iterations (Loops)
  • Logic
  • Debugging
  • Methods
  • Variables


What is programing?

Good question, there is no point trying to learn something if you don't even know what it is you are learning. Wiki defines programming as:
Wikipedia wrote Computer programming (often shortened to programming or coding) is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic.


Get it? If not, let me explain. What it is saying is that when you are programming you are creating the code for a program. So what ever browser you are using, that was coded. Your operating system, that was coded. So someone has sat down and wrote in the programming of there choice the application you are using.

What is a "language" and some examples

Much like English, French, German there are many different programming languages. Each one is different. They are different in a few ways such as the syntax.
Two examples of this are Java and VB6. If I wanted to do an "if" statement then print the result then I would do this (Parts have been omitted).
Java

int test = 1;
if ( test > 1 )
{
System.out.println("test is more than 1");
}else{
System.out.println("test is not more than 1");
}


Compared to VB6

Dim test As Integer
test = 1
If test > 1 Then
MsgBox test
End If


There are many many more and they differ in many many ways.

Some common terms

Debugging - If your programming is not working as you expected you would debug it. This means that you try and find the errors in the program using some tips and tricks such as stepping through the program or adding printouts to test variables and statements.
Compiling - This is where you need to put your code together to be run.
Syntax - ""In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language. The syntax of a language defines its surface form." - Wiki
Semantics - In computer science, the term semantics refers to the meaning of languages, as opposed to their form (syntax). According to Euzenat, semantics "provides the rules for interpreting the syntax which do not provide the meaning directly but constrains the possible interpretations of what is declared." In other words, semantics is about interpretation of an expression. Additionally, the term is applied to certain types of data structures specifically designed and used for representing information content." - Wiki

Sequence


double cost = num1 * num2;
System.out.print( "The total is" );
System.out.print( cost );


Above we see an example of multiplying two numbers together.

Sequence is really simple and is that it will run through the lines of code. So in the above example it would times two numbers together and store them in a "double" it would then say the total is then print out the value of "cost" so all it has done is run down the lines of code and done what it has said.

Iteration

It would take us ages and make the program uncontrollable if we had to repeat lines over and over again and in many situations impossible if you had to do it for every single variable scenario. So to get around this, there is iteration or looping. This basically allows us to do the same bit of code over and over again as many times as we want.

So we could do this (Java)


Int test = 0;
test++;
test++;
test++;
test++;
test++;

This would mean that test is now has a value of 5. As ++ means add one. However an easier way would be this.


int test = 0;
while( test < 5 )
{
test++;
}


What that would do is to say while test is less that 5 add one to it. When its 5 stop.

Logic

Logic, logic in many ways is one of the hardest things in programming to be able to do. It can't really be taught. Basically, every scenario would have many answers to it. Logic comes in in two ways, firstly a solution to the situation that works. Secondly, the most effective solution. This is the bit that is hard to do.
Take this problem, create a triangle of stars at a user entered width. Like so:
5
*****
*****
*****
*****
*****

Now there are many ways you could do this such as

public class Main
{
    public static void main( String args[] )
    {
        System.out.print("#Enter the amount of rows and columns: ");
        int amount = BIO.getInt();

        for ( int z = 0 ; z < amount ; z++ )
        {
            for ( int x = 0 ; x < amount ; x++ )
            {
                System.out.print( "*" );
            }
        x = 0;
        System.out.println();
        }
    }
}


Now this way is by no means the best way, its jut one answer to the problem. Logic can depend on you and your style of programming. To improve your logic, you would need to find small problems and map them out. Use seudo code and flowcharts to get an idea of how you want the program to work.

Debugging

Debugging can be one of the biggest things in programming. It allows you to identify errors and where there are issues. Take this example I had, I was working on a collision based on x and y coordinates of a ball. I wanted to see if the ball had hit a wall, so I added a print out saying collision when the statement of is the ball colliding true. That meant I could see when it was colliding and what part of the IF's where wrong.
So, some of the useful things are:
The inbuilt debugger, most programs have an inbuilt debugger so you can put a break-point in and then go line by line through your program and see what the values of the variables are at each line.
Print outs, print out useful information that can be used to see if conditions are true. This is much like the debugger but is in real time so you can see if it gets repeated.
Use other values, is this error only with that value? I had a program that worked with every number but 11 once.
There is more, however that covers most points. However there is at lot more, debugging is worth being good at.

Methods

Well, if you have made it this far then we will go in to some more basics. Firstly, methods. A method is a section of code that you knows work and has been tested, it is also to keep code well organized. For example.

public class Main
{   
    public Main()
    {
        int x = 10;
        int y = 25;
       
        int result = add(x,y);
        System.out.println(result);
    }
   
    public int add(int x, int y)
    {
        int result = x + y;
        return result;
    }
}

Could also be done like

public class Main
{   
    public Main()
    {
        int x = 10;
        int y = 25;
       
        int result = x + y;
        System.out.println(result);
    }
}


Now for this example, doing no2 would be easier. However, this is for my example. So, time to break this down.

int result = add(x,y);
Ok, now this above line is the confusing line. What we are doing is creating a integer called "result" and the value of it is the returned value of the method add. The x,y in the () are what we are sending to the method. So we are giving the method add the values of x and y so 10 and 25.

public int add(int x, int y)
Ok, this line is where we define our method. We are saying its a public method, so it can be accesed from many places. We will be returning an integer value. It's called add. The values we get in to this method will be called x and y. Now x and y could be called anything like mum or jord it does not matter.

return result;
This line is what we are giving back from the method. So we do our calculation and then we store it and return the result of that.

Variables

One of the main parts of programming is variables and storing data. There are many types of variables and they change per language you are using, however the basics are the same. In each language they are called different things and are declared in different ways, here is an example.

Int x = 0;
Double y = 0.00;
Long z = 0;
String c = "This is a string";

Well, those are some of the most common variables used in Java. Int, Double, Long deal with numbers, String deals with all chars. What a variable does is take a value it is allowed to take, numbers etc, and then store it for you to use.

You can do many things with variables, such as change them.

Int x = 0;
x = 5;


Add them together

Int x = 0;
Int y = 10;
Int z = x + y;


Compare them

Int x = 0;
Int y = 10;
If ( x == y )


Notice, in Java its = to assign but == to compare. This is the same in a few languages.

Variables work not like normal math. For example, x = y + 10; would not make sense mathematically. However you need to look at it like this. x = (y+10) so you would add 10 to y then say that y+10=x.

Hope this helps some people, please leave some feedback on things I missed, things I did not explain well and things you liked. Good luck!

Credit:
Wiki - For some quotes and references
My programming tutors - Obvious reasons are obvious
Everything else was typed and worded by me


Last edited by Kyle93 ; edited 3 times in total

The following 5 users thanked Kyle93 for this useful post:

Churro- (10-12-2012), TTG-Flashing (08-26-2012), jkg2249 (06-25-2012), xInfected (04-23-2012), Blankeh (04-20-2012)
#2. Posted:
Chris
  • Winter 2023
Status: Offline
Joined: Nov 27, 201013Year Member
Posts: 1,469
Reputation Power: 19356
Motto: Only you can judge your life. You have to live up to your own expectations.
Motto: Only you can judge your life. You have to live up to your own expectations.
Status: Offline
Joined: Nov 27, 201013Year Member
Posts: 1,469
Reputation Power: 19356
Motto: Only you can judge your life. You have to live up to your own expectations.
Nice topic mate very detailed this might come in handy later so I bookmarked
#3. Posted:
iHasZombiesHD
  • Prospect
Status: Offline
Joined: May 22, 201112Year Member
Posts: 679
Reputation Power: 46
Status: Offline
Joined: May 22, 201112Year Member
Posts: 679
Reputation Power: 46
Pretty good man. Right now working on a project with my friend. Its a mod tool. Same exact source as Horizon, the closest i have ever seen
#4. Posted:
Ahri
  • Administrator
Status: Offline
Joined: Mar 21, 200915Year Member
Posts: 1,352
Reputation Power: 57230
Motto: mwah
Motto: mwah
Status: Offline
Joined: Mar 21, 200915Year Member
Posts: 1,352
Reputation Power: 57230
Motto: mwah
Oh my god, reading this makes my head hurt.

Noob friendly I would guess, but I'm not much of a coding person.

Great Job on the topic.
#5. Posted:
OG-
  • TTG Senior
Status: Offline
Joined: May 03, 201112Year Member
Posts: 1,532
Reputation Power: 64
Status: Offline
Joined: May 03, 201112Year Member
Posts: 1,532
Reputation Power: 64
If i will ever try to learn how to code, i will come straight to this post!
#6. Posted:
Torquay
  • Rising Star
Status: Offline
Joined: Sep 21, 201013Year Member
Posts: 711
Reputation Power: 31
Status: Offline
Joined: Sep 21, 201013Year Member
Posts: 711
Reputation Power: 31
Nice Post Bro

Film
#7. Posted:
Blankeh
  • Winter 2020
Status: Offline
Joined: Aug 22, 201013Year Member
Posts: 4,218
Reputation Power: 261
Status: Offline
Joined: Aug 22, 201013Year Member
Posts: 4,218
Reputation Power: 261
Well I just read through it and it helped me quite a bit.

Some bits I had to re-read to get it stuck in my head, but that's just me

Well put thread, I have bookmarked for further reference.
#8. Posted:
Kyle93
  • Retired Staff
Status: Offline
Joined: Jun 25, 201013Year Member
Posts: 4,078
Reputation Power: 2628
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Status: Offline
Joined: Jun 25, 201013Year Member
Posts: 4,078
Reputation Power: 2628
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Dil wrote Oh my god, reading this makes my head hurt.

Noob friendly I would guess, but I'm not much of a coding person.

Great Job on the topic.


Cheers man. Programming > Ponies

Any parts you would like to see re-worded?

OG- wrote If i will ever try to learn how to code, i will come straight to this post!


Awesome, glad to know. Anything you would like to see added?

Film wrote Nice Post Bro

Film


Thanks, anything you would to see added?

Blankeh wrote Well I just read through it and it helped me quite a bit.

Some bits I had to re-read to get it stuck in my head, but that's just me

Well put thread, I have bookmarked for further reference.


Thanks a lot, if you had to re-read bits is there ways I can make them clearer?

To_Catch_A_Predator wrote Nice topic mate very detailed this might come in handy later so I bookmarked


Thanks man, as you know if you wanna know anything send me a pm :p
#9. Posted:
Zoo
  • TTG Addict
Status: Offline
Joined: Aug 13, 201112Year Member
Posts: 2,113
Reputation Power: 103
Status: Offline
Joined: Aug 13, 201112Year Member
Posts: 2,113
Reputation Power: 103
This is very informative. Nice job! I will refer back to this when I get a little interested in learning more then just HTML/PHP. :p

Also, gratz on the sticky!
#10. Posted:
iHasZombiesHD
  • Prospect
Status: Offline
Joined: May 22, 201112Year Member
Posts: 679
Reputation Power: 46
Status: Offline
Joined: May 22, 201112Year Member
Posts: 679
Reputation Power: 46
Oh god a sticky ? Nice job man
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.