Optimal voting solution
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?
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.
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.
精彩评论