Skip to main content
added 8 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is that it’s now simpler to introduce new keyskey values since knowledge of key values is isolated. Something the switch can’t do for you.

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is that it’s now simpler to introduce new keys since knowledge of key values is isolated. Something the switch can’t do for you.

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is that it’s now simpler to introduce new key values since knowledge of key values is isolated. Something the switch can’t do for you.

added 5 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is that it’s now simpler to introduce new keys since knowledge of key values is isolated. Something the switch can’t do for you.

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is it’s now simpler to introduce new keys since knowledge of key values is isolated. Something the switch can’t do for you.

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is that it’s now simpler to introduce new keys since knowledge of key values is isolated. Something the switch can’t do for you.

added 195 characters in body; added 2 characters in body; added 24 characters in body; added 39 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is it’s now simpler to introduce new keys since knowledge of key values is isolated. Something the switch can’t do for you.

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

Well you can do it with an if-else-if chain but... yuck.

If we can ditch the variables and do some restructuring*:

latestValueMap.put(key, getLatestData().getValue(key));  
previousValueMap.put(key, getPreviousData().getValue(key));

* Assumes a, p, and t values are all of the same type. A detail not made clear in the question.

This allows you to control moving the information the same way, with the key. It’s held differently but it’s all still there.

The advantage is it’s now simpler to introduce new keys since knowledge of key values is isolated. Something the switch can’t do for you.

Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading