I personally like copious whitespace and good variable names.
Here's the code I got online: (Copied and pasted here, I didn't make it look worse)
float Bounce::easeOut(float t,float b , float c, float d) {
if ((t/=d) < (1/2.75f)) {
return c*(7.5625f*t*t) + b;
} else if (t < (2/2.75f)) {
float postFix = t-=(1.5f/2.75f);
return c*(7.5625f*(postFix)*t + .75f) + b;
} else if (t < (2.5/2.75)) {
float postFix = t-=(2.25f/2.75f);
return c*(7.5625f*(postFix)*t + .9375f) + b;
} else {
float postFix = t-=(2.625f/2.75f);
return c*(7.5625f*(postFix)*t + .984375f) + b;
}
}
(
It's a static member function in an otherwise empty class. I don't know why they didn't just use a namespace)
Here's the same code, but after being added to my library:
float BounceEase(float position)
{
//Optimization for end points, which are the most common spots.
if(position == 0.0f || position == 1.0f)
{
return position;
}
if(position < (1.0f / 2.75f))
{
return (7.5625f * position * position);
}
else if(position < (2.0f / 2.75f))
{
position -= (1.5f / 2.75f);
return (7.5625f * position * position + 0.75f);
}
else if(position < (2.5f / 2.75f))
{
position -= (2.25f / 2.75f);
return (7.5625f * position * position + 0.9375f);
}
else
{
position -= (2.625f / 2.75f);
return (7.5625f * position * position + 0.984375f);
}
}
(
There's minor differences because their version takes more parameters, but those parameters are constant in my code so I cut them out. The point is the whitespacing and the variable names)
@Nypyren: I like code like that. Sometimes few lines (hiding the rest of the lines in well-named functions) are a great benefit for legibility.
I have alot of C++ code that looks similar. LoadFileAsString(), LoadFileAsStringList(), LoadCSVFile(), LoadFileAsStringMap(), etc...
This code:
StringList stringList = String::CommentedLinesRemoved(LoadFileAsStringList(filepath), '/');
if(stringList.empty())
return false;
for(const auto &str : stringList)
{
auto keyValue = StringToPair<std::string, std::string>(str, '=', ConvertFromString<std::string>, String::RemoveFlankingQuotes);
this->SetVariable(keyValue.first, keyValue.second); //Add each key-value pair to the PathResolver's map.
}
Parses this file:
//--------------------------------------------------------------------------------
//Config file paths. These paths tell the game engine where to find the different types of config files.
//--------------------------------------------------------------------------------
%ENGINE-CONFIG% = "%CONFIG%/Engine/"
%GAME-CONFIG% = "%CONFIG%/Game/"
%USER-DEFAULTS% = "%GAME-CONFIG%/User Defaults/"
%USER-SETTINGS% = "%USER%/Settings/"
%DISPLAY-SETTINGS% = "%USER-SETTINGS%/Display Settings/"
Helper functions for the win!