Skip to content

vichcruz/programming-languages-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tutorial on Go

The code in this repository is part of the Programming Languages and Paradigms (PLP) Seminar at the University of Zurich.

In the Tutorial session, we will implement a simple web crawler that fetches the titles of a list of websites both synchronously and concurrently using goroutines.

Preparation

Install Go

  1. Download and install Go from the official website: https://golang.org/dl/
  2. Follow the installation instructions for your operating system.
  3. Verify the installation by opening a terminal and running:
    go version
    You should see the installed Go version.

Set Up the Project

  1. Clone this repository to your local machine:
    git clone https://github.com/vichcruz/programming-languages-tutorial.git
  2. Navigate to the project directory:
    cd programming-languages-tutorial

Running the Code

  1. Open a terminal and navigate to the project directory.
  2. The exercise code is located in the version-0 folder. You can run it using:
    cd version-0
    go run .
  3. We will progressively work on versions 1 to 4 during the tutorial.
  4. The complete solution code is located in the version-5 folder. Please don't look at it yet. If you want to see the expected output of the crawler, you can run it using:
    cd version-5
    go run .

Project Structure

  • main.go: The main entry point of the application.
  • Fetcher.go: Contains the function to fetch the title of a webpage.
  • ConcurrentCrawler.go: Implements the concurrent web crawler using goroutines.
  • go.mod: Go module file specifying dependencies.

Version Differences

  • version-0: Basic synchronous web crawler.
  • version-1: Introduces goroutines for concurrent crawling, but without proper synchronization or result collection.
  • version-2: Adds a channel to receive titles from concurrent goroutines, but has a bug in the receiving loop.
  • version-3: Fixes the channel receiving logic and adds timing measurements to compare concurrent vs synchronous performance.
  • version-5: Complete solution with proper concurrent crawler using sync.WaitGroup for goroutine synchronization and buffered channel for result collection.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages