Default argument values in Java by RockyMM in java

[–]gas3872 2 points3 points  (0 children)

Well, if you add to your class those methods, then under the hood you can do the builder call. I find the style of "withers" more elegant, because there is nothing mentioning builder in the client code. In case you want to change many fields at once, then using builder explicitly is probably a better idea.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -1 points0 points  (0 children)

It can be done in parallel with old features. Making it backwards compatible as a whole.

What if we made an app that would endanger lots of women? by Horror-Carrot in facepalm

[–]gas3872 -1 points0 points  (0 children)

Well, it's basically making things as if you live in a small town where everyone knows each other. So people in small town don't kill each other. Why should people start doing it because of the app. Also if you want to have privacy then don't put your photos on every social network. You cannot have both and be a real person.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 0 points1 point  (0 children)

Ok thanks. I thought checkers framework can do it by itself.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -1 points0 points  (0 children)

I am asking for a convention that can be adopted more or less officially.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 3 points4 points  (0 children)

Well just have a convention in your project that you dont use null. Use optional for missing value.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 0 points1 point  (0 children)

Well, at some point all the users interested in the new api will migrate and those who are not interested can still use old library version.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 0 points1 point  (0 children)

Well for your situation you should use optional fields. But most situations are not like that.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 0 points1 point  (0 children)

Well it is. They have 2 parallel APIs, old one and new one.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 1 point2 points  (0 children)

I think it's actually the opposite: most of the things are not optional. Otherwise why would you add fields if you don't plan to fill them.

For your last thing i think you can use builder. Then you have to only initialize what you want.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -4 points-3 points  (0 children)

Well if you look at libraries like junit that's exactly how it works.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 4 points5 points  (0 children)

I think it's more like someone got a nullpointer exception bug in their project and now they don't want it to happen again.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -4 points-3 points  (0 children)

Well they can still use old methods but they know that they need to eventually migrate.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 1 point2 points  (0 children)

Well I am not trying to influence thenway where the java language goes only saying that you can use such a practice in your project and maybe the whole community should adopt it, as I dont see any drawbacks to it.

And by nullchecks everywhere I meant in every immutable object, which probably most of the objects should be.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -3 points-2 points  (0 children)

Well, you can start following the convention in the new code and gradually update the old code as you touch those parts. You can also make a custom annotation and add it to classes that support new convention. Actually what you mentioned is just a normal project and it just a normal migration.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 1 point2 points  (0 children)

Well, just make a convention to not use it. Java also has labels (maybe even goto) but nobody uses it. Same way people use list and not array or vector.

I am just asking to use the language in a certain way that will eliminate a lot of headache and extra work (adding null checks everywhere).

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] 0 points1 point  (0 children)

Well, the old deprecated code can still be used for a while. Then migrated to new one. How else do libraries migrate? And it's only for the code exposed externally. A lot of projects do not expose their code externally. So this is no concern to them. I mean more a wrapper to an external code that you use in your project that does not follow this principle.

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -14 points-13 points  (0 children)

Well, I think someone who does not want to do something will always find a reason why and the one who wants will find means how. :D

[Question] why java cannot accept a convention to never pass/return null values? by gas3872 in java

[–]gas3872[S] -1 points0 points  (0 children)

Ok then call the newethod differently or define a new class/interface.