Mauritius Blog Tracker Tracking Mauritian Blogs 2014-01-18T00:04:15Z http://www.mauritiusblogtracker.com/feed/atom WordPress InF <![CDATA[Fundamentals of Programming: Part 7 – Loops]]> http://www.geekscribes.net/blog/?p=1777 2012-04-08T21:30:13Z 2012-04-08T21:30:13Z This article comes from GeekScribes

Fundamentals of Programming: Part 7 – Loops

]]>
Welcome to Part 7: Loops! I hope you have enjoyed the previous parts and if you haven’t checked them yet, you should! Here’s a link to Part 1!

In this part, we consider another fundamental building blocks of programs: Loops. What are they? Simply, a method for telling your computer to do the same thing a bunch of times. Nothing too hard huh? Let’s get on with it!

As I said, a loop is a cycle, where the ending point is also the starting point. I.e. when you reach the end, you actually find yourself at the start.

A loop in programming is pretty much the same: You tell your computer execute a set of instructions for a number of times or until some condition is met. Then stop repeating and proceed with other stuff.

Say you want to write a program that models a bunny. The bunny only knows how to jump. Now, you want that bunny to jump 5 times. How would you do that?

You can write it like this:

Jump
Jump
Jump
Jump
Jump

That is, you write your instructions 5 times. If you want 10 jumps, you write 10 jump instructions. If you want 100 jumps, you write 100 jumps instructions. If you want 10,000? Ugh… You see the problem? You don’t want to have to write that instruction 10,000 times! And that’s why you’d use a loop. Wouldn’t it be nice to just tell the program “do this 10,000 times”? Something like:

do 10,000 times{
	jump
}

That would be nice huh? Well, you just wrote a loop! It’s not exactly written like above, but the true ways of writing loops look just like that.

There are 3 main ways of writing loops, and we’ll go through each of them in turn, and I’ll tell you when to use them.

For Loop

The first way, but probably the weirdest way of writing a loop is the For loop. Sorry, but it really doesn’t look like the loop above! The other kinds of loops do look friendlier though! If I want to write that loop above as a For loop:

for (int i = 0; i < 10000; i++){
    jump
}

WHAT IS THAT THING?!! It’s so hard to read! Lol… no it isn’t. Wait, we’ll go through it in parts.

“for” is perhaps the easiest thing to read. It’s a keyword indicating a For loop and in the end, you will come to just read it as “for 10,000 times”.

(int i = 0; i < 10000; i++) ouch… But hey, do you see this consists of 3 parts? Let’s break it down, it’s not that hard!

int i = 0; We are just saying, initialize variable i as an Integer, and set its value as zero to begin with. This is done only ONCE in the loop, i.e. the start!

i < 10000; If you have read the part on Conditions, this is familiar to you now. It’s just a check to see if the value of i is LESS than 10000. This check is performed at EVERY RUN of the loop. Hence, we’ll check the value of i 10,000 times during execution.

i++ that’s new! It’s the short form of “i = i + 1″, i.e. add 1 to the current value of i. The incrementing is done ONCE every run, so we increment the value of i 10,001 times! What? Yep, 10,001 times! Remember, 0 to 9999 is 10,000 times! But see, the loop stops at 10,000 times right, so the value of i has to become 10,000 at some point. 0 to 10,000 is? 10,001!

So if we read the whole thing now:

for (int i = 0; i < 10000; i++) means, "do the following instructions for 10,000 times". The variable i is what we call a loop counter. It keeps track of how many times we have executed the loop so far, i.e. how many times we have run our instructions in a loop. The loop counter acts as our memory, so we remember how many times we’ve done that loop.

Why do we need 3 parts? We need a starting point (i = 0). We also need to know when to stop (i < 10000). Finally, we need to update our count of how many times we’ve run so far (i++). With those 3 elements together, we’re able to know where we start, how many times we looped and when we stop.

We start counting at zero and every time the loop executes, we increment the value of i (i++) once. We continue running the loop until i is no longer less than 10,000 i.e. i = 10,000 stops the loop. After those checks and whatnot, our bunny jumps! Then we restart, check the value of i, increment it, bunny jumps, check value of i, increments it, bunny jumps etc… until 10,000.

While Loop

So that was one way of doing looping. We can also use a While loop. This one looks simpler, but beware, it has a trap!

while (i < 10000){
    jump
}

As before, “while” is a keyword indicating that a loop should be done.

(i < 10000) is a check, so we know when to stop. So we read "while i is less than 10,000, do these instructions"

Have you noticed the trap yet? It may not be that obvious, so compare with the For loop above. Tip: i++

The incrementing of the counter i is missing! What happens if you do that? You have a bunny that never stops jumping! An infinite loop!

Since you're never incrementing the value of i, the check will always return true since every time we compare, i is still zero. The loop never stops and in the end, you have a very tired bunny.

You have to be really careful about not missing the incrementer if you're using While loops. If you're not counting, or doing some other kind of check, you need to make sure there's a stopping condition for the loop. Otherwise, you will in most cases, have a non-responding program to deal with while it's stuck in the loop.

Infinite loops do have their uses though. For example, you can keep repeating your program to read an unknown number of inputs from the user, until they enter "quit" for example. Since you don't know when to stop, you just run infinite number of times and implement a manual stop condition. We'll see about that in the ending section of this part!

Here's a correctly written While loop that behaves as we expect:

int i = 0
while (i < 10000){
    jump
    i++
}

But why do you ever need a While loop? A For loop works perfectly well for this task! It happens that you're performing actions that don't rely on a counter. Or you don't really know when you have to stop. A For loop runs for a finite number of times. A While loop can run for as long as you want it to, maybe depending on some external condition or some user action. Here's an example:

while ( isUserPresent() ){
    jump
}

In this loop, we're using a function isUserPresent. You can ignore it for now. Just know that it'll return true if the user is currently sitting at their desk. It returns false if the user is not present. Functions come in the next part.

This loop will have our bunny jump if the user is there to see it. If the user leaves, the check becomes "false" and the loop stops. The bunny then stops jumping and the loop ends.

As you can see, this While loop depends on an external condition that's not related to counting. You don't know for how long the user will be at their desk and so in effect, you're executing the loop until the user leaves, potentially executing an infinite number of times (user never leaves). You can't easily do this with a For loop, since it's finite.

A While loop gives you more flexibility to control when to start, how many times to execute and when to stop. Or if you wish, you can continue as long as you want (infinite loop).

Do While Loop

A third way of writing loops is the Do While loop, also called Repeat Until loop. This is not present in all languages, but can be quite useful in some conditions. Let's compare with a While loop.

int i = 10000
while (i < 10000){
    jump
    i++
}

What happens in this case? Check the initial value of i (10,000)? while (i < 10000) never executes because i is NOT less than 10,000. It is EQUAL to 10,000! So your loop never runs!

There are cases when you want the loop to run at least once before the check is made. Say for example, you want the bunny to jump at least once, even if there may not be any user. You would not be able to do this with the While loop without extensive checking and tricking the program. But you can very easily do this with a Do While loop:

do{
    jump
}while (isUserPresent());

Note how we shifted the check AFTER the instructions. So no matter what, we'll still execute the "jump" instruction at least once before we reach the first check for user presence.

This kind of loop is less frequently used as compared to the above two, but am including it just so you know it exists. One realistic scenario where you might want to use a Do While loop is to check that the user's input is what you expect, and if it's not, keep asking for an input until you get what you want. Here is a non-language-specific example:

do{
    Output "Say Y or N: "
    Get user input
}while (input != "Y" || input != "N");

I chose to give a non-language-specific example to keep it as simple as possible.

This block of code will execute at least once and ask the user to either type "Y" or "N". We then read what the user typed. Finally, we check if the input was either "Y" or "N". If the value input was neither of these, we basically drop into an infinite loop until we get what we want. That is, we keep asking the user until they say either "Y" or "N" and then stop the loop.

This illustrates an example of where you need to get the input first, then decide what to do. You could have used a While loop too:

Output "Say Y or N: "
Get user input
while (input != "Y" || input != "N"){
    Output "Say Y or N: "
    read input
}

Notice how you're repeating the instructions? That's something you want to avoid in programming. Stick to the Don't Repeat Yourself (DRY) principle in programming. The Do While is a simpler alternative here.

Break and Continue

Before we end, there are two important keywords that you need to know. If you read Part 6 on Conditions, you've already seen "break" used inside a Switch block.

"break" tells your program to "break out" of the structure it current is in. It's mainly used in loops, where you want to manually stop the loop, especially if you're using an infinite loop and want to manually stop at some point.

"continue" tells your loop to ignore the rest of the instructions in the loop and restart with the next cycle of the loop.

Let's see examples of these keywords:

int i = 1
while (true){

    jump
    i++

    if (i == 10000){
        break
    }

}

The loop above is a complex way of just stopping when i is 10,000. We're using an infinite While loop. Notice while (true)? Well, the check will always return true since we're saying it's "true"! There is no stopping condition there. Instead, we use an If condition to do the check, and "break" the loop when we want. So when i reaches 10,000, we break out of the loop and stop it. Fairly stupid way to do it, but it's just to illustrate "break".

do{
    output "Say Y or N: "
    read input

    if (input == "N"){
        continue
    }

    output "Hello!"
}while(true);

The loop above is again, an infinite loop. We want the user to type "Y" or "N". If they type "N", we don't greet them since "continue" is activated and the loop restarts, skipping the output line. If they say "Y", the If condition doesn't trigger and we say "Hello!" to them.

P.s. Normally, you don't compare Strings like that. You don't do input == "N" for e.g. but would use some function. We'll see about that later.

That's all for this part on loops. Remember, they just allow you to tell the computer to do a set of actions multiple times. There are multiple ways of writing them, and you'll use different ways depending on what you want to achieve. For finite loops where you know how many times you want to execute, use For. For more flexibility, use While. If you want to run at least once before checking, use Do While.

