Brendan Eich, Bjarne Stroustrup, Graydon Hoare

Things people tell me that they know: “full-stack JavaScript is the Future”, “everyone should know C”, “Rust is the best language for Systems Programming”… Most people hear stuff like this, and say to themselves, is that true? ~ Haseeb Qureshi, Converge: Why Engineers Disagree About Everything (Talk)

Migrating between C++, JavaScript and Rust today has never been easier, language features/syntax seem to be converging, recent updates to each language added features exclusive to other languages.

Syntax

Features

  • ECMAScript 2017 (JS) now features shared memory and atomics, and even things like threads are possible through service workers.
  • C++ 17 now features array destructuring, and upcoming features like modules will make the language even closer to higher order languages.
  • Rust now has a TypeScript-like Language Server, which is similar to Visual Studio’s C++ Intelisense.

Performance across each language is also getting closer:

  1. JavaScript’s WebAssembly proposal is bringing with it a huge boost in performance, and regular JavaScript is among the fastest dynamically typed languages out there. (Ruby, Python, etc.)
  2. C++ through it’s long history of focusing on performance, has always been extremely fast.
  3. Rust is fast, at times even better than C/C++ in performance, according to The Computer Language Benchmarks Game K-Nucleotide benchmark.

Table of Contents

  1. Installation — Get off the ground and programming immediately.
  2. Modules — Creating and installing modules, and how to structure your modules/applications.
  3. Syntax — An overview of the syntax differences of each language.

JavaScript

Brendon Eich is known as a bit of an apologist because of some bad decisions early on with the language, nevertheless, thanks to no small effort on the part of the many people contributing to the evolution of the language, modern JavaScript is a pleasure to develop in.

Installation

Download and install the Node Version Manager for your machine:

Then open up a terminal such as Hyper and type:

Or you can visit The Node Foundation and download the current version of Node.

Alternatively you can visit a code editing website like Codepen, but bear in mind there are missing features between browser and server versions of JS.

There’s also TypeScript and Flow, tools that add static type checking to the JavaScript language.

Recommended — Use a Type checker like TypeScript or Flow for your code.

File Structure

Execution

C++

C++ is a mature language that has a lot of heritage. Developed by Bjarne Stroustrup in Bell Labs as an extension to C, it became its own language once people coming from C began to see how much more maintainable their codebases were with class hierarchies and template metaprogramming.

Installation

No matter what platform you’re developing on, you’ll want to have the following tools:

  • CMake — The most popular package toolchain for C++, abstracts your project away from your IDE and makes compiling libraries easier.
  • Conan — The most popular C++ package manager, makes dependency management in C++ much easier.

Windows

Download Visual Studio 2017 Community Edition.

Linux

OSX

Download XCode.

Rust

Rust has become pretty popular, with exciting research projects ranging from using it to build web browsers like Servo to even entire operating systems and game engines.

This is thanks to the strong emphasis on ergonomics, performance, and security that the Rust standard body pushes for.

Jack Moffitt, developer for the Rust powered browser Servo, said on The Changelog that:

“All of [ our security critical bugs with Firefox WebAudio ] were array out of bounds/use after free errors and all of them would have been prevented by the Rust compiler [ instead of C ].”

Installation

Windows

Visit win.rustup.rs to get an installer .exe.

Linux / OSX

From there you can easily find integrations with code editors like VS Code or Atom.

File Structure

In Rust, any folder can be a module if it has a Cargo.toml file (which is basically an .ini file similar to NPM's package.json), and often you'll see a script to handle building the package as well.

Here’s a sample Cargo.toml file:

Execution

Syntax

Imports, Namespaces, Exports

With node, every JavaScript file is treated as an isolated module, and the index.js file of a given folder indicates the folder's root JavaScript file.

Until C++ Modules come along, the following is the standard way of modularizing code. There’s no strict path rules in C++.

Modules in Rust follow the convention of having mod.rs indicate the root module of a given folder, and every submodule must be declared with the keyword mod.

Enums

Enums don’t exist in JavaScript, but are available in TypeScript:

Structs

JavaScript doesn’t have types, so no need to define structs. Types aren’t limited to being just structs in TypeScript though.

Classes

Normally in C++ you would declare your class in a header .h or .hpp file, and write the implementation in a .cpp file.

Alternatively you can use just a header and write the implementation as inline statements, or write the implementation in the class, but you’ll need to juggle when you declare variables/functions due to there not being declaration hoisting.

In Rust, there is no keyword class, instead you can create class-like constructs through a struct to represent your state, and implementation blocks (impl), which are sort of like cpp files.

Functions

JavaScript features 2 function types, the first being a function bound to the global scope unless specified otherwise, and the second being bound to the scope of where the function was declared, Fat Arrow Functions.

In C++ lambdas are denoted with a scope capture [...scopevars], followed by the standard parenthesis for arguments and curly brace for the body of the function () { }.

In Rust lambdas follows the signature |...params| { body }, with the curly braces around the body being optional.

Destructuring

C++ 17 recently added destructuring as a native language feature:

Rust has intuitive destructuring for Structs and arrays:

Interfaces

C++ interfaces are possible through classical inheritance.

Templates/Generics

There’s no such thing as templates/generics in JS, but you do have Generics in TypeScript and Flow.

Common Modules

Conclusion & Further Reading

Getting a full grasp of a programming language to the point where you’re able to write anything takes time, however reading each language’s manual will help tremendously.

JavaScript

The TypeScript Handbook gives a clear introduction to the newest JavaScript features as well as teaching best practices with the TypeScript toolset.

For more resources, check out my post on developing javascript applications.

C++

The C++ Programming Language book by the author of the language, Bjorne Strustrup, is a great summary of the entire language.

For more resources, check out my post on designing C++ libraries..

Rust

Rust features advanced variable binding patterns that come from functional programming, so be sure to review the chapter on patterns.

Talks

Podcasts

Books

Communities

https://Alain.xyz | Graphics Software Engineer @ Marmoset.co. Guest lecturer talking about 🛆 Computer Graphics, ✍ tech author.