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

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?

4

u/SapphicRain Apr 07 '21

I'd probably just feed a string array at that point. Depending on how the data is used. Or make a class that represents the data contained in a row so I can process data in a self explanatory way (less need for over documenting things)

2

u/ColdPorridge Apr 07 '21

Why use a class instead of something more functional like a DataFrame?

1

u/GregariousFrog Apr 07 '21

Didn't occur to me to be honest. DataFrames probably make more sense for my application, but what I'm really worried about is, is it bad practice to have 4000 objects at runtime if the only purpose of the objects is to hold <1kb string data each? It's not going to scale up, number of objects and data size is going to stay the same.

3

u/ColdPorridge Apr 07 '21

I would probably use a dataframe. Pandas if you’re using Python. It will be the simplest answer and is a marketable skill to have.

9

u/pentaduck Apr 07 '21

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