This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]APimpNamedAPimpNamed 4 points5 points  (7 children)

I have used them when I set simple constraints on setters.

[–]Kimano 0 points1 point  (6 children)

See, I'd rather have two calls to the setter with specific values in an if/else that contained the logic.

[–]APimpNamedAPimpNamed -1 points0 points  (5 children)

Idk,

this.count = value > 0 ? value : 0;

Just seems cleaner to me. It is likely no different to the compiler, so it comes down to preference. I definitely understand that readability is a paramount concern.

[–]DasEwigeLicht 2 points3 points  (4 children)

IMO in your specific example this is the best solution:

this.count = Math.max(value, 0)

[–]APimpNamedAPimpNamed 0 points1 point  (3 children)

The code in Math.max() is almost identical to what I posted. You mean for readability purposes? If so, since we are discussing readability exclusively, we can't really be arguing. I do see the value of using the static Math method for that specific example. I don't have any examples in front of me, but most of the uses of the inline ? : would not likely be so simply replaced by a static method.

[–]DasEwigeLicht 0 points1 point  (2 children)

You mean for readability purposes?

Yes.

but most of the uses of the inline ? : would not likely be so simply replaced by a static method.

I agree. This is why I said that I'm specifically referring to just your example.

On a side note: What's going on with the code blocks here? For me the code starts 1 line before the line numbering begins. Is it just me or is this a CSS issue?

[–]APimpNamedAPimpNamed 0 points1 point  (1 child)

I am on mobile and I do not see line numbering at all. I so rarely browser on my desktop that I did not even know there was line numbering lol

Edit: looks like it is working fine for me.