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

1

u/Lost4468 Apr 07 '21

I mean there could be actual legitimate uses for having that many or more. Large mathematical data structures could hold things like that and be somewhat appropriate.

I could actually think of a few ways it might actually be an ok or even a decent idea to do this in python. But not Java.

4

u/deegeese Apr 07 '21

Large mathematical data structures use actual data structures like arrays or trees.

Having 255 properties is a pretty strong sign that the designer has failed to properly encapsulate unrelated classes.

1

u/Lost4468 Apr 08 '21

Large mathematical data structures use actual data structures like arrays or trees.

It depends on what exactly we're talking about. It's not uncommon to see this, and can actual be useful. E.g. you need a ton of parameters for the maths, but they're not related, it doesn't really make much sense to put them in an array there. It's quite common in python, because you can just create a dictionary of the parameters, and then pass them as arguments.

2

u/deegeese Apr 08 '21

Can you name a mathematical function/relationship that actually needs more than a dozen non-array parameters?

1

u/Lost4468 Apr 08 '21

Not off the top of my head because it's hard to recall something I could also write here. One thing that's not uncommon to see is large structures like matrices or similar have a parameter for every part of themselves.

But I don't know why you're acting like this is rare in languages like python? It's very common to pass around a large number of parameters, it's not bad design in python.

2

u/deegeese Apr 08 '21

You’re proving my point.

A math function that takes a dozen parameters for the matrix elements is a bad design because they could just pass an array.

When Python functions take a ton of parameters, it’s usually because most of them are optional and it’s just syntactic sugar vs passing a dict for configs.

1

u/Lost4468 Apr 08 '21

A math function that takes a dozen parameters for the matrix elements is a bad design because they could just pass an array.

Most do, they allow both. There's plenty of valid reasons you might want both.

And yes there are still plenty of maths functions where it does not make sense to house them in an array.

When Python functions take a ton of parameters, it’s usually because most of them are optional and it’s just syntactic sugar vs passing a dict for configs.

Literally what I already said.