##The Basics
###Installation
####Windows Users
First off, get msysgit (download here). It is the official Windows Git distribution, and comes with a terminal that has your standard bash commands as well as Git.
##The Basics
###Installation
####Windows Users
First off, get msysgit (download here). It is the official Windows Git distribution, and comes with a terminal that has your standard bash commands as well as Git.
If you would like to use *nix tools on Windows, you have two main options:
bash
, ls
, cd
, grep
, and the other core utilities)
and a DLL that provides some Linux system emulation (signals, etc.). However, Cygwin tends to take the
"everything but the kitchen sink" approach, so I generally prefer the second option, MSYS.Single-line comments are started with //
. Multi-line comments are started with /*
and ended with */
.
C# uses braces ({
and }
) instead of indentation to organize code into blocks.
If a block is a single line, the braces can be omitted. For example,
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
Exceptions are used over return codes/errnos to handle errors, as they are the idiomatic error handling mechanism in modern C++ code.
// MSVC apparently doesn't have C's getline | |
// This is a poor man's implementation of it using fgets. | |
// See the man page at | |
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html | |
size_t getline(char** buf, size_t* bufLen, FILE* f) | |
{ | |
if (buf == nullptr || bufLen == nullptr) | |
{ | |
errno = EINVAL; | |
return -1; |
#include <cstdio> | |
struct Node { | |
int data; | |
Node* next; | |
}; | |
Node* makeList(int count) | |
{ | |
Node* const head = new Node(); |
// See http://sean-parent.stlab.cc/presentations/2016-10-10-runtime-polymorphism/2016-10-10-runtime-polymorphism.pdf | |
// or an earlier version, "Inheritance Is The Base Class of Evil" | |
#include <iostream> | |
#include <memory> | |
#include <string> | |
#include <vector> | |
using namespace std; |
Original text here: https://whydavewhy.com/2013/08/16/loyalty-and-layoffs/ |