Dart for C++ Developers
Move from C++ to standalone Dart through typed functions, null safety, collections, errors 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 text by inserting values into std::cout with <<, and you add the line break yourself with '\n' or std::endl, which also flushes. Dart interpolation occurs inside ordinary string literals using dollar-prefixed names or braces, and print writes one…
C++1#include <iostream>2 3int main() {4 int lane = 3;5 std::cout << "lane:" << lane << '\n';6}Dart1void main(){final lane=3;print('lane:$lane');}Boolean Conditions
C++ and Dart both short-circuit && and ||. A C++ condition accepts anything contextually convertible to bool: integers, pointers and objects with an explicit operator bool. Dart has no such conversion; a nullable bool? must be checked explicitly, and ordinary…
C++1#include <iostream>2 3bool probe() {4 std::cout << "probe\n";5 return true;6}7 8int main() {9 if (false && probe()) {10 std::cout << "open\n";11 } else {12 std::cout << "closed\n";13 }14}Dart1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}Functions and Returns
Like C++, Dart has free functions at the top level of a file, but it needs no forward declaration or header: a function can be called before its declaration, and other files import the library that defines it. C++ has no expression-bodied function syntax; a…
C++1#include <iostream>2#include <string>3 4bool is_log(const std::string& name) {5 return name.ends_with(".log");6}7 8int main() {9 std::cout << is_log("server.log") << '\n';10}Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}Iterables and Laziness
C++ algorithms such as std::transform are eager: they write every result as soon as they are called. C++20 range views such as std::views::transform are lazy like Dart Iterables: the function runs when an element is read, and again each time it is read.…
C++1#include <iostream>2#include <ranges>3#include <vector>4int main(){std::vector<int> v{2,3};auto result=v|std::views::transform([](int n){std::cout<<"visit:"<<n<<"\n";return n*2;});std::cout<<"made\n";std::cout<<result.front()<<"\n";}Dart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}Parsing and Validation
C++ std::from_chars reports failure through the errc in its result and writes the value into an output argument. std::stoi throws std::invalid_argument instead, and both accept a numeric prefix, so std::stoi("12px") returns 12. Dart tryParse returns the…
C++1#include <charconv>2#include <iostream>3#include <string>4int main(){std::string s="nope";int n=0;auto r=std::from_chars(s.data(),s.data()+s.size(),n);std::cout<<(r.ec==std::errc{}?std::to_string(n):"invalid")<<"\n";std::cout<<std::stoi("42")<<"\n";}Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}Classes and Instances
A C++ class object is a value: Lamp b=a copies its fields, and sharing one needs a pointer or a reference. Dart class instances always have reference semantics; assignment shares the instance, and there is no copy constructor or stack allocation to choose.…
C++1#include <iostream>2class Lamp{public:bool on=false;void toggle(){on=!on;}};3int main(){Lamp a,b;a.toggle();std::cout<<std::boolalpha<<a.on<<":"<<b.on<<"\n";}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.