I hope you found this part interesting. If you have questions, please ask in the comments section below. Suggestions welcome!

In the same series:

This article comes from GeekScribes

Fundamentals of Programming: Part 7 – Loops


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Fundamentals of Programming: Part 6 – Conditions]]> http://www.geekscribes.net/blog/?p=1768 2012-04-09T09:11:49Z 2012-03-13T18:41:31Z This article comes from GeekScribes

Fundamentals of Programming: Part 6 – Conditions

]]>
Welcome again! In this series, we go on to the first of the essential building blocks of programming: conditions. This is the first part of the series that starts to deal with blocks of code, as opposed to just independent lines. So without delay, let’s start.

In this long series, we’ll cover condition blocks using if-else and if-else if-else. We cover checks using AND, or and NOT (! symbol). We finally end with the switch statement. I doubt you’ll be able to grasp everything in one go as a beginner, so go slow, maybe a section at a time, try to understand how it works before moving on.

What are conditions?

It happens that you need your program to take decisions based on checks and conditions. That is, you want your program to perform a set of actions in case A, but perform another set of actions in case B. That’s where conditions come in. It allows you to implement decision points in your programs.

Associated with a condition is a check. Usually, you will be checking what the value of a variable is. Then based on this value, you will branch out and do different things.

Conditions start with the keyword if, followed by a check. There may be another section, called else which gets executed if the condition check turns out to be false. Within these two sections, there can be other conditions too. These are called nested conditions.

Let’s see a blank, simple condition block:

if (condition){
	do this
}
else{
	do that
}

This is perhaps, your first serious encounter with a block of code, so let’s devote some time to how it is structured.

First notice the { and } braces. These indicate where a block starts and ends. I.e. they tell which statements are part of which blocks. Think of those as boundaries. Everything within the first set of { } is for the if-block and everything in the second { } is for the else-block. Not all languages use braces to separate blocks like these; Python for e.g. uses indentation to indicate blocks. So you just indent lines under an if and these lines are considered under the control of the if-block. Other languages use keywords, such as  “end if”. It’s all programming-language dependent, so when programming, you will use the method your language imposes.

Just for clarity, here is this same example, but in those different ways I just mentioned:


if (condition):
	do this
else:
	do that

if (condition)
	do this
else
	do that
end if

So that’s structure. Let’s focus on the if line: if (condition). The condition is the check which will determine which block gets executed. You will normally decide what to do based on a variables’ values. This is an actual example:


if (x > 0){
	output "X is positive"
}
else (x < 0){
	output "X is negative"
}

Here, we want to check if x is positive or negative, and tell the user what it is. Let’s consider three cases:

  • x is 2: The if statement’s condition will see what value x has. It sees 2. Is 2 greater than 0? True, so we go into the if-block and execute the output line. The user sees “X is positive”. After executing that, we DO NOT execute the else part. The else-block is only executed if the condition was not matched. So after outputting the line, we finish.
  • x is -1: The if statement’s condition checks the value of x. It sees -1. Is -1 greater than 0? False. We skip over to the else part since we didn’t get a match. The if-block is NOT executed. We go inside the else-block and execute the output line. The user sees “X is negative”. After this, we finish.
  • x is 0: The if statement’s condition is checked. Is 0 > 0? False! (It’s not greater! It’s greater or equal, but we’re only checking greater here). Since the if-block condition failed, we go to the else part and output “X is negative”. That’s probably not what we wanted. Did we really want to tell the user that zero is negative? (Oh by the way, in computing, you can have positive-zero and negative-zero!)

You can see that we’re missing a condition here, for the case where x is zero. There are multiple ways to do that, one is not available in all languages. Let’s see 3 ways:

First:


if (x > 0){
	output "X is positive"
}

if (x < 0){
	output "X is negative"
}

if (x == 0){
	output "X is zero"
}

This works, but normally, you don’t want to do that because it increases the number of lines of code unnecessarily. Programmers like compact code and you may get a few stares if you do that while working as a programmer. Do note that you can have if-blocks on their own too. You don’t always need an else-part.

Second, nested blocks or if-ception if you want. If inside if:


if (x > 0){
	output "X is positive"
}
else{

	if (x < 0){
		output "X is negative"
	}
	else{
		output "X is zero"
	}

}

Can you understand what we did here? We check if x is positive. If it is not, we do the else-block. In there, we find another condition check, so we again check the if part. This time, is x negative? If not, we do the else. Well, if the number is not positive (first if) and not negative (first if in else-block), we guess that it has to be zero (else in else-block).

Third, else if:


if (x > 0){
	output "X is positive"
}
else if (x < 0){
	output "X is negative"
}
else{
	output "X is zero"
}

This way is similar to the nested-block one (second) but it’s just shorter to write. Programmers like shorter-to-write. It just has an “else if” keyword which is additional condition checks if the first if fails. So here, we check the first if to see if X is positive. Nope? Check the second if (else if). Is x negative? Nope. We go to the else block then and output “X is zero”.

There is a short way for checking the values of booleans:


if (isSunny)
	go out
else
	stay indoors

isSunny is a boolean variable. For boolean variables. you don’t need to write if (isSunny == true) or if (isSunny == false). You just write if (isSunny) and it’s sufficient to get the condition block working. It’s just a short, recommended way to check for boolean variables’ values.

Oh to check if it’s false? if (!isSunny). ! operator reverses the value, so true becomes false, false becomes true. This check is frankly, weird but heavily used once you understand it. Prepare for weirdness!

Two cases happen. We want to execute the if statements only if isSunny is TRUE!

For simplicity, read !isSunny as NOT-is-sunny or is-NOT-sunny if you wish.

  • isSunny is true: So if (!isSunny) will reverse the value, hence we get if (false). The if-block is skipped.
  • isSunny is false: if (!isSunny) will flip the value again, and we get if (true) this time. The if-block is now executed. That’s what we wanted. Execute only when the boolean is false.

Did you notice the lack of { and } in this example? It’s not a mistake. If your condition blocks if and else have only a single line within, you can leave out the brackets, again for making programs shorter. Personally, I just put them in, single-line or not. Just makes things clearer for me. But what you do is your decision! :D

Multiple condition checks

What happens if you want to check for multiple conditions at once before deciding whether to go into a block? For that, there is AND and OR operators. They are usually represented using symbols && for AND and || for OR. Those are two ampersands and two “pipe” symbols. Look for it on your keyboard. It’s usually to the left of “Enter” or the Z key.

Quick recap: For AND, all conditions must be true for the whole check to be true. If any condition fails, we have false. For OR, at least one condition has to be true for the whole check to be true.

Here you have 2 examples:


if ( isSunny && (day == "Saturday") ){
	go out
	buy groceries
	meet friends
}
else{
	stay indoors
}

The if-condition now has the && (AND) symbol, so we’re checking for 2 conditions here. First, isSunny has to be true AND it has to be saturday. If it’s not sunny or it’s not saturday, we go to else. If it’s both sunny and saturday, then we go to the if-block.

You will also notice that the different conditions can be put in their own brackets. These brackets help with ordering which operations are performed first. You’ve seen that at work in the previous post. The second example shows this:

if ( isFree || (day == "Saturday" && isSunny) ){
	go out
	buy groceries
	meet friends
}
else{
	stay indoors
}

Here we see the OR and AND both at work. Due to brackets being used, we consider the second check as a compound check. So if I’m free OR if it’s both saturday AND it’s sunny, then I go out, buy groceries and meet friends.

If isFree alone is true, it’s sufficient to do the if-block i.e. go out. But if I’m not free, the second part has to be true. Thus if I’m not free, but it’s both saturday AND sunny, then I go out.

Those AND and OR conditions take some getting used to, so don’t worry too much if you don’t completely understand them here. You will, with practice.

To summarize:

Conditions allow you to take decisions in your programs. You will check values of variables and if these are true or false, you take different actions. There are multiple ways to write conditional blocks and the one you choose depends on the programming language you’re writing in. You can have if checks nested in other if or else blocks for extended checks or you can use else if constructs if the language supports it. If you want to check for multiple conditions, use AND and OR.

Just before we end, what happens if you have lots of checks to perform. Well, you can use lots of if-blocks and face the anger of other programmers! Or you can use the switch statement, also known as the select statement.

Switch statement

The switch statement (or select statement) is really language-dependent. Some languages allow you to do comparisons, others just pure equality. Others vary the way the blocks are ordered. It’s just varied. Java for example, has only introduced switch equality checks for strings recently (Java 7) 15 years after the feature was requested. I’ll stick to one language-independent version here just to illustrate how it works. This one only supports equality check on numbers.

Here goes:

switch (dayOfWeek){

	case 1:
		output "Monday"
		break
	case 2:
		output "Tuesday"
		break
	case 3:
		output "Wednesday"
		break
	case 4:
		output "Thursday"
		break
	case 5:
		output "Friday"
		break
	case 6:
		output "Saturday"
		break
	case 7:
		output "Sunday"
		break
	default:
		output "Wrong day!"
		break
}

Ooooh that was long! Basically, we tell the switch statement which variable we want to examine, so here “dayOfWeek”. The various “case” lines represent possible values for the dayOfWeek variable.

Notice, it only supports equality checks! You can’t for example check if dayOfWeek > 6 in the switch statement!

So we check the value of dayOfWeek. Then jump to the appropriate “case” line and execute its statements. Say dayOfWeek is 3. We check case 1, which is equivalent to if (dayOfWeek == 1). Nope. Case 2, if (dayOfWeek == 2). Nope. Case 3, if (dayOfWeek == 3)? Yes. We then go into it and execute output “Wednesday”. Then break? What is break?!

“break” is a keyword you will use in the future series on looping. It tells your program to “break out” of the block it’s currently in. Hence, when we hit the “break” statement, we go directly to the closing bracket and we finish.

That “break” keyword in all those case statements is critically important. If you don’t have them, you will “fall through” the other case statements and execute everything, irrespective of the cases’ values being checked, until a “break” is encountered. I.e. you may get unexpected results! Try it for fun and see someday.

You can use that as “feature” too if you wish:

switch (x){

	case 0:
		do something
	case 1:
	case 2:
	case 3:
		do that too
		break
	case 5:
		do other
		break
	default:
		do something else
		break
}

In this case, if a zero is encountered, the switch statement will “do something”. Since there is no break, it’ll also “fall through” 1,2,3 and “do that too” and finally break. This could be useful in situations where you want zero to execute one statement in addition to what 1,2,3 normally do. Maybe zero is a slightly special case or something.

If either 1, 2 or 3 is encountered, they all lead to “do that too” and break”. I.e. 1,2,3 are the same thing and lead to the same action being performed.

Finally “default” represents a case where nothing was matched. Think of it as a last-resort case that’s useful to handle errors like invalid inputs from users.

Phew! That was a long part, eh! You now know how to make your program take decisions! I recommend that you re-read this part if you don’t understand it at one go. It’s quite a mouthful to chew at once. I hope you got something out of it. As usual, post your questions and suggestions in the comment section, and see you in the next part.

Note: Technically, you don’t compare strings’ values directly like day == “Saturday”. You would use a function or method such as equals(), like day.equals(“Saturday”). I left those out for simplicity here as these come in a future part. Also, I tried to keep using pseudo-code here, so there are no semi-colons on statements. Just so you know! :D

In the same series:

This article comes from GeekScribes

Fundamentals of Programming: Part 6 – Conditions


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Fundamentals of Programming: Part 5 – Data Types]]> http://www.geekscribes.net/blog/?p=1762 2012-04-09T09:12:01Z 2012-02-29T19:18:16Z This article comes from GeekScribes

Fundamentals of Programming: Part 5 – Data Types

]]>
Hello! Continuing with the Fundamentals of Programming series, we will now look at what Data Types are. If you have not read the earlier series, now would be a good time to start. You can click here go to Part 1.

What are Data Types? Well, they are a way for you to tell the computer what kind of data you are referring to. In English, you have two basic kinds of data types: numbers and letters. To a computer, those would be “char” and “integer”. Char is short for “character” and integer means a whole number, without fractions or decimal points.

Unlike humans, computers are not so intelligent (yet!) and need to be told exactly what kind of data they are dealing with. For us, numbers are “3″ and “3.24″. For a computer, you’d need to specify “integer” for whole numbers, “float” or “double” for decimal numbers and even specify the sign! Talk about smart!

Just how many data types are there?!

Lots! And they have specific uses too. We have to start somewhere, so let’s start with numbers.

  • Integers: They are whole numbers. E.g. “3″, “210″ and even “4521″ are all integers. They are represented as 2 bytes (16 bits) in most programming languages. They can be signed (positive/negative) or unsigned.
  • Float: These are “floating point” numbers. Fancy term for “decimal numbers” or fractions if you want. E.g. “2.35″, “30.16″ are floating point numbers. Floating point numbers are actually stored in a quite complex, as a sign bit, an exponent, a fraction and a bias. You don’t need to know all that, but if you want to… Floats are stored on 4 bytes.
  • Double: For a rather obscure reason, floating point numbers are not precise enough. Computers have troubles dealing with the fractional part and after a number of digits after the decimal, you lose precision. So for high-precision decimal numbers, you use double. It’s stored on a massive 8 bytes for high-precision numbers e.g. used in scientific data.

Various languages define other data types e.g. Date or Currency, but the 3 above are almost universal.

What about text? Here it’s easier.

  • Char: This represents a single character. Note, characters include letters, numbers and symbols, but you can’t make calculations using char. They’re the literal representation of the number. For e.g. ‘n’, ‘N’ and ’7′ are chars. Note the single quotes.
  • String: Basically, you can think of them as an array of chars. They are just sequences of characters. E.g. “Hello” is a string. Note, double quotes.

Normally, to avoid confusion, chars are represented inside single quotes while string are within double quotes.

How would you represent true or false?

  • Booleans: It’s a “true” or “false” value that can only be one at a time. Programs don’t have a separate data type for that. They normally just represent true as “1″ and false as “0″.

There are a few other data types you may want to know of, although per-se, they are not necessarily “primitive” data types:

  • Enumerations: Sometimes you want data that only comes from within a list of values which you define (or enumerate). For example, “Days of the week” would be “Monday, Tuesday, Wednesday… Sunday”. You can then make checks to see if some value falls within your list.
  • Array: This is a sequence of other data types. As I stated before, arrays have data types in most languages i.e. they are typed. You can such as, have arrays of integers, floats, or chars – strings basically.
  • Map: This is a abstract type that allows you to store a number of key-value pairs as mappings. For e.g. you can map Strings to Integers or Integers to Strings or even Strings to Strings. For e.g. “John – Doe” would be a mapping of “Forename-Surname”. The key is “John” and the value is “Doe”. I could ask the map for “John” and it would give me the corresponding value, which is “Doe”, if I was looking for surnames.
  • Set: A set can be thought of as an array that does not allow duplicates. You cannot have a set like [2][3][2] for example. If you tried that, it’d just store it as [2][3] and ignore duplicates, in most cases. It could also complain about duplicates in some languages.
  • Queue: This structure is like an array, but you read from one side and put new things from the other. It’s like a queue in real life: people join at the end of the queue and leave from the head. It is a First-In-First-Out (FIFO) structure.
  • Stack: Data is read and written to from the same end. Think of a pile of plates. The last one you put is the first one you will take off the pile. It’s is a Last-In-Last-Out (LILO) structure. Or First-In-Last-Out (FILO) if you want.
  • Pointer: A pointer points to a memory location. For example, you can have a pointer that references the memory location where an integer is stored for e.g. Or have a pointer to indicate at which point you have reached in an array.

Why are there all these data types? Why do you need them at all? That’s because computers represent data and use them differently. You cannot do calculations with strings directly. You cannot addition two booleans. The different types are useful when you want to do type-checking, for example, the user has not input letters when you’re trying to do calculations with numbers. Or you are trying to put letters in an array for floats for example. The compiler in strict languages will complain bitterly and prevent you from committing mistakes, so your programs break less often.

Operators

There are different operators you can use on different data types. Here are the most commonly used operators:

  • = :Not equal to! Yep! Not Mathematics! This sign means “assignment“. It is used to assign values to variables!
  • == :This one is what you know as “equal to“. It compares equality and returns “true” or “false” depending on what it finds.
  • === :Some languages have this sign. It compares both values and data types. If both are same, then “true” is returned, otherwise “false”.
  • + :Normally represents addition. I.e. the sum of two numbers. In some languages however, it can also represent joining two strings. For e.g. “2+2″ will give “4″. But, “Hello” + “World” will give “HelloWorld”.
  • - :Subtraction. Simple. “5-3″ will give “2″.
  • * :Unlike Mathematics, where x represents multiplication, in programming, you use asterisk. “2*2″ gives “4″.
  • / :This one is division. “4 / 2″ gives “2″.
  • % :Modulo operator. It gives the remainder of a division operation. E.g. “5 % 2″ would give 1. It is useful to check if a number is even or odd. Even number % 2 would give zero. Odd numbers give 1.
  • .  :That’s a dot. Some language use it to join (concatenate) two strings, instead of + to avoid confusion. So, “Hello” . “World” gives “HelloWorld”.

Below are comparison operators. They return true or false (boolean data type) depending on what the condition is.

  • > :Greater than sign. Used in comparisons.
  • >= :Greater or equal to sign.
  • < :Less than sign
  • <= :Less than or equal to sign.
  • ! :Represents “not“. I.e. it inverses other operations. For example !(x>2) is “not x greater than 2″ or “x not greater than 2″ which is equivalent to saying (x<=2), or “x is less or equal 2″. E.g. != is not-equal. Careful here, != is not equal. It’s not !==. Strange, but that’s how it is!
  • AND: The boolean AND operation. Please see below.
  • OR: The boolean OR operation. Again, please see below.

The last 2 operators are mainly used with Boolean data types. You use them to make a series of checks to see what the values are. For AND, all the conditions must be true for the final result to be true. If a single condition is false, the net result is false. For OR, at least ONE condition must be true for the end result to be true. If any is false, you don’t care. It’s still true. If none are true, then you get false.

Here are some examples of comparison operators and their boolean outputs:

  • 2 > 3  :False
  • 3 > 2  :True
  • 2 >= 2  :True
  • 2 == 2  :True
  • 1 != 2  :True (1 is not equal to 2? Yep)
  • 2 != 2  :False (2 is not equal 2? It is. Hence, false)

Here are boolean AND and OR comparisons:

  • (2 > 3) OR (2 == 2)   :True since (2==2 is true)
  • (2 > 3) AND (2 == 2)  :False. All conditions must be true and (2 > 3) isn’t true.
  • (1 == 1) OR ( (2>3) AND (4>3) )  :True. This one is tough! First, you check the inner-brackets. (2>3) is false, and without needing to check the rest, you know AND will now return false. (1==1) OR (false) is how the expression looks now. So (1==1) OR (false) returns TRUE since (1==1) is true, while the other is false, so you don’t care.
  • (2>3) AND ( (1==1) OR (2==2) )  :False. Why? Because even if the inner OR returns true for both, the first part of AND, (2>3) is false, so the whole thing becomes false.

I understand that the above is a bit hard to understand for beginners. Do try a few other examples on your own or re-read this section if you are having troubles. Don’t worry too much if you don’t understand it at first. It comes together with practice and familiarity with programming languages.

