Skip to main content
added 138 characters in body
Source Link
Lie Ryan
  • 12.5k
  • 2
  • 33
  • 43

An IDE can help assist with navigating through hard to read code, by it shouldn't be used as an excuse to actually write hard to read code.

There's noYou don't necessarily need for refactoring here. All you really need to do is to explicitly specify the name of the argument when calling, many languages allow you to specify arguments by keyword instead of positionally:

sendEmail(contact, isCompany=True)

Another weaker alternative, is to set the argument name as an actual variable:

boolean isCompany = True
sendEmail(contact, isCompany)

but of course this has the drawback of potentially be misleading or incorrect if you refactor the method and rename the argument to something else.

Using typed enum is of course more desirable, but if you're stuck with the API that you have, the above are great alternatives.

An IDE can help assist with navigating through hard to read code, by it shouldn't be used as an excuse to actually write hard to read code.

There's no need for refactoring here. All you really need to do is to explicitly specify the name of the argument when calling, many languages allow you to specify arguments by keyword instead of positionally:

sendEmail(contact, isCompany=True)

Another weaker alternative, is to set the argument name as an actual variable:

boolean isCompany = True
sendEmail(contact, isCompany)

but of course this has the drawback of potentially be misleading or incorrect if you refactor the method and rename the argument to something else.

An IDE can help assist with navigating through hard to read code, by it shouldn't be used as an excuse to actually write hard to read code.

You don't necessarily need refactoring here. All you really need to do is to explicitly specify the name of the argument when calling, many languages allow you to specify arguments by keyword instead of positionally:

sendEmail(contact, isCompany=True)

Another weaker alternative, is to set the argument name as an actual variable:

boolean isCompany = True
sendEmail(contact, isCompany)

but of course this has the drawback of potentially be misleading or incorrect if you refactor the method and rename the argument to something else.

Using typed enum is of course more desirable, but if you're stuck with the API that you have, the above are great alternatives.

Source Link
Lie Ryan
  • 12.5k
  • 2
  • 33
  • 43

An IDE can help assist with navigating through hard to read code, by it shouldn't be used as an excuse to actually write hard to read code.

There's no need for refactoring here. All you really need to do is to explicitly specify the name of the argument when calling, many languages allow you to specify arguments by keyword instead of positionally:

sendEmail(contact, isCompany=True)

Another weaker alternative, is to set the argument name as an actual variable:

boolean isCompany = True
sendEmail(contact, isCompany)

but of course this has the drawback of potentially be misleading or incorrect if you refactor the method and rename the argument to something else.