Язык программирования Go | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- 18% translated in draft.
If you do not want to register an account, you can sign in with OpenID.
A Tutorial for the Go Programming Language | ||
Introduction | ||
Hello, World | ||
Compiling | ||
Echo | ||
An Interlude about Types | ||
An Interlude about Allocation | ||
An Interlude about Constants | ||
An I/O Package | ||
Rotting cats | ||
Sorting | ||
Printing | ||
Prime numbers | ||
Multiplexing | ||
Introduction[Top] | ||
This document is a tutorial introduction to the basics of the Go programming language, intended for programmers familiar with C or C++. It is not a comprehensive guide to the language; at the moment the document closest to that is the language specification. After you've read this tutorial, you might want to look at Effective Go, which digs deeper into how the language is used. Also, slides from a 3-day course about Go are available: Day 1, Day 2, Day 3. | В этом документе изложенны основы языка Go для программистов знакомых с С и С++. Это не исчерпывающее описание языка, некоторые моменты подробно описаны в спецификации. После прочтения этого обзора, возможно вам будет интересно ознакомиться с Effective Go, в котором более подробно описано, как используется язык. Так же есть слайды 3-дневного курса Go: день 1, день 2 и день 3. | |
The presentation here proceeds through a series of modest programs to illustrate key features of the language. All the programs work (at time of writing) and are checked into the repository in the directory /doc/progs/. | Изложенный материал продолжает серия небольших программ для иллюстрации ключевых возможностей языка. Все программы работоспособны (на момент написания) и расположены в хранилище в директории /doc/progs/. | |
Program snippets are annotated with the line number in the original file; for cleanliness, blank lines remain blank. | Отрывки программ снабжены номером строки в оригинальном файле; для чистоты, пустые строчки остаются пустыми. | |
Hello, World[Top] | ||
Let's start in the usual way: | ||
05 package main | ||
07 import fmt "fmt" // Package implementing formatted I/O. | 07 import fmt "fmt" // пакет отвечающий за форматированный ввод/вывод | |
09 func main() { 10 fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n"); 11 } | 09 func main() { 10 fmt.Printf("Привет, мир!; or Καλημέρα κόσμε; or こんにちは 世界\n"); 11 } | |
Every Go source file declares, using a package statement, which package it's part of. It may also import other packages to use their facilities. This program imports the package fmt to gain access to our old, now capitalized and package-qualified, friend, fmt.Printf. | Каждый входной файл в Go объявляется с использованием пакетного оператора, частью которого является пакет. Можно также импортировать другие пакеты для использования их функционала. | |
Functions are introduced with the func keyword. The main package's main function is where the program starts running (after any initialization). | Функции объявляются с ключевым словом func. Программа начинает выполняться с функции main основного пакета (после инициализации). | |
String constants can contain Unicode characters, encoded in UTF-8. (In fact, Go source files are defined to be encoded in UTF-8.) | Строки могут содержать Unicode символ в UTF-8. (В действительности, исходные файлы Go кодированны в UTF-8.) | |
The comment convention is the same as in C++: | ||
/* ... */ | ||
// ... | ||
Later we'll have much more to say about printing. | ||
Compiling[Top] | ||
Go is a compiled language. At the moment there are two compilers. Gccgo is a Go compiler that uses the GCC back end. There is also a suite of compilers with different (and odd) names for each architecture: 6g for the 64-bit x86, 8g for the 32-bit x86, and more. These compilers run significantly faster but generate less efficient code than gccgo. At the time of writing (late 2009), they also have a more robust run-time system although gccgo is catching up. | Go - компилируемый язык. На текущий момент есть два компилятора. Gccgo - Go компилятор использующий GCC. Есть так же серия компиляторов с разными (и странными) именами для каждой архитектуры процессора: 6g для 64-битных, 8g для 84-битных, и так далее. Эти компиляторы значительно быстрее, но генерируют менее эффективный код чем gccgo. На данный момент (конец 2009 года), они также имеют более оптимизированную систему реального времени, хотя gccgo догоняет их. |
© google.
