Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RqWithHeaders is not immutable #646

Closed
2686747 opened this issue Mar 8, 2016 · 12 comments
Closed

RqWithHeaders is not immutable #646

2686747 opened this issue Mar 8, 2016 · 12 comments

Comments

@2686747
Copy link

2686747 commented Mar 8, 2016

RqWithHeaders changes after new RqPrint(rqWithHeaders).print(); This test will not pass.

@davvd
Copy link

davvd commented Mar 15, 2016

@yegor256 please do something about this issue

yegor256 pushed a commit that referenced this issue Mar 15, 2016
@yegor256
Copy link
Owner

@2686747 it's not a bug. it's by design. this is how it should work. I created a test to confirm that: fb89dde

@2686747
Copy link
Author

2686747 commented Mar 15, 2016

@yegor256 ok, but what about "immutable"?

@yegor256
Copy link
Owner

@2686747 immutability doesn't mean that return values are always the same. immutable doesn't mean constant. see http://www.yegor256.com/2014/12/22/immutable-objects-not-dumb.html

@2686747
Copy link
Author

2686747 commented Mar 17, 2016

@yegor256 good point, but now you have to leave this link everywhere in project's javadocs, because we have Java and wiki. And all is clear here: state doesn't change. And sorry, but when i call print(smth) - i don't expect than print will change this something and i talk not just about immutable now. We're using decorators in each line practically - do i have to check all of them for print(smth)? And i didn't start with a thread-safety yet.

@yegor256
Copy link
Owner

@2686747 but print() doesn't change anything. it's just an input stream, which works in a non-immutable way. not our object. we just return an input stream. how it behaves - not our area of responsibility. see?

@2686747
Copy link
Author

2686747 commented Mar 17, 2016

@yegor256 I understand completely but why i have to worry about implementation of some object? I don't see InputStream, i see Request which is marked as immutable and thread-safe. And of course i expect it won't change after some external method execution, especially such harmless as print() . And if it's impossible we have to remove all "immutable and thread-safe" and leave very clear attention in javadocs

@yegor256
Copy link
Owner

@2686747 you just misunderstand what "immutable and thread-safe" means. you think they mean "constant", while it's not true. the problem is in your understanding, not in our texts :)

@2686747
Copy link
Author

2686747 commented Mar 21, 2016

@yegor256 please, reread this smart man )))

@yegor256
Copy link
Owner

@2686747 yeah, I read that dude, a few times :) check this out: http://www.yegor256.com/2014/12/09/immutable-object-state-and-behavior.html

@2686747
Copy link
Author

2686747 commented Mar 21, 2016

@yegor256 how is your own example with side effect different from RqPrint(request).print() (except syntax of course)?

@yegor256
Copy link
Owner

@2686747 we're dealing with a mutable InputStream here, that's why we inevitably have that side effect. we can't get rid of it, without breaking the entire idea of mutable input streams in Java. blame Java, not us :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants