/ 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
Sofa TelevisionRemoteControl
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); }