Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.
not extensible enough, rename to TWENTY_TWO_BLANK_SPACES

Adbot
ADBOT LOVES YOU

Hughlander
May 11, 2005

Elman posted:

code:
private static String BLANK_SPACES = "                      ";

I remember some stupid legitimate reason for having to do that like 20 years ago. drat if I remember what it was, but just that I spent like most of a day trying to figure out another way to handle it. It was C++ and we were slicing a std::string for <reasons> and having a static one to do it turned out to have a big perf boost. However this was also the project that before I came along spent something like 60% of it's CPU time in std::string constructor. Which was addressed by changing about 2000 method signatures from foo(std::string bar) to foo(const std::string& bar)...

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Volguus posted:

There's always need for speed, and there's never a need for arbitrarily reducing it. The system will have enough bottlenecks as it is, why introduce a new one for no reason? UUIDs are fine if you have distributed databases, but if you don't, why bother?

"Because then you can just slap a record in the database without worrying about ID collision or having to ask it what ID it came up with. Perfect for anything a user creates on the fly." - the Indian contractors who did V1 of our core system

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Munkeymon posted:

the cheap contractors who did V1 of our core system

Fixed that for you. It's not the nationality that's the problem.

Volguus
Mar 3, 2009

Munkeymon posted:

"Because then you can just slap a record in the database without worrying about ID collision or having to ask it what ID it came up with. Perfect for anything a user creates on the fly." - the Indian contractors who did V1 of our core system

Funny that you mention that. About 10 years ago I was working at a relatively big company (which since has faded into obscurity and was making smartphones that were named after a fruit) and was assigned to a project to help them actually deliver something after almost 1 year of delays (the project was several years old, but the delay was only 1 year). Out of 20 people assigned to that project, 18 were TATA consultants.
My first look at the database, there were no primary keys (no column was assigned the "primary key" attribute in any of the tables) and no foreign keys (of course). When I asked why? "We solve conflicts in software" :bang:
Anyway, after pestering them for weeks they finally grudgingly agreed to add primary keys to the tables (no foreign keys, but hey ... baby steps). What do they add? UUIDs. Better than nothing, but ... haha.

Dylan16807
May 12, 2010

repiv posted:

Twitters API legitimately has to encode Tweet IDs as strings because they exceeded 2^53 Tweets, so the IDs can no longer be represented as Javascript numbers :bravo:

TooMuchAbstraction posted:

To be honest, if you asked me to pick an ID format for something, I'd probably pick 64-bit int by default. That's 18 sextillion! That's a lot! The fact that this is limited to 9 quadrillion in Javascript would not have immediately leapt out to me as a problem.

Twitter didn't run out, they wanted to make it easier to generate tweet IDs by splitting it into timestamp/machine/sequence. Which is fair, but they decided they needed to lay it out as 4 billion tweets per second for 70 years, taking 63 bits. They could have easily fit it in 53 bits if they wanted to.

A pure tweet counter would be around 40 bits right now.

Dylan16807 fucked around with this message at 00:42 on Dec 13, 2017

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!

Munkeymon posted:

"Because then you can just slap a record in the database without worrying about ID collision or having to ask it what ID it came up with. Perfect for anything a user creates on the fly."
Yes let us see... A 128-bit UUID stored as a 36 byte string, as a primary key, hence indexed, and as a foreign key, let us suppose in two other tables and indexed. 1M rows per table. 36*2*3*1M=216MB. Probability of next insertion collision 2^108.

One random 64-bit integer stored as an 8 byte integer, &c, 48MB. Probability of next insertion collision 2^44. Use two 64-bits if you have the need for higher collision avoidance, and still shave off half the storage requirements.

Sadly I've seen these where the number of rows is around 100M.

Hughlander
May 11, 2005

PhantomOfTheCopier posted:

Yes let us see... A 128-bit UUID stored as a 36 byte string, as a primary key, hence indexed, and as a foreign key, let us suppose in two other tables and indexed. 1M rows per table. 36*2*3*1M=216MB. Probability of next insertion collision 2^108.

One random 64-bit integer stored as an 8 byte integer, &c, 48MB. Probability of next insertion collision 2^44. Use two 64-bits if you have the need for higher collision avoidance, and still shave off half the storage requirements.

Sadly I've seen these where the number of rows is around 100M.

That's why you drop the 2ish bits from the UUID that specify the type and are fixed for the type you're using and put them in your signed 128 bit number type then you have the exact same storage requirements as your 2 64 bits.

Sedro
Dec 31, 2008

PhantomOfTheCopier posted:

A 128-bit UUID stored as a 36 byte string

Nobody actually does this, right?

john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.
My DB primary keys are composite keys of every column.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
My primary key is the json column.

Volguus
Mar 3, 2009

Sedro posted:

Nobody actually does this, right?

If you dont have the UUID type in the database, how else are you gonna store it? 2 64 bit ints? nah....

Kazinsal
Dec 13, 2011

Volguus posted:

If you dont have the UUID type in the database, how else are you gonna store it? 2 64 bit ints? nah....

Time for a REALLYBIGINT type.

fritz
Jul 26, 2003

Sedro posted:

Nobody actually does this, right?

Hi is this your first day in the thread

Hughlander
May 11, 2005

Kazinsal posted:

Time for a REALLYBIGINT type.

See previous post DECIMAL(128, 0) postgresql types can take a UUID if you drop the type bit.

PhantomOfTheCopier
Aug 13, 2008

Pikabooze!
PostgreSQL has a built in uuid type. https://www.postgresql.org/docs/9.1/static/datatype-uuid.html

I've seen engineers cling to their uuid designs stored as MySQL strings for primary keys everywhere as if it would keep the Titanic afloat. They usually seem to recognize some absurdity, so they truncate it to save space. :downsgun:


Edit: Yeah it's a common MySQL antipattern. vvvv Haha. Also, PostgreSQL has a native inet type. Just cast it to an ipv6 address. :buddy:

Edit 2: There's a 16 byte interval type. I don't know if it would work, but it could be converted to microseconds since, as we all know, they have the same storage requirements so they're the same. :downs:

Edit 3: Interval fails as microseconds (out of range), but the inet type behaves: select trim(trailing ':' from regexp_replace(replace('01234567-89ab-cdef-fedc-ba9876543210'::uuid::text,'-',''),'(....)',E'\\1:','g'))::inet;

PhantomOfTheCopier fucked around with this message at 05:10 on Dec 13, 2017

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Sedro posted:

Nobody actually does this, right?

I've seen them stored as a 38 byte string (with braces around it just to make sure you realize it's a GUID).

Naturally it was a VARCHAR(100) column.

EssOEss
Oct 23, 2006
128-bit approved
:bandwagon:

Do you enjoy byte order issues? Isn't it nice how you cannot just make a GUID into bytes by taking away the dashes but you also have to flip the byte order of several fields because Microsoft once treated it as a combination of integers and backward compatibility being what it is, it remains so in many systems?

That being said, if you use sequential IDs in your datebase, I hate you and think you belong in this thread.

Xik
Mar 10, 2011

Dinosaur Gum
Let me tell you about our integration layer that tries to keep track of sequential ids for inserts independently of the database.

Cancelbot
Nov 22, 2006

Canceling spam since 1928

Nhibernate HiLo?

We hit an INT limit on our user table once, decided to change it to UUID but that broke replication and we ended up detaching a few thousand relations before realising and having to try and fix that poo poo by hand.

b0lt
Apr 29, 2005

Sedro posted:

Nobody actually does this, right?

Microsoft requires you to transmit a GUID as a 78-byte null terminated UTF-16 string with braces over USB for some WinUSB functionality.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



EssOEss posted:

That being said, if you use sequential IDs in your datebase, I hate you and think you belong in this thread.

I thought sequential integer IDs indexed better?

TooMuchAbstraction posted:

Fixed that for you. It's not the nationality that's the problem.

Of course not, it's the toss-requirements-over-the-wall offshoring... which usually does (did?) seem to happen with Indian firms, and definitely did in this case.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Volguus posted:

There's always need for speed, and there's never a need for arbitrarily reducing it. The system will have enough bottlenecks as it is, why introduce a new one for no reason? UUIDs are fine if you have distributed databases, but if you don't, why bother?

That's... an almost perfect example of missing the point about the bottleneck analogy. If your system has 'enough bottlenecks as it is', then as long as you're working downstream of a bigger one, that's precisely when you shouldn't optimize for speed, because the system won't benefit from it unless the bigger bottleneck is removed.

Using UUID is far from arbitrarily reducing speed, either (can't think of any example of that, other than sprinkling sleep() around). They make idempotency trivial, for example, and they make any kind of data sharing between databases safe and easy.

canis minor
May 4, 2011

b0lt posted:

Microsoft requires you to transmit a GUID as a 78-byte null terminated UTF-16 string with braces over USB for some WinUSB functionality.

:stonklol:

Volguus
Mar 3, 2009

NihilCredo posted:

That's... an almost perfect example of missing the point about the bottleneck analogy. If your system has 'enough bottlenecks as it is', then as long as you're working downstream of a bigger one, that's precisely when you shouldn't optimize for speed, because the system won't benefit from it unless the bigger bottleneck is removed.

Using UUID is far from arbitrarily reducing speed, either (can't think of any example of that, other than sprinkling sleep() around). They make idempotency trivial, for example, and they make any kind of data sharing between databases safe and easy.

If in your database you store your UUID as varchar (for whatever reason, incompetency or the database support), you are arbitrarily reducing speed. Made some tests many years ago on an Oracle database, testing varchar vs bigint as primary keys, and the insert was slightly slower while the select was a lot slower (more than 15% is I remember correctly).

However, yes, if you need to share data between databases, this is a hit that you are accepting and is part of the core functionality. There's no way around it. Using the UUID type in the database would most likely improve things to the point that speed is equal, though I have not personally tested that.

EssOEss
Oct 23, 2006
128-bit approved

Munkeymon posted:

I thought sequential integer IDs indexed better?

Yes, in theory, but the convention is to replace the last 4 bytes of GUIDs with a timestamp, which at least in SQL Server basically makes them sequential without losing enough randomness to matter. There is also a builtin function in T-SQL for doing something along the lines of this.

Mind you, I have never noticed a difference when benchmarking this with any of the databases I have worked with (not more than low tens of GBs of data, so perhaps too small to matter really). Perhaps it only shows up under heavier load than I ever run into.

Volguus posted:

If in your database you store your UUID as varchar (for whatever reason, incompetency or the database support), you are arbitrarily reducing speed.

Right, just as you would if you wrote files to disk by uploading them to an FTP server and then using wget to save them to My Documents. That's just not an appropriate way to do this. There is a difference between paying a price in functionality by "optimizing" something without a need (as when using ints, thereby giving up GUID features) and just doing it wrong (in which case you win nothing, such as when storing GUIDs in their string-serialized form as varchar).

EssOEss fucked around with this message at 17:04 on Dec 13, 2017

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



EssOEss posted:

Yes, in theory, but the convention is to replace the last 4 bytes of GUIDs with a timestamp, which at least in SQL Server basically makes them sequential without losing enough randomness to matter. There is also a builtin function in T-SQL for doing something along the lines of this.

Mind you, I have never noticed a difference when benchmarking this with any of the databases I have worked with (not more than low tens of GBs of data, so perhaps too small to matter really). Perhaps it only shows up under heavier load than I ever run into.

You mean https://www.codeproject.com/Articles/388157/GUIDs-as-fast-primary-keys-under-multiple-database ?

EssOEss
Oct 23, 2006
128-bit approved
Yeah, that article appears to accurately represent the concept, though it manages to be impressively verbose about it.

Elman
Oct 26, 2009

code:
private String createPassword() {    
    return RandomStringUtils.randomAlphanumeric(6);
  }
This is what you get when you password reset. And there's no way to change your password, you can only reset it to a new "random" one :psyduck:

Elman fucked around with this message at 10:25 on Dec 14, 2017

Space Kablooey
May 6, 2009


You know what? I'm fine with the idea that you can't pick your own password.

The disclaimer is that I'm used to password managers.

Edit: no wait this is terrible

Space Kablooey fucked around with this message at 16:34 on Dec 14, 2017

Volguus
Mar 3, 2009

Elman posted:

code:
private String createPassword() {    
    return RandomStringUtils.randomAlphanumeric(6);
  }
This is what you get when you password reset. And there's no way to change your password, you can only reset it to a new "random" one :psyduck:

The only time when this is appropriate is when an account is created by an administrator and a "reset password" email is being sent to the user, to prevent anyone form logging in in the meantime. Otherwise ... hah.

Pollyanna
Mar 5, 2005

Milk's on them.


Firefox raises an error if a function references an argument that is not part of its signature and was not passed into the function. Chrome does not and will happily execute the rest of the function anyway. :downs:

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Pollyanna posted:

Firefox raises an error if a function references an argument that is not part of its signature and was not passed into the function. Chrome does not and will happily execute the rest of the function anyway. :downs:

Could you clarify what you mean here?

It's perfectly normal in JavaScript to refer to variables that a function closes over but which are not formal arguments to the function.

Internet Janitor fucked around with this message at 18:36 on Dec 14, 2017

redleader
Aug 18, 2005

Engage according to operational parameters

Pollyanna posted:

Firefox raises an error if a function references an argument that is not part of its signature and was not passed into the function. Chrome does not and will happily execute the rest of the function anyway. :downs:

Can you post an example? This... doesn't seem right, even for the zany world of JS.

Pollyanna
Mar 5, 2005

Milk's on them.


Now I’m not so sure. All I know is that a function that’s supposed to have event passed to it didn’t have it in its signature, but called preventDefault in the body. Chrome was fine with it, but Firefox broke.

canis minor
May 4, 2011

You're not talking about event/window.event by any chance?

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yeah must be using event.preventDefault. window.event is non-standard (from IE) but I guess chrome supports it. FF does not.

https://jsfiddle.net/z3o1ehkb/

https://developer.mozilla.org/en-US/docs/Web/API/Window/event

Hilariously, the MS document link about that attribute redirects to MDN on Window.Event the class!

Space Kablooey
May 6, 2009


MS and Mozilla are working together to make MDN the default JS reference.

redleader
Aug 18, 2005

Engage according to operational parameters

Pollyanna posted:

Now I’m not so sure. All I know is that a function that’s supposed to have event passed to it didn’t have it in its signature, but called preventDefault in the body. Chrome was fine with it, but Firefox broke.

Hah, oh yes. I've hit this one before.

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


:ms: IE ruins things yet again.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply