Note per il potenziale talk per la DevFest del GDG di introduzione alle generics del go
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Antonio De Lucreziis a11a034355 Tolti esempi prototipo 1 year ago
.github/workflows grrrr 1 year ago
assets Iniziata pulizia delle slide 1 year ago
examples Tolti esempi prototipo 1 year ago
.gitignore First draft notes 1 year ago
Makefile foewhfuoewhow 1 year ago
POST.md Molte slide 1 year ago
README.md Agginuto extra per chi non sa il go 1 year ago
extra-slides.md Started post and things 1 year ago
go.mod commit 1 year ago
go.sum First draft notes 1 year ago
package.json marp bug, fixed some paths 1 year ago
pnpm-lock.yaml Pulita un po' la repo 1 year ago
post-v2.md Started post and things 1 year ago
slides.md Ultimo commit pre-talk 1 year ago

README.md

Introduzione alle Generics in Go - DevFest GDG

Repo con tutti gli esempi e le slides della presentazione.

Descrizione. In questo talk introdurremo le generics del Go 1.18 e vedremo alcuni pattern ed anti-pattern del loro utilizzo.

 

   

 

Setup

These slides are made using Marp

$ npm install

Usage

To preview and build the slides use

# Show slides preview
$ npm run preview

# Build slides
$ npm run build:html
$ npm run build:pdf

Go

There is a Makefile with various utilities for running, build and decompiling the Go examples.

# Show usage
$ make

# Run/build/decomp examples
$ make run-<subproject> 
$ make compile-<subproject> 
$ make compile-noinline-<subproject> 
$ make decomp-<subproject> 
$ make decomp-noinline-<subproject> 

Extra: Per chi non sa cosa sono le interfacce leggere prima questo

type Circle struct {
    Radius float64
}
type Rectangle struct {
    Width, Height float64
}

type Shape interface {
    Area() float64
    Perimeter() float64
}

func (c Circle) Area() float64 {
    return c.Radius * c.Radius * math.Pi
}
func (c Circle) Perimeter() float64 {
    return 2 * c.Radius * math.Pi
}
func (c Circle) Curvature() float64 {
    return 1 / c.Radius
}

func (r Rectangle) Area() float64 {
    return r.Width * r.Height
}
func (r Rectangle) Perimeter() float64 {
    return 2 * r.Radius * math.Pi
}
func (r Rectangle) CornerCount() int {
    if (r.Width == 0 && r.Height == 0) { return 0 }
    if (r.Width == 0 || r.Height == 0) { return 2 }
    return 4
}

func AreaOverPerimeter(s Shape) float64 {
    return s.Area() / s.Perimeter()
}

// c1 := Circle{ Radius: 5.0 }
c1 := Circle{ 5.0 }

// r1 := Rectangle{ Width: 2.0, Height: 3.0 }
r1 := Rectangle{ 2.0, 3.0 }

AreaOverPerimeter(c1)
AreaOverPerimeter(r1)