Here are the truth tables for AND and OR, if you are interested:

AND: Only true if ALL conditions are true.

True-True = True
True-False = False
False-True = False
False-False = False

OR: True if AT LEAST ONE condition is true.

True-True = True
True-False = True
False-True = True
False-False = False

I end this post on Data Types and Operators here. I hope it was not too hard to understand and you now have a fairly good grasp of what data types do and why they are needed. If you have questions, please ask in the comments section below. Other programmers’ views are welcome too. See you in the next series!

In the same series:

This article comes from GeekScribes

Fundamentals of Programming: Part 5 – Data Types


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Fundamentals of Programming: Part 4 – Variables and Arrays]]> http://www.geekscribes.net/blog/?p=1748 2012-04-09T09:12:03Z 2012-02-12T18:11:02Z This article comes from GeekScribes

Fundamentals of Programming: Part 4 – Variables and Arrays

]]>
Welcome to Part 4 where we will talk about variables and arrays are. If you’ve read the previous 3 parts, you would have noticed that I’ve used a few variables already, like A, B, Tc and Tf for example. In this section, we go deeper into what variables are, how to use them and finally, how to cope with situations where you have lots of variables to use, or don’t really know how many you need in fact!

So let’s begin this fairly short part, shall we?

Variables

If you’ve studied Mathematics before, you should already know what variables are. You must have encountered questions that involved X and Y. For example, “X apples cost 10. How many do 2X apples cost?” or much more complex questions involving “dy/dx” etc.

Variables in Maths, as the name suggests, represents a piece of information that can change i.e. it is variable. It acts as a place-holder for various values and you can plug-in different values in a variable and it will change  the result at the end.

For example, “X + 2″. If I say, X = 1. The result is 3. If now X = 8, the result is 10. If X = 20, the result is 22. The result will change depending on the value you give to the variable X.

Similarly in programming, you need those “placeholders”. For example, if you ask the user to input two numbers, you need somewhere to store those. You’d put them in two variables, which you can use later. You don’t really care which values the user inputs. Whatever they will input, they will go in two variables you define, say A and B.

Then in your calculation, you can use the inputs directly, without caring about their values. Variables can be used at all stages of a program. They can store user inputs, store intermediate results during processing or store results of processing before output. They are an essential component of any program.

What to add them? A+B. Multiply them? A*B. Divide? A/B. Did you notice something? The symbols are a bit different from normal mathematics. Let’s check that for a moment:

Addition is +. Subtraction is -. Those two are same as in Maths. However, multiplication is represented by an asterisk, *. Division is represented by a slash. Power is represented by ^. And depending on context, % can either represent percentage, or more often, modulo (the remainder of a division operation).

Back to our variables. So just to make it clear, variables are placeholders that will eventually store values or results of operations. You name variables and can then access their values by this name. Do notice, YOU name variables so be sure to use meaningful names for your variables! This is really important if you don’t want to get lost in your program. Unless in very specific cases, don’t use names like A, B or X. Instead, use names like “firstinput”, “second input” and “result”. It makes this clearer when you’re reading code. This is called “self-documenting” code, code which is clear just by reading it.

Here’s an example where variables are used:


Define variables: firstnum, secondnum

Input two numbers: firstnum, secondnum

resultadd = firstnum + secondnum

resultsub = firstnum - secondnum

resultmult = firstnum * secondnum

resultdiv = firstnum / secondnum

Output resultadd, resultsub, resultmult, resultdiv

We made use of 6 variables, two numbers and four to store the result of four operations. We then output them to the user.

Check the first line. We used a line: define. Before you use variables, you have to define them, i.e create them. It’s like that in most programming languages: you define variables before you can use them otherwise the compiler will complain bitterly! Not all languages force this, but it’s good-practice to define all your variables before you use them. Normally you will also specify the data type of the variable too, but we’ll see that in the next part.

Do you notice something? The variable names are rather hard to understand. “resultmult”? “secondnum”? There are conventions for variable formats, and most programming languages consider variables to be case-sensitive. That is, if you write a variable name all in caps and the same variable all in lower-case, they’d be two different variables. “NAME”, “name”, “Name”, “nAmE” would all be different variables. Therefore, there should be conventions to make sure everyone is writing the same way.

The two most commonly used ways are: camel-casing and underscore:

Here’s how you name variables for camel-casing: the first letter of the first word is lowercase. All other words have their first letter as uppercase. There are no spaces. E.g. “thisIsAVariable”, “anotherVariable”. If there is a single word, it starts with just a lowercase e.g. “variable”.

If you’re using underscore, you use all lowercase letters and separate multi-words with underscores. Thus, “this_is_a_variable”, “another_variable”, “variable”.

Whichever you use, stick to it. Normally, most people use camel-casing since it takes less space and is generally easier to type than having to reach the underscore button. But again, your choice unless imposed by a project.

So just to summarize, variables are placeholders for data needed by your program. Name them correcly to make sure it’s clear what they’re storing. Stick to conventions.

Arrays

Now, arrays. What are they? You can think of them as many variables together. Why would you need that? Well, what if I wanted the user to input 100 numbers? Would you create 100 variables, like “firstNum”, “secondNum”, “thirdNum” etc up to “hundredthNum”? Ok good luck if you want to try that. How about adding them all? Will you go re-writing each one?

Nah, you need arrays. Think of arrays as a series of variables stuck together, they’re reachable under a single name.

You can visualize an array like this [ ] [ ] [ ] [ ] [ ]. This would represent an array with 5 slots, and each of those slots can be thought of as a variable in itself. Like variables, arrays also have names and you reference to a particular slot inside an array by number. Array slots usually start from zero up to whatever you define.

So for example, if I create an array of 5 slots, called myArray, its slots will be o, 1, 2, 3, 4. For a total of 5 slots. If I wanted to get the 3rd slot of the array? I’ll reference it like this: myArray[2]. Huh, 2? But you said 3rd slot! It’s correct! Remember, you start from zero! The nth slot is referred to as n-1. Confusing huh? Don’t worry, you’ll get used to it. We are all confused at the start. (Arrays are zero-indexed.)

So if we wanted to re-write that program above, but instead use arrays for the two numbers input and arrays for the results too, it’ll be like this:


Define arrays: myNum[2], result[4]

Input two numbers: myNum[0], myNum[1]

result[0] = myNum[0] + myNum[1]

result[1] = myNum[0] - myNum[1]

result[2] = myNum[0] * myNum[1]

result[3] = myNum[0] / myNum[1]

Output result[0], result[1], result[2], result[3]

Whoa, that’s a lot to write. Copy-paste is your friend! No really, it is. Use it! That’s what I did.

Check the 1st line. We defined our two arrays. The numbers in this case represent the size of the array. That is, we said, we want two arrays, one having 2 slots and one having 4. Just like variables, you will need to define your arrays and their size before you can start using them.

Of course, there are situations when you don’t really how know big an array you need. Languages provide various mechanisms to cover this and we won’t do that here since this is a “fundamentals” series. But if you do want more information, go look for “dynamic arrays” and “arraylists” as a start.

If you want to go into arrays, Inception style, you can have arrays inside arrays… Yes! Arrays inside arrays inside arrays inside arrays inside arrays too if you want, although, that would be a bit too much. Normally, we only use arrays-in-arrays to represent tables. Conceptually, it’d look like this:


       0     1    2              0     1     2
0 [  [ a ]  [ ]  [ ]  ]   1 [  [ b ]  [ ]  [ c ]  ]

or if that helps, vertically:

       0     1     2

0 [  [ a ]  [ ]  [   ]  ]

1 [  [ b ]  [ ]  [ c ]  ]

How would you go about referencing the various slots? Well, two brackets. Let’s say this array is called “myArray”.

To reference “a” you reference the outer array first, then the inner one. Thus:

a would be: myArray[0][0]

b would be: myArray[1][0]

c would be: myArray[1][2]

What you just saw above is an array of size 3 inside an array of size 2.To define it, you’d call: myArray[2][3]. Thus, an array of size 2, with an array of size 3 inside. Want more? myArray[2][3][4]. An array of size 2, containing an array of size 3, containing an array of size 4. That’d be a 3-dimensional table. Too complex for this series! Those are called multi-dimensional arrays and are pretty useful to store, as you can guess, tabular data. E.g. students and their corresponding marks. It’ll be something like this, for simplicity:


[  [ "John" ]  [ 84 ]  ]

[  [ "Ann" ]   [ 89 ]   ]

But above, you see how arrays can be used to store inputs and results for output. They’re not hard to understand and use once you’ve done it a couple of times.

As you can guess, arrays have data types too, and you will need to specify it before you can put any data inside. Some languages restrict arrays so that an array can only contain a single data type. Others don’t care and you can stuff whatever you want in an array. We’ll get to the basics of that in the next part on data types.

Careful when using arrays. If you reference a slot that doesn’t exist or has no data yet, you might either get an error or get junk data. So check where you’re reading from or writing to to avoid weirdness.

Finally, loops are particularly useful when working with large arrays but this will be for another part!

I guess that’s it for this part on Variables and Arrays. If you have questions, suggestion etc, just ask in the comments section below. Hope this section was informational for you, and see you next time.

In the same series:

This article comes from GeekScribes

Fundamentals of Programming: Part 4 – Variables and Arrays


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Fundamentals of Programming: Part 3 – Style, Indentation and Comments]]> http://www.geekscribes.net/blog/?p=1729 2012-04-09T09:12:05Z 2012-02-07T15:16:08Z This article comes from GeekScribes

Fundamentals of Programming: Part 3 – Style, Indentation and Comments

]]>
Welcome to Part 3 of the multi-post series on Fundamentals of Programming. Last time, I just touched upon one very important point regarding style in programming: indentation. In this series, we’ll see a bit more about styles in programming. You can think of those as the “formatting” used in programming. We’ll end with the importance of conventions, comments and consistency in programming. I hope you will enjoy this part and learn something.

Editors and IDEs help!

Last time, we saw about indentation. Basically, indentation is making specific lines of code offset a bit so that you know at a glance where they belong. There are two ways of making indentation while programming: one is to use tabs (i.e. the tab key) and one is using multiple-spaces e.g. (press the space key 4 times).

Which one you use depends on you. As long as you stick to the style you choose, you should be alright. Now, if you’re writing code for other people e.g. open-source projects or a company, they may enforce a style on you i.e. you should only use space for e.g. because upstream, some other people have troubles with tabs. At this stage, you shouldn’t worry too much about those. In any case, you can have your Integrated Development Environment (IDE) do the substitution for you for e.g. replace a single press of the Tab key by 4 spaces.

You still remember what an IDE is, right? It’s that program that makes the task of writing other programs easier. Like a word processor for writing programs.

It’s a good idea to use an IDE when writing programs. Which IDE you will use largely depends on which language you are writing in, so we won’t go into the various IDEs that exist. If you write in many languages, or don’t want the hassle of having to install and learn an IDE, you could use so-called “Programmer Notepads”.

I did say you’re fine using Windows’ Notepad program. Actually you are. Only, it is not specially meant for writing programs. It’s just a generic text editor.

These are text editors that have IDE-like functions especially code highlighting, syntax checking, code completion and indentation guidelines for e.g. There are many of those out there, so I’ve listed the 5 most common ones so you have something to start. Just choose one and start typing! The number of features provided will vary from just syntax highlighting to fairly complex things like versioning through plugins. So just get one of those 5 and you should have an easier task at writing code:

  1. Notepad++
  2. PSPad
  3. Programmer’s Notepad
  4. Crimson Editor
  5. Notepad2

On Linux and other Unix variants, you will have the all-powerful Vim and Emacs, as well as GUI variants such as Kate and GEdit. Am just listing those here for reference, but if you’re already on Linux, you should probably already have found those. They probably come ready installed with your OS anyway so just find where they are and start using them. :)

Which editor you choose doesn’t really matter as long as it does what you want, and it makes things simple. If your editor makes a simple task more complex, you should either consider using another editor or see whether you’re doing stuff right in the first place! Editors vary in terms of features: some people like editors that does everything from highlighting brackets to sending satellites in space on their own. Others just want a place to type and if it provides pretty colors, fine! See what you want in an editor and choose appropriately.

At first, it’s good to try a lot of them to see which one you like. But after a while, try to choose one and learn how it works. You don’t want to keep switching editors mid-project and having to re-learn where the various options e.g. search and replace are found. I.e. find one and love it.

When you’re using one of these editors, the task of checking indentation, finding where brackets and braces open and close etc are handled automatically. That’s one less thing to worry about. But you still need to ensure your indentation is correct. Let’s see how pseudo code would look in one of these editors: Notepad++.

And here’s how it looks in plain old Notepad:

You can see a few things are different from the Notepad++ image. First, the “reserved” or keywords are highlighted in a different color: blue. Second, brackets are highlighted so you can easily identify where pairs of brackets start and end (they are bolded here). Quoted text is in a different color, so if you accidentally missed a quote, you’d see everything in grey and you know something is off. See the faint dotted lines below “If”? They represent indentation guides. That is, they show where the “If” is going to end and what code falls under the control of the If. Similarly, if I had different levels of indentation, I’d see additional lines.  Finally, you can see line numbers. If you’re writing code and a friend says there’s a problem on line 13028, you don’t have to start counting but can go directly to it! Notepad cannot do this for you.

All these little things really help when you are writing large programs with thousands of lines. You can immediately see where a block starts or ends without having to do a ton of scrolling.

I think you’ve got the point now. Use an editor or an IDE. It makes life easier!

 

Comments

What are comments? It’s as the name says, things you write in the code to make it clearer when reading it. They’re like small notes you write in the code itself to describe bits of code that might be difficult to understand at first glance.

Why would you want to type additional things and make things more tiring? Well, comments help. A lot! A LOT! They may not make sense now, but think about reading the same code, but 2 years later. Will you remember then, what that obscure piece of code does? Probably not. If you have put comments there, then yes, you’ll know immediately.

First, don’t write stupid comments. After you start programming, it’s no use commenting every single line of code. That is both senseless and wasting time. Things like (a+b) are obvious to any programmer. What you should be commenting is when you have codes that do special tasks. For e.g.

Does this make sense?

Does it now?

Now you know the importance of comments.

Comments are identified by different symbols in different languages so make sure to use the right symbol, but here is a quick rundown of the most common symbols used to identify comments in code.

 

Now you how what comments are, i.e. descriptions about code, written in the code itself and identified using special symbols, I advise you to use plenty of these where you think the code is not very clear or easy to understand. You’ll learn what to comment as you start writing more and more code. It then becomes second-nature and you’ll wish every programmer out there commented their code appropriately.

Consistency

Consistency refers to writing code in the same style, every time. This is not always possible as sometimes different projects impose different styles. But whatever style you will choose, stick to it. I.e. be consistent.

For e.g. I like plenty of white space in my code. I find it makes stuff easier to read. The second one is how I’d write this code. The first one could be written by another person who likes compactness and minimalism. Both do the same thing. If it makes sense to them, fine.

But now, if I start arbitrarily switching between the various styles, for e.g. I use different numbers of white-spaces or different styles of opening and closing brackets, it makes things tough for others.

We’ll see more styles of coding in the other parts, especially after we start “Conditions”. It then becomes important that you write in one consistent way instead of as-you-please. Just keep this point in mind at the moment: choose your style and stick to it. Don’t change mid-way because you think brackets are prettier on their own line. You’ll make many other people angry!

That’s it for this rather short part. I hope you found it interesting. As usual, ask your questions using the comments box below and I welcome comments from other programmers if they think I could have written things better or provided more details. See you in the next part!

In the same series:

This article comes from GeekScribes

Fundamentals of Programming: Part 3 – Style, Indentation and Comments


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Fundamentals of Programming: Part 2 – Pseudo Code and Batch Jobs]]> http://www.geekscribes.net/blog/?p=1718 2012-03-31T00:57:13Z 2012-02-04T20:45:15Z This article comes from GeekScribes

Fundamentals of Programming: Part 2 – Pseudo Code and Batch Jobs

]]>
Hello, welcome to Part 2 of the series. In this section, we’ll start with some actual code writing. “Code” is a short term to refer to “programming lines” i.e. instructions. So when someone is “coding”, they’re actually “writing programs”. I’ll use that word for short.

We’ll start with writing some instructions in pseudo-code. What is pseudo-code? Does it mean pseudo-programming? Yes, sort of.

You want to make sure you understand how to write and understand pseudo-code because that’s what I’ll be using through the rest of this series. They’re easy, English-like statement so don’t worry too much.

Pseudo Code

Pseudo-code refers to instructions written in a structured language. That is, there are specific words to represent specific things. Like commands for e.g. You’ll understand what I mean soon. The good thing about pseudo code is that it is programming language-independent. You can write instructions in pseudo-code then hand your sheet to any programmer and he or she will be able to write a program based on that. Why? Because pseudo-code represents instructions in an independent way. The programmer will then be able to translate those in the language of his/her choice with appropriate syntax.

In short, pseudo-code are step-by-step instructions to solve problems, written in a “strict” way that can then be used as guideline when writing a program.

Algorithms are usually step-by-step instructions to solve a problem. You could say that pseudo-code is  a way to write algorithms. For e.g., some algorithm in mathematics can say, you need to square this, differentiate that. In pseudo-code, you’re just writing the things to do in a structured way. So for the purpose of this article, I’d say they mean the same things. Just step-by-step instructions.

How do programs begin? They start in the mind of a programmer as a series of steps that must be completed to solve a problem. Programmers think in terms of pseudo-code, and then use those to write programming language codes. Sometimes they write these instructions on paper or a whiteboard to make it easier for them, but for simple things, they just do it mentally. It becomes simple enough with some practice.

To get you started, let’s assume you’re telling a friend how to draw a simple house. You need to tell them instructions. What would you be telling him/her? Write down your commands.

If I were to do that, I’d probably write those lines:

Draw a square, each line being 10 cm. (walls)
At the top of the square, draw a triangle, touching the square. (roof)
Inside the square, draw two smaller squares near the top. (windows)
Near the bottom of the square, in the middle, draw a small rectangle. (Doors)

Hopefully, that should give you a decent-looking house drawn like a 5-year old. Congratulations, you just wrote some pseudo-code!

Let’s see another example. We want to have the computer ask the user for two numbers, add those two numbers and then show the result to the user. Simple enough, huh?

This example has 3 sections: an input section (asking the user), a processing section (add numbers) and an output section (show the result). Those 3 steps are the basic things that happen in programs. These 3 things occur in almost all programs, although they may not be very apparent in all programs.

So let’s see how we can write pseudo codes for this problem:

Input 2 numbers, a and b.
Result = a + b.
Output result.

Simple, yes? This is pseudo-code for addition of two numbers. If you look carefully, you will see I used “a” and “b”. These are called variables and we’ll see about those in the next part. Basically, these act as two generic numbers so whatever 2 numbers the user will tell the computer, they will be represented as a and b.

This is a simple set of instructions and a number of things could go wrong in that. It’s also fairly limited in terms of functions. What if you want something else than addition? What about multiplication? Can’t do. Actually, we can. We will do this in the lesson about conditions. What about adding more than two numbers? Can’t do. Oh yes we can, but in loops lesson! :D

Normally pseudo-code has a fairly strict syntax so that code written by different people. If a person writes “Input 2 numbers” and another “Enter 2 numbers”, it’s still ok. But if a 3rd writes “Shout 2 numbers”… then no. Thus, pseudo-code uses a restricted number of words in English, normally words which you will normally find in other programming languages. For e.g. “input”, “output”, “if”, “else” etc. You’ll learn about those words as we go along.

Batch Jobs

Sometimes, programs don’t ask the user for any inputs. They just take their inputs from some file or from some other place. Batch jobs, or batch programs, are those programs that run without the user having to supply any data during running. Data, as in numbers, text or other information. They run, do their processing and could do some outputs, although not all of them do.

Let’s see about two examples of batch jobs. First example will read a series of numbers from a file and add them all together. If you don’t understand some parts, don’t worry too much. I’ll cover them in next parts. So, here it is:


Open numbers file. While there are more numbers to read in file

	Add number just read to Total.

End

Output Total.

Close File

Here, we didn’t ask the user for inputs. We just get numbers from a file and add them all to a total count then show that to the user. The “inputs” are actually read automatically so the program can run fast, i.e. doesn’t have to wait for the user to supply numbers one by one. Thus we had to tell the computer to open the needed “numbers” file, read off it and finally close it when it’s done.

Note one thing: the “Add number just read to Total” is a bit off-sided as compared to the rest. This is called “indentation” and it makes reading code blocks easier. At a glance, we can know that this line falls under the control of the “While block”.

Which do you prefer in terms of clarity:

While there are more numbers to read in file
Add number just read to Total.
End

Or:

While there are more numbers to read in file
Add number just read to Total.
End

Guess I already know the answer.

Code blocks are important in programming since they normally do different things as the program is running. So seeing what code is running under the control of which blocks is very important and I encourage you to properly indent your code when you are writing inside blocks. You will learn what this particular block of code does if you read the “Loops” part of this series.

Let’s see another example. This time, no inputs, no outputs. Just processing. The “output” is actually writing to a file. We’ll do the same thing as above: read numbers in a file and find their total. But we’ll then write this number in another file.


Open numbers file

While there are more numbers to read in file

	Add number just read to Total

End

Open results file

Write Total to results file

Close results file

Close numbers file

This time, we don’t show the user anything. We just read from one file and write to another. Basically, if this program was ran, the user would just see the program start and exit, and nothing else happen. They will have to open the results file to see something had happened.

That’s it for this part. I hope you enjoyed it and learnt something interesting. If you have questions, just ask in the comments below. Again, I ask programmers out there to please provide suggestions and comments. Thank you for reading and see you in Part 3.

In the same series:

This article comes from GeekScribes

Fundamentals of Programming: Part 2 – Pseudo Code and Batch Jobs


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Fundamentals of Programming: Part 1 – Introduction]]> http://www.geekscribes.net/blog/?p=1706 2012-03-01T17:54:37Z 2012-02-03T21:02:40Z This article comes from GeekScribes

Fundamentals of Programming: Part 1 – Introduction

]]>
Hello there! Welcome to my Fundamentals of Programming series of post. In this series, I will teach you about the basics of programming, i.e. the building blocks and what makes a program tick. I will NOT teach you Java, C++, PHP, Python or whatever pretty language you can think of. Instead, I’ll keep it language-independent so that even a complete beginner to programming will be able to follow.

I don’t know how many parts there will be and I don’t know if I’ll have time to write about everything I can think of at the moment.

Here is what I intend to cover. I may add other things afterwards:

  1. What is programming? Questions and IDEs
  2. Algorithms, Pseudo Code, Batch Jobs
  3. Style, Indentation and Comments
  4. Variables and Arrays
  5. Data Types
  6. Conditions
  7. Loops
  8. Errors and Bugs
  9. Functions
  10. Classes
  11. Libraries and Plugins
  12. Syntax and Programming Languages
  13. In Real Life

So please stick around and I hope you will enjoy reading my series of posts. Of course, your comments, questions and suggestions are welcome. I’d really like if my programmer friends, contacts and anonymous readers out there would provide some inputs in these posts to help beginners.

Without further delays, let’s start.

What is programming?

That.

Ugh! What are all those brackets?! What are those awful colors! Public WHAT?! My brain is melting!

Keep calm! Breath in. Breath out. Are you alright? Fine. Don’t worry about this at the moment. You’ll understand more as we go along so just be patient. At least, be positive! It’s in English!

Programming is basically giving instructions to a computer so that knows how to accomplish some task. Why would you need that? Well, everything you do on your computer, you’re doing it through programs. You’re currently viewing this page through a program that allows you to view webpages. You are using a program that gives you an environment to run other programs. Everything is a program. You are in the Matrix. Haha.

Well yes, programs are everywhere. And guess what? Each of these programs were written in some programming language. That thing you just saw above? That was a programming language. That’s what is used to make programs. That is, the “Firefox” or “Internet Explorer” or “Safari” or “Chrome” etc you are using to view this page at the moment? It was written in a language that resembles that one above.

Programming is writing programs in some language. There you have it.

 

Why do we need programming?

Simple! To make your computer understand what to do or what you want it to do. There’s a difference in that and we’ll see about it a bit later.

Computers are generally dumb machines of metal, silicon, plastic and lots of tiny little stuff that beep, light up and do other wonderful things. But they don’t really understand English. They only work with 2 numbers: zeroes and ones.

Programming is you telling it instructions, but you have to tell the instructions in some language the computer understands. If you think you have to write in zeroes and ones, you’d be correct but not completely.

Programming in zeroes and ones was done at the very start. It was hard as hell because, well, do you think something like 01001100 is meaningful to a human? Nope.

Some person thought it would be a good idea to translate some of those codes into meaningful words and have the computer translate this language into its zeroes and ones.

That person hence created a program that converts English words like “if” into computer-meaningful things like 01001100. Nowadays, you write English and your computer figures the rest out for you after you click a few buttons here and there. Then you see your shiny new program running and you’re happy.

This translation process, if you wish to know, is called “compilation”. There’s also “interpretation”. Both are basically translations, but compilation is done all-at-once while interpretation is done as-you-go.

 

How many languages are there?

Too many. Estimate? Above 4500. Be scared.

 

Waaait what?! How can I learn all that?!

You’re not supposed to. You’ll probably be fine learning one of them and you can write nice little programs. But why do we need so many languages? That’s because languages are created for specific tasks. For e.g. PHP is used to create dynamic web sites. That is, the web pages react to things you do, instead of being just boring, static, non-changing pages.

Other languages are for other things for e.g. C++ is used when there’s need for high speed of execution i.e. the program should run fast.

 

So how do I get started?

Well, you could read books on some language you want to learn. But if you don’t understand programming itself, it’s pretty much pointless to do that. Did you learn English by reading Shakespeare? OMG FOR REAL?!

Nah you probably started by learning letters. And made a mess on walls everywhere. Then you learnt words. Swear words I bet. Then you created sentences. Then you wrote your first paragraph etc etc until at the end, you can finally understand English pretty well.

Programming is like that too. You have to start from the start. What is the start? Letters.

Not really. Programming languages are mostly in English. Mostly. There are some truly weird things out there. But yes, mostly English. So you already have a head start. What you need to learn are the words actually. And that’s what this series of posts will try to teach you about.

You’re not expected to be able to write codes at the end of the series. That will probably be for another series some time later. But at the end, I hope you’ll be able to read a program and able to think about how to write your own program.

I’ll make sure to use plenty of examples while writing so you get to know how programmers think when they are confronted with a solution.

 

Is there any special equipment I need?

Not really. All you need is a working, powered-on computer, keyboard, mouse, screen and an Internet connection. Since you’re here reading this, you’re all fine.

Ironically, you’ll be using programs to write programs. Interesting huh? First programs were actually “written” using punch cards so these were not really programs. Then after a whole lot of troubles and annoyances, we arrived at the languages we use today. Be happy you don’t have to program in binary. Zeroes and Ones, if you didn’t know what binary (2 numbers) means.

Programmers do use a number of tools to facilitate their task. You can use “Notepad”, that simple text-writing program in Windows that nobody likes. Love it, it’s a nice program. If you’re  using Mac or Linux or some other operating system, just find a text editor and use it.

When you become more familiar and get more powerful (HAR!), you’ll want to use more capable tools. We call these “Integrated Development Environments” (IDEs). Fancy term for “big program that allows me to write big programs”. It’s still a sort of Notepad. Just one on steroids.

You don’t need to bother about any of these for the moment, although you may want to check out Notepad since it makes writing the basic codes I’ll show you WAY easier.

 

Alright, that’s it for part 1, the Introduction. In the next part, we’ll move on to how programs are born. See you! If you have questions and comments, use the form below.

 

In the same series:

 

Sources:

Picture

This article comes from GeekScribes

Fundamentals of Programming: Part 1 – Introduction


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Online Services Mauritius Does Not Have And Why]]> http://www.geekscribes.net/blog/?p=1637 2012-02-13T10:23:13Z 2012-01-15T17:23:17Z This article comes from GeekScribes

Online Services Mauritius Does Not Have And Why

]]>
First post of 2012. So let’s start with something like a wish list. In this post, I’ll run down through a list of online services Mauritius should have and why it doesn’t have these relatively common services.

Let’s start.

Online Shopping

I know a few of you will say that Mauritius has a few online shopping sites now. For example, the multishop is considered Mauritian. But you have to agree, there are not so many Mauritian online shopping sites online yet, despite many shopping malls opening in the country.

Sadly, even the big names in shopping don’t have websites. For example, none of our well-known bookstores have websites where you can check their catalogue! Come’on people, it’s 2011. Even if you don’t have online-shopping facilities, an online catalogue is a must! But nope, not even that.

