## terça-feira, setembro 18, 2007

### How Google Docs works in real life

Today along with the announcement of the brand new presentation support in Google Docs, which you should already know about by now, the Official Google Blog posted a nice video explaining the idea behind Google Docs, and how it works in real life.

This video is very simple, but is very interesting, enjoy:

## segunda-feira, setembro 17, 2007

### Working inside a Virtual Machine

I've been thinking about this for a while now, and last friday I decided to make a development environment inside a Virtual Machine, in my point of view it has more advanges than disadvantages.

Actually I'm working most with Delphi 2006, and if you already used it, you may know that this thing is a memory eater like nothing else, and also it sucks out a lot of cpu power (maybe it has a folding@home client running inside it, because I've always wondered why it needs so much cpu power to make autocomplete works, but anyway...).

So the main concern of most people is the application performance when running inside the Virtual Machine, I'm not going to lie, it isn't 100% the speed of a native operating system running on real hardware, but it is, believe me, a lot faster than you may think.

But I'll leave the speed for a later post because I didn't have enough time to work on it to see how it really performs on a real coding routine, but for now I'll leave the first impressions and the pros and cons (in my opinion) about having a development environment inside a Virtual Machine.

Pros:

1 - Very easier to backup up a full working environment, so if you screw up, or have some hardware failures, you can go back to work in no time.

2 - Transportable, you can always carry your Virtual Machine inside a portable Hard Drive and work from any computer.

3 - You can share it with your co-workers, if someone needs to work on your project, but doesn't have the tools, components or whatever it needs to compile installed, you can just hand him a copy of your VM and he will be able to begin working instantaneously.

4 - Safer, if use your VM just to work with the tools you need, and don't install any crap you find on the internet on it, it will be harder to screw it up, because most people are always installing a lot of crap they find on the internet on their pcs, and it can fuck up everything.

Cons:

1 - You will need a fast pc, with at least 2GB of ram, and the VM will most likely eat half of it.

2 - It is a bit slower than native OS on real hardware.

3 - It uses a lot more disk space, because you will have to install windows or whichever OS you use in the Virtual Machine, and it uses a lot of space.

So, if you have a similar experience, or think I'm just talking bullshit, post a comment, so I can learn more about it and be sure I'm doing the right thing, because what I want with this is to have a safer work environment which I can be sure that will always be available, and will save me of the headache that is installing everything from scratch over and over again.

## sexta-feira, setembro 14, 2007

### Javascript: Send Tab key on Enter.

I just finished doing some dirty work in javascript, and it's some interesting stuff.

The problem was with a software I wrote in PHP for the previous company I used to work, a user bought a bar code reader and wanted to use it with the software, but the stupid bar code reader sends an "Enter" key after it reads the bar code, so the software submited the form and the user got really pissed.

function getIndex(input)  {    var index = -1, i = 0, found = false;    while (i < input.form.length && index == -1)      if (input.form[i] == input)index = i;      else i++;    return index;  }function SendTab(objForm, , strField, evtKeyPress){  var aKey = evtKeyPress.keyCode ?    evtKeyPress.keyCode :evtKeyPress.which ?      evtKeyPress.which : evtKeyPress.charCode;  if (aKey == 13)  {    objForm[(getIndex(objForm[strField])+1) % objForm.length].focus();  }}

I found most part of this solution on google and just adapted it to my needs, sorry about not giving the credits to the author, but I got pieces of code from a lot of places and can't find them again, if you are the author of some of this code, please let me know.

To use it, just put this on your input code:
onkeypress="return SendTab(document.forms['f'], 'yourfieldname', event);"

It will process the "Enter" key as a Tab and go to the next input.

## quarta-feira, setembro 12, 2007

### Tip: Debug using watches

if you are developer or just a coder wannabe like me, you may know that usually it takes more time to debug and correct errors then to write the code itself.

So it is essential to always try a better and more improved way of debugging, and always know what your development tool or ide can offer you.

When I worked with php, debugging was a serious problem, because I didn't use any ide or debugger, just a raw text editor, sometimes I had to do some ninja stuff to find bugs, like adding a var_dump everywhere to find out where the bug was, good old times...

But now as I'm working with Delphi and Visual Studio I have better tools, but is having a plane worth something if you can't fly it? Hell no!

So, I'll give a tip to beginners who still don't use watches, because they help a lot.

If you are not a beginner, but don't use watches, shame on you!

Watches:

I don't know exactly how to define it but it is a debugger feature that keep watching your variable and object values (ok, that is obvious but at least I tried).

An example is easier to understand:

Imagine that you have a loop that in each iteration increments the variable I with some value. You can just add a breakpoint after the increment and pass the mouse over it can't you? But it is a pain isn't it? what if your loop takes 100 iterations and you have 2 variables? You are gonna make a hole in you desk from moving you mouse back and forth to see the value of each variable.

Watches make this task much simpler, almost all modern IDEs have Watches, to add a watch often you need to right click the variable or object and select Add Watch, or in the debug window you click in Add Watch or New Watch and type the variable name... but how doest it work?

Lets imagine that you have the variables I and K in a loop, if you add a watch to each one, and add a breakpoint inside the loop, when the debuger stops on the breakpoint, the values of K and I will show up in the watches window, so you can see and navigate through the values (if it is an object) without using the mouse or dumping de variable on the a terminal.

Here an example of a watch window in Visual Studio, isn't it easier to see the values?

Off course this is a very very stupid example, watches become more and more powerfull as the code complexity grows.

Keeping it short, If you don't use it, you should try it out right now, because it can save a hell lot of time when debugging!

## quinta-feira, setembro 06, 2007

### Delphi UI design, a nightmare for any coder

Just a quick post to yell about how boring it is to design User Interfaces, I had to do something simple, add a tab inside a window then add a Toolbar and a grid inside it...

First I spent a lot of time trying to figure out how to make the stupid toolbar dock inside the tab, but I did it, but as I always do, I forgot to add everything inside a GroupBox! Crap!

At this time I was already really really pissed of, then I tried to add the GroupBox but anything wanted to go inside the GroupBox, Cutting and Pasting didn't work, I was becoming more and more pissed off...

And when I get pissed I try to stay calm and think "isn't there a better way to do this?" then I get those Aha! moments, so I tought, if Delphi isn't helping me, let's do it in a more fun way, then I just opened the dfm code, that luckly is a very simple hierarchy, and everything was in place in less than 30 seconds.

So the tip is, sometimes the UI designer just keeps getting in you way and its better to just open up some code editor and do it by hand (so much funnier), but you need to KNOW what are you doing, otherwise you will just fuck everything up!

Delphi's dfm file are organized in a very very simple hierachy, it is something like this:

object Frame1: TFrame object Panel1: TPanel   object EditInicio: TcxDateEdit     Left = 67     Top = 5     TabOrder = 0     Width = 100   end endend

So in this case, there is a TFrame and inside it a Panel and inside the Panel a cxDateEdit, it you want to move the DateEdit inside the Frame1, you just need to do this:

object Frame1: TFrame object EditInicio: TcxDateEdit   Left = 67   Top = 5   TabOrder = 0   Width = 100 end object Panel1: TPanel endend

Simple isn't it? The problem is to know when to stop trying to make something quicker using a UI designer that actually slows you down, and when to just open up the source code and just hack!

## terça-feira, setembro 04, 2007

### Lesson 8: Conditionals

Today we are gonna learn one of the most important and most used things in computer programming, conditionals.

Conditionals are used to make your program follow a certain path if some of the conditions are match, I'll give an example based on our daily life, imagine the necessary actions for you to brush your teeth, take the toothbrush, take the toothpaste, put a little bit of toothpaste on the toothbrush.

Now imagine that we want to make a robot to automatize these actions, how do we program your robot, something like this:
Take the toothbrushTake the toothpaste tubeOpen the toothpaste tubePut some toothpaste on the toothbrushClose the toothpaste tube

Everything seems simple, but I'm gonna make it more complicated, what would this robot do if the tooth paste is already open? Will it pick up the tube and try to open it, or will it try opening the tube that is already open, or maybe it will crash.

This can look obvious for us, but in case the tube is already open we know that we don't need to open it, but the robot doesn't think like us.

It's in cases like this that we need the conditionals, to write a better robot program we need to use conditionals so it can executed the proper action based on some environment conditions, let's rewrite our robot actions, but now adding conditionals.
Take the toothpaste tubeIf the toothpaste tube end is closed   Open the end   Hold the endPut some toothpaste on the toothbrushIf holding the end   Close the end

Notice that the action "open the end" is some spaces to the right, I used those spaces to illustrate that this action will be executed just if the line before is is match, in programming these spaces are called indentation, and as we will see on the next lesson, they are very important in Python!

Now let's try making our program better, let's presume you want your robot to beep and stop when you are out of toothpaste, who would we do that?

Again, being out of toothpaste is a condition, let's see how the program would look like:
Take the toothpaste tubeIf the toothpaste tube is empty   BeepElse   If the toothpaste tube end is closed       Open the end       Hold the end   Take the toothbrush   Put some toothpaste on the toothbrush   If holding the end       close the end

Notice that our robot will only work if the toothpaste tube isn't empty, it will test if the toothpaste tube is empty, it if is, it will just stop, if it's not it will execute what is inside the "Else", and if the end is open it will just put some toothpaste on the toothbrush and will not open the end, and if it's not holding the end it will not close the end.

This lesson was just theory, but this theory is very important, so in case you have any doubts, comment!

### Lesson 7: Working with strings and numerical types

Today we are gonna learn how to make the infamous application that calculates the average number of two numbers

Take it easy, you should be think "here comes another useless lesson", but before jumping to conclusions, read this lesson, I can assure that you will learn some new and useful things with this little application.

As our lesson today is a bit practical, let's get direct to the point, open up IDLE in edit mode and type the following code:
#!/usr/bin/env python# -*- coding: utf-8 -*-a = raw_input("Type a number: ")b = raw_input("Type another number: ")print "The average of these number is:"print (a + b) / 2

Notice that we already have some new stuff, the second line tells which encoding is used in our text, it isn't mandatory, but IDLE will ask for a encoding if you use some non-ascii chars and don't put this line.

Another new thing is this line:
a = raw_input("Type a number: ")

This line shows the message "Type a number: " on the screen and puts the cursor after the phrase so the user can type some text, and when the user hits Enter this text is stored on the variable "a", notice the variable and the equals signal before the word raw_input.

You should have noticed that it displays "Type a number", but is possible to type any text and that you cause an error, so run you program and type just 2 integer numbers, like: 10 and 15.

If you did everything right, you should get the following error:
TypeError: unsupported operand type(s) for /: 'str' and 'int'

Take it easy, the error was intentional.

Even when you type just numbers on the terminal, the function raw_input will always set the variable as string, so even if you type 10, 10 in this case won't be and integer, but a string with the text 10, that's why you got that error, because we tried to sum 2 strings and then divide it by and integer.

Erase the last line of you program and add the following:
print a + b

Run you program and type: 10 and 15 (or another number) and take a look at the results:
1015

Did you understand? If you use the plus (+) signal to sum 2 strings you are joining them together.

Now that you should have understood why did we get that error, I'll explain how to fix it.

I think you already have done some operations with things that have different measure units, like sum 300 minutes with 2 hours and get the results in hours, and you know that to do this kind of operation both values need to be in the same measure unit, like minutes or hours, the same happens in programming.

To work with numbers, you first need to convert the values to the same (or equivalent) numerical type, because its impossible to sum the string "1" with the number 1, so before doing any operation we need to convert the typed numbers to integer, so let's see how do we fix our program:

Erase again the last line of you code and type the following on its place:
print ((int(a) + int(b)) /2)

You code should look like this:
#!/usr/bin/env python# -*- coding: utf-8 -*-a = raw_input("Type a number: ")b = raw_input("Type another number: ")print "The average is:"print ((int(a) + int(b)) /2)

Run this program and type the numbers 10 and 15 to see what happens.

If everything is right, you should obtain the result 12 (try with other numbers, just run the program again), but there is something wrong isn't there?

The average between 10 and 15 is 12.5 and not just 12, but why did we get 12?

Its simple, when we use int(a) and int(b) we are converting the value of the variables to integer, when we sum 2 integer we get another integer and when we divide by and integer (2) Python returns an integer, because in python a division between 2 integer will always return an integer, so let's change our code again.

We have several ways to fix this problem, add the following lines to the end of you code and test it typing the numbers 10 and 15:
print ((int(a) + int(b)) /2.0)

It will print 12.5 because when we changed 2 to 2.0 we are dividing by a float, so Python returns a float.
print float((int(a) + int(b))) /2

This one will return 12.5 too, because we sum the numbers and integers but convert the result to float and then divide by 2, Python returns a float when we divide a float by an integer.
print (float(a) + float(b)) /2

This on works too, because the sum of 2 floats returns a float and dividing a float by a integer a float is returned.

Now you can confess, you never imagined that a simple program like this could be so complicated and have so many concepts!

If you have any questions, suggestions or corrections, please comment!

### Lesson 6: Logical and arithmetical operators

We all know how to solve the expression 1 + 1 don't we? E also we know that the result is 3 (just kidding), but still some people doesn't that the numbers in this expression are called operands and the plus (+) signal is called operator, so by know you should have another operators in mind, operators like plus (+) and minus (-) are called arithmetical operators, because they are used to solve arithmetical expressions.

In computer's programming we also have another kind of operators, called logical operators, they are used in logical expressions and just return true or false, take a look at the following tables with the most used arithmetical and logical operators in computer programming.

Arithmetical:
**      Exponentiation+x, -x  Positive, Negative*, /, % Multiplication, Division, Remainder+, -    Addition, Subtraction

You should at least know the majority of the operators above, the only one that a few people may know is the Remainder (%), it returns the remainder of a division, for example: 3 % 2 would return 1 because 3 divided by 1 is 1 and 1 remains, the operator % returns the reminder of a division.

The operators above are processed from top to bottom (using the above table order), so the expression:
1 + 3 * 2

Is processed in the following order: first 3 * 2 that will result in 6, then 6 + 1 that will result in 7, test it, open up a Python shell and type? 1 + 3 * 2.

And as I'm a nice guy, I'll not make you remember the order of the operators (like some teachers that never did real code in their life do), there is a way for you to organize the expression so it executes in the order that you want, using parenthesis, like in mathematics, the most internal parenthesis are processed first, so if we want the sum to be processed before the multiplication we need to write our expression like this:
(1 + 3) * 2

Type the above code in Python and see what happens

Logical:
or                   Boolean operator ORand                  Boolean Operator ANDnot                  Boolean Operator NOT<, <=, >, >=, !=, == Comparisons

Like we have learned in our previous lesson a Boolean variable have just 2 possible values (true or false), logical operators are used in logical expressions and they always return true or false, take a look at the expression:
5 > 3

The above expression is a logical expression and returns true, because its true that 5 is bigger than 3, now a little more complex expression:
5 > 3 ou 3 > 4

The expression above would return false too, because the operator OR returns true if one of the two expressions is true.
The following expressions return false:
10 != 10 -> is 10 different from 10? false!10 > 10 -> is 10 bigger 10? false!10 == 11 -> is 10 equals 11? false!

Like we have learned before, true or false to the computer means 1 (true) or 0 (false), on and off, so to process this expressions, the computer multiplies or sum, depending on the operator, it looks complicated at first sight but to help you understand I made some tables, take a look:

Operator AND
1 0 | 1 * 0 = 0 -> false0 * 1 = 0 -> false1 * 1 = 1 -> true0 * 0 = 0 -> false

So for the operator AND return true, both variables need to be true.

Operator OR
1 + 0 = 1 -> true0 + 1 = 1 -> true1 + 1 = 1 -> true0 + 0 = 0 -> false

It the OR operator's case, its necessary just one of the variables to be true, the expression will be false just when both variables are false, what is exactly the contrary of the AND operator.

Operator NOT
The operator not just returns the inverse value of the Boolean variable, so not true is false, and not false is true, as we see bellow:
not 1 -> 0not 0 -> 1

There are more logical and arithmetical operators, but we are not studying them right now, this lesson is just a introduction about the most used operators, if you want to read more about it, take a look here

And as always, if you have any questions, suggestions or corrections, please comment!

### Lesson 5: What are and how to use variables

Variables are one of the most used things in computer programming, basically a variable stores a value in the computer's memory and can be modified at any time, in computer programming there are several variable types and today we are gonna learn what are and how to use the most important variable types in C# and Python.

Basic variable types:

There are several variable types, below there is an explanation of the most used variable types (language independent):

Boolean: can be either true or false. Ex: true, True, false, 0,1.
Char: can have just one character. Ex. 'A', 'c', '1';
String: stores several characters. Ex: "This is a string";
Integer: stores just integer numbers. Ex: -10, 10, 5000, -30000, etc.
Decimal (decimal, float, double, etc): stores numbers with one or more decimal digits. Ex: 0,01 - 10,0001.

Each programming language threats these types differently, in some like languages like C# you need to declare the variable with it's type before using it, others like Python the variable declaration occurs automatically when you store it's first value, others like PHP doesn't have a defined type for the variable, the interpreter controls everything based on the variable value.

There are advantages and disadvantages in what we call strong and weak typed languages, strong typed is when the compiler or interpreter makes mandatory to declare the variables with it's types defined, weak typed is when the compiler controls the variables types based on their values, for beginners the idea of not having to declare and convert variable types are tempting, but the truth is that it just creates a bad habit and make you write insecure code.

Variable names:

Both Languages that we are studying here have basically the same naming rules, every variable should start with a letter or underscore and can have just letters and numbers, also avoid using non-ascii characters, the following variable names are valid:

_name, name1, name, NAME, n4m3, etc.

The following are invalid:
1name, $name, %name, name$, etc.

You should also notice that both C# and Python are case sensitive, so the variable "Name" is different from "name".

Now we are gonna see how to declare variables in Python and C#.

Python Variables:

To understand it better we will first see how to declare and use a variable in python, for this task we are gonna use one of Python's best features, the interactive shell!

Open IDLE, and in case you IDLE is configured to open in edit mode, just click on Run -> Shell.

First we will see how a Boolean variable in Python works, type on the shell and press Enter (for each command you type on the shell you need to press enter, so I'll not say this again):
a = True

In case you type "true" instead of "True", you will get an error, because Python is case sensitive.

With that code we just declared the variable "a" with a Boolean type, also we set its value as True, to be sure that this variable is a Boolean, type:
type(a)

You shell should look like this:
>>> a = True>>> type(a)<type 'bool'>

Now type the following lines:
b = 'string'c = 1d = 1.0

And see each variable type typing:
type(b)type(c)type(d)

You terminal should look like this:
>>> b = 'string'>>> c = 1>>> d = 1.0>>> type(b)<type 'str'>>>> type(c)<type 'int'>>>> type(d)<type 'float'>

Now type:
b + c

You should get the following error:
Traceback (most recent call last): File "<pyshell#9>", line 1, in <module>   b + cTypeError: cannot concatenate 'str' and 'int' objects

You got this error because it's not possible to sum a integer type variable with a string type variable, some languages allow this kind of operation (run away from them), but normally you will need to convert both variables to the same type.

Now type:
print b

It should output the text "string" in your terminal, because when you use: "print b" you are saying to the compiler: "Print the value of the variable b on the screen", and in this case the value of the variable b is the text "string", now do another test, type:
b = 'new b value'print b

Now we changed the value of b and printed the new value on the screen.

In the next lesson we are gonna learn what are and how to use arithmetic operators and logical operators and also how to use this variables in mathematical expressions among other things!

As always, if you have any questions, suggestions or corrections, please comment!

### Lesson 4: Your first program in Python

In our previous lesson we learned how to set up Python in our box.

In this lesson we are gonna learn how to make our first program, the infamous Hello World, there is a legend that tells that once you can run the Hello World program in a language, you can do anything with that language, think you can do it?

First Python program: Hello World

First we need to change some configs in IDLE, so open IDLE clicking on Start -> Programs -> Python 2.5 -> IDLE.

The first time you open IDLE, it opens a shell, soon we are gonna play a little with the shell but for now let's change the IDLE's config so it opens an editor window when you start it.

So click on Options -> COnfigure Idle -> General and check the options: Open in Edit Window and No Prompt, after that just click OK, close IDLE and open it again.

Now each time we open IDLE it will start with a blank text file

Now type the following code in IDLE:
#!/usr/bin/env pythonprint "Hello World"

After typing it press F5 a message will pop up saying that you need to save your file, just click OK and save the file, after saving it IDLE will open a shell window and the result of code will show up, your screen should look like this:

Running Python from a terminal:

There is another way to run python code, using a terminal. If you are using windows do the following:

Click on Start -> Execute, type cmd and hit Enter, a terminal will show up, type the following on it:
path=%path%;c:\python25

c:\python25 should be changed to whichever folder you installed python on.

After that cd to the folder where you salved the file hello.py (use cd c:\path\to\your\folder), remember that this hello.py could be written on notepad or any other text editor, now type:
python hello.py

The phrase "Hello World" should show up, keeping it short:
path=%path%;c:\python25cd c:\pathpython hello.py

Linux Users

If you are using linux and doesn't have IDLE, create a new text file in your favorite text editor with the contents described above and save it as hello.py.

On linux you have 2 options to run python programs, in a terminal, change to the folder where you saved the file (cd \home\user\yourfolder\) and typing this:
python hello.py

Or you can give it execute permission on the file and run it, like this:
chmod +x hello.py./hello.py

If you were able to make this program run, congratulations you have a bright future as a programmer, if you were not able to do it, maybe you should try working with something else.

As this is our first program, I'll explain how the lessons from now on will work, as you already know how to create and run a file using IDLE, I'll not repeat these steps on the next lessons.

And all the code we write here will be explained line by line, and that's what I'm going to do now with our hello world program.

Program Explanation:

The first line: #!/usr/bin/env will always be the first line in every python program, this code tells that the file is a python script, and also tells where the python interpreter is, so always put this line in the beginning of all python scripts and for better compatibility always use: /usr/bin/env python.

print "Hello World": this line tells python "Show the text Hello World on the screen".

This program is so simple that any explanation about it is just a waste of mine and your time, so I'll stop here, the purpose of this lesson was to teach you how to run a program and see the results, in the next lesson we are gonna learn a little more about Python's syntax and what are variables.

If you have any questions, suggestions or want to correct some mistake, please comment!

### Lesson 3: Setting up our development environment

In this lesson we are gonna learn what is necessary to install and configure so we can code in Python

First we have to download some tools, and off course all these tools are free to use.

Windows XP users:

Python 2.5

The package comes with the Python 2.5 interpreter and a text editor and shell, IDLE.

You just have to execute the installer as usuall and click next..next..next.. finish :)

