about
11/07/2023
IdiomsAndPatterns Repo
IdiomsAndPatterns code

Idioms and Patterns  Repository

Comparing C#, C++, and Rust

Quick Status Many short demos only a few installed Demonstration code coming Documentation yes Test cases NA Static library NA Build requires dotnet, CMake, Rust installed Planned design changes Add many short fragments
The goal of this repository, Idioms and Patterns, is similar to that of the Bits repository, to compare features of several languages. But they have very different user interfaces.
I'm debating how best to manage these two repositories. For now, Idioms and Patterns will stay as is, while Bits continues to grow.

1.0 Contents

This repository is starting a growing sequence of short stories about Idioms and Patterns, that we illustrate with code snippets from C#, C++, and Rust.

2.0 Snippets

Here are the currently planned code snippets. The ordering of some of these may change. Ordering so that each code snippet depends only on its predecessors doesn't necessary provide a good logical ordering. I'll be thinking about this as the list gets completed.

  1. Tooling Tools to develop C#, C++, and Rust on both Windows and Linux

  2. Hello World use C# with dotnet CLI, C++ with CMake, and Rust with cargo to build Hello World

  3. Hello Objects Declare Classes/Structs and create instances.

  4. Manage data Explore types. Consider bind, copy, assign, and move operations

  5. Basic DIP Demonstrate basic Dependency Inversion Principle

  6. Generic DIP Demonstrate Dependency Inversion Principle using Generic Trait

  7. Iteration Demonstrate iteration through strings, slices, and byte arrays

  8. Create static libraries Explore projects with library and console executive

  9. Explore performance use timers written in each language to compare performances

  10. Explore ownership implement simple graphs using C# references, C++ (smart) ptrs, and Rust indexes

  11. Sharing with Rc<T> and Arc<T> Shared data

  12. Explore strings C#, C++, and Rust all use different string types

  13. Iterations Iterating over byte arrays and strings

  14. More strings Creating, mutating, converting

  15. Functions Syntax, passing by value and reference, return types

  16. User defined types Declaring, instantiating, methods, access, state mutation

  17. Generics Parameterization, Policies, lifetimes

  18. Traits Bounds on generic types, Static and dynamic dispatching

  19. Lambdas Syntax, data capture, transporting across scopes

  20. Liskov Substitution Principle Inheritance, dynamic dispatch, trait objects

  21. Dependency Inversion Principle Interfaces, object factories, trait objects

  22. Decorator Pattern Structure, application flow

  23. Observer Pattern Structure, application flow

3.0 Build

The three languages have different tool chains, but this story shows that the build processes can be very similar. Our goals are to build on both Windows and Linux. We do that using Visual Studio Code as a text editor and building from its terminal.
  • C# code was built from the command line with dotnet.
  • C++ code was built from the command line using CMake.
  • Rust code was built from the command line using the rust cargo tool.
All of these builds work in nearly identical ways on both OS platforms.

4.0 Status

Less than half completed
  Next Prev Pages Sections About Keys