1

I have a simple blog webapp where users may vote.

What would be the advantages of having a single integer that goes up or down(should negative numbers be allowed?), or having a likes and dislikes counts that only go up.

Which is more flexible, which is more optimal?

TheOne
  • 10,819
  • 20
  • 81
  • 119
  • Optimal for what? What are you planning on doing with the data? Do you need to display # of upvotes? # of downvotes? No? Yes? – Oded Dec 30 '10 at 16:37
  • 1
    So, you don't know what kind of flexibility or features you need and expect us to divine the future for you? – Oded Dec 30 '10 at 16:42
  • 1
    You need to define the requirements before you start coding. Look online at how and what polls are used for and decide what you like. Looking for "integer optimization" at this point is futile. – P.Brian.Mackey Dec 30 '10 at 16:43

2 Answers2

2

To have two counters on the DB side (for likes and dislikes) is more flexible and allows you to give more choices in the future. But it's a bit more expensive than only one.

Habax
  • 1,274
  • 17
  • 26
  • Or you could record the total number of votes along with the single up down vote value. Both may amount to the same thing with a little arithmatic. You can do stuff like say 87% of 42 votes were positive. – dqhendricks Dec 30 '10 at 16:45
2

Tracking both the number of likes and dislikes allows viewers to see how many people liked/disliked the post, rather than just the difference of the two numbers. That gives you the ability to illustrate how many people have seen the post and bothered to vote.

If that is important to you, it may be worth it to keep track of the extra number.

Ivy
  • 887
  • 1
  • 7
  • 25