SlideShare a Scribd company logo
/ WordFriday
enterprise, noun
enterprise, noun
 a project or undertaking that is especially bold,
complicated or arduous
 readiness to engage in undertakings of difficulty, risk,
danger or daring
 a design of which the execution is attempted
 a commercial or industrial undertaking
 a firm, company or business
 a unit of economic organisation or activity
Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
enterprise, noun
 a project or undertaking that is especially bold,
complicated or arduous
 readiness to engage in undertakings of difficulty, risk,
danger or daring
 a design of which the execution is attempted
 a commercial or industrial undertaking
 a firm, company or business
 a unit of economic organisation or activity
Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
code, noun
 a set of instructions for a computer
 a computer program, or a portion thereof
 a system of words, figures or symbols used to
represent others, especially for the purposes of secrecy
 a set of conventions or principles governing behaviour
or activity in a particular domain
Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
Fizz buzz is a group word
game for children to teach
them about division.
http://en.wikipedia.org/wiki/Fizz_buzz
Players generally sit in a circle. The player
designated to go first says the number "1", and
each player thenceforth counts one number in
turn. However, any number divisible by three is
replaced by the word fizz and any divisible by five
by the word buzz. Numbers divisible by both
become fizz buzz. A player who hesitates or
makes a mistake is eliminated from the game.
http://en.wikipedia.org/wiki/Fizz_buzz
Players generally sit in a circle. The player
designated to go first says the number "1", and
each player thenceforth counts one number in
turn. However, any number divisible by three is
replaced by the word fizz and any divisible by five
by the word buzz. Numbers divisible by both
become fizz buzz. A player who hesitates or
makes a mistake is eliminated from the game.
http://en.wikipedia.org/wiki/Fizz_buzz
Players generally sit in a circle. The player
designated to go first says the number "1", and
each player thenceforth counts one number in
turn. However, any number divisible by three is
replaced by the word fizz and any divisible by five
by the word buzz. Numbers divisible by both
become fizz buzz. A player who hesitates or
makes a mistake is eliminated from the game.
http://en.wikipedia.org/wiki/Fizz_buzz
Adults may play Fizz buzz as a
drinking game, where making
a mistake leads to the player
having to make a drinking-
related forfeit.
http://en.wikipedia.org/wiki/Fizz_buzz
[citation needed]
Fizz buzz has been used as an
interview screening device for
computer programmers.
http://en.wikipedia.org/wiki/Fizz_buzz
FizzBuzz was invented to avoid
the awkwardness of realising
that nobody in the room can
binary search an array.
https://twitter.com/richardadalton/status/591534529086693376
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
// Define constants
#define FIZZ "fizz"
#define BUZZ "buzz"
#define NULL 0
#define PI 3.14
std::string FizzBuzzCalculator(int n)
{
// Declarations
char buffer[1024];
memset(buffer, 0, 1024);
std::string retval;
auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; };
auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; };
// Check to see if argument is between 1 and 100, otherwise log and throw
if (n < 1 || n > 100)
{
sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n);
Log::Instance().Write(buffer);
throw std::invalid_argument(buffer);
}
// Check if need to write number
if (!isDivisibleBy3() & !isDivisibleBy5())
{
sprintf(buffer, "%i", n);
}
// Assign return value (retval) and return
retval.assign(buffer, strlen(buffer));
return retval;
}
I have yet to see any problem,
however complicated, which,
when you looked at it in the
right way, did not become still
more complicated.
Anderson's Law
http://www.adampetersen.se/articles/fizzbuzz.htm
http://www.adampetersen.se/articles/fizzbuzz.htm
enum class fizzbuzzed
{
fizz = -2,
buzz = -1,
fizzbuzz = 0,
first = 1,
last = 100
};
constexpr fizzbuzzed fizzbuzz(int n)
{
return
n % 3 == 0 && n % 5 == 0 ? fizzbuzzed::fizzbuzz :
n % 3 == 0 ? fizzbuzzed::fizz :
n % 5 == 0 ? fizzbuzzed::buzz :
fizzbuzzed(n);
}
enum class fizzbuzzed
{
fizz = -2,
buzz = -1,
fizzbuzz = 0,
first = 1,
last = 100
};
constexpr fizzbuzzed fizzbuzz(int n)
{
return
n % 15 == 0 ? fizzbuzzed::fizzbuzz :
n % 3 == 0 ? fizzbuzzed::fizz :
n % 5 == 0 ? fizzbuzzed::buzz :
fizzbuzzed(n);
}
Maciej Piróg
"FizzBuzz in Haskell by Embedding a Domain-Specific Language"
string fizzbuzz(int n)
{
string result;
if (n % 3 == 0)
result += "Fizz";
if (n % 5 == 0)
result += "Buzz";
if (result.empty())
result = to_string(n);
return result;
}
string fizzbuzz(int n)
{
static const string fizzed[] { "", "Fizz" };
static const string buzzed[] { "", "Buzz" };
const string result =
fizzed[n % 3 == 0] + buzzed[n % 5 == 0];
return result.empty() ? to_string(n) : result;
}
Maciej Piróg
"FizzBuzz in Haskell by Embedding a Domain-Specific Language"
string fizzbuzz(int n)
{
auto fizz =
[=](function<string(string)> f)
{
return
n % 3 == 0
? [=](auto) { return "Fizz" + f(""); }
: f;
};
auto buzz =
[=](function<string(string)> f)
{
return
n % 5 == 0
? [=](auto) { return "Buzz" + f(""); }
: f;
};
auto id = [](auto s) { return s; };
return fizz(buzz(id))(to_string(n));
}
string fizzbuzz(int n)
{
auto test =
[=](int d, string s, function<string(string)> f)
{
return
n % d == 0
? [=](string) { return s + f(""); }
: f;
};
auto fizz = bind(test, 3, "Fizz", _1);
auto buzz = bind(test, 5, "Buzz", _1);
auto id = [](auto s) { return s; };
return fizz(buzz(id))(to_string(n));
}
A work of art is the
unique result of a
unique temperament.
Oscar Wilde
Cargo cult programming is a style of computer
programming characterized by the ritual inclusion of
code or program structures that serve no real purpose.
http://en.wikipedia.org/wiki/Cargo_cult_programming
Signal-to-noise ratio (often abbreviated SNR or
S/N) is a measure used in science and engineering
that compares the level of a desired signal to the
level of background noise.
Signal-to-noise ratio is sometimes used informally
to refer to the ratio of useful information to false or
irrelevant data in a conversation or exchange.
http://en.wikipedia.org/wiki/Signal_to_noise_ratio
https://twitter.com/ExpertBeginner1/status/603188084725981185
A common fallacy is to assume authors
of incomprehensible code will somehow
be able to express themselves lucidly
and clearly in comments.
Kevlin Henney
https://twitter.com/KevlinHenney/status/381021802941906944
Cargo cult programming is a style of computer
programming characterized by the ritual inclusion of
code or program structures that serve no real purpose.
Cargo cult programming can also refer to the results of
applying a design pattern or coding style blindly
without understanding the reasons behind that design
principle.
http://en.wikipedia.org/wiki/Cargo_cult_programming
http://www.bonkersworld.net/object-world/
http://www.bonkersworld.net/object-world/
OBJECT-ORIENTED
VenetianBlind
Door
Television
Picture
Glass
SofaTelevisionRemoteControl
Peephole
Naomi Epel
The Observation Deck
People will be using the words
you choose in their conversation
for the next 20 years. You want
to be sure you do it right.
Unfortunately, many people get
all formal [...]. Just calling it what
it is isn't enough.
They have to tack on a flowery,
computer science-y, impressive
sounding, but ultimately
meaningless word, like Object,
Thing, Component, Part,
Manager, Entity, or Item.
class ConditionChecker
{
public:
virtual bool CheckCondition() const = 0;
...
};
class Condition
{
public:
virtual bool IsTrue() const = 0;
...
};
Refactoring (noun): a change made to
the internal structure of software to
make it easier to understand and
cheaper to modify without changing
its observable behavior.
Refactor (verb): to restructure
software by applying a series of
refactorings without changing the
observable behavior of the software.
Functional
Operational
Developmental
Connection * CreateServerConnection()
{
// Declarations
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
// Get address and check that its OK (throw an exception if its not)
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Convert adress to bytes and check that its OK (throw an exception if its not)
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Get port and check that its OK (throw an exception if its not)
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Convert port too bytes
port = htons(atoi(cfgPort.data()));
// Creation connection and check that its OK (throw an exception if its not)
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
// Return the connection
return result;
}
Connection * CreateServerConnection()
{
// Declarations
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
...
}
Connection * CreateServerConnection()
{
...
// Get address and check that its OK (throw an exception if its not)
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Convert adress to bytes and check that its OK (throw an exception if its not)
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Get port and check that its OK (throw an exception if its not)
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Convert port too bytes
port = htons(atoi(cfgPort.data()));
...
}
Connection * CreateServerConnection()
{
...
// Creation connection and check that its OK (throw an exception if its not)
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
// Return the connection
return result;
}
Connection * CreateServerConnection()
{
// Declarations
...
// Get address and check that its OK (throw an exception if its not)
...
// Convert adress to bytes and check that its OK (throw an exception if its not)
...
// Get port and check that its OK (throw an exception if its not)
...
// Convert port too bytes
...
// Creation connection and check that its OK (throw an exception if its not)
...
// Return the connection
...
}
Connection * CreateServerConnection()
{
// Declarations
...
// Get address and check that it's OK (throw an exception if it's not)
...
// Convert address to bytes and check that it's OK (throw an exception if it's not)
...
// Get port and check that it's OK (throw an exception if it's not)
...
// Convert port to bytes
...
// Creation connection and check that it's OK (throw an exception if it's not)
...
// Return the connection
...
}
Connection * CreateServerConnection()
{
...
...
...
...
...
...
...
}
Connection * CreateServerConnection()
{
char buffer[1024];
std::string cfgAddress;
unsigned long address;
std::string cfgPort;
unsigned short port;
Connection * result;
cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
port = htons(atoi(cfgPort.data()));
result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
char buffer[1024];
std::string cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
unsigned long address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
std::string cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
unsigned short port = htons(atoi(cfgPort.data()));
Connection * result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.data()));
Connection * result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
...
Connection * result = new Connection(address, port);
if (!result || !result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
...
Connection * result = new Connection(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
std::auto_ptr<Connection> CreateServerConnection()
{
...
std::auto_ptr<Connection> result(new Connection(address, port));
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
std::unique_ptr<Connection> CreateServerConnection()
{
...
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result;
}
Connection * CreateServerConnection()
{
...
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.data()));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.data());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.data()));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(atoi(cfgPort.c_str()));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
sprintf(buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
sprintf(buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
sprintf(buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "port");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
snprintf(buffer, sizeof buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
return result.release();
}
Connection * CreateServerConnection()
{
char buffer[1024];
...
if (cfgAddress.empty())
{
snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address");
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
if (address == -1)
{
snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str());
Log::Instance().Write(buffer);
throw ConnectionException(buffer);
}
...
}
Connection * CreateServerConnection()
{
...
if (cfgAddress.empty())
{
std::stringstream buffer;
buffer << "Configuration value missing: " << "address";
Log::Instance().Write(buffer.str());
throw ConnectionException(buffer.str());
}
...
if (address == -1)
{
std::stringstream buffer;
buffer << "Invalid address: " << cfgAddress;
Log::Instance().Write(buffer.str());
throw ConnectionException(buffer.str());
}
...
}
Connection * CreateServerConnection()
{
...
if (cfgAddress.empty())
{
static const char * logMessage = "Configuration value missing: address";
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
...
if (address == -1)
{
auto logMessage = "Invalid address: " + cfgAddress;
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
...
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
static const char * logMessage = "Configuration value missing: address";
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
auto logMessage = "Invalid address: " + cfgAddress;
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
static const char * logMessage = "Configuration value missing: port");
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
auto logMessage = "Failed to connect: " + cfgAddress + ":" + cfgPort;
Log::Instance().Write(logMessage);
throw ConnectionException(logMessage);
}
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
{
FailedToConnect("Configuration value missing: address");
}
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
{
FailedToConnect("Invalid address: " + cfgAddress);
}
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
{
FailedToConnect("Configuration value missing: port");
}
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
{
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
}
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result.release();
}
Connection * CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result.release();
}
std::unique_ptr<Connection> CreateServerConnection()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = ConfigurationManager::Instance().GetValue("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().GetValue("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = ConfigurationManager::Instance().ValueOf("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = ConfigurationManager::Instance().ValueOf("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer()
{
auto cfgAddress = Configuration::Instance().ValueOf("address");
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
auto cfgPort = Configuration::Instance().ValueOf("port");
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer(
const std::string & cfgAddress, const std::string & cfgPort)
{
if (cfgAddress.empty())
FailedToConnect("Configuration value missing: address");
auto address = inet_addr(cfgAddress.c_str());
if (address == -1)
FailedToConnect("Invalid address: " + cfgAddress);
if (cfgPort.empty())
FailedToConnect("Configuration value missing: port");
auto port = htons(stoi(cfgPort));
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort);
return result;
}
std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port)
{
auto result = std::make_unique<Connection>(address, port);
if (!result->IsOK())
FailedToConnect(address, port);
return result;
}
std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port)
{
return std::make_unique<Connection>(address, port);
}
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Programming Tricks
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Programming Tricks

More Related Content

What's hot

Testing the Next Generation
Testing the Next GenerationTesting the Next Generation
Testing the Next Generation
Mike Harris
 
Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)
Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)
Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)James Clause
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
Kosei ABE
 
