Python Tutorial Chapter 1 -Hello World!-

python logo

 

As I said in one of my first posts, there are plenty of good reasons to program in Python and as I love this language, I will try to do tutorials, kind of  “from zero to hero”. I wish this tutorial makes you learn about Python.

 

What you will need for this tutorial:

  • Python 3
  • PyCharm (well, any other IDE will work, I just chose this one for this because I feel it is the best one).
  • Eager to learn

So, any comments, ideas, questions, whatever, just comment here or in the video I will answer.

 

P.S.: Notice that I don´t have any script for the videos, so when I press “record” I only have the idea of what I am going to talk, so I am not sure of what I am going to say at the beggining of the video.

Code & Beer. Belatrix Oktoberfest!

codeandbeer

Today I am in Chacras de Coria, Mendoza, at “Code & Beer” event, where I am was invited to talk about migration to Selenium 3. If you are near, please join us, it will be fun. Programming, food, beer, what else is needed for a good night?

Getting to Mendoza is not easy right now, the local airport is closed so you have to go to San Juan and from there take a bus…

20161027_054203

 

But then good things happen… A day of work in a peacefull place…

20161027_140520 20161027_140531 20161027_140620 20161027_140625 20161027_140629

 

Developers life is something great, it takes me to great places like this, meet cool people, learn lots of new things.

Hackatrix!

Today I am at University of Palermo for assisting in a hackaton sponsored by Belatrix, the company where I work. My role is to help the competitors to make the best possible work, I wish all goes good!

Four teams creating social applications, competing for the glory.  Let the game begin!

A week in Perú

peru

One good thing of my work is that from time to time I have to leave Buenos Aires and travel to another city/country.

Taking my flight to Lima
Taking my flight to Lima

This is my second time in Lima, both times for work (and yes, made a little tourism), and let me tell you something, traveling for work have good and bad things.

Luckily I am travelling one or two times per year, so I don’t leave home often, I have a wife and two little daughters, so some times it is hard to be alone in another country. I know of people that travel so often that I think that airports are their second home.

 

The good thing of traveling for work is that no technology replaces face to face meetings. ten minutes here talking with the team some times replaces hours of Skype, Slack or whatever. This is something for an entire post, but nothing replaces face to face.

View from the office, sometimes I think that the sun doesn't exist in Lima.
View from the office, sometimes I think that the sun doesn’t exist in Lima.

Talking about the industry, from what I was talking here with people, there are lots of great people (I really hate the term “human resource”), but lack of big system companies compared to other places, so maybe it is a bit harder to get a dream job, but not to hard. But Perú is growing, you can see it easily, so I think that lots of companies will start and grow big in no time.

img-20161010-wa0008

Final words: food in Perú is GREAT. I don’t do advertisement, but places like “La Lucha” are a must. You have to eat “Cerdo al cilindro” (pork at cylinder), you will have a better understanding of the meaning of life.

TestingAr VII a really nice Meetup

TestingArVII

Yesterday I had the honor to speak in one of the greatest QA meetings in Argentina: TestingAr. In the seventh edition it was hold at Belatrix headquarters in Buenos Aires and I talked about What, when, where and why to automate. It was a great experience, I wish I can be in more meetings like this.

The video is in Spanish (as it was the Meetup) and cannot be inserted, so the link is shown:

Link To The Video

After that there was a lot of food and beer and then a great explanation of Docker was done by Matias Lespiau, he really knows a lot about Docker, really enjoyed hearing his conference.

Link To The Video

And then a lot of questions, more contacts, more beer, exchanging experiences, well it was a great night.

Test automation. Dealing with common excuses

free_shutterstock_58878098_robot

Some companies still reject the idea of doing automation, and they have some arguments for that. In this post I will talk about the four most common that I heared:

  1. It takes time to program the base.
  2. It needs some difficult to get QA/Developers.
  3. It is easier to make only manual testing.
  4. “Maybe in the future…” excuse. So, the QA lose a lot of time testing manually and not getting time to automate test cases.

Let me say it clear:  I think that are only excuses of people that are afraid to change thinking that they are buying a risk. So for any of those excuses there is an answer, so lets talk about each one of them:

It takes time to program the base.

Yes, it takes time, but in long term it saves more. Automating the regression makes people in the team only think in new features leaving the everyday teting to a computer.

