##If you have preconditions return early
If you have preconditions return early
if( !record.empty() )
{
// CODE
}
// If the precondition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
##Use constructors
Use constructors
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";
##If you have preconditions return early
if( !record.empty() )
{
// CODE
}
// If the precondition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
##Use constructors
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";
If you have preconditions return early
if( !record.empty() )
{
// CODE
}
// If the precondition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
Use constructors
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";
##If you have pre-conditionspreconditions return early:
if( !record.empty() )
{
// CODE
}
// If the pre-conditionprecondition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
##Use constrctursconstructors
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";
##If you have pre-conditions return early:
if( !record.empty() )
{
// CODE
}
// If the pre-condition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
##Use constrcturs
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";
##If you have preconditions return early
if( !record.empty() )
{
// CODE
}
// If the precondition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
##Use constructors
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";
##If you have pre-conditions return early:
if( !record.empty() )
{
// CODE
}
// If the pre-condition for doing work is that it is not empty
// Then test and return immediately.
if (record.empty()) {
return;
}
// CODE
Now your code does not suffer lots of indenting and becomes easier to read.
##Use constrcturs
std::ifstream infile;
infile.open( filename );
// Easier to read and write as:
std::ifstream infile( filename );
I think we can simplify that loop:
std::sort( record.begin(), record.end() );
std::cout << record;
while( std::next_permutation( record.begin(), record.end() ))
{
std::cout << ", " << record
}
std::cout << "\n";