Re:Gangnam Style breaks YouTube viewer count
by IvyMike on Tuesday December 02, 2014 @06:48PM
(#8690919)
In C/C++, unsigned ints can result in a few very subtle bugs--more details here:
http://stackoverflow.com/a/1555186/67591
TL;DR: Google's C++ coding standard says: "Document that a variable is non-negative using assertions. Don't use an unsigned type."
As someone who has written a lot of C++ code to interact with hardware: I view an unsigned as a bucket of bits, and a signed as a number.
Re:Gangnam Style breaks YouTube viewer count
by hk__2 on Tuesday December 02, 2014 @06:28PM
(#8690822)
It is an easter egg: http://www.reddit.com/r/compsci/comments/2nrjc7/gangnam_styl...
Re:Gangnam Style breaks YouTube viewer count
by rkachowski on Tuesday December 02, 2014 @06:41PM
(#8690883)
Ah i see, i didn't expect Google to back up an easter egg with an associated G+ post
Re:Gangnam Style breaks YouTube viewer count
by srtjstjsj on Tuesday December 02, 2014 @11:13PM
(#8691874)
Usually it's not cool to advertise an easter egg, but when you are a big corporation, you try hard.
Re:Gangnam Style breaks YouTube viewer count
by spb on Tuesday December 02, 2014 @07:13PM
(#8691023)
Say you're comparing the number of views between two different videos as (video_A.views - video_B.views). How do you represent that the second video has more views than the first?
Re:Gangnam Style breaks YouTube viewer count
by nly on Tuesday December 02, 2014 @08:31PM
(#8691332)
video_B.views > video_A.views
Re:Gangnam Style breaks YouTube viewer count
by tempestn on Tuesday December 02, 2014 @09:05PM
(#8691459)
And what if you want to say how many more? You'd have to first check which one is greater, and then subtract in the right direction. The code is simpler if you just use signed integers.
Re:Gangnam Style breaks YouTube viewer count
by bobbykjack on Wednesday December 03, 2014 @04:13AM
(#8692630)
To say "b has n more views than a", you need two operations whether you use signed or unsigned ints. Signed let's you say "these two videos have n different views" but, to be honest, it seems unlikely that you be doing either in so many places in your codebase, or so frequently during execution, to make the extra operation that significant.
Re:Gangnam Style breaks YouTube viewer count
by tempestn on Wednesday December 03, 2014 @04:27AM
(#8692676)
Yes, in this specific example you still need the same number of operations. My point was, when you just use signed integers, it's easier to conceptualize and harder to screw up. It's more flexible for unforeseen future use cases. Also, this is a very simplified example case; in most scenarios those unforeseen possibilities will be more significant.
Given that switching to unsigned saves you exactly one bit, it's just not usually worth it. How often do you need exactly 32 bits of unsigned space, when 31 isn't enough, and you can't use 63? (I'm talking about standard-length integers here, not extreme situations where you're trying to make maximum use of 8 bits of storage or similar.)
Re:Gangnam Style breaks YouTube viewer count
by xxxyy on Tuesday December 02, 2014 @06:18PM
(#8690769)
Legacy code I guess (from some really ancient times). Also tiny bugs like this make great content for blog posts, just like the 301+ views thing.
Re:Gangnam Style breaks YouTube viewer count
by lmm on Tuesday December 02, 2014 @06:44PM
(#8690900)
Lots of languages don't bother with a separate unsigned type. Maybe the backend is written in Java.
Re:Gangnam Style breaks YouTube viewer count
by divegeek on Tuesday December 02, 2014 @06:33PM
(#8690839)
Java doesn't have unsigned integer types. Google is mostly a Java shop.
Re:Gangnam Style breaks YouTube viewer count
by hobo_mark on Tuesday December 02, 2014 @06:43PM
(#8690895)
That is mostly false.
Re:Gangnam Style breaks YouTube viewer count
by fishnchips on Tuesday December 02, 2014 @07:07PM
(#8691002)
Java is mostly confined to Android and the frontend (think GWT) which do not constitute a large proportion of the Google internal code as far as I can recall.
But it's real?! It seems incredibly absurd that it could actually overflow, how are signed values useful for a count of views? How are you going to have negative views?