last day (14 days later) » 

12:33 PM
0
Q: Is there any reason for this construct?

nablexThis is not my code but I was trying to evaluate code quality of an opensource project and one of the first things I encountered is this: public class WriterOutputStream extends OutputStream { ... @Override public void write( byte[] b, int off, int len ) throws IOException { ...

 
Vote to close... it's not your code and you're not maintaining it either. You say one would need a new byte array - have you considered the case where one doesn't want to write the whole array?
 
@Pimgd It's code review, bit of a misleading name for a site if this is not allowed. Secondly I don't think you have actually read the entire post because the rest of your comment makes no sense: I'm saying you don't need a new byte array. Partial array writing is why the entire write(byte[], int, int) even exists.
 
Consider the internals of write(byte[] array, int start, int end) or write(byte[] array, int offset, int length). How would you convert to String without arraycopy for partial array writes? This method is better; it circumvents arraycopy when you want to write a full byte[].
 
I would use the constructor "String(byte[] bytes, int offset, int length, Charset charset)" which specifically exists for this situation. Secondly suppose I am looping over a byte array and just using "write(bytes, 0, read)". It would copy it every time instead of doing even the most basic of checks if len == b.length - offset
 
I did not know that constructor existed. ... that could be one reason why they did it.
 
12:33 PM
The existence of the constructor makes their trick obsolete actually so it is a strike against using that construct.
 
=) I'm not justifying it, just saying it's a reason for why they could have done it.
You could submit a push for the project changing it around, but I'm not sure they'll accept if all you do is alter the interface.
 
ah finally, sorry, the chat was not working correctly
it's actually not an interface change, it is a classicly overridden method from OutputStream with a very odd implementation
 
doesn't java come with a writeroutputstream too
 
apache has one, java (afaik) only has an OutputStreamWriter which basically wraps a writer around an outputstream instead of (like here) an outputstream around a writer
ironically the apache one has the correct implementation
did you see my additional question? i'm genuinly curious whether a link would've been ok instead of a code blurb
 
they do all sorts of weird crap
Yeah I saw... you'd get blasted with another close reason
"Questions must include the code to be reviewed"
 
12:42 PM
that is a messed up combination of rules. how can you ever get an opinion on code you saw in a publicly accessible place?
 
Well it's so because we can comment on things other than the ones you ask
if you want to know if your comments are okay you can also get performance optimizations, remarks about naming, indentation, spacing, algorithm choice, etc...
all those comments are off-topic when it comes to a public piece of code: you can't do anything with them.
 
so basically...next time i should phrase it as..."i wrote this code but i have the following considerations..."?
 
"Please explain my code to me" is also a close reason, albeit not listed
hmmh
still, your question is interesting, it ought to be on-topic somewhere
I think it's best suited for StackOverflow
It's too specific for Programmers
Others in chat agree
you should put it on SO
 
Hi.
I am going to clean up some of the comments on the question that are now here.
@nablex I think you are right, there's a confusing set of rules....
but, I think the confusion in large part comes from a misunderstanding that you may have about what a Code Review is.
 
12:59 PM
▲▲ that
 
I've cleaned up the question to the point where I think it could get migrated, explicitly referring to byte[] and OutputStream
 
Nope, not going to migrate that.
> Is this indicative of (really) bad design or is there some issue that I'm missing that could explain why it is structured like this?
Code Review in particular, and Stack Exchange in general, is not a place to parade people's code and poke holes at it.
 
You think it needs overhauling to be nicer?
 
If it is your code, and you want help, then that's different. If it is someone else's code, then ask them to present their code here, and we can help.
 
Or you take offense to the concept of the question in general?
 
1:03 PM
offense is too strong a word here.
 
So basically when you want to form a cohesive (argumented) opinion on an open source project, you can't ask the community whether something odd is indeed bad or if there is something you don't know?
 
I know but I don't have a good word to put there
 
As it stands, it is against what Code Review does, and, I believe the answer would be too opinionated to be on topic on Stack Overflow.
 
I can just shut up, go home and in the resulting report state that the code is simply bad. or I could assume that there are things I don't know and hope the community can enlighten me
 
@nablex I am not saying that your question is a bad question (and in fact, I can answer your basic question....), what I am saying is that it is off-topic for Code Review.
 
1:05 PM
given these two suggestions, I would think the latter is more fair
it is indeed a basic question but much like duff's device it may simply be a relic of the olden days. a methodology that once existed (before my time) but is no longer relevant
I'm asking for the non-obvious answers
 
So, I have a predicament......
I am a moderator hre, and I have to protect the 'scope' of the site. It is clear to me that this question is off topic for here.
The reason is that code review is designed to improve the abilities and code of the programmer, it is not a debugging or understand-the-code service.
Since you are not the programmer, the programmer's abilities and code will not be improved by your question being posted here.
 
no but mine might be and anyone else's who reads this question afterwards (if any)
 
Now, understanding the problem will be beneficial for you, and others, which makes this possibly a question for SO.
(too specific and localized for programmers though, I think).
 
What would make it opinionated for SO?
It's yes or no, really.
 
But, your question basically amounts to: I think this person writes bad code, am I right?
 
1:09 PM
It needs a rewrite to not mention "is this bad design"
 
And, if I am right, and the code sucks, what would make a person do that?
^^^ that is what is too broad/opinionated for SO.
Code Review as a site has a delicate relationship when migrating to other sites.
I have to take that in to consideration as well.
So, here's what I will do.
I will answer the basic question here in this chat, and I will keep the question closed here, and not migrate it at all.
So, @nablex - interested in knowing why people code that way?
 
I don't think that's what he asked
Given that he's creating his own I/O library and such
its not "why do people code crap" but more "hey, is this the mistake I think it is or could I alter my project to be even more awesome?"
 
Well, it is a mistake, but the degree of the mistake could be anything from 0 to 'really bad'.
 
From what I can see the mistake transforms O(n) into O(2n)
 
Only if someone actually calls the first method.
@nablex - Pentaho Kettle?
I should mention this to Matt.
 
1:24 PM
google
@rolfl what is that?
 
Some code I have worked with before, and I have known Matt for a few years ;-)
Should tell him his code sucks ;-)
 
ahahaha
 
I have just connected with my old channels to Matt.... let's see if he responds ;-)
 
1:55 PM
@nablex - FYI:
09:37:38 < rolfl> Thought you would like to see this (I am a mod on Code Rview now...)
09:38:19 < rolfl> http://codereview.stackexchange.com/q/63358/31503
09:38:45 < rolfl> Matt ... I believe that is your code....
09:39:17 < rolfl> (on Code Review we do not review other people's code.... so it is closed).
09:40:37 < pentaho_mcasters> rolfl: I'm sure there's some question in there somewhere :-)
09:42:11 < rolfl> I figure that the base use case for the code will never call the indexed-version, so it won't matter, but, taken in isolation, there is a performance fix available ;-)
 

last day (14 days later) »