The Computer Monkey
The Computer Monkey is a blog loosely based around the modern world, the Internet, computing and advancing, yet as ever new but possibly ludicrous technologies. Where an area strikes me with interest or inspiration, I'll write up about it to share with you readers and with a bit of luck you'll enjoy reading it!
Monday, 4 July 2011
What's Annoyed Me blog
Hi readers, I've decided to start a new blog with a completely different outlook, reflecting on the troubles and annoyances surrounding life. The What's Annoyed Me Blog will hopefully interest some readers and bring them delight, as I intend to makle a more personal impression on the blog. The blog will try to entale personal stories relating to my anger for everyday hurdles, and even try to impose solutions to what may seem nightmare issues. As ever, a humorous undertone will be part of it's integrity and you can view it here.
Saturday, 2 July 2011
Back and ready to blog
Hi everyone, I started the Computer Monkey Blog quite some time ago now but I never kept up with the writing within the year. On top of being lazy, procrastination and actually doing my studies, I think I've come to terms with where I went wrong last time.
So I built my little page on blogger and gave it a nice gimmicky name. Boom! It was up! And all it took was a measly five minutes. Thereafter came writing the material however, you'll probably notice that in my previous posts I tried to write something almost once every two days. In reality, at least now anyway I was probably overestimating how much time I actually had. Two days goes faster than you think! Nonetheless I think I need to remind myself that blogging is a hobby. I'm writing because I enjoy it... not because I have to. I'm also pretty guilty with initial fascinations, but this time I'm not going to let that peddle me out. Well, thats the plan anyway. My goal is blog to my heart's content and blog when the time feels write. Here's to hoping it works for me this time.
So I built my little page on blogger and gave it a nice gimmicky name. Boom! It was up! And all it took was a measly five minutes. Thereafter came writing the material however, you'll probably notice that in my previous posts I tried to write something almost once every two days. In reality, at least now anyway I was probably overestimating how much time I actually had. Two days goes faster than you think! Nonetheless I think I need to remind myself that blogging is a hobby. I'm writing because I enjoy it... not because I have to. I'm also pretty guilty with initial fascinations, but this time I'm not going to let that peddle me out. Well, thats the plan anyway. My goal is blog to my heart's content and blog when the time feels write. Here's to hoping it works for me this time.
Labels:
blogging hobby,
blogging issues,
Blogging return
Tuesday, 3 November 2009
Delphi Tutorial Part 3
Loops
It can be very tedious for someone to write out code that needs to be repeated on more than occasion. Likewise, it can be impossible to predict how many times we want some code to repeated. REPEAT, WHILE and FOR are statements that enable us to avoid these kind of situations, and without them, programming would be almost certainlly a very dull task.
The WHILE statement is the most conventional form of a loop. If you want to execute lines of code repeatedly, but you unsure if you want to execute them in the first place, this is the loop to choose. While a certain condition is true, the code is repeated.
a:=1;
while (a<=3)
begin
writeln(a);
a:=a+1;
end;
You can see by this example, the integer(a) is continuously output on screen until it is equal to or less than 3. Therefore, the numbers 1, 2 and 3 should be written on each line. You can see that this can be particularly useful when you need to ensure some code is repeated a certain number of times. Although, the FOR loop can do the same job but do the counting for you.
for i:=1 to 3 do
writeln(i);
This loop assigns the value 1 to the variable to begin with, and then counts up to 3 as it outputs each number turn by turn. The next example shows how the same can be applied to character variables (assigned as char), and also how loops can count down as well as up.
for mycharacter:='D' downto 'A' do
writeln(mycharacter);
This loop should result in the characters D, C, B and A to be output on screen in this exact order.
The last type of loop (REPEAT) executes code on at least one occasion, and then a check is made with an ending conditional statement. In contrast, the conditional statement is marked using the word UNTIL, and if the condition is true then the loop is stopped.
a:=1;
repeat
writeln(a);
a:=a+1;
until (a>3)
end;
Like the other examples, the variable a is output to the console with each iteration of the loop. The variable is incremented by one with each iteration until the number is larger than 3. Therefore 1, 2, and 3 are all written out on different lines.
In the next section of this tutorial you will learn how to organise your programs by sectioning parts of code into procedures or functions.
It can be very tedious for someone to write out code that needs to be repeated on more than occasion. Likewise, it can be impossible to predict how many times we want some code to repeated. REPEAT, WHILE and FOR are statements that enable us to avoid these kind of situations, and without them, programming would be almost certainlly a very dull task.
The WHILE statement is the most conventional form of a loop. If you want to execute lines of code repeatedly, but you unsure if you want to execute them in the first place, this is the loop to choose. While a certain condition is true, the code is repeated.
a:=1;
while (a<=3)
begin
writeln(a);
a:=a+1;
end;
You can see by this example, the integer(a) is continuously output on screen until it is equal to or less than 3. Therefore, the numbers 1, 2 and 3 should be written on each line. You can see that this can be particularly useful when you need to ensure some code is repeated a certain number of times. Although, the FOR loop can do the same job but do the counting for you.
for i:=1 to 3 do
writeln(i);
This loop assigns the value 1 to the variable to begin with, and then counts up to 3 as it outputs each number turn by turn. The next example shows how the same can be applied to character variables (assigned as char), and also how loops can count down as well as up.
for mycharacter:='D' downto 'A' do
writeln(mycharacter);
This loop should result in the characters D, C, B and A to be output on screen in this exact order.
The last type of loop (REPEAT) executes code on at least one occasion, and then a check is made with an ending conditional statement. In contrast, the conditional statement is marked using the word UNTIL, and if the condition is true then the loop is stopped.
a:=1;
repeat
writeln(a);
a:=a+1;
until (a>3)
end;
Like the other examples, the variable a is output to the console with each iteration of the loop. The variable is incremented by one with each iteration until the number is larger than 3. Therefore 1, 2, and 3 are all written out on different lines.
In the next section of this tutorial you will learn how to organise your programs by sectioning parts of code into procedures or functions.
Saturday, 31 October 2009
Delphi Tutorial Part 2
Conditional Statements
So far we have made a program to execute a bunch of fixed commands, so no matter what happens, all of the statements in that program will be carried out in chronological order. There are many cases though where we only want to carry out actions under certain cases or conditions, and this exactly what we're going to do in this part of the tutorial. The statements IF, ELSE and CASE will be demonstrated here to bring out a decision based element in our program. To do this, we will request an input about someones age and provide either a younger or an older user response.
Whenever we want to make a simple decision we use IF. The statements that follow IF are considered to be the conditions or expressions.
If (a=1) then
Begin
writeln('a equals 1');
end;
All of the commands after then are executed if the conditions turn out to be true. Above you can see that if the variable a equals 1, then the actions between begin and end are executed. In this scenario, the message "a equals 1" is output on screen. As this is an If statement though, and not the end of our program, END has to be terminated with a semi-colon.
You can choose to declare more than one condition in an IF statement, by using more than one group of brackets. We also have to separate two or more conditions using operators like OR, AND, XOR. The code below is an example of how we do this, and how much of a difference these operators can make.
Using the OR operator
If (a=1) OR (b=1) then
begin
writeln('either a or b equal 1');
end;
Using the AND operator
If (a=1) AND (b=1) then
begin
writeln('both a and b equal 1');
end;
In the first case, either a or b can be equal to one for the If statement to be true. Although with the second case, both a and b have to be equal to one for the if to be true. If the statement is in fact false, we can also choose to bind some instructions to this false condition using ELSE. ELSE in programming is just like saying, otherwise do this...
If (a=1) AND (b=1) then
begin
writeln('both a and b equal 1');
end
else
begin
writeln('either a or b does not equal 1');
end;
Now you can see that if a or b isn't equal to one, then a message is written on screen declaring that this is the case. However now that we have used the ELSE statement, we also have to shift the semi-colon from the IF clause down to the ELSE clause. Even better, you can choose to remove begin and end from both of these clauses if there is only one line inside them, like so.
If (a=1) AND (b=1) then
writeln('both a and b equal 1')
else
writeln('either a or b does not equal 1');
Here is a list of most of all the possible operators you can use in Delphi, with a small explanation of the purpose of each. Most of these are to be used in actual expressions like an equals sign, unlike the example above where AND/OR are used to join up expressions.
AND: both expressions on either side of this operator must be true to execute the code.
OR: one of the expressions on either side of the operator must be true to execute the code.
XOR: the expression on the left must be true, or the expression on the right must be false.
NOT: the expression that follows must be false for the condition to be true.
=: the left side of an expression or equation must be exactly equal to the right side for it to be true.
<: the left side of the equation must be less than the right side for the condition to be true.
<=: the left side of the equation must be less than or equal to the right side to be true.
>=: the left side of the equation must be larger or equal to the right side to be true.
=!: the left side of the equation must not be equal to the value on the right to be true.
<>: the left and right side of the equation cannot be equal to each other for the condition to be true.
You can go a step further with the IF and ELSE statements by rooting them off one another.
if (a=1) then
begin
if (b=1) then
writeln('both a and b equal 1')
else
writeln('just a equals 1');
end
else
if (b<>1) then
writeln('both a and b don't equal 1');
Sometimes you can have a ridiculous number of these statements, and so the CASE statement exists to simplify things greatly.
Case a of
1: writeln('a equals 1'); //case 1
2: writeln('a equals 2'); //case 2
3: writeln('a equals 3'); //case 3
else
writeln('a is less than 1 or larger than 3');
The only problem with the case statement, is that you can't use a string variable. You have to use an ordinal or fixed variant, such as an Integer.
Now that you have got to grips with how conditional statements work, hopefully you should understand the new code we will be adding below to our program.
program MyFirstProgram;
var
nameVar: String; //name variable
age: Integer;
begin
writeln('What is your name? ');
readln(nameVar);
writeln('Hello '+nameVar+' how old are you?');
//new code starts here
readln(age);
if age<23 then
writeln('Oh, so do you still study?')
else
writeln('What do you do for living?');
end.
We've added a new variable called age to use in our conditional statement, and have classed it as an integer as we only want to store a whole number. We then use IF to see if the age that was input, was less than 23 and then proceed accordingly. If the age was less than 23 we ask if this person is still studying, but otherwise we ask what they do for a living.
The next chapter in this tutorial covers loops, and how a process can be repeated as often as you want without re-typing code.
So far we have made a program to execute a bunch of fixed commands, so no matter what happens, all of the statements in that program will be carried out in chronological order. There are many cases though where we only want to carry out actions under certain cases or conditions, and this exactly what we're going to do in this part of the tutorial. The statements IF, ELSE and CASE will be demonstrated here to bring out a decision based element in our program. To do this, we will request an input about someones age and provide either a younger or an older user response.
Whenever we want to make a simple decision we use IF. The statements that follow IF are considered to be the conditions or expressions.
If (a=1) then
Begin
writeln('a equals 1');
end;
All of the commands after then are executed if the conditions turn out to be true. Above you can see that if the variable a equals 1, then the actions between begin and end are executed. In this scenario, the message "a equals 1" is output on screen. As this is an If statement though, and not the end of our program, END has to be terminated with a semi-colon.
You can choose to declare more than one condition in an IF statement, by using more than one group of brackets. We also have to separate two or more conditions using operators like OR, AND, XOR. The code below is an example of how we do this, and how much of a difference these operators can make.
Using the OR operator
If (a=1) OR (b=1) then
begin
writeln('either a or b equal 1');
end;
Using the AND operator
If (a=1) AND (b=1) then
begin
writeln('both a and b equal 1');
end;
In the first case, either a or b can be equal to one for the If statement to be true. Although with the second case, both a and b have to be equal to one for the if to be true. If the statement is in fact false, we can also choose to bind some instructions to this false condition using ELSE. ELSE in programming is just like saying, otherwise do this...
If (a=1) AND (b=1) then
begin
writeln('both a and b equal 1');
end
else
begin
writeln('either a or b does not equal 1');
end;
Now you can see that if a or b isn't equal to one, then a message is written on screen declaring that this is the case. However now that we have used the ELSE statement, we also have to shift the semi-colon from the IF clause down to the ELSE clause. Even better, you can choose to remove begin and end from both of these clauses if there is only one line inside them, like so.
If (a=1) AND (b=1) then
writeln('both a and b equal 1')
else
writeln('either a or b does not equal 1');
Here is a list of most of all the possible operators you can use in Delphi, with a small explanation of the purpose of each. Most of these are to be used in actual expressions like an equals sign, unlike the example above where AND/OR are used to join up expressions.
AND: both expressions on either side of this operator must be true to execute the code.
OR: one of the expressions on either side of the operator must be true to execute the code.
XOR: the expression on the left must be true, or the expression on the right must be false.
NOT: the expression that follows must be false for the condition to be true.
=: the left side of an expression or equation must be exactly equal to the right side for it to be true.
<: the left side of the equation must be less than the right side for the condition to be true.
<=: the left side of the equation must be less than or equal to the right side to be true.
>=: the left side of the equation must be larger or equal to the right side to be true.
=!: the left side of the equation must not be equal to the value on the right to be true.
<>: the left and right side of the equation cannot be equal to each other for the condition to be true.
You can go a step further with the IF and ELSE statements by rooting them off one another.
if (a=1) then
begin
if (b=1) then
writeln('both a and b equal 1')
else
writeln('just a equals 1');
end
else
if (b<>1) then
writeln('both a and b don't equal 1');
Sometimes you can have a ridiculous number of these statements, and so the CASE statement exists to simplify things greatly.
Case a of
1: writeln('a equals 1'); //case 1
2: writeln('a equals 2'); //case 2
3: writeln('a equals 3'); //case 3
else
writeln('a is less than 1 or larger than 3');
The only problem with the case statement, is that you can't use a string variable. You have to use an ordinal or fixed variant, such as an Integer.
Now that you have got to grips with how conditional statements work, hopefully you should understand the new code we will be adding below to our program.
program MyFirstProgram;
var
nameVar: String; //name variable
age: Integer;
begin
writeln('What is your name? ');
readln(nameVar);
writeln('Hello '+nameVar+' how old are you?');
//new code starts here
readln(age);
if age<23 then
writeln('Oh, so do you still study?')
else
writeln('What do you do for living?');
end.
We've added a new variable called age to use in our conditional statement, and have classed it as an integer as we only want to store a whole number. We then use IF to see if the age that was input, was less than 23 and then proceed accordingly. If the age was less than 23 we ask if this person is still studying, but otherwise we ask what they do for a living.
The next chapter in this tutorial covers loops, and how a process can be repeated as often as you want without re-typing code.
Thursday, 29 October 2009
Delphi Tutorial Part 1
Variables
Variables in programming are used to hold useful bits of information. Numbers, characters, words, lists, memos, and any kind of data that needs to be referenced to, should have an associated variable. Variables in Computing also need to be assigned to different classes. These will be covered in a latter part of the tutorial, but in summary, they tell us what kind of data input there should be, and restrain us from using inappropriate data. In Delphi for example, the string class holds 225 bytes of data (255 characters), the integer class can hold any number between -2147483648 and 2147483647, and the double class can hold a decimal value up to 308 or negative 308 base 10. These three classes are the only ones you will need for now, but other very useful classes will covered in the course of this tutorial. A variable should proceed var in the main program with a unique name, followed by a colon and the class. Below I have wrote a sample program to show how a variable can be used to store your name, and give you a welcome message.
program MyFirstProgram;
var
nameVar: String; //name variable
begin
writeln('What is your name? ');
readln(nameVar);
writeln('Hello '+nameVar+' how are you doing today?');
readln();
end.
Since you probably only just discovered the language five minutes ago, we will need to cover some syntax here.
Every application in Pascal must begin with the word Program and there by followed by the name you would like to assign to it. This is our first command in our program, so therefore like any other instruction we need to terminate the command with a semi-colon. After this we declare our list of variables following var and then we initiate the main body of our program with the word begin. Thankfully we end our program just as easily using the word end. Programmers often refer to these as the beginning and the end of a clause. writeln() is used to output text to the screen, and an input is taken from the next line using readln() where hopefully the user should type in their name. Note, the name of the variable has been placed in between the brackets in order to return the value we need. You may notice at the end of of our writeln statement, we have added text to the end of it by using two '/' characters. This is known as a comment, and in bigger and more commercial situations these permit us to post reminders or pointers for you or any colleagues you may have. Then lastly, the writeln command is used again to output text but with the addition of the user's name. A variable here can almost be treated like a number, the name is inserted just by using addition signs and the name of the variable. The final line uses a read command with no output variable, to ensure that the text can be read by the person. Without this the program would just instantly end on the input of your name.
Variables of the Integer or floating point class can be treated similarly. The main difference is that only values can be added to them as opposed to text. We could have a variable name called a, and then assign a value to this using an equals sign. Likewise we could do the same with a variable named b, add the two together and then return this value to a third variable (called c maybe).
program AnotherProgram;
var
a: Integer;
b: Integer;
c: Integer;
begin
a:=1;
b:=1;
c:=a+b;
writeln(c);
readln();
end.
Delphi was made to assign values to variables by using the colon and the equals sign, but it is worth remembering that the standard is just the equals sign.
The next part of the tutorial will be about conditional statements, to help you understand how to trigger actions under certain events where necessary.
Variables in programming are used to hold useful bits of information. Numbers, characters, words, lists, memos, and any kind of data that needs to be referenced to, should have an associated variable. Variables in Computing also need to be assigned to different classes. These will be covered in a latter part of the tutorial, but in summary, they tell us what kind of data input there should be, and restrain us from using inappropriate data. In Delphi for example, the string class holds 225 bytes of data (255 characters), the integer class can hold any number between -2147483648 and 2147483647, and the double class can hold a decimal value up to 308 or negative 308 base 10. These three classes are the only ones you will need for now, but other very useful classes will covered in the course of this tutorial. A variable should proceed var in the main program with a unique name, followed by a colon and the class. Below I have wrote a sample program to show how a variable can be used to store your name, and give you a welcome message.
program MyFirstProgram;
var
nameVar: String; //name variable
begin
writeln('What is your name? ');
readln(nameVar);
writeln('Hello '+nameVar+' how are you doing today?');
readln();
end.
Since you probably only just discovered the language five minutes ago, we will need to cover some syntax here.
Every application in Pascal must begin with the word Program and there by followed by the name you would like to assign to it. This is our first command in our program, so therefore like any other instruction we need to terminate the command with a semi-colon. After this we declare our list of variables following var and then we initiate the main body of our program with the word begin. Thankfully we end our program just as easily using the word end. Programmers often refer to these as the beginning and the end of a clause. writeln() is used to output text to the screen, and an input is taken from the next line using readln() where hopefully the user should type in their name. Note, the name of the variable has been placed in between the brackets in order to return the value we need. You may notice at the end of of our writeln statement, we have added text to the end of it by using two '/' characters. This is known as a comment, and in bigger and more commercial situations these permit us to post reminders or pointers for you or any colleagues you may have. Then lastly, the writeln command is used again to output text but with the addition of the user's name. A variable here can almost be treated like a number, the name is inserted just by using addition signs and the name of the variable. The final line uses a read command with no output variable, to ensure that the text can be read by the person. Without this the program would just instantly end on the input of your name.
Variables of the Integer or floating point class can be treated similarly. The main difference is that only values can be added to them as opposed to text. We could have a variable name called a, and then assign a value to this using an equals sign. Likewise we could do the same with a variable named b, add the two together and then return this value to a third variable (called c maybe).
program AnotherProgram;
var
a: Integer;
b: Integer;
c: Integer;
begin
a:=1;
b:=1;
c:=a+b;
writeln(c);
readln();
end.
Delphi was made to assign values to variables by using the colon and the equals sign, but it is worth remembering that the standard is just the equals sign.
The next part of the tutorial will be about conditional statements, to help you understand how to trigger actions under certain events where necessary.
Wednesday, 28 October 2009
A world without the Internet
Some have wondered what the world would come to if the Internet just suddenly disappeared. Some would become jobless; large online businesses like Google and Yahoo would collapse; people could lose contact, and generally the world would be a duller place. Over at www.cracked.com people have posted their own visions of a World tomorrow, without the Internet. People have been rewarded for their works in a photoshop competition.
The World tomorrow if the Internet disappeared
The World tomorrow if the Internet disappeared
Monday, 26 October 2009
How to start Programming
There are many ways to which someone can choose to program, but I think a lot of people don't realise the potential that is out there. People can choose to do electronic programming which is known as low-level programming, or develop software of their own (high-level programming). Both of which are now widely available, but nevertheless the processes carried out in the two are different. Without a doubt, programming is easier and more flexible than people think or make it out to be. At the most, with a month's learning anyone can grasp the basics, start to build a business application or even start to build their own game. The beauty of programming is that you don't need encyclopedic knowledge of a Computer language to make a application or software solution, but the logic and the techniques you apply are the key. Programming is almost like a puzzle. Anyone can solve one over time, but what is the quickest way to do it? This blog focuses on this software orientated side of programming, and hopefully after reading this, you will feel more comfortable in choosing a language and starting to write some basic programs yourself.
What makes a good programmer?
A good programmer is usually distinguished by his or her ability in logical thinking. Despite what some people think, Maths is not largely involved until someone decides to delve into fields like Artificial Intelligence, or 3D programming. Even in these cases, the methods applied relate to formulae that have already been found out and provided for us. So, don't let this put you off. However, if you seriously want to make programming a career, patience is essential. There will at some point come a time, where theres a problem with your work, or you are simpy unsure how to implement. Problems like these that arise like this can be very frustrating at times, and can take many hours to solve. It will take persistence and some visualisation to see through these situations and debug your programs. Those who can visualise and seperate their programs into neat, logical and simple instructions are one step ahead into thinking like programmers.
What Computer Language should I write in?
There are so many languages to choose from now, it can be quite hard to conclude which language is best for you and your programs. Pascal/Delphi, Python and Visual Basic are what I believe to be some of the best beginner programming languages out there. Both Borland Pascal/Delphi and Visual basic come with good interfaces, and are packaged with the .NET framework for you to instantly make your own Windows applications. All of which are easy to get to know, Python in particular, and all of them having thriving online communities with the exception of Delphi. Pascal/Delphi has roots that go back as far as the 1980's, hence why there is a lack of online support. Although, I still think it is a logical language to start learning with, even if some dislike the syntax and structure it uses. I intend to bring back some of its delights with a small 10 step guide below into learning Delphi.
10 steps to understanding Delphi
I have decided to release a quick Delphi tutorial in different posts, over the course of a few days. Before you begin this guide though you will need to download and install a compiler. Unfortunately, in the process of writing this post I found out that Borland Delphi 2006 is no longer available for free download. Two good alternatives though can be found here and here.
Two very good sources on Delphi are Delphi.about.com and Delphibasics.co.uk if you choose to gather more in depth knowledge. I will also be posting some of my own projects in the future for people to try out for themselves.
What makes a good programmer?
A good programmer is usually distinguished by his or her ability in logical thinking. Despite what some people think, Maths is not largely involved until someone decides to delve into fields like Artificial Intelligence, or 3D programming. Even in these cases, the methods applied relate to formulae that have already been found out and provided for us. So, don't let this put you off. However, if you seriously want to make programming a career, patience is essential. There will at some point come a time, where theres a problem with your work, or you are simpy unsure how to implement. Problems like these that arise like this can be very frustrating at times, and can take many hours to solve. It will take persistence and some visualisation to see through these situations and debug your programs. Those who can visualise and seperate their programs into neat, logical and simple instructions are one step ahead into thinking like programmers.
What Computer Language should I write in?
There are so many languages to choose from now, it can be quite hard to conclude which language is best for you and your programs. Pascal/Delphi, Python and Visual Basic are what I believe to be some of the best beginner programming languages out there. Both Borland Pascal/Delphi and Visual basic come with good interfaces, and are packaged with the .NET framework for you to instantly make your own Windows applications. All of which are easy to get to know, Python in particular, and all of them having thriving online communities with the exception of Delphi. Pascal/Delphi has roots that go back as far as the 1980's, hence why there is a lack of online support. Although, I still think it is a logical language to start learning with, even if some dislike the syntax and structure it uses. I intend to bring back some of its delights with a small 10 step guide below into learning Delphi.
10 steps to understanding Delphi
I have decided to release a quick Delphi tutorial in different posts, over the course of a few days. Before you begin this guide though you will need to download and install a compiler. Unfortunately, in the process of writing this post I found out that Borland Delphi 2006 is no longer available for free download. Two good alternatives though can be found here and here.
Two very good sources on Delphi are Delphi.about.com and Delphibasics.co.uk if you choose to gather more in depth knowledge. I will also be posting some of my own projects in the future for people to try out for themselves.
Subscribe to:
Posts (Atom)