helloworld

Hello World in Multiple Languages Extravaganza: Go

Hello world project extravaganza, the Go version.

Synopsis

This repository contains a version of “Hello World” programs written in Go;

indeed this is part of a fun and educational project that showcases how to print “Hello World” in different programming languages. The goal is to have a “Hello World” program in every programming language. This project is inspired by the GitHub Hello World project and you can found it in Hello World Extravaganza website.

check out the code

To get started, clone this repository to your local machine:

git clone https://github.com/silviotorre/helloworld.git

Getting Started

To run the “Hello World” program navigate to the project directory and run the program. Follow the instructions below to run the “Hello World”. Go programming language is a statically-typed, compiled programming language known for its simplicity, efficiency, and built-in support for concurrency. It promotes clean code, offers fast execution, and provides powerful features like goroutines and channels for concurrent programming.

go build hello_world.go
./hello_world

Here’s an example of a more complex “Hello, World!” program in Go that demonstrates the use of patterns and some exclusive advantages of the Go language like Goroutines and Channels.

```go
go build hello_world2.go
./hello_world2
```

Here’s an example of a unit test for the given code. The test ensures that each goroutine receives the expected message and prints it correctly.

```go
go test hello_world2.go hello_world2_test.go
``` Or you can run the test with the following command:

    ```go
    go test -v
    ``` The `-v` flag enables verbose output, which prints the name of each test and its result. You can also use the `-run` flag to run only specific tests. For example, the following command runs only the `TestHelloWorld` test:

```go
go test -v -run TestHelloWorld
```  The *go test* command also supports the `-bench` flag to run benchmarks. For example, the following command runs all benchmarks in the package:

```go
go test -bench .
``` 

Goroutines

Goroutines are lightweight concurrent threads of execution in Go. They are designed to be lightweight and efficient, allowing you to run multiple tasks concurrently within a single program. Goroutines are managed by the Go runtime and utilize multiplexed thread scheduling, meaning that they can be scheduled onto multiple OS threads as needed.

Goroutines are created using the go keyword followed by a function call. When a function is called as a goroutine, it starts running concurrently alongside other goroutines. Goroutines are independent of each other and can execute simultaneously, enabling concurrent execution without the overhead associated with traditional threads.

The key advantages of using goroutines are:

Channels

Channels are a fundamental construct in Go that facilitate communication and synchronization between goroutines. A channel is a typed conduit through which you can send and receive values between goroutines. It provides a safe and efficient way to exchange data or signals between concurrent processes.

To create a channel, you use the make function with the chan keyword followed by the type of the values that will be passed through the channel. For example, make(chan int) creates an unbuffered channel of type int.

Channels can be used to:

Channels in Go have the following characteristics:

Overall, goroutines and channels form the core concurrency primitives in Go, enabling easy and efficient concurrent programming while maintaining synchronization and communication between different parts of a program.

Personal notes

I like Go! It’s a very interesting language, it’s easy to learn and it’s very powerful. I like the fact that it’s a compiled language and it’s very fast. I like the fact that it’s a statically typed language and it’s very safe. I like the fact that it’s a modern language and it’s very productive. I like the fact that it’s a concurrent language and it’s very efficient. I like the fact that it’s a simple language and it’s very readable. I like the fac… ok, I think you got the point. I like Go!

tasks

Extra Credit

Contributing

Feel free to contribute your own “Hello World” programs to this repository. Simply create a new directory with the name of the programming language and add a file named hello-world. with your implementation. Don't forget to update the README file to include your contribution!

Contributors

License

References

Home of this project

Enjoy and happy coding!