Exceptions
It is better to pass the property name to the exception constructor and let the exception class define the message. It is better because:
- It's more DRY. If you have to throw that exception from another function you need to create the same message.
- Single responsibility
- Easier to test - only need to test the exception and the property name. The test will not break if you decide to change the message.
- Logging - when your exceptions connected to some logging mechanism and a tool. You can search for this specific exception and specific property name.
Naming
I think a good name for a map is a name describing the key and the value. I think values_
should be called propertyName2Value
.
#Suggested Additions
Suggested Additions
- Add a specific exception to the case get is called with the wrong type
- implement operator[]
Performance
It is probably a micro-optimization but map
operations runtime complexity are O(log N) where unordered_map
operations are O(1).
Exceptions
It is better to pass the property name to the exception constructor and let the exception class define the message. It is better because:
- It's more DRY. If you have to throw that exception from another function you need to create the same message.
- Single responsibility
- Easier to test - only need to test the exception and the property name. The test will not break if you decide to change the message.
- Logging - when your exceptions connected to some logging mechanism and a tool. You can search for this specific exception and specific property name.
Naming
I think a good name for a map is a name describing the key and the value. I think values_
should be called propertyName2Value
.
#Suggested Additions
- Add a specific exception to the case get is called with the wrong type
- implement operator[]
Performance
It is probably a micro-optimization but map
operations runtime complexity are O(log N) where unordered_map
operations are O(1).
Exceptions
It is better to pass the property name to the exception constructor and let the exception class define the message. It is better because:
- It's more DRY. If you have to throw that exception from another function you need to create the same message.
- Single responsibility
- Easier to test - only need to test the exception and the property name. The test will not break if you decide to change the message.
- Logging - when your exceptions connected to some logging mechanism and a tool. You can search for this specific exception and specific property name.
Naming
I think a good name for a map is a name describing the key and the value. I think values_
should be called propertyName2Value
.
Suggested Additions
- Add a specific exception to the case get is called with the wrong type
- implement operator[]
Performance
It is probably a micro-optimization but map
operations runtime complexity are O(log N) where unordered_map
operations are O(1).
Exceptions
It is better to pass the property name to the exception constructor and let the exception class define the message. It is better because:
- It's more DRY. If you have to throw that exception from another function you need to create the same message.
- Single responsibility
- Easier to test - only need to test the exception and the property name. The test will not break if you decide to change the message.
- Logging - when your exceptions connected to some logging mechanism and a tool. You can search for this specific exception and specific property name.
Naming
I think a good name for a map is a name describing the key and the value. I think values_
should be called propertyName2Value
.
#Suggested Additions
- Add a specific exception to the case get is called with the wrong type
- implement operator[]
Performance
It is probably a micro-optimization but map
operations runtime complexity are O(log N) where unordered_map
operations are O(1).