It needs some difficult to get QA/Developers.

Maybe this is the strongest excuse. The profile of a QA automation is someone that is half QA and half developer (depending on the project maybe more QA than developer or more dev than QA is needed, but lets say it is half and half). The truth is that today any developer should learn a little about QA (at least for knowing about how to face unit testing) and QA people should learn at least a little about development, not only because of automation, but because knowing what the developers are doing is a great thing. I remember being on the QA side and having to debug some Cobol code (even if I don’t know Cobol, knowing how to program made me understand a lot about what the developers were doing). So, if you get the right and motivated people, they will learn how to deal with the other part.

It is easier to make only manual testing.

Maybe you think that is easier to click a button and see the result than make the computer click the button and see the result. But think of this: a person works for 8 hours, he gets tired, makes mistakes, needs time to take a coffee, gets frustrated, have bad days. The computer doesn’t care about all this, it just works and do what was told to do. Another advantage: automated test can run at any time, you can make a scheduled task to make lists of tests run every night, or you can integrate a smoke to any new code commit, so the automation program can quickly see if the basic functionalities work well.

“Maybe in the future…”

If you make a QA team go over and over again a regression, a smoke or whatever, they will be running in circles without really doing lots of new things. Having those things automated will not only give lots of time to your QA team to work on more productive things, but will save time and money.

I am not saying that manual QA must disapear, there are lots of things that must be done manually, but adding automation to your project you will save lots of time and money and you will win quality and value. In future posts I will talk about what kind of test must be manual and which test cases should be automated.

Let’s program the Game Of Life

gol1

Ok, this is the first “coding post” of the blog and it is not in Python! You red my first post and thought that this blog was going to be about Python, and then, a programming post using JavaScript. Well… here you will see a lot of things in a lot of languages.

Note: You can grab lots of game of life algorithms in different languages for free from Rosetta Code.

In this post we will start with the game of life coding by doing the logic in javascript, so, next time we can start programming the html part with canvas.

 

So, lets get started: first lets create our gameOfLife.js file, the logic of the game:

For a good start, our 2 dimensional array will be 10×10 positions:

var x = new Array(10);
for (var i = 0; i < 10; i++) {
    x[i]= new Array(10);
}

For now, all the positions will take a 0 or 1 in a random way:

for (var i = 0; i< 10;i++){
  for (var j=0;j<10;j++){
    x[i][j]=Math.floor(Math.random()*2);
  }
}

Until we have some good way to see it, lets put the output in the console, so I was thinking in a simple function like this:

function showOnLog(myArray){
  var line="";
  for (var i = 0; i< 10;i++){
    for (var j=0;j<10;j++){
      line = line+myArray[i][j].toString();
    }
    console.log(line+"\n");
    line = "";
  }
}

So, if we send the array there we should see our initial state.

And now let’s run this (for showing purpose I will run it with node, but any way to run your js is good):

gol1

Now, we have to change it in cycles so, we will enter in a new for and look for our 4 rules:

  1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by over-population.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

To do so, we need a function to count the neighbours of a cell:

function neighboursCounter(myArray, posx,posy){
  counter = 0;
  if(posx>0){
    if (myArray[posx-1][posy]==1){
      counter++;
    }
    if(posy>0){
      if (myArray[posx-1][posy-1]==1){
        counter++;
      }
    }
    if(posy<myArray[posx].length-1){
      if (myArray[posx-1][posy+1]==1){
        counter++;
      }
    }
        
  }
  if(posy>0){
    if (myArray[posx][posy-1]==1){
      counter++;
    }
  }
  
  if(posy<myArray[posx].length-1){
    if (myArray[posx][posy+1]==1){
      counter++;
    }
  }
  if(posx<myArray[posx].length-1){
    if(posy>0){
      if (myArray[posx+1][posy-1]==1){
        counter++;
      }
    }
    if (myArray[posx+1][posy]==1){
      counter++;
    }
    if(posy<myArray[posx].length-1){
      if (myArray[posx+1][posy+1]==1){
        counter++;
      }
    }
  }
  
  return counter;
}

 

And, once you have the status you need a function to determine the status of the cell given the rules:

