Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.

As @konijn pointed out in his comment, that may confuse maintainers. Anyway, extracting it out into a separate function solves the issue (#6).

  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.

As @konijn pointed out in his comment, that may confuse maintainers. Anyway, extracting it out into a separate function solves the issue (#6).

  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.

As @konijn pointed out in his comment, that may confuse maintainers. Anyway, extracting it out into a separate function solves the issue (#6).

  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.

added 224 characters in body
Source Link
palacsint
  • 30.4k
  • 9
  • 82
  • 157

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.key could be declared inside the while loop.

As @konijn pointed out in his comment, that may confuse maintainers. Anyway, extracting it out into a separate function solves the issue (#6).

  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.
  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.

As @konijn pointed out in his comment, that may confuse maintainers. Anyway, extracting it out into a separate function solves the issue (#6).

  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.

Source Link
palacsint
  • 30.4k
  • 9
  • 82
  • 157

A few minor notes:

1.

Have the function StringReduction(str)

strictly speaking, the parameter name is different:

function StringReduction(s) 

:-)

1.

var original, key; 

I'd put the variable declarations to separate lines. From Code Complete 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

It could prevent some diff/merge conflicts (you modify the first variable, a coworker the second one at the same time).

  1. key could be declared inside the while loop.
  1. The name original could be lastString or lastValue since it's not the original string, it's the result of the last loop.

  2. Indentation is not consistent. Most of the places it's two spaces but the while loop is only one space indented, the body of the for loop has three spaces.

  3. I'd extract out the for loop to a string translate(string, replacements) function for better readability.