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

730

u/echosalik Apr 07 '21

Meaning someone wrote a constructor with 255 parameters? ... Why?

591

u/646c726f576f6c6c6548 Apr 07 '21

Don't ever mess with the working code

204

u/echosalik Apr 07 '21

I get that, but I actually hate this logic. I have written codes years ago that I look at it now an I am like, WTF did i do it like that? I could have just done xyz and that would have been better and more efficient.

This usually is the case with complex queries. I have to actively stop myself from making changes to queries that are running multiple reports. It's really hard to stop myself from making changes. I am a kind of person that format codes before debugging. It annoys a lot of people but fk it.

I NEED TO SEE IT IN A CERTAIN WAY/FORMAT FOR MY BRAIN TO SEE WHATS WRONG WITH IT.

So yeah...

100

u/Spynder shameless stealing content to r/YandereTechnique Apr 07 '21

"Don't mess with a working code unless you 100% know how to make it better"

75

u/echosalik Apr 07 '21

Or make a branch experiment then merge changes... Git FTW

29

u/aloha2436 Apr 07 '21

Not if you can’t run or test it locally 🤪

16

u/echosalik Apr 07 '21

Now that's a problem I've never had... I should have not jinxed it...

10

u/1studlyman Apr 07 '21

Having worked in large ventures which have no test bed or test hardware, it happens far too often than it should. Some of us have been on teams where they only test when the hardware is returned for maintenance and it's only a system test.

→ More replies (19)

6

u/Spyridox Apr 07 '21

I do know 100% how to make it better: delete it and start over

→ More replies (2)
→ More replies (2)

59

u/bschlueter Apr 07 '21

There comes a time when even working code needs to be examined. Also, if it was working then why did someone add another parameter?

66

u/Willinton06 Apr 07 '21

Ok let’s just say it’s a very dynamic piece of code

→ More replies (1)

13

u/Lost4468 Apr 07 '21

There comes a time when even working code needs to be examined.

Ha! People would be shocked if they realised just how much of our infrastructure is run on software that we don't even have the source code for anymore, much less the ability to do something about it.

There are companies (and government agencies) out there where a large part of their infrastructure is running and no one in the company knows how, or sometimes even where to it's running. The software industry changes its mind on how thing should be done all the time these days, but you go back a few decades and the etiquette was so much worse, there's so much software and infrastructure out there from back then that had zero regard for documentation, versioning, tidy code, bus factor, even code comments. Oh and a ton of it is also caught up in copyright no mans land, where companies didn't ever properly get the rights to the source code or even the software sometimes.

It's really a mess out there. This is one of the advantages to open source software that is often forgotten.

5

u/646c726f576f6c6c6548 Apr 07 '21

It was from a pragmatically generated file in android studio where each parameter is a view in a single layout and the app had more than 255 views in a single layout

6

u/sharpened_ Apr 07 '21

But why on earth would it need to pass in All The Views if you're only ever going to use 1 at a time?

Seems like a refactor of that function is in order, what hellish software will write code like that? Or is programmatically generated code generally simple?

I've only ever touched it once, and that basically created getters and setters from a table.

→ More replies (1)

17

u/Skipcast Apr 07 '21

Sounds like a good candidate for this sub

7

u/cmd-t Apr 07 '21

Why not? I mean you just rerun the test sui... oh

→ More replies (1)
→ More replies (1)

38

u/chronos_alfa Apr 07 '21

If the constructor had 255 parameters, that means the object probably had 255 properties... JESUS

53

u/Epacnoss Apr 07 '21

255 properties at very minimum

48

u/chu121su12 Apr 07 '21

No need that much properties. You can do toString and concat them all thus storing them as single string.

11

u/paradoxon Apr 07 '21

Or keep a map of name value pairs with matching string parsing

11

u/SapphicRain Apr 07 '21

I hate this. You're doing too much. You need more classes to break up the workflow. Or find a way to use Arrays

4

u/GregariousFrog Apr 07 '21

What if the class is 40 string variables and constructor and nothing else? I'm making an object for every row in a 40 column csv file for an assignment, if that's important. It feels kinda stupid, but I just can't tell. Should I just use arrays?

→ More replies (4)

9

u/pentaduck Apr 07 '21

Not necessarily. A few parameters could've been used to initialize a single member.

→ More replies (8)

13

u/iNetRunner Apr 07 '21

Well, if you used varargs you’d only be limited to 64k bytes total. E.g. a constructor with 16k integer parameters; no problem. (Besides the mental, practical etc. issues…)

→ More replies (5)

9

u/[deleted] Apr 07 '21

That or it was the result of codegen, which does sound a bit more reasonable provided I don’t have to use the constructor myself without some kind of builder

Even so sounds incredibly situational to be reasonable lol

→ More replies (1)
→ More replies (5)