Don’t bother trying to buy furniture online. Clothes? Hardly any local sites. I’d even say, no local sites as far as I know. Electronics? Same. Most other things? Nope.

Why?!

I say, we don’t  have local online shopping for 3 reasons:

Firstly, buyers will not have a method for safely paying online while sellers are unable to accept electronic money. Remember, Paypal does not accept Mauritian account holders to receive money. I don’t think any of the other payment processors let Mauritians accept money too. Local banks could have done something about that by implementing our own, local payment processor. Some effort is being done, such as paying by mobile phone. But those are not applicable online yet. For now, there is no method to buy online, short of putting your credit card online directly – something few Mauritians want to do. The fear that “people will steal my credit card number if I put it on the Internet” is very much present.

Second reason: lack of customers. Maybe I’m wrong here, but I think not many people know how to shop online yet. At least in Mauritius, they don’t. Even if we had local shops selling stuff online, not many people would know how to buy. Granted, we can teach them easily but the distrust of online shopping will remain present for quite a long time. Considering the few customers wanting the convenience of online shopping, I doubt many stores will want to invest in creating shopping websites. Although, that does not explain why they don’t even have online catalogues.

For the third reason, you only have to look at our postal service. It’s not that fast, not that reliable and worst of all, does not make an effort to encourage people to use its services. It’s not completely at fault here: there is just not enough reason to use the postal service for shopping at the moment – there are so few online shopping sites anyway! Let’s hope that in the future, the postal service standard increases in the country, as the number of shopping sites increase.

 

Auction Site

I’m not saying we should have a local Ebay.co.mu or something, but we could at least have a functional auction site by now.

I remember we had a few, but as far as I know, they’re all dead. Due to lack of interest? Probably  not. Some even ran quite successful advertising campaigns, using bill-boards etc. But? They didn’t have the variety of products people were expecting.

Above all else, they were not very user-friendly. Most looked like pages filled with pictures and text, but not a simple, guided page on how to use the site to buy stuff.

We had a few but they all died I think. Due to lack of interest? Probably not. I’d say they went off quite well, but they didn’t

Why?!

They were not real auction sites anyway. There were merely catalogues where people posted what they had to sell and others searched through. To buy stuff, you’d have to contact the seller manually, arrange for payment and collection offline. Not very secure, huh? And, no warranties!

Secondly, Orange.mu’s Classifieds site is king in this domain. It’ll not be easy to dislodge it and take its place as “auction catalogue”. You’d have to come up with a really creative solution. We’ve not reached there yet.

Finally, no online payment facilities. Again!

 

A portal / Discussion Forum

Strangely enough, Mauritius does not even have an “official” discussion forum! I mean, a place where people just sign in to have a chat and discuss country issues. Don’t tell me Facebook has completely obliterated forums – it has not.

Facebook is good for keeping track of what friends are doing but it’s not that good for discussions with people you don’t know personally.

Most countries have specialized forums for discussing specialist topics – such as, lowyat.net for Malaysia’s Tech Community to discuss about technology and buy/sell/trade computer or electronic parts.

We did have a few forums, such as Nubaz. I was a member there for a long time but finally, the discussions died down as people got more interested in Facebook and spam-bots overran the site.

Why?!

Facebook mainly. It was much easier to use than a forum. You could have your own profile, stalk people’s pictures etc…, things which you cannot do when using a forum – most people use avatars and nicknames anyway. Posting on forums is relatively tedious and disorganized as compared to Facebook. Can Facebook pages replace a forum? Nope. Your discussions will get lost too quickly on the page walls. You’d also need one page per discussion topic.

I wish someone would spawn a Mauritian forum again, where we can discuss with fellow Mauritians about day-to-day topics, the news but also, buy and sell second-hand stuff. That at least would attenuate the need for an online auction site. One can run auctions quite easily using a forum.

I have one question: how come none of the private radios have forums? Are they THAT hard to moderate?!

 

Bus Route Planning

Update: Carrotmadman points me to this site: mauritius-buses.com. The site allows you to plan your journey by bus.

What I had in mind was a site, where you can set your current location on a map, and type in your destination, or again click on a map, and it’ll give you all possible bus routes to this destination, schedules, estimated travel times etc. But mauritius-buses certainly does the job. The presentation needs some work e.g. the map, and the prices need reviewing: “Total price: 19 / 9 / 10 MUR” from Port Louis (victoria) to Curepipe is only Rs. 19? But at least, that’s one more service we have. Thanks Carrotmadman.

A major annoyance to me. I never know which bus to take and where to find them in bus stations! I’d just ask friends if they know which bus to take then wander through bus stations trying to look for that bus, and if all else fail, ask around until I finally find it. So much for tourist-friendly!

Why can’t we have a simple journey planner in Mauritius? You enter your starting point and your destination and it gives you the potential bus routes you can take, the route numbers, where the buses are found at which bus stations and their schedules.

Why?!

Too many bus companies! How can one expect to have a site that regroups all those companies and plan their routes, give their fares, schedules etc…?

Turns out you can. Ever heard of crowd-sourcing?

You just need to have a website, maybe powered by Google Maps. Then leave it to regular travelers or even the companies themselves to add their details and maintain it. That should be easier than having one entity maintain the whole thing. If a company doesn’t want to maintain their routes, too bad. That’s lost money for them.

I can’t imagine why a service like that doesn’t exist when almost every year, computer science students at the University of Mauritius are given projects that often contain route-planning and geo-location. I’m pretty sure it’s the same for University of Technology students too.

Can’t one of the companies take one of these projects as a prototype, have it refined and implemented? Can’t UoM / UTM themselves run one of these projects on their infrastructure and maintain it? What’s the point of Universities if none of their research ever gets used?

You want even more features? How about the service letting you buy and print your ticket in advance? How about buying long-term tickets for e.g. a ticket which you can use for a whole week?

Oh I forget… payment facilities. AGAIN!

 

Movie Renting service

Piracy is high in Mauritius. Why? Because we don’t have good things to watch on TV, buying original media is ridiculously expensive (Rs. 2000 for a recent DVD, are you kidding me?) and you can’t rent legal media to watch / listen. Video on Demand, while available, is not great.

What I want is a Netflix-like service. I understand that our local Internet speeds may prevent streaming HD content without Orange complaining that everyone’s leeching off its bandwidth. And I can tell you, if we did have a streaming service, Orange will probably charge you additional just to watch stuff. You’d be a “heavy downloader” or whatnot and therefore, must pay more.

So what can we have? A site that allows you to rent movies / music online. You pay a monthly fee, just like you’d pay a monthly utility bill. You then access your account on their site and they post what you’ve chosen to you.

Think of it like an online video club. Instead of going there in person, you choose what you want in person and they post it to you. After that, you just post it back to them. Posting charges are paid by the company and included in your monthly bill.

Not a critical service, but it’d be interesting to have.

Why?!

Our postal service. First, it’s relatively slow. A letter takes around 3 days to come from Mahebourg to Port-Louis. Second, there’s a big risk of breakage. Third, it’s quite expensive to post small parcels, even locally. Fourth… it’s easier to just pirate the damn thing if you want it so much. But hey, I was trying to suggest a legal alternative here!

 

SME marketplace

Do we have a Business-to-Business marketplace for SMEs and handicrafts in Mauritius? Nope. What if I wanted to say, buy 1000 mini-dodos to give as gift? Where do I go to find that? I’d have to contact SMEDA probably, then get the address of a few artisans. Then contact each of them individually and see if they can match my order of 1000 dodos. Etc etc… Basically, a long process.

If they had an online B2B market place, I’d just browse through, find who makes dodos and what size of order they can take. The site would list their contact details, pictures of their products etc…

I’d like a site like Etsy or Alibaba but for Mauritius. I don’t think there is such a site yet. In what way would this help? Boost our SMEs and startups of course! If no one knows what they’re doing, how can they hope to secure clients? A site like this may even help them reach an international market, who knows.

You can even extend the site to make it into a business directory with an SME corner, so that the site is able to help Mauritian businesses in general. For example, if I ask you to find me all the resellers of Logitech in Mauritus, how would you go about it? Open the Yellow Pages directory and go through the “Computer” sections? How about all the website hosting providers in Mauritius that can offer unmetered bandwidth and hosting space? Good luck searching!

Why?!

Lack of will. I can’t imagine any other reason such a site doesn’t exist. There is simply no will to invest effort in implementing such a service.

 

Local knowledge / Search service

Ever tried Orange.mu’s site? It is supposed to search the Mauritian webspace. Do try it and you’ll notice that it never returns anything Mauritian.

We need a local knowledge site, sort of like a Wiki for Mauritius or something similar. Say I want to find a mechanic in Quatre Bornes. Where do I search for that? Google? You won’t get meaningful results. There are no good places to search for local info about Mauritius.

Another example: You’re in the south and want to find a good restaurant to have lunch with some friends, especially Chinese food. How do you search for that? Would Google tell you that there’s a good restaurant, with good user reviews, found on the 2nd floor of some building that sells awesome noodles? Nah, I doubt it. You’d need local knowledge for that. Even better, searchable local knowledge. With pictures and user reviews if possible.

Here’s another example of where crowd-sourcing could help: just create the service and allow users to add their own local knowledge to it.

Why?!

No one wants to invest in such a service? I don’t really know why Orange.mu doesn’t offer this service. One could think local knowledge would be important, but I guess, not enough for Mauritius.

P.s. for fun: Orange.mu search just searches Google for you anyway! So much for local search! Is our local web space so meaningless? :D

So there you have it. My list of online services Mauritius ought to have but sadly, doesn’t. Can you think of other online services that would be good to have in Mauritius? Are there other reasons why we don’t already have these services? Is there one particular serivce you know of and want to recommend to others? Comment below!

This article comes from GeekScribes

