Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Caesura Coding Standard, version 1.
- //Copyright (C) 2014 Caesura Industries(R)
- #include <iostream>
- #include <functional>
- #include <conio.h> //Always include conio.h. Don't know what it does but it's probably important.
- //Spaces only, 4 spaces per tab.
- //Do not use "namespace std", or any namespace.
- //Just do this, if you really need it. Don't
- //put everything here, only things you'll use
- //often, like cout and string. And of course,
- //using this is optional, in the sense that,
- //if you're fine with it, just put std:: in
- //front of everything. And don't typedef it
- //either, that's just unreadable.
- using std::cout;
- using std::string;
- namespace spc {
- //Yes, this is how we define functions.
- //Just pretend "auto" is "def" or "defun"
- //and it feels a bit more lispy. It's also
- //more consistent with lambdas.
- auto myfunc (int, int) -> int;
- template<typename T>
- auto newfunc (T) -> T;
- class MyClass {
- //public/private don't get tabbed
- //class name is always uppercase,
- //functions and namespaces are lowercase.
- public:
- MyClass();
- ~MyClass(); //Yes the tilde in the destructor goes back a space.
- auto func() -> string;
- auto geta() -> int&;
- private:
- int a;
- };
- } //Namespace ends here, everything gets defined outside.
- spc::MyClass::MyClass() : a(3) {
- //always use initializer lists.
- cout << "I'm awake\n";
- }
- spc::MyClass::~MyClass() {
- cout << "I'm done\n";
- }
- auto spc::MyClass::func() -> string {
- return "a is " + std::to_string(a) + "\n";
- }
- auto spc::MyClass::geta() -> int& {
- //Write setters/getters like this
- //for the love of god don't make two
- //separate functions just return
- //a reference.
- //By the way, setters are good to
- //control what goes in a variable.
- //Even if you don't need this control,
- //it's good to be consistent.
- return a;
- }
- auto spc::myfunc (int x, int y) -> int {
- //Open brackets don't get a new line, because
- //that's ugly as sin, especially in a world
- //where screens are wider than they are longer.
- //each "else" gets a new line.
- if (x == y) {
- return 1;
- }
- else if (x <= y) {
- return y;
- }
- else {
- return x;
- }
- }
- //Of course, templates get their own line.
- template<typename T>
- auto spc::newfunc (T x) -> T {
- return x;
- }
- auto main(int argc, char **argv) -> int {
- spc::MyClass c;
- cout << c.func();
- c.geta() = 5;
- cout << c.func();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement