Skip to content

Instantly share code, notes, and snippets.

@joyhuang9473
joyhuang9473 / team_c++_style_guide_names_and_order_of_includes.h
Last active October 18, 2015 06:54
All of a project's header files should be listed as descendants of the project's source directory without use of UNIX directory shortcuts . (the current directory) or .. (the parent directory). For example, project/Classes/Entity/Role/Role.h should be included as:
#include "Entity/Role/Role.h"
@joyhuang9473
joyhuang9473 / team_c++_style_guide_conditionals.h
Last active October 18, 2015 07:02
Prefer no spaces inside parentheses. The if and else keywords belong on separate lines.
if (condition) { // no spaces inside parentheses
... // 4 space indent.
} else if (...) { // The else goes on the same line as the closing brace.
...
} else {
...
}
// Sort conditional statements may be written on one line if this enhances readability.
if (x == kFoo) return new Foo();
@joyhuang9473
joyhuang9473 / team_c++_style_guide_loops_and_switch_statements.h
Last active October 18, 2015 08:08
If not conditional on an enumerated value, switch statements should always have a default case (in the case of an enumerated value, the compiler will warn you if any values are not handled). If the default case should never execute, simply assert:
switch (var) {
case 0: // 4 space indent
... // 8 space indent
break;
case 1:
...
break;
default:
assert(false); // If the default case should never execute, simply assert
}
@joyhuang9473
joyhuang9473 / team_c++_style_guide_boolean_expressions.h
Last active October 18, 2015 07:28
When you have a boolean expression that is longer than the standard line length, be consistent in how you break up the lines.
if (
this_one_thing > this_other_thing &&
a_third_thing == a_fourth_thing &&
yet_another && last_one
) {
...
}
@joyhuang9473
joyhuang9473 / team_c++_style_guide_variable_and_array_initialization.h
Last active October 18, 2015 07:56
You may choose between =, (), and {}; the following are all correct:
int x = 3;
int x(3);
int x{3};
string name = "Some Name";
string name("Some Name");
string name{"Some Name"};
@joyhuang9473
joyhuang9473 / team_c++_style_guide_class_format.h
Last active October 18, 2015 08:09
Sections in public, protected and private order, each indented zero space.
class MyClass : public OtherClass {
public: // Note the 0 space indent!
MyClass(); // Regular 4 space indent.
explicit MyClass(int var);
~MyClass() {}
void someFunction();
void setSomeVar(int var);
int getSomeVar();
@joyhuang9473
joyhuang9473 / team_c++_style_guide_constructor_initializer_lists.h
Created October 18, 2015 08:02
Constructor initializer lists can be all on one line or with subsequent lines indented four spaces.
// When it all fits on one line:
MyClass::MyClass(int var) : some_var_(var), some_other_var_(var + 1) {}
// When it requires multiple lines, indent 4 spaces, putting the colon on
// the first initializer line:
MyClass::MyClass(int var)
: some_var_(var), // 4 space indent
some_other_var_(var + 1) { // lined up
...
DoSomething();
@joyhuang9473
joyhuang9473 / team_c++_style_guide_namespace_formatting.h
Created October 18, 2015 08:05
The contents of namespaces are not indented.
namespace {
void foo() { // Correct. No extra indentation within namespace.
...
}
} // namespace
@joyhuang9473
joyhuang9473 / coursera-stanford-machine-learning-class-assignment-ex1-multi-predicted-price-console-output.m
Last active March 26, 2019 13:25
In ex1data2.txt, console outputs of predicted price with Octave
% error output
% ============
Normalizing Features ...
Running gradient descent ...
Theta computed from gradient descent:
334425.499894
100131.267805
3639.767537
@joyhuang9473
joyhuang9473 / coursera-stanford-machine-learning-class-week3-assignment-compute-cost-and-gradient.m
Last active November 16, 2015 12:40
Compute and display initial cost and gradient in ex2data1.txt.
% Octave console output
Cost at initial theta (zeros): 0.693147
Gradient at initial theta (zeros):
-0.100000
-12.009217
-11.262842