Tactics course
Tactics courseTactics course
Tactics course
Ganti Kanisa
 
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Raman Kannan
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & more
Mattias Geniar
 
The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)
Patricia Aas
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
corehard_by
 
M12 random forest-part01
M12 random forest-part01M12 random forest-part01
M12 random forest-part01
Raman Kannan
 
M11 bagging loo cv
M11 bagging loo cvM11 bagging loo cv
M11 bagging loo cv
Raman Kannan
 
M09-Cross validating-naive-bayes
M09-Cross validating-naive-bayesM09-Cross validating-naive-bayes
M09-Cross validating-naive-bayes
Raman Kannan
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
Phillip Trelford
 

What's hot (14)

Testing the Next Generation
Testing the Next GenerationTesting the Next Generation
Testing the Next Generation
 
Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)
Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)
Leakpoint: Pinpointing the Causes of Memory Leaks (ICSE 2010)
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
 
Tactics course
Tactics courseTactics course
Tactics course
 
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & more
 
The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
Transmogrify
TransmogrifyTransmogrify
Transmogrify
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
M12 random forest-part01
M12 random forest-part01M12 random forest-part01
M12 random forest-part01
 
M11 bagging loo cv
M11 bagging loo cvM11 bagging loo cv
M11 bagging loo cv
 
M09-Cross validating-naive-bayes
M09-Cross validating-naive-bayesM09-Cross validating-naive-bayes
M09-Cross validating-naive-bayes
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
 

Similar to Clean Coders Hate What Happens To Your Code When You Use These Enterprise Programming Tricks

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
Kiwamu Okabe
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
mounikanarra3
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Saranya saran
 
C tutorial
C tutorialC tutorial
C tutorial
Anurag Sukhija
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
Arthur Puthin
 
control statement
control statement control statement
control statement
Kathmandu University
 
Compiler design.pdf
Compiler design.pdfCompiler design.pdf
Compiler design.pdf
Nitesh Dubey
 
BHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptxBHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptx
Sasideepa
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
DevGAMM Conference
 
Python
PythonPython
Python
대갑 김
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
TIB Academy
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
RAJWANT KAUR
 
Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.
Esehara Shigeo
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
Vikash Dhal
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Sayed Ahmed
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
securityxploded
 

Similar to Clean Coders Hate What Happens To Your Code When You Use These Enterprise Programming Tricks (20)

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
C tutorial
C tutorialC tutorial
C tutorial
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
control statement
control statement control statement
control statement
 
Compiler design.pdf
Compiler design.pdfCompiler design.pdf
Compiler design.pdf
 
BHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptxBHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptx
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Python
PythonPython
Python
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
 