In case you want to take a look in IDLE, it is in Start -> Programs -> Python25 -> IDLE

Linux Users:

If you use linux, you should already have python installed, so it will be necessary just install the IDLE IDE, if you use Ubuntu or Debian, just open up a terminal and type the following:

sudo apt-get install idle

Obs. The Idle installation is optional, you can use any linux text editor you like, such as gedit, vim ,emacs, kate, etc.

In the next lesson we are gonna learn how to write our first application Python!

If you use any other linux distro and this lesson doesn't work for you, please comment if you have problems or want to add something, and as always, suggestions and corrections are welcome!

### Lesson 2: What do i need to start programming?

Now that you know the basics about what is computer programming we should start something more interesting, i m gonna explain the basics about the Python Language.
But before that we need to understand what is a compiler and an interpreter.

As i said in the last lesson, computers just understand binary, so if you want it to understand your code you should talk to it in Binary, but as you have noticed is kinda hard to understand binary, so you need something to translate the code you write to binary, and that is called a compiler, or interpreter.

What is the difference between a compiler and an interpreter?

The main difference about a compiter and an interpreter is simple, imagine a book writen in english, you want this book to be available in japanese, if we compile this book, we are gonna print another book writen in japanese, like another copy, but if you know english and japanese, you can read the book in english and understand it in japanese, because you are interpreting it as you read.

So, the compiler creates a binary object that can be read by the computer and the interpreter translates on the fly and sends it in binary so the computer understands it, in both cases we get the same result.

Some examples of compiled languages are:
C, C++, C#, Pascal, Clipper, Java, etc.

And some examples of interpreted languages:
Python, PHP, Ruby, etc.

But, what do i really need to start programming?

The answer is simple, you just need a compiler or interpreter and a text editor.

Ok, i understand why i need the compiler or interpreter, but why a text editor? Don't i need an application like, Delphi, Visual Studio, etc?

No, you don't really need an ide (integrated development environment), Delphi and Visual Studio are just tools that helps you in the coding process, but they aren't really necessary.

So, can i code in notepad?

The answer is yes, but just if you like to suffer :)

What are we going to use in our coding?

We are going to use the following application in our lessons:
IDLE for Python

In the next lesson we are gonna set up our development environment, if you have any questions or want to add or correct something, please comment.

### Lesson 1: What is computer programming?

Basically computer programming is the process of writing source code in a programming language to make a computer do some task, a simple example would be a calculator.

Everyone knows how a calculator works, but if you think about it, it is just doing some predefined task, you know that 1 + 1 is 2 but for each arithmetical calculation there is a rule, and a calculator is simply following this rules.

It is a predefined task, computers can´t think, so everything it does is follow the steps the programmer told him to, but how do you teach a computer to sum numbers?

As you may know, the "native" computer language is binary, so if you want to talk to the computer without a programming language you will need to talk to him in binary, and that's is kind hard isn't it?

Just for example, can you translate this?

01000011 01101111 01101110 01100111 01110010 01100001 01110100 01110101 01101100 01100001 01110100 01101001 01101111 01101110 01110011 00101100 00100000 01111001 01101111 01110101 00100000 01101011 01101110 01101111 01110111 00100000 01101000 01101111 01110111 00100000 01110100 01101111 00100000 01110101 01110011 01100101 00100000 01100001 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01110100 01110010 01100001 01101110 01110011 01101100 01100001 01110100 01101111 01110010 00100000 00111010 00101001

No? But that's how computers understand everything.

So what is a programming language?

If we didn't have any programming language we would have to talk to the computer in Binary Code.

Basically a programming language is a way to programmers talk to computers with an easier language instead of binary, and without making everything from scratch, the main difference between all programming languages are the syntax, off course each programming language is best for this or that task, each has its own set of libraries and functions, etc.

People think that programming is about programming languages, but it IS NOT!

Programming is about logic and algorithms.

Imagine if you want to talk to a Japanese guy, but you don't know even a word in Japanese, so you think "i can't talk to him because i don't know Japanese", but that is wrong, you CAN talk to him, not talk using a spoken language but you can make him understand what you want by drawing, making gestures, etc but first you need to know how to think in a way of making him understand you.

Talking to computers is the same thing, if you are bad in logic you will never be able to talk to a computer even if you know the syntax of all the programming languages in the world.

What programming language should i start or use?

I can't answer that for you, each person like this or that language, but the truth is that you can't live only with one language, each language is more suited for a task, you can try doing everything in just one language but just if you want to suffer, because for certain tasks, is faster for you to learn a new language than try making it in your current language.

You can start with any language, some says that this or that language is best, at university you will most likely learn pascal or C.

But in my own honest opinion, i think that for starters its better to start with a modern language like python or C#, because these languages already have a support for a lot of modern things that languages like pascal doesn't have, like object oriented programming, exception handling, etc.

I think its difficult to learn Object Oriented Programming once you are too used to Structural programming, so i recommend using a modern language, but that's just my opinion.

### Coding Lessons

Hi,

I'm stiiiiiiiiiiiiiiiiil aliiiiiiiiiiiiiiiiiiive (and coding)!

So starting today, I'll try to take at least half hour a day to write something stupid here, but first of all I need to get everything in place.

The first thing I did was to convert this blog to the new blogger layout (its way better and has tags, hurray!).

The second thing was to delete a lot of post (yes you should thank me for that because it was a dark time of my life, when I lost all my senses and started posting digg histories here.. argh!).

The third was to delete a new blog I started some days ago, and just try to keep everything on this one.

And the forth thing, is what I'm gonna do right now, wich is move all the posts of another blog I started (coding lessons) to this one. Sadly the blog is discontinued, but just as a memento I will copy all the lessons to this blog, so all the hours I spent working on that blog doesn't become stardust.

And thats it, I'll not promise to write here everyday because if I do it, it will start to be an obligation and then I'll get depressive about having to do it and will just stop.

So, perhaps you will see some good posts soon, perhaps not, who knows, just add me to your rss reader and pray :)