Online Services Mauritius Does Not Have And Why


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[[Solved] Firefox’s Right-Click Menu Overlaps Flash/Javascript Menu]]> http://www.geekscribes.net/blog/?p=1677 2012-02-08T13:16:57Z 2011-12-02T19:20:44Z This article comes from GeekScribes

[Solved] Firefox’s Right-Click Menu Overlaps Flash/Javascript Menu

]]>
Just a quick post here. If you get this problem when right-clicking on Flash videos and sometimes in application-like web interfaces, the solution follows. It’s easy too.

So solution to prevent this overlapping of menus:

 

Go to Tools → Options → Content → Click on Advanced button (opposite Javascript) → Check “Disable or Replace Context Menus” checkbox.

That’s it. Problem solved. This was tested on the new Youtube and a few other sites. The solution worked fine. Let me know if it works for you.

(source)

This article comes from GeekScribes

[Solved] Firefox’s Right-Click Menu Overlaps Flash/Javascript Menu


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0
InF <![CDATA[Mauritius is not a cyber island yet. Here’s why.]]> http://www.geekscribes.net/blog/?p=1614 2012-02-05T01:41:04Z 2011-09-30T14:24:00Z This article comes from GeekScribes

Mauritius is not a cyber island yet. Here’s why.

]]>
For some reason, our political leaders are bent on using the word “cyber” whenever the get the opportunity to. Everything is cyber here: Cyber caravan, Cyber Crime or something along that line as well as a few other cyber things here and there. What does “cyber” mean anyway?

Merriam-webster says something about “the culture of computers”. It must be a joke: I hardly see any kind of “culture of computers” in Mauritius.

We are far, VERY FAR from deserving being called a cyber island yet. Why? Lots of reasons actually…

Stuck in Slow Lane, in 1st gear with a broken clutch

What’s the fastest Internet speed in Mauritius? I guess that’d be around 40Mbps that the Government has I think. For home users? That’d be around 4Mbps. That’s LAME! You don’t consider yourself cyber with speeds like that!

Cloud services? HD Streaming? Online desktop? E-working? What, you mad? None of this would work on low-megabit speeds like that. A service like Dropbox loses its attraction. Streaming? Forget it. Ask Carrotmadman about football streams! We can’t have our own BBC iPlayer because of the slowness.

The good thing is, Orange has been doubling the speed quite consistently over recent years. If this trend continues, we may get 8Mbps in what, 4 years or so? Too slow!

Another good news: Some ISP, Bharat Telecommunications Ltd, has applied for an ISP license to ICTA. Funny thing is, I can only find the license. I think I saw that in L’Express but I cannot find the original news again. They promised 10Mbps before 2012 ends or something like that. I’ll believe it when I see it.

For now, you’re stuck watching your lolcat videos on Youtube but with everything going in stop-motion. Very fun.

Education is either expensive or lacking

We have like, 5 Universities now, all of them offering a range of IT courses, most of them should just be called “Systems Engineering and Coding” instead of fancy names like “Bsc. Computer Applications”. It’s just that: we do tons of programming and very little of what remains.

Networking? Databases? Security? Mere modules in a Bsc. Show me one Bsc. course in Mauritius that focuses only on Game Development? Only on mobile technologies and development? Nah, we don’t have that kind of specialization.

We don’t need them. Or, to be more precise, our BPOs don’t need them. Maybe they’d need a few of those mobile tech guys, but Game Developers? Nope. BSc. in Security etc are not required because companies want their Sec people to have CCSPs and Microsoft Security Whatevers and Ethical Hacker something! They don’t care about your old-time BSc that still teaches how Ping of Death works. Nooo, they want you to be able to configure an IPS, not how to understand how it works!

Why’s that? Why aren’t non-programming Bsc or other university courses not in demand? We don’t have research. UoM calls itself a University but as far as I know, doesn’t do much research. Sure, we have people doing their PhDs and stuff, but most of the things they do are either just stuffed in a library somewhere, or cannot be put into practice in the country. That’s it for the demand, so there’s no supply as well.

On the other hand, there is immense demand for professional-level certificates like CCNA, CCNP, MCITP and whatever fancy acronyms you can think of. Those courses are really cool and do teach you quite a lot of practical stuff that Universities won’t teach you, or more precisely, cannot teach you because they don’t have the latest and shiny toys.

For those wanting professional certificates, they have to go to private training centres? What’s wrong? Those courses are ridiculously expensive! CCNA is a “mere” Rs. 30,000 at best. MCITP? Rs. 150,000 or so. And people DO shell out the cash to do those because it’s easy to get jobs when you got yourself a shiny new MCITP Virtualization certification (or not, employers are starting to see the tricks and do more hands-on interviews now).

Government, instead of trying to invent Cyber-names, should instead create a regulatory body for training centres. Like a Price Observatory for professional certificates. Also, we need loan schemes to be able to afford the high cost. This has to be sustainable: if you resort to this scheme, you need to get a letter from your employer to show that your newly-acquired skills would be useful to them and you will have to refund the cost of your training + interests over the next 2 years or something. There’s no point in 13-year old kids getting CCIEs when they won’t use it and just waste money. Unless you know, they’re genius 13-year-olds or something.

Where are the startups??

90% of University IT graduates join a BPO less than 6 months after completing their studies. That’s not an official fact, just my personal observation. Most of my IT-related friends are currently in BPOs. As far as I know, none of them started their own company. That is, none of them created a startup.

Worse is, a few of them are really good at what they do, and their undergrad dissertation, with a bit of polishing could be a viable commercial product. But no, they just join BPOs like herded sheep. I understand them: Rs. 23,000 for fresh graduate is a lot of money.

The downside is that without Startups, our local IT industry is stifled. We don’t have big name players here because they don’t have anything to invest in here: they just shift out their boring work and maintenance to be done here by undergrad grunts. Not fun, but at least it brings money.

That and a boatload of call-centres. I remember the beginnings of Ebene Cyber City… I used to call it Call Centre City. Because that’s what it was filled with. That and Government bodies.

In my opinion, call centres are not IT. Yes, they use IT. Yes, they employ IT people. No, they don’t contribute anything new to the IT sector in general. They are just services, some of them existing only to annoy people into buying crap.

I do wish there were more startups. The market in Mauritius is small but that doesn’t mean you can’t sell your services to international folks. There are a good number of success stories with local companies mainly working with foreign ones, so there is hope for startups, only if people are willing to take the risk. Yes, startups do fail. A lot of them do. A few of them turn into giants like Google.

The void called Online Services

Try buying a cinema ticket online. Or try ordering a few computer parts or electronics stuff to be delivered to your doorstep. Ok, forget buying. You got a call from some number on your mobile but don’t know who that is. You want to do a reverse phone lookup. Or, you want to do a normal phone lookup, why not?

Tried any of those? Of course not! Why? Because the services are NOT available! You can’t do anything online! No services, no checking up bus time-tables, no booking a taxi, barely any online shopping, nothing! Cyber-island? More like, mall-island! You’re supposed to do all your shopping in big-ass malls that sell expensive junk. Yes, funny.

Why don’t we have any of those anyway? No one’s investing in them, that’s why! Secondly, but more importantly, we don’t have a local payment systems. Banks are more interested in getting you to shift your money from under your mattress to their vaults, that’s it. They’re not interested in investing a ton of cash in creating a local payment system!

And they’re wrong. They’d have made a ton of cash in return. People would have signed up for paid services just to get access to this payment service. They’d pay for security. They’d pay for convenience. They’d pay for being lazy. I’d pay for being lazy!

Who wouldn’t want to book their Harry Potter ticket online instead of standing like a pole in a long queue at Star Cinemas? Or check at what time and where they can get a bus to Quatre Cocos or wherever? Those services would be popular. If only they existed.

Oh, and it’d also help with that “culture of computers” thing. When someone’s told that they can avoid standing for 2 hours in a queue by using this computer-thing-service, they’d want to learn how to do that. They’d want to learn what else they can do. They’d develop a culture of computers. We’d become a Cyber Island! Yay!

We also need a more developed web-space. For now, we only have lots of Mauritian blogs but if that were to change with say, Chapeau La Paille having their webpage, Rose-Hill transport having theirs (instead of a crappy old un-updated website), we’d be better off.

Missing the cool stuff

Finally, I come to the point that grieves me most. I can’t find the computer parts I want! I can’t find that shiny gadget I want. Or if I can, it’s just too expensive!

I should probably do a comparison between Mauritian and Malaysian prices when it comes to computer parts. Just for the lulz, although I know their market is much bigger than ours. It’d be fun, probably.

I mean, really, how many good computer shops are there in Mauritius? I can name like, 5.

The main problem is not that parts are missing, but that there is no competition, or not enough competition. And not enough market. And not enough culture of computers.

Monopolies. Ah, monopolies. Am looking at you, Orange. You too, 5 computer shops. You are seriously ruining the fun. Not much to say here. It’s just that we’re stuck with drooling over parts online, parts that we cannot find in Mauritius. Too bad.

Ok forget that. We also lack specialized services. The craze is for smartphones lately and those things EAT data. Try finding a big data package from one of our… two operators. None exists. Sure, you can get a 1GB a month for a huge price but there’s no all-rounder packages to be had. Like, I’d like 200 mins of calls, 100Mb of data and say, 300 SMS for around Rs. 300. Nope, can’t have. Market too small. Need. More. Profits! PROOOFITS!

I’ll just stop here. If you’ve read all text above, you’d now know why I think Mauritius is no cyber island yet. I also offered a few suggestions about what I think could improve the situation. There is hope! All is left in the hands of our leaders, companies and corporates to decide if we could really earn that title afterwards. The future is not bright, is it?

This article comes from GeekScribes

Mauritius is not a cyber island yet. Here’s why.


]]>
GeekScribes http://www.geekscribes.net/blog/feed/ 0