Start translate of 2.1

This commit is contained in:
James Miranda
2016-09-30 17:31:29 -03:00
parent 0e89e09044
commit 1f81ba4287

View File

@@ -1,34 +1,34 @@
# 2.1 Hello, Go
Before we start building an application in Go, we need to learn how to write a simple program. You can't expect to build a building without first knowing how to build its foundation. Therefore, we are going to learn the basic syntax to run some simple programs in this section.
Antes de iniciar a construção de aplicações completas em Go, nós precisamos aprender a escrever um programa simples, afinal, você não pode construir um prédio sem antes construir sua fundação. Sendo assim, vamos aprender a sintaxe básica para executar alguns programas simples nessa seção.
## Program
## Programa
According to international practice, before you learn how to program in some languages, you will want to know how to write a program to print "Hello world".
Seguindo a reconhecida prática internacional, antes de aprender como programar em qualquer linguagem, você precisa saber como escrever um programa que imprime a famosa frase "Hello world".
Are you ready? Let's Go!
Pronto pra esse primeiro desafio? Vamos lá!
package main
import "fmt"
func main() {
fmt.Printf("Hello, world or 你好,世界 or καλημ ́ρα κóσμ or こんにちは世界\n")
}
It prints following information.
Isto irá imprimir a seguinte informação.
Hello, world or 你好,世界 or καλημ ́ρα κóσμ or こんにちは世界
## Explanation
One thing that you should know in the first is that Go programs are composed by `package`.
## Explicação
`package <pkgName>` (In this case is `package main`) tells us this source file belongs to `main` package, and the keyword `main` tells us this package will be compiled to a program instead of package files whose extensions are `.a`.
Uma coisa que você precisa entender em primeiro lugar é que os programas Go são compostos de pacotes (identificados pela palavra-chave `package`).
Every executable program has one and only one `main` package, and you need an entry function called `main` without any arguments or return values in the `main` package.
`package <pkgName>` que no nosso exemplo é `package main`, identifica que esse código pertence ao pacote `main` e a palavra `main` indica que esse pacote será compilado em um programa ao invés de um pacote com extensão `.a`.
In order to print `Hello, world…`, we called a function called `Printf`. This function is coming from `fmt` package, so we import this package in the third line of source code, which is `import "fmt"`
Todo programa executável possui um, e somente um, pacote `main` e este último precisa conter uma função nomeada como `main` sem nenhum argumento ou valores de retorno.
Para exibir a mensagem `Hello, world…`, foi utilizada uma função chamada `Printf`. Esta função faz parte do pacote `fmt`, então nós importamos esse pacote na terceira linha do código usando a instrução `import "fmt"`.
The way to think about packages in Go is similar to Python, and there are some advantages: Modularity (break up your program into many modules) and reusability (every module can be reused in many programs). We just talked about concepts regarding packages, and we will make our own packages later.
@@ -40,7 +40,7 @@ On the sixth line, we called the function `Printf` which is from the package `fm
As we mentioned in chapter 1, the package's name and the name of the folder that contains that package can be different. Here the `<pkgName>` comes from the name in `package <pkgName>`, not the folder's name.
You may notice that the example above contains many non-ASCII characters. The purpose of showing this is to tell you that Go supports UTF-8 by default. You can use any UTF-8 character in your programs.
You may notice that the example above contains many non-ASCII characters. The purpose of showing this is to tell you that Go supports UTF-8 by default. You can use any UTF-8 character in your programs.
## Conclusion