function newState(actualValue,neighbours){
  cellState=0
  if(actualValue==1){
    if(neighbours>1 && neighbours<4){
      cellState=1;
    }
  }else{
    if(neighbours==3){
      cellState=1;
    }
  }
  return cellState;
}

All these values will be put in a second auxiliar array (If I put them in the actual array the values of a cell will be calculated using the modified values, so, lets create a new function with an array that will receive the new values:

function arrayState(myArray){
  var x = new Array(10);
  for (var i = 0; i < 10; i++) {
    x[i] = new Array(10);
  }
  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      myNeighbours = neighboursCounter(myArray,i,j);
      x[i][j]=newState(myArray[i][j],myNeighbours);
    }
  }
  return x;
}

And at least, the loop with steps to make it work (for the example I will hardcode it to 5):

for (var steps = 0; steps< 5; steps++){
  x=arrayState(x);
  console.log("Step: "+steps.toString());
  showOnLog(x); 
}

This is all for this post, in the next one, we will add the web part and star quitting all the hardcoding.

If you want the latest code of this project, you can clone it from github

Game of Life

gol1

Today we are going to talk about something that fascinated me for a long time. The Game of Life by John Conway.

Game of Life is a zero-player game created by mathematician John Conway in 1970 and is a cellular automation game.  This game is about cells that are born, live and dies in different turns with some simple rules.

Let´s say our world is a grid and every position of the grid can have a living cell or no cell. In every turn by some rules that I am about to describe, for every point of the grid a cell can born, keep alive or die.

The rules are:

  1. Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  2. Any live cell with two or three live neighbors lives on to the next generation.
  3. Any live cell with more than three live neighbors dies, as if by over-population.
  4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Simple, right? Well, yes, but still fascinates lots of people (including me).

Another thing: What is the meaning of “neighbors”? Every point on the grid has 8 neighbors that are the adjacent points (I am trying to use points instead of cells, because I am using “cells” for our living creatures in the game).

If you still don’t understand well what is this about, well, maybe John Conway can explain a little more about his “game”, some good concepts and if he hats or not his creation (the channel Numberphile that is really great BTW contains some other videos of John Conway).

There are some “patterns” that appear in the game:

Game of Life Patterns
Game of Life Patterns

 

There are lots of implementations of the game in any language that you like, so, starting next post lets do some code to implement this on JavaScript and Canvas (yes, last post I was talking about how great is Python, but in the first coding post I will be doing this in JavaScript, this is how crazy is this blog).

What´s more, I just found an old video in my channel about an implementation I made using QB64:

Why Python?

print(Hello world!)

Welcome to my blog. Here my idea is to learn things, teach them, show my experience gained in lots of years in the software industry, some techie, technology, science and  I will talk about some personal things from time to time.

Even if the code here will be in lots of different languages, I will mostly show things in Python (specially Python 3). Why is that? Well… I am kind of fan of Python, but there are more reasons on why choosing or at least considering Python for development:

  1. It is easy to to create readable code: Python guides you to create clean and easy to read code while write the code.
  2. Coding speed: As it is very easy to write code, the speed on development is fast.
  3. Works almost everywhere: You write it in one machine/OS, it is highly probable that will run in other machines/OS.
  4. You want to do something? Python has the framework. With Python you can write code for the web (Django/Flask), create video games (PyGame), automate test (Selenium), even write mobile apps (Kivy).
  5. It is easy to learn: You can learn how to write code in Python in a couple of hours.
  6. There is a lot of jobs in Python.

Some people thinks that Python is kind of a toy and not a real language. Let me tell you that these people are wrong. Python is a serious thing and used in real life by top ranked companies, for  example:

  • Google: lots of things in the crawler and the earch engine are written in Python
  • Dropbox: They started with Python, they keep using it.
  • NASA.
  • Red Hat: for the installer and configuration
  • IBM
  • US Government (CIA).
  • Spotify: well, let them explain how they use it
  • And many, many more.

So, I am not telling you that oher languages are not as good as Python. Sometimes it is about how you like to code and which language fits you better and sometimes it is about what is best for what you are trying to do. For me, Python is great, ut I know lots of people that prefer Java, Ruby, C# and many more and they can give me great reasons to use them (well, someone at the office is teaching me Node.JS). The important thing at the end of the day is enjoy coding.

1 2