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

Code in ctors #62

Closed
akryvtsun opened this issue May 30, 2017 · 13 comments
Closed

Code in ctors #62

akryvtsun opened this issue May 30, 2017 · 13 comments

Comments

@akryvtsun
Copy link
Contributor

In some ctors we have method calls for JDK's standard static methods. E.g.
https://github.com/yegor256/cactoos/pull/22/files#diff-537f42dacf5c41ee51d8dc12c8560ce5R51
or
https://github.com/yegor256/cactoos/pull/22/files#diff-537f42dacf5c41ee51d8dc12c8560ce5R73
Also look on ctors in
https://github.com/yegor256/cactoos/blob/master/src/main/java/org/cactoos/text/FormattedText.java
in master branch.

Sometimes we even have some non static JDK calls. E.g.
#20 (diff)

Question: have we avoid all of such method calls at all? So, literally,

Only new calls are available in ctors

rule everywhere?

It yes, have we avoid usage standard Arrays.asList and Collections.unmodifiableSet and create substitute for them?

@0crat
Copy link
Collaborator

0crat commented May 30, 2017

@Englishman I'm not managing this repo, remove the webhook or contact me in Slack //cc @yegor256

@g4s8
Copy link
Contributor

g4s8 commented May 30, 2017

@Englishman I've never tried before this approach (only new in constructors) but it looks interesting. As for Collections.unmodifiableSet and Arrays.asList I think we should avoid jdk static methods like any other static methods in constructor because they are procedures, so if we use procedures in constructors we put a code in constructors.

@akryvtsun
Copy link
Contributor Author

@g4s8 basically the idea is from here
http://www.yegor256.com/2015/05/07/ctors-must-be-code-free.html

@g4s8
Copy link
Contributor

g4s8 commented May 30, 2017

@Englishman yes, I've read it, but I thought this rule is less strict. Like do not put a lot of code in contructor but one or two method calls is ok.

@akryvtsun
Copy link
Contributor Author

@g4s8 yes, I guessed so. But look on this part of discussion
#20 (comment)

@yegor256
Copy link
Owner

@Englishman yes, we must avoid any code in constructors. So, these static method calls are evil, but if you look at what's inside them, you will see that they are actually just making new objects. But I agree that we should create substitutes for them. Feel free to submit PRs.

@yegor256
Copy link
Owner

@Englishman is this ticket still actual? I believe we can close it

@ghost
Copy link

ghost commented Apr 16, 2018

@yegor256 @Englishman please close this issue as it's actually a number of issues:

  1. introduce class for Locale.getDefault issue
  2. update 20 usages of Arrays.asList issue
  3. update 61 usages of Collections... issue

@yegor256
Copy link
Owner

@ashtonhogan why me?

@llorllale
Copy link
Contributor

@Englishman please close this issue

@llorllale
Copy link
Contributor

@Englishman can we close this?

@llorllale
Copy link
Contributor

@Englishman closing

@0crat
Copy link
Collaborator

0crat commented Apr 25, 2018

The job is not in WBS, won't close the order

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

5 participants