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.
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…
Go1package main2 3import "fmt"4 5func main() {6 lane := 37 fmt.Printf("lane:%d\n", lane)8}Dart1void main(){final lane=3;print('lane:$lane');}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.
Go1package 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}Dart1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}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…
Go1package 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}Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}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…
Go1package 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}Dart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}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…
Go1package 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}Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}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…
Go1package 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}Dart1class 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 questionsFirst Dart Programs
6 lessonsFlow and Decisions
5 lessonsFunctions and Values
6 lessonsCollection Pipelines
6 lessonsParsing and Failures
3 lessonsObjects and State
6 lessonsContracts and Reuse
7 lessonsEquality and Testing
3 lessonsParcel Depot Project
4 lessonsFinal Source Ports
2 lessonsFrequently 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.