r/badcode • • Apr 07 '21

java Apparently Java can only handle 255 parameters in a constructor...

Post image
4.0k Upvotes

249 comments sorted by

View all comments

Show parent comment

155

u/SireBillyMays Apr 07 '21

As someone who has inexplicably taken multiple advanced courses in databases:

pls no.

133

u/bundabrg Apr 07 '21

I have one vendor who has a single column of 128 characters in a table. Just one column.

It's a hospital thing so patient number is characters 5-8, ward characters 10-13 etc with every char used.

It gets worse. The patient number got too large so.patient number is now characters 5-8, then append character 106 and character 119.

And there's lots more insanity like this. I swear when we got the documentation the person giving them to us sounded ashamed on the phone (not their fault, they inherited it).

63

u/SireBillyMays Apr 07 '21

So, wait. they have a database, where one of the tables is literally one field consisting of 128 chars, then they have subdivided that field into subfields?

Sounds like hell to work with right now, but honestly doesn't sound that hard to fix.

47

u/bundabrg Apr 07 '21

It gets worse (sorta). I have to use SOAP to interface with it :(

10

u/-IoI- Apr 07 '21

That fucking sucks, hopefully something like WCF or LINQ in the middle to ease the pain a bit

32

u/Lost4468 Apr 07 '21

So, wait. they have a database, where one of the tables is literally one field consisting of 128 chars, then they have subdivided that field into subfields?

It sounds like it was originally a paper implementation, in which case this sort of string representation can be incredibly efficient. If I give you a ton of drawers filled with patient details and tell you "find this patient", then if the records were assigned this sort of string, it would be very easy for you to narrow it down to a few records. I don't know how old the system is, but /u/bundabrg maybe it's because of this?

So then when they get digitised people don't want to move to a new system, or more likely you can't even change it because the hospital(s) are running two systems at once for a while. So you end up with weird data structures that make sense for paper records, but make no sense for computers.

Sounds like hell to work with right now, but honestly doesn't sound that hard to fix.

I don't know so again maybe /u/bundabrg could chime in. But one of the problems with this sort of thing is there's frequently literally hundreds of exceptions. Because it's a paper system over the years people have said e.g. "oh let's just start this one with 'OUTSIDE' since it comes from outside the country" or all sorts of weird similar exceptions. Well for 'OUTSIDE' it's easy to write an exception, but there's often so many of these exceptions, and no documentation, the people working there don't have a list of the exceptions they've made over the decades. And then once you end up with enough exceptions you realise there are plenty of ambiguous ones you can't possibly decide by writing basic if statements.

And it's medical as well, so you really don't want to risk mixing up records, violating HIPAA, not properly finding a record, etc. So you end up just being stuck with the stupid system. To fix it you need to go through everything manually and change it all out at once, which requires a fuck ton of time and money.

13

u/EvilPencil Apr 07 '21

Yeah, I think the fix would be to create a view that gives a more "normal" representation and yet doesn't create a second source of truth. Once all the consumers are interacting with the view instead of the underlying tabe, then do a migration and switch the inserts/updates over to the new schema.

6

u/HIPPAbot Apr 07 '21

It's HIPAA!

3

u/Lost4468 Apr 07 '21

Hungry hungry HIPAAs?

6

u/Tornadic_Outlaw Apr 07 '21

If it really is bad enough that you couldn't write code to fix it, then it isn't usable as is. Exceptions nobody knows about aren't exceptions, they are errors, and if a human tried to look at the data they would make the same mistakes the computer made.

And if you are that concerned about losing ambiguous information in the current filing method you could even keep that column for legacy data and not populate it for new records.

3

u/dakta Apr 07 '21

If it really is bad enough that you couldn't write code to fix it, then it isn't usable as is.

This is a great measure for software, or any system really. If it's so bad that you can't add a sane workaround interface on top, then it's not safe to use as-is and should be replaced ASAP.

1

u/Lost4468 Apr 07 '21

If it really is bad enough that you couldn't write code to fix it, then it isn't usable as is. Exceptions nobody knows about aren't exceptions, they are errors, and if a human tried to look at the data they would make the same mistakes the computer made.

There are plenty of situations where humans can read the exceptions and you can't write software to figure it out.

And if you are that concerned about losing ambiguous information in the current filing method you could even keep that column for legacy data and not populate it for new records.

So keep this 128 char column for legacy data, then start using something else from now on? What is the advantage then? You can't really use the new data, you're just going to have to compile it into the old form whenever it's needed.

You're just going to further fragment it if anything. You need to stop and go through and change it all, that's the way out of this mess.

→ More replies (2)

9

u/shh_coffee Apr 07 '21 edited Apr 07 '21

Sounds like it may be getting populated by a COBOL system where they're not dividing the patient record by it's fields when writing to the DB and they're just sending the whole patient record as one DB field. That would also explain the weird patient number append as in COBOL fields have fixed length and that sounds like someone just went "we can add another number by adding a field at the end of the record called ws-patient-num-append" or something so not to mess with the existing field lengths.

Just taking a wild guess though.

7

u/fakehalo Apr 07 '21

I wonder if this is the result of a migration from ancient times where they needed the original "database" structure for some portion of their codebase, which is likely no longer around.

Reminds me of things I've seen from decades ago.

→ More replies (1)

6

u/slower-is-faster Apr 07 '21

I worked for an insurance company that had an oracle database they paid a lot of money for. Their apps “document”, was stored as encrypted XML in a table with just one column - this was what they used oracle for.

→ More replies (1)

19

u/echosalik Apr 07 '21

Yeah there comes a time where whatever you learned in the courses get thrown out... Like normalisation... It's good to have but not applicable everywhere... And idk why whenever I get newbies and i tell them to create joins without FKs, thier first statement is can we do that?

I'm like yeah, FKs are not required, makes things fast but not required.

FKs can really create a mess where inter-dependent data doest not come in a linear fashion, offline first apps.

7

u/PurpleMysticLlama Apr 07 '21

Lol bois, let's just take the relationship out of a relational database. We'll handle all of this in code np. Future developers? What happens when I leave? 'Fuck them' is what happens.

8

u/SireBillyMays Apr 07 '21

I mean, what you just mentioned was literally part of one of my courses (that course was, admittedly "applied databases".)

A lot of that course centered around grounding us a little though. "What you learn in the other courses might be theoretically perfect, but it's hardly necessary - nor efficient - for most systems you're likely to work on."

With that being said:

If you have a database with 80-90 columns you should probably look at what you're actually doing, and whether or not it's actually optimal. That could easily make things a giant headache to work with...

(I also must say I do enjoy only doing databases recreationally, where I can bend the "rules" a fair bit...)

2

u/echosalik Apr 07 '21

Oh i assumed university/degree courses... Those, atleast here, are really subpar...

And yeah... Due to this 80 90 column thing we moved towards json in columns. Make. Everything so much easy... Especially if you follow a schema to heart... And then create views for reports.

We had one experiment that was pretty successful and really stable, set it and forget it product. Server syncing and everything... That was a fun experiment...

6

u/SireBillyMays Apr 07 '21

They were university courses, but one of the ex-industry profs wanted a more applied course to be taught as a grounding act to counterbalance the other more theory focused courses.

I don't necessarily think that most of the database courses are subpar, but moreso that most of them aren't intended to prepare people for working WITH databases, but more to prepare people for working ON databases, but then most institutions don't have any applied courses.

Sounds like you managed to get out of a sticky situation then.

→ More replies (2)

2

u/Wizdemirider Apr 07 '21

Wait so what do we get exactly? A cross join? I don't understand how we can have something like an inner or left join without a common column.

10

u/WalditRook Apr 07 '21

The column data needs to be common, but it isn't required that the referential integrity be enforced.

Honestly, I think it's pretty rare you'd ever want to actually do that, but as an example:

Consider a parking management system that records both registered vehicles (from a payment system) and detected vehicles (from cameras with OCR), using licence plates in both tables - while you could create an extra table to store all plates, it's not really necessary, but you might well wish to compute joins between those tables.

4

u/Wizdemirider Apr 07 '21

Ahh okay, that does make sense since SQL only requires you to mention which columns to join on. Thank you!

2

u/dakta Apr 07 '21

Wait, people actually think that you can only join on explicitly defined foreign keys? I guess that's probably good practice to consider when designing a schema, but for ad-hoc queries on existing data it's pretty common to join on arbitrary columns. Heck, with a little CAST or CONVERT they don't even have to be the same column type or data format.

→ More replies (8)