Jump to content

Why did* Youtube use signed 32bit integers?

werto165
Go to solution Solved by slashes_2_asses,

I don't know why, I didn't know this before, that is such a dumb decision... I'm guessing this was never an issue before and nobody noticed?

It's not a dump decision. I think you are.  :D

 

Read this: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Integer_Types

 

TL;DR : Singed integers make it easier to correct errors.

After reading that gangnam style is at the limit of a signed 32 bit integer, I was wondering why they used a signed integers, it's not like you can have negative views. Surely they could just use an unsigned integer that was 32bit. There must be a reason for this, can anyone explain why they would used a signed integer instead of an unsigned one? 

 

article: http://www.theverge.com/2014/12/3/7325819/gangnam-style-broke-youtube-view-counter

 

@slashes_2_asses Thanks. 

Some people, including some textbook authors, recommend using unsigned types to represent numbers that are never negative. This is intended as a form of self-documentation. However, in C, the advantages of such documentation are outweighed by the real bugs it can introduce. Consider:

 

for (unsigned int i = foo.Length()-1; i >= 0; --i) ...

 

This code will never terminate! Sometimes gcc will notice this bug and warn you, but often it will not. Equally bad bugs can occur when comparing signed and unsigned variables. Basically, C's type-promotion scheme causes unsigned types to behave differently than one might expect.

So, document that a variable is non-negative using assertions. Don't use an unsigned type.

CPU: Intel 3570 GPUs: Nvidia GTX 660Ti Case: Fractal design Define R4  Storage: 1TB WD Caviar Black & 240GB Hyper X 3k SSD Sound: Custom One Pros Keyboard: Ducky Shine 4 Mouse: Logitech G500

 

Link to comment
Share on other sites

Link to post
Share on other sites

After reading that gangnam style is at the limit of a signed 32 bit integer, I was wondering why they used a signed integers, it's not like you can have negative views. Surely they could just use an unsigned integer that was 32bit. There must be a reason for this, can anyone explain why they would used a signed integer instead of an unsigned one? 

 

article: http://www.theverge.com/2014/12/3/7325819/gangnam-style-broke-youtube-view-counter

 

I don't know why, I didn't know this before, that is such a dumb decision... I'm guessing this was never an issue before and nobody noticed?

Owner of a top of the line 13" MacBook Pro with Retina Display (Dual Boot OS X El Capitan & Win 10):
Core i7-4558U @ 3.2GHz II Intel Iris @ 1200MHz II 1TB Apple/Samsung SSD II 16 GB RAM @ 1600MHz

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know why, I didn't know this before, that is such a dumb decision... I'm guessing this was never an issue before and nobody noticed?

It's not a dump decision. I think you are.  :D

 

Read this: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Integer_Types

 

TL;DR : Singed integers make it easier to correct errors.

Link to comment
Share on other sites

Link to post
Share on other sites

It's not a dump decision. I think you are.  :D

 

Read this: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Integer_Types

 

TL;DR : Singed integers make it easier to correct errors.

 

LOL, fair enough, didn't know that... You learn something new every day :D

Owner of a top of the line 13" MacBook Pro with Retina Display (Dual Boot OS X El Capitan & Win 10):
Core i7-4558U @ 3.2GHz II Intel Iris @ 1200MHz II 1TB Apple/Samsung SSD II 16 GB RAM @ 1600MHz

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×