More from Kevlin Henney

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
Kevlin Henney
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
Kevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
Kevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Kevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Kevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
Kevlin Henney
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
Kevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
Kevlin Henney
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
Kevlin Henney
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
Kevlin Henney
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
Kevlin Henney
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
Kevlin Henney
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
Kevlin Henney
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
Kevlin Henney
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
Kevlin Henney
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
Kevlin Henney
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
Kevlin Henney
 
Good Code
Good CodeGood Code
Good Code
Kevlin Henney
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
Kevlin Henney
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
Kevlin Henney
 

More from Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 

Recently uploaded

Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 

Recently uploaded (20)

Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 

Clean Coders Hate What Happens To Your Code When You Use These Enterprise Programming Tricks

  • 1.
  • 2.
  • 3.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. enterprise, noun  a project or undertaking that is especially bold, complicated or arduous  readiness to engage in undertakings of difficulty, risk, danger or daring  a design of which the execution is attempted  a commercial or industrial undertaking  a firm, company or business  a unit of economic organisation or activity Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
  • 11. enterprise, noun  a project or undertaking that is especially bold, complicated or arduous  readiness to engage in undertakings of difficulty, risk, danger or daring  a design of which the execution is attempted  a commercial or industrial undertaking  a firm, company or business  a unit of economic organisation or activity Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
  • 12. code, noun  a set of instructions for a computer  a computer program, or a portion thereof  a system of words, figures or symbols used to represent others, especially for the purposes of secrecy  a set of conventions or principles governing behaviour or activity in a particular domain Concise Oxford English Dictionary ∙ Oxford English Dictionary ∙ Merriam-Webster's Collegiate Dictionary
  • 13.
  • 14. Fizz buzz is a group word game for children to teach them about division. http://en.wikipedia.org/wiki/Fizz_buzz
  • 15. Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is eliminated from the game. http://en.wikipedia.org/wiki/Fizz_buzz
  • 16. Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is eliminated from the game. http://en.wikipedia.org/wiki/Fizz_buzz
  • 17. Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is eliminated from the game. http://en.wikipedia.org/wiki/Fizz_buzz
  • 18. Adults may play Fizz buzz as a drinking game, where making a mistake leads to the player having to make a drinking- related forfeit. http://en.wikipedia.org/wiki/Fizz_buzz [citation needed]
  • 19. Fizz buzz has been used as an interview screening device for computer programmers. http://en.wikipedia.org/wiki/Fizz_buzz
  • 20. FizzBuzz was invented to avoid the awkwardness of realising that nobody in the room can binary search an array. https://twitter.com/richardadalton/status/591534529086693376
  • 21. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 22. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 23. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 24. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 25. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 26. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 27. // Define constants #define FIZZ "fizz" #define BUZZ "buzz" #define NULL 0 #define PI 3.14 std::string FizzBuzzCalculator(int n) { // Declarations char buffer[1024]; memset(buffer, 0, 1024); std::string retval; auto isDivisibleBy3 = [&]() { if (n % 3 == 0) { strcpy(buffer, FIZZ); return true; } return false; }; auto isDivisibleBy5 = [&]() { if (n % 5 == 0) { strcat(buffer, BUZZ); return true; } return false; }; // Check to see if argument is between 1 and 100, otherwise log and throw if (n < 1 || n > 100) { sprintf(buffer, "FizzBuzzCalculator, argument must be in range: %i", n); Log::Instance().Write(buffer); throw std::invalid_argument(buffer); } // Check if need to write number if (!isDivisibleBy3() & !isDivisibleBy5()) { sprintf(buffer, "%i", n); } // Assign return value (retval) and return retval.assign(buffer, strlen(buffer)); return retval; }
  • 28. I have yet to see any problem, however complicated, which, when you looked at it in the right way, did not become still more complicated. Anderson's Law
  • 29.
  • 30.
  • 33. enum class fizzbuzzed { fizz = -2, buzz = -1, fizzbuzz = 0, first = 1, last = 100 }; constexpr fizzbuzzed fizzbuzz(int n) { return n % 3 == 0 && n % 5 == 0 ? fizzbuzzed::fizzbuzz : n % 3 == 0 ? fizzbuzzed::fizz : n % 5 == 0 ? fizzbuzzed::buzz : fizzbuzzed(n); }
  • 34. enum class fizzbuzzed { fizz = -2, buzz = -1, fizzbuzz = 0, first = 1, last = 100 }; constexpr fizzbuzzed fizzbuzz(int n) { return n % 15 == 0 ? fizzbuzzed::fizzbuzz : n % 3 == 0 ? fizzbuzzed::fizz : n % 5 == 0 ? fizzbuzzed::buzz : fizzbuzzed(n); }
  • 35. Maciej Piróg "FizzBuzz in Haskell by Embedding a Domain-Specific Language"
  • 36. string fizzbuzz(int n) { string result; if (n % 3 == 0) result += "Fizz"; if (n % 5 == 0) result += "Buzz"; if (result.empty()) result = to_string(n); return result; }
  • 37. string fizzbuzz(int n) { static const string fizzed[] { "", "Fizz" }; static const string buzzed[] { "", "Buzz" }; const string result = fizzed[n % 3 == 0] + buzzed[n % 5 == 0]; return result.empty() ? to_string(n) : result; }
  • 38. Maciej Piróg "FizzBuzz in Haskell by Embedding a Domain-Specific Language"
  • 39. string fizzbuzz(int n) { auto fizz = [=](function<string(string)> f) { return n % 3 == 0 ? [=](auto) { return "Fizz" + f(""); } : f; }; auto buzz = [=](function<string(string)> f) { return n % 5 == 0 ? [=](auto) { return "Buzz" + f(""); } : f; }; auto id = [](auto s) { return s; }; return fizz(buzz(id))(to_string(n)); }
  • 40. string fizzbuzz(int n) { auto test = [=](int d, string s, function<string(string)> f) { return n % d == 0 ? [=](string) { return s + f(""); } : f; }; auto fizz = bind(test, 3, "Fizz", _1); auto buzz = bind(test, 5, "Buzz", _1); auto id = [](auto s) { return s; }; return fizz(buzz(id))(to_string(n)); }
  • 41. A work of art is the unique result of a unique temperament. Oscar Wilde
  • 42. Cargo cult programming is a style of computer programming characterized by the ritual inclusion of code or program structures that serve no real purpose. http://en.wikipedia.org/wiki/Cargo_cult_programming
  • 43. Signal-to-noise ratio (often abbreviated SNR or S/N) is a measure used in science and engineering that compares the level of a desired signal to the level of background noise. Signal-to-noise ratio is sometimes used informally to refer to the ratio of useful information to false or irrelevant data in a conversation or exchange. http://en.wikipedia.org/wiki/Signal_to_noise_ratio
  • 45. A common fallacy is to assume authors of incomprehensible code will somehow be able to express themselves lucidly and clearly in comments. Kevlin Henney https://twitter.com/KevlinHenney/status/381021802941906944
  • 46. Cargo cult programming is a style of computer programming characterized by the ritual inclusion of code or program structures that serve no real purpose. Cargo cult programming can also refer to the results of applying a design pattern or coding style blindly without understanding the reasons behind that design principle. http://en.wikipedia.org/wiki/Cargo_cult_programming
  • 47.
  • 51.
  • 52. People will be using the words you choose in their conversation for the next 20 years. You want to be sure you do it right. Unfortunately, many people get all formal [...]. Just calling it what it is isn't enough.
  • 53. They have to tack on a flowery, computer science-y, impressive sounding, but ultimately meaningless word, like Object, Thing, Component, Part, Manager, Entity, or Item.
  • 54. class ConditionChecker { public: virtual bool CheckCondition() const = 0; ... };
  • 55. class Condition { public: virtual bool IsTrue() const = 0; ... };
  • 56.
  • 57.
  • 58. Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. Refactor (verb): to restructure software by applying a series of refactorings without changing the observable behavior of the software.
  • 59.
  • 61. Connection * CreateServerConnection() { // Declarations char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; // Get address and check that its OK (throw an exception if its not) cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Convert adress to bytes and check that its OK (throw an exception if its not) address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Get port and check that its OK (throw an exception if its not) cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Convert port too bytes port = htons(atoi(cfgPort.data())); // Creation connection and check that its OK (throw an exception if its not) result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } // Return the connection return result; }
  • 62. Connection * CreateServerConnection() { // Declarations char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; ... }
  • 63. Connection * CreateServerConnection() { ... // Get address and check that its OK (throw an exception if its not) cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 64. Connection * CreateServerConnection() { ... // Convert adress to bytes and check that its OK (throw an exception if its not) address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 65. Connection * CreateServerConnection() { ... // Get port and check that its OK (throw an exception if its not) cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 66. Connection * CreateServerConnection() { ... // Convert port too bytes port = htons(atoi(cfgPort.data())); ... }
  • 67. Connection * CreateServerConnection() { ... // Creation connection and check that its OK (throw an exception if its not) result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 68. Connection * CreateServerConnection() { ... // Return the connection return result; }
  • 69. Connection * CreateServerConnection() { // Declarations ... // Get address and check that its OK (throw an exception if its not) ... // Convert adress to bytes and check that its OK (throw an exception if its not) ... // Get port and check that its OK (throw an exception if its not) ... // Convert port too bytes ... // Creation connection and check that its OK (throw an exception if its not) ... // Return the connection ... }
  • 70. Connection * CreateServerConnection() { // Declarations ... // Get address and check that it's OK (throw an exception if it's not) ... // Convert address to bytes and check that it's OK (throw an exception if it's not) ... // Get port and check that it's OK (throw an exception if it's not) ... // Convert port to bytes ... // Creation connection and check that it's OK (throw an exception if it's not) ... // Return the connection ... }
  • 72. Connection * CreateServerConnection() { char buffer[1024]; std::string cfgAddress; unsigned long address; std::string cfgPort; unsigned short port; Connection * result; cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } port = htons(atoi(cfgPort.data())); result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 73. Connection * CreateServerConnection() { char buffer[1024]; std::string cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } unsigned long address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } std::string cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } unsigned short port = htons(atoi(cfgPort.data())); Connection * result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 74. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.data())); Connection * result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 75. Connection * CreateServerConnection() { ... Connection * result = new Connection(address, port); if (!result || !result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 76. Connection * CreateServerConnection() { ... Connection * result = new Connection(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 77. std::auto_ptr<Connection> CreateServerConnection() { ... std::auto_ptr<Connection> result(new Connection(address, port)); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 78. std::unique_ptr<Connection> CreateServerConnection() { ... auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result; }
  • 79. Connection * CreateServerConnection() { ... auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 80. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.data())); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 81. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.data()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.data())); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.data(), cfgPort.data()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 82. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(atoi(cfgPort.c_str())); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 83. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 84. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { sprintf(buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { sprintf(buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { sprintf(buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { sprintf(buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 85. Connection * CreateServerConnection() { char buffer[1024]; auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "port"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { snprintf(buffer, sizeof buffer, "Failed to connect: %s:%s", cfgAddress.c_str(), cfgPort.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } return result.release(); }
  • 86. Connection * CreateServerConnection() { char buffer[1024]; ... if (cfgAddress.empty()) { snprintf(buffer, sizeof buffer, "Configuration value missing: %s", "address"); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... if (address == -1) { snprintf(buffer, sizeof buffer, "Invalid address: %s", cfgAddress.c_str()); Log::Instance().Write(buffer); throw ConnectionException(buffer); } ... }
  • 87. Connection * CreateServerConnection() { ... if (cfgAddress.empty()) { std::stringstream buffer; buffer << "Configuration value missing: " << "address"; Log::Instance().Write(buffer.str()); throw ConnectionException(buffer.str()); } ... if (address == -1) { std::stringstream buffer; buffer << "Invalid address: " << cfgAddress; Log::Instance().Write(buffer.str()); throw ConnectionException(buffer.str()); } ... }
  • 88. Connection * CreateServerConnection() { ... if (cfgAddress.empty()) { static const char * logMessage = "Configuration value missing: address"; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } ... if (address == -1) { auto logMessage = "Invalid address: " + cfgAddress; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } ... }
  • 89. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { static const char * logMessage = "Configuration value missing: address"; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { auto logMessage = "Invalid address: " + cfgAddress; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { static const char * logMessage = "Configuration value missing: port"); Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { auto logMessage = "Failed to connect: " + cfgAddress + ":" + cfgPort; Log::Instance().Write(logMessage); throw ConnectionException(logMessage); } return result.release(); }
  • 90. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) { FailedToConnect("Configuration value missing: address"); } auto address = inet_addr(cfgAddress.c_str()); if (address == -1) { FailedToConnect("Invalid address: " + cfgAddress); } auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) { FailedToConnect("Configuration value missing: port"); } auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) { FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); } return result.release(); }
  • 91. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result.release(); }
  • 92. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result.release(); }
  • 93. Connection * CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result.release(); }
  • 94. std::unique_ptr<Connection> CreateServerConnection() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 95. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 96. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = ConfigurationManager::Instance().GetValue("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().GetValue("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 97. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = ConfigurationManager::Instance().ValueOf("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = ConfigurationManager::Instance().ValueOf("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 98. std::unique_ptr<Connection> ConnectToServer() { auto cfgAddress = Configuration::Instance().ValueOf("address"); if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); auto cfgPort = Configuration::Instance().ValueOf("port"); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 99. std::unique_ptr<Connection> ConnectToServer( const std::string & cfgAddress, const std::string & cfgPort) { if (cfgAddress.empty()) FailedToConnect("Configuration value missing: address"); auto address = inet_addr(cfgAddress.c_str()); if (address == -1) FailedToConnect("Invalid address: " + cfgAddress); if (cfgPort.empty()) FailedToConnect("Configuration value missing: port"); auto port = htons(stoi(cfgPort)); auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect("Failed to connect: " + cfgAddress + ":" + cfgPort); return result; }
  • 100. std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port) { auto result = std::make_unique<Connection>(address, port); if (!result->IsOK()) FailedToConnect(address, port); return result; }
  • 101. std::unique_ptr<Connection> ConnectToServer(in_addr_t address, in_port_t port) { return std::make_unique<Connection>(address, port); }