Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

##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";
Fix typo. Fix indentation.
Source Link
Morwenn
  • 20.2k
  • 3
  • 69
  • 132

##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";
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

##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";
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /