Dart for C Developers
Move from C 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 C programs.
C and Dart side by side
The same program in C and in Dart, from the lessons of this course.
Output and Comments
C writes output with printf, which ends the line only when the format string contains \n and fills each %d from a separate argument. Dart print always appends a newline, and interpolation names a value directly inside a string. A top-level main is still the…
C1#include <stdio.h>2 3int main(void) {4 int lane = 3;5 printf("lane:%d\n", lane);6 return 0;7}Dart1void main(){final lane=3;print('lane:$lane');}Boolean Conditions
C accepts any scalar as a condition: zero is false and everything else, including a non-NULL pointer, is true. Even bool from stdbool.h is an integer type. Dart conditions and logical operands must have type bool, so an integer needs an explicit comparison…
C1#include <stdbool.h>2#include <stdio.h>3 4static bool probe(void) {5 puts("probe");6 return true;7}8 9int main(void) {10 int ready = 0;11 if (ready && probe()) {12 puts("open");13 } else {14 puts("closed");15 }16 return 0;17}Dart1bool probe(){print('probe');return true;}2void main(){final ready=0;if(ready!=0 && probe()){print('open');}else{print('closed');}}Functions and Returns
C functions are already top-level, but each must be declared before its first call, and headers share prototypes between files. Dart top-level functions need no prototypes, and an arrow can return one expression. C has no string suffix test and prints a bool…
C1#include <stdbool.h>2#include <stdio.h>3#include <string.h>4 5static bool is_log(const char *name) {6 size_t length = strlen(name);7 return length >= 4 && strcmp(name + length - 4, ".log") == 0;8}9 10int main(void) {11 puts(is_log("server.log") ? "true" : "false");12 return 0;13}Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}Iterables and Laziness
C has no built-in lazy sequences: a loop over an array runs eagerly, and deferring work means storing a function pointer next to the data and calling it only when a value is requested. Dart map and where build that kind of deferred view for you. Unlike a…
C1#include <stdio.h>2 3struct mapped {4 const int *items;5 int (*fn)(int);6};7 8static int twice(int n) {9 printf("visit:%d\n", n);10 return n * 2;11}12 13static int first(struct mapped m) { return m.fn(m.items[0]); }14 15int main(void) {16 const int items[] = {2, 3};17 struct mapped result = {items, twice};18 printf("made\n");19 printf("%d\n", first(result));20 return 0;21}Dart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}Parsing and Validation
C atoi returns 0 for text it cannot read, so a failure looks like a valid zero; strtol reports failure through its end pointer and errno, and it skips leading whitespace and stops at trailing garbage unless you check what end points to. Dart int.parse throws…
C1#include <errno.h>2#include <stdio.h>3#include <stdlib.h>4 5static int parse(const char *text, long *out) {6 char *end;7 errno = 0;8 long value = strtol(text, &end, 10);9 if (end == text || *end != '\0' || errno == ERANGE) return 0;10 *out = value;11 return 1;12}13 14int main(void) {15 long value;16 if (!parse("nope", &value)) printf("invalid\n");17 if (parse("42", &value)) printf("%ld\n", value);18 return 0;19}Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}Classes and Instances
C groups data in a struct and behavior in free functions that take a pointer to it, with no methods and no dynamic dispatch unless you add function pointers yourself. A Dart class bundles instance fields and methods, dispatches methods dynamically, and…
C1#include <stdbool.h>2#include <stdio.h>3 4struct lamp {5 bool on;6};7 8static void lamp_toggle(struct lamp *self) { self->on = !self->on; }9 10int main(void) {11 struct lamp a = {false}, b = {false};12 lamp_toggle(&a);13 printf("%s:%s\n", a.on ? "true" : "false", b.on ? "true" : "false");14 return 0;15}Dart1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp();a.toggle();print('${a.on}:${b.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 C Developers for?
For people who already write C and want to learn Dart. Each lesson starts from C 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 C basics: variables, conditions, loops, functions and collections.
How many lessons does Dart for C Developers have?
Dart for C Developers contains 48 interactive lessons you can complete at your own pace.
What does Dart for C 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 C Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.