Menu
CoddyTech
Course

Dart for Go Developers

Move from Go to standalone Dart through typed functions, null safety, collections, exceptions and object contracts. Build a four-step parcel depot, use classes, interfaces and mixins, then port two complete Go programs.

Go and Dart side by side

The same program in Go and in Dart, from the lessons of this course.

  1. Output and Comments

    Go prints with fmt.Println, which puts a space between operands, or with fmt.Printf verbs such as %d. Dart print takes one value and appends a newline, and interpolation names a value directly inside a string. Both start at a top-level main, but Dart needs no…

    Go
    1package main2
    3import "fmt"4
    5func main() {6	lane := 37	fmt.Printf("lane:%d\n", lane)8}
    Dart
    1void main(){final lane=3;print('lane:$lane');}
  2. Boolean Conditions

    Go and Dart both require bool conditions and short-circuit && and ||; neither treats 0, an empty string or nil as false. A Dart bool is an object that cannot hold null unless its type is written bool?, while a Go bool simply starts at its zero value, false.

    Go
    1package main2
    3import "fmt"4
    5func probe() bool {6	fmt.Println("probe")7	return true8}9
    10func main() {11	if false && probe() {12		fmt.Println("open")13	} else {14		fmt.Println("closed")15	}16}
    Dart
    1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}
  3. Functions and Returns

    Go and Dart both allow top-level functions, so no class is needed. Dart writes the result type before the name rather than after the parameters, and an arrow body returns a single expression. A Go function can return several values; a Dart function returns…

    Go
    1package main2
    3import (4	"fmt"5	"strings"6)7
    8func isLog(name string) bool {9	return strings.HasSuffix(name, ".log")10}11
    12func main() {13	fmt.Println(isLog("server.log"))14}
    Dart
    1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}
  4. Iterables and Laziness

    Go slice code is eager: a for loop that builds a result slice runs every iteration at once. Laziness exists only as iterator functions (iter.Seq) that you write or get from helpers such as slices.Values. Dart map and where on an Iterable are lazy by default…

    Go
    1package main2
    3import "fmt"4
    5func main() {6	nums := []int{2, 3}7	result := make([]int, 0, len(nums))8	for _, n := range nums {9		fmt.Printf("visit:%d\n", n)10		result = append(result, n*2)11	}12	fmt.Println("made")13	fmt.Println(result[0])14}
    Dart
    1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}
  5. Parsing and Validation

    Go strconv.Atoi never throws: it returns a result and an error (a *strconv.NumError) that the caller checks. Dart int.parse throws FormatException, while int.tryParse returns null. Their accepted syntax is not interchangeable: Dart ignores surrounding…

    Go
    1package main2
    3import (4	"fmt"5	"strconv"6)7
    8func main() {9	if _, err := strconv.Atoi("nope"); err != nil {10		fmt.Println("invalid")11	}12	n, _ := strconv.Atoi("42")13	fmt.Println(n)14}
    Dart
    1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}
  6. Classes and Instances

    Go has structs with methods declared outside the type, and assigning a struct copies it, so a pointer receiver is needed to change it in place. Dart classes declare fields and methods together, construction does not require new, and a variable holds a…

    Go
    1package main2
    3import "fmt"4
    5type Lamp struct {6	on bool7}8
    9func (l *Lamp) Toggle() {10	l.on = !l.on11}12
    13func main() {14	a, b := Lamp{}, Lamp{}15	c := a16	a.Toggle()17	fmt.Printf("%v:%v:%v\n", a.on, b.on, c.on)18}
    Dart
    1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp(),c=a;a.toggle();print('${a.on}:${b.on}:${c.on}');}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Go developers

Learn Dart from another language

Frequently asked questions

Who is Dart for Go Developers for?

For people who already write Go and want to learn Dart. Each lesson starts from Go you know and shows how Dart does the same thing, so you skip the beginner basics.

Do I need to know Dart already?

No. The course starts with your first Dart program. You need Go basics: variables, conditions, loops, functions and collections.

How many lessons does Dart for Go Developers have?

Dart for Go Developers contains 48 interactive lessons you can complete at your own pace.

What does Dart for Go Developers cover?

The course is organized into chapters covering: First Dart Programs, Flow and Decisions, Functions and Values, Collection Pipelines, and more.

Is Dart for Go Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Dart for Go Developers for free

Get started