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

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.

1

u/Lost4468 Apr 07 '21

There's not really any excuse for not being able to do that on the vast majority of projects these days, really very few things need to be that way.

And by local I don't mean literally on your computer, but in a development environment for you managed by you.

1

u/echosalik Apr 07 '21

Well the only case i see the issue is when the deployment architecture isn't x86/x64. Then I'd say it might be annoying to get hold of a system with an arm or riscv or that IBM ISA I don't remember the name of.

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

6

u/Spyridox Apr 07 '21

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

2

u/tanjoodo Apr 07 '21

Also cover it in unit tests first

2

u/CarbonasGenji Apr 07 '21

I think you added an extra zero to your 10%

3

u/PM_YOUR_SOURCE_CODES Apr 07 '21

In this case don't refactor code, but rather expand classes and add new functionality and only change where you call them.

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

4

u/botle Apr 07 '21

Why can't it be a very dynamic piece of code that organizes the data in some type of structures?

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.

4

u/646c726f576f6c6c6548 Apr 07 '21

It's pretty simple, but creates thing thing called a binding and is a wrapper that makes it easier to refer to different views.

We also weren't using Fragments like we should have and ended up having to after this.

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

2

u/lestofante Apr 07 '21

i mean, is a code that probably break anyway by just looking at it, nobody is gonna notice a real difference

1

u/fakeplasticdroid Apr 08 '21

Correction: don't ever mess with untested code. And something tells me a class that takes nearly 255 parameters to construct wasn't written with testability in mind.