Page MenuHomePhabricator
Contents

The Swap File
Updated 2,580 Days AgoPublic

I got tired of forgetting syntax when I switch between languages, so I'm starting this wiki page. If we make it extensive enough, it might just be publication-worthy someday!

Structure

Each language entry should show the following, in the following order.

Demo
Comment
Doc Comment
Multiline Comment
Multiline Doc Comment
Imports
Resolve namespaces
Declare integer "foo" as 3
Declare string "bar" as "Hello, world!"
Function "say"...
   Accept string (message), string (caller), and integer (repeat number).
   Print as "msg (caller, num)"
   Return type boolean, return true.
   For example, the second permutation of the "while" statement should call msg with "while", 2, and bar
If foo > 0, call msg.
Declare integer "i" as 0.
While i < foo, call msg and increment i.
For n > foo, call msg.

C++

C++
//Comment
///Doc Comment
/*Multiline Comment*/
/**Multiline Doc Comment*/

//Imports.
#include <string>
#include <iostream>
#include "myFile.hpp"

//Resolve namespaces.
using std::string;

//Declare variables.
string bar = "Hello, world!";

bool say(string msg, string caller, int time)
{
   std::cout << msg << "(" << caller << ", " << std::to_string(time) << ")" << endl;
   return true;
}

//If statement.
if(foo > 0)
{
   //Print out.
   say(bar, "If", 1);
}

int i = 0;

//While loop.
while(i < foo)
{
   //Print out.
   say(bar, "While", i+1);
   //Increment.
   i++;
}

//For loop.
for(int n = 0; n < foo; n++)
{
   //Print out.
   say(bar, "For", n+1);
}
Last Author
jcmcdonald
Last Edited
Jul 22 2015, 8:45 PM

Event Timeline

jcmcdonald edited the content of this document. (Show Details)