The financial application I am building contains data which is a number that corresponds with two terms. It works like this:

  • number > 0 = overspend
  • number < 0 = underspend

Unfortunately the overspend/underspend terms do not have a neutral term, like nospend or whateverspend. Now I'm unsure about how to save this data in for example a database column. What name do I give to this database column? Or how do I handle it in my back-end? double <...spend> = // a number?

So, like the question says: How do I handle a definition in my application that does not have a neutral term, but either a positive one, or a negative one?

closed as primarily opinion-based by gnat, Bart van Ingen Schenau, Blrfl, amon, user22815 Mar 6 '17 at 23:54

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Are you asking us what to do (e.g. defining one column or several) or merely what to call something (e.g. nospend or over_or_under_spend)? – Kilian Foth Mar 6 '17 at 8:36
  • Well I'm asking how to handle this situation. Of course it would be nice if someone knows a neutral term for this, but I'm pretty sure that a situation like this occurs for other terms as well. over_or_under_spend would be a solution, but it suddenly becomes a very long variable. – Jelle Mar 6 '17 at 8:45
  • Would the close-voter be so nice to explain why this question should be closed? Thank you. – Jelle Mar 6 '17 at 10:18
  • This seems more like a user experience stackexchange question. – Philipp Mar 6 '17 at 10:59
  • 3
    You need to ask the people who are paying you to write the application what they want it called. We can't answer that. – Blrfl Mar 6 '17 at 11:43

You wouldn't save the overspend/underspend flag. You would save "number". Then you can always check if it is positive, negative or 0 in query/view or in business logic.

If you save both "number" and the overspend/underspend flag then you have redundant data in the database with is bad for several reasons, most importantly you open the possibility that they could get out of sync (eg. "number" is updated but you forget to update the flag).

If you have say "budget" and "expenditure" as two columns, then you don't need to also save the difference between these two, which seem to be what "number" is.

  • I currently do not save a flag, nor do I plan to do so. The whole point of this question is how to name the "number" variable in code/database design. I currently name it overspend, but this is not a good solution, because if the number is negative, it will actually say double overspend = <underspend number>. – Jelle Mar 6 '17 at 10:05
  • @Jelle - you just say "number", but what does this number represent then? If you have say "budget" and "expenditure" as two column, then you don't need to also save the difference between these two. – JacquesB Mar 6 '17 at 10:45
  • It represent the overspend or underspend of a project. For the sake of simplicity, you can compare it to either profit or waste. – Jelle Mar 6 '17 at 10:46
  • @Jelle: But how do you know this value? Surely this is the result of some calculation, eg. budget minus expense. – JacquesB Mar 6 '17 at 10:48
  • Yes this is the case. And I already know that you want to say 'Don't save this number, it is the result of a calculation.' But unfortunately, this number is part of a report, so it must be saved. – Jelle Mar 6 '17 at 10:49

Name the variable as if it's always positive. Having a negative value already implies the opposite situation. So, in your case, use overspend.

For example; a negative value in a variable called profit implies loss rather than actual profit. A negative value in time_until_X implies X already happened.

  • This is the way I'm currently using it, so unless there won't be a better answer, I will continue to do so. – Jelle Mar 6 '17 at 10:57
  • This is actually a good advice. Even Chapter 11 of Code Complete doesn't address an issue like that, and the "always positive" rule goes well with the "always write an if in the positive" way. +1. – Machado Mar 6 '17 at 15:01

You could name your column "Spend" which contains "under" when number < 0, "over" when number > 0, otherwise NULL.

  • 1
    The problem with that is that it 'spend' also means 'expenses', so it could actually bring confusion. – Jelle Mar 6 '17 at 8:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.