Primary-ish key



  • Well, here we are with our home-grown entity framework, and after a lot of hours trying to debug some weird data corruption in a part of the app I've just taken over... I find out how some of our "unique" entity IDs are created:

    [code]

    entity.Id = Guid.NewGuid().GetHashCode();
    [/code]

    Sigh...


  • Discourse touched me in a no-no place

    I don't think even snoofle's custom-made cluebat will help you here.



  • Yeah, due to likely hashcode collisions, you should be hashing 3 or 4 times, at least.



  • I like how if you search "GetHashCode();" the preview text Google gives you is:

    @The Googles said:

    Object.GetHashCode Method (System)
    msdn.microsoft.com/en-us/.../system.object.gethashcode.aspx

    The default implementation of the GetHashCode method does not guarantee unique return values for different objects. Furthermore, the .NET Framework does ...

    Forget reading the docs, they didn't even Google the function's name.


  • Winner of the 2016 Presidential Election

    @blakeyrat said:

    Forget reading the docs, they didn't even Google the function's name.

    Given that such a guarantee with a 32-bit integer couldn't reasonably be made, a few moments of thought could have revealed the problem with no research at all.

    Plagiarized chart


  • Now, this seems to be some .NET-SQLServer thing, but, doesn't SQLServer supports, you know, generated keys? trigger? I bet it does, so why reinvent the wheel?



  • @ubersoldat said:

    Now, this seems to be some .NET-SQLServer thing, but, doesn't SQLServer supports, you know, generated keys? trigger? I bet it does, so why reinvent the wheel?

    You're assuming. Nobody mentioned SQL Server.



  • OK, which RDBMS doesn't support this?

    Sorry, I was assuming they were using a RDBMS



  • @ubersoldat said:

    OK, which RDBMS doesn't support this?

    Sorry, I was assuming they were using a RDBMS

     

    OP said "home grown entity framework".  I'm assuming a home-grown database, too. I'm torn between a flat, comma deliminated text file, [b]OR[/b] a directory in which each file represents one line in the database, and each file's name is its PK.

     



  • @Lorne Kates said:

    OP said "home grown entity framework".  I'm assuming a home-grown database, too. I'm torn between a flat, comma deliminated text file, OR a directory in which each file represents one line in the database, and each file's name is its PK.

     

    For the sake of my own sanity, I'm going to be slightly more optimistic and pretend that it's a SQLite database.

    Running on a server.

     



  • @ubersoldat said:

    generated keys? trigger? I bet it does, so why reinvent the wheel?
    Reinventing the wheel might not be that bad if they just stopped after <font face="Lucida Console" size="2">Guid.NewGuid()</font>. You get less collissions with unique keys.



  • @curtmack said:

    For the sake of my own sanity, I'm going to be slightly more optimistic and pretend that it's a SQLite database.

    SQLite does support autogenerated integer primary keys. @curtmack said:

    Running on a server.

    If it's not changing often, it might even be the fastest option. SQLite is faster than full database servers most of the time, the cost being database-wide write lock.

    So SQLite wouldn't be a WTF (however the WTF is the entity framework—it might even be using a non-WTF database underneath).



  • I saw this error in 1991. JD was storing a "bit check", his own hash code for your file. He said "If you change even ONE BIT in that file the big check will change. I said "Suppose you've got a 64KB file. That's 512K bits. Your bit check is only 32 bits. Obviously lots of different file content values must map into the same bit check value." He paused, said "You're right", and never mentioned bit checks again.

    JD was a good programmer, and had made a program that he was selling. Lots of programmers will make this mistake.



  • @Julia said:

    Well, here we are with our home-grown entity framework

    Introducing the greatest waste of time when it comes to reinventing the wheel, the homebrewed ORM.

    Any errors? You're on your own pal.



  • @Bulb said:

    SQLite does support autogenerated integer primary keys.
    @curtmack said:
    Running on a server.
    A few years ago I was chatting with somebody developing some kind of application (IIRC it was for identifying similar/duplicate images), where he stored identification data in a SQLite database. Not a problem, right? Except that he decided to make the database available to applications running over a network. Instead of doing the sensible thing, and switching to a real database, he decided that writing a server around SQLite was the right way to go for it...



  • @blakeyrat said:

    You're assuming. Nobody mentioned SQL Server.

    True, but it is. And I've got to the point where I stop asking why... having pointed it out and asked for it to be redone, the next iteration of WTFishness is to SELECT the entire table - a billion rows in one case - and take MAX(id) + 1.

    In my defence, I stepped into this pseudo-ORM long after it had been cobbled together. TRWTF was me not spotting red flags at interview :(



  • @Julia said:

    ... having pointed it out and asked for it to be redone, the next iteration of WTFishness is to SELECT the entire table - a billion rows in one case - and take MAX(id) + 1.

    Hopefully (for our sake), it's not a real PK or indexed at all, and that query actually scans the table!



  • @boomzilla said:

    Hopefully (for our sake), it's not a real PK or indexed at all, and that query actually scans the table!

    You don't work here by any chance? :)



  • @Julia said:

    @blakeyrat said:
    You're assuming. Nobody mentioned SQL Server.

    True, but it is. And I've got to the point where I stop asking why... having pointed it out and asked for it to be redone, the next iteration of WTFishness is to SELECT the entire table - a billion rows in one case - and take MAX(id) + 1.

    In my defence, I stepped into this pseudo-ORM long after it had been cobbled together. TRWTF was me not spotting red flags at interview :(

    Why are so many programmers so pants-wettingly afraid of learning how a relational database works? I mean these are guys who will happily dive into much more complex topics, like learning all the naunces of XML and XSLT, but give them 3 lines of SQL and suddenly they're running and hiding behind a couch.

    Bugs the crap out of me.


  • Discourse touched me in a no-no place

    @blakeyrat said:

    Why are so many programmers so pants-wettingly afraid of learning how a relational database works? I mean these are guys who will happily dive into much more complex topics, like learning all the naunces of XML and XSLT, but give them 3 lines of SQL and suddenly they're running and hiding behind a couch.

    Bugs the crap out of me.

    Why? Because they have the same attitude about SQL that you seem to have about Linux?


  • @PedanticCurmudgeon said:

    Why? Because they have the same attitude about SQL that you seem to have about Linux?

    You asking me? Because I'm not one of those people, I like relational databases.

    But if your little theory here is right, and even if you believe that the reason I dislike Linux is that I'm scared(?) of it, then why don't they just use MongoDB? Or some other type of non-relational database? If I'm opposed to Linux that doesn't mean I'm opposed to the concept of "operating systems" altogether. I just use a different OS. So it still doesn't make sense.

    Ah, but I believe you weren't trying to actually present a theory, I believe you were just trying to win Bonus Forum Pointz by vaguely implying I'm a hypocrite in some way. I'm afraid there will be no Bonus Forum Pointz award this day for that clumsy attempt, friend.



  • @blakeyrat said:

    Why are so many programmers so pants-wettingly afraid of learning how a relational database works?

    I'm going to take a wild stab that it's because many programmers love having a computer work for them, and so making it do things correctly is an afterthought.
    Since relational databases are mostly about describing the data, it falls into the 'afterthought' category, so they don't like it.


  • Discourse touched me in a no-no place

    @blakeyrat said:

    @PedanticCurmudgeon said:
    Why does that bug you? Because they have the same attitude about SQL (that they shouldn't have to learn anything) that you seem to have about Linux?

    You asking me? Because I'm not one of those people, I like relational databases.

    See clarifications above.



  • @Salamander said:

    @blakeyrat said:
    Why are so many programmers so pants-wettingly afraid of learning how a relational database works?

    I'm going to take a wild stab that it's because many programmers love having a computer work for them, and so making it do things correctly is an afterthought.
    Since relational databases are mostly about describing the data, it falls into the 'afterthought' category, so they don't like it.

    Or perhaps RDBMS admins have a certain... reputation... that scares away anyone with a beard of less than 3 inches length?

    That said, one should at least know the basics about the systems one is using.



  • @Delve said:

    Or perhaps RDBMS admins have a certain... reputation... that scares away anyone with a beard of less than 3 inches length?

    That said, one should at least know the basics about the systems one is using.

    At least a greybeard usually knows his stuff, even if he is a BOFH. Our three DBAs (yes, we have three, and we're an entirely Microsoft shop) are absolutely useless.



  • @joe.edwards said:

    Given that such a guarantee with a 32-bit integer couldn't reasonably be made, a few moments of thought could have revealed the problem with no research at all.


    Plagiarized chart

     

    That climbs faster than I expected. The Birthday Paradox always surprises me.

     



  • @Medinoc said:

    @joe.edwards said:

    Given that such a guarantee with a 32-bit integer couldn't reasonably be made, a few moments of thought could have revealed the problem with no research at all.


    Plagiarized chart

     

    That climbs faster than I expected. The Birthday Paradox always surprises me.

    It would be a lot slower if the numbers at the bottom were 1, 2, 3...



  • @Sutherlands said:

    It would be a lot slower if the numbers at the bottom were 1, 2, 3...

    And the winner of the "stating the fucking obvious" award goes to...



  • @Hmmmm said:

    @Sutherlands said:
    It would be a lot slower if the numbers at the bottom were 1, 2, 3...

    And the winner of the "stating the fucking obvious" award goes to...

    Obvious, but wrong.



  • @boomzilla said:

    @Hmmmm said:
    @Sutherlands said:
    It would be a lot slower if the numbers at the bottom were 1, 2, 3...

    And the winner of the "stating the fucking obvious" award goes to...

    Obvious, but wrong.

    Pray tell in what (non-pedantically-dickweedish) way it is wrong...



  • @Hmmmm said:

    @boomzilla said:
    @Hmmmm said:
    @Sutherlands said:
    It would be a lot slower if the numbers at the bottom were 1, 2, 3...

    And the winner of the "stating the fucking obvious" award goes to...

    Obvious, but wrong.


    Pray tell in what (non-pedantically-dickweedish) way it is wrong...

    I won't even try to say it better than...
    @Yogi Berra said:

    You better cut the pizza in four pieces because I'm not hungry enough to eat six.



  • @boomzilla said:

    I won't even try to say it better than...

    Then your reply was completely pointless as what you quoted bears no relation to the subject being discussed.  They were talking about the rate that a graph climbs and if you redraw that graph with the horizontal axis rescaled to show 1,2,3 up to 10 with the vertical axis at the same scale then you wont even be able to tell the curve is climbing at all.



  • @Hmmmm said:

    @boomzilla said:
    I won't even try to say it better than...

    Then your reply was completely pointless as what you quoted bears no relation to the subject being discussed.  They were talking about the rate that a graph climbs and if you redraw that graph with the horizontal axis rescaled to show 1,2,3 up to 10 with the vertical axis at the same scale then you wont even be able to tell the curve is climbing at all.

    whoosh



  • @boomzilla said:

    @Hmmmm said:
    @boomzilla said:
    I won't even try to say it better than...

    Then your reply was completely pointless as what you quoted bears no relation to the subject being discussed.  They were talking about the rate that a graph climbs and if you redraw that graph with the horizontal axis rescaled to show 1,2,3 up to 10 with the vertical axis at the same scale then you wont even be able to tell the curve is climbing at all.

    whoosh

    You still haven't answered the question.  Implying that I haven't understood the connection between your post and the subject also implies that the real answer is because you were being pedantically dickweedish but I don't expect you to understand that (or admit to it on the off chance you do)...



  • @Hmmmm said:

    You still haven't answered the question. 

    Yeah, explaining jokes is considered bad form, so I haven't.

    @Hmmmm said:

    Implying that I haven't understood the connection between your post and the subject also implies that the real answer is because you were being pedantically dickweedish but I don't expect you to understand that (or admit to it on the off chance you do)...

    I guess dickweedery is in the eye of the beholder, which your rude "stating the fucking obvious" seemed to be to me. Potato, potatoe.



  • So Hmmmm wins the "douchebag" award (no small feat on these forums!) and boomzilla wins the "saying stupid stuff that doesn't make sense" award (also not a small feat).



  • @Sutherlands said:

    So Hmmmm wins the "douchebag" award (no small feat on these forums!) and boomzilla wins the "saying stupid stuff that doesn't make sense" award (also not a small feat).

    Nah...It's easy when you just quote the master.



  • Is there an award for pointlessly cryptic, logically inconsistent, not quite something Yoda would say quotes?



  • Hush, children. You will all get your chance to talk like a bagel.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.