about
9/18/2022
CodeBits Repo
Bits github Repo

Code Bits Repository

organized bits of syntax, idoms, and patterns

Quick Status Short Bits Enable easy comparison of languages Demonstration code Demos in C++, Rust, and C# Documentation yes Test cases NA Static library NA Build requires Rust, C++, C# installed Planned changes Add more bits

Contents:

The purpose of Code Bits is to present a sequence of compileable code snippets that illustrate the syntax, idioms, and small patterns, for each of a set of languages. With these a user can learn a new language by looking at a sequence of small codes in the new language and directly compare each of those with snippets from a familiar language. At this time we provide code for three programming languages: C++, Rust, and C# C++ Hello, Rust Hello, C# Hello,

User Interface

Making that comparison in an ergonomic fashion is challenging. It isn't obvious how to move back and forth between code fragments in two languages and also allow navigation among the codes in one language, illustrating different bits of syntax, especially in a way that users will find easy to grasp. The idea behind the UI adopted for Code Bits is to support horizontal navigation between languages and vertical navigation between the various code snippets in a single language. I've used a wooden barrel analogy. Each stave in the barrel holds a series of code fragments in a single language. The bands that hold the barrel together hold navigation buttons allowing rotation of the barrel to show another language. The space between bands has three panels for (Left) brief statement of what this fragment is, (Middle) implementing code, (Right) commentary and output generated by the implementing code. This is illustrated in the diagrams, below:
Figure 1. Barrel Metaphor Figure 2. Code Bits UI
The cross-hatched region in Firgure 1. holds the contents of Figure 2., from the Rust stave. The bands hold buttons that rotate the barrel and present the same view for another language, e.g., the left button in the hello world section will rotate the C++ stave into view at the hello world level. Lower levels do the same thing, rotating to another language at the same level. To navigate vertically, click the Sections button on the bottom menu as shown in Figure 3.
Figure 3. Code Bits Vertical Navigation
Each one of the menu items: hello, objects, data, ... is a link to the corresponding level in the current language. So clicking each of the links in the Sections menu will walk vertically down the stave for that language. Alternately, you can simply scroll down to see levels in sequence. If you have a very wide screen or dual monitors you can right click on either of the show buttons and select "Open Link in New Window" to compare the Bits for two languages side-by-side.

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. Hello data Explore types. Consider bind, copy, assign, and move operations

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

  6. Data Structures Demonstrate standard data structures

  7. Functions Demonstrate function syntax

  8. Generic functions Demonstrate syntax for generic functions

  9. Basic DepInverPrinc Demonstrate basic Dependency Inversion Principle

  10. Generic DIP Demonstrate Dependency Inversion Principle using Generic Trait

Build:

The three languages have different tool chains, but the Tooling link, above, shows that 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.

Status:

The UI is stable and seems to work well, once users understand how it works. The analogy discussion is intended to make the operation scheme easy to grasp for new users. User testing is starting, and you can supply feedback here. Code snippets and discussion are being added and should be complete by the end of Fall 2022.
  Next Prev Pages Sections About Keys