#Can't understand this from Java docs

1 messages · Page 1 of 1 (latest)

crystal summitBOT
#

<@&987246399047479336> please have a look, thanks.

crystal summitBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

jaunty brook
#

it gives information that the numbers must be relatively small

#

and bytes are usually used for things like I/O

radiant fractal
#

The idea is that you want to prevent invalid values
For example, an age can't be negative, so if possible, use a type which has no negative values (such a type doesn't exist in java tho), and so, int this case, you would need to add checks to verify the age
But in case a type exist
But if you have a value, which is always an integer, to prevent invalid decimal values, you would use an int, so if someone sees the int type, he knows there can't be any decimal values after the comma.
This can also be used with byte, ie the value can't go higher than 127, so you can use a byte to signal that so the person reading this code knows that values above 127 are not allowed
Tho I want to add a warning here, because it only works if the limits, are -128 to 127, if the limits are for example 100 ie if you have a score that can go from 0 to 100, then it wouldn't make sense to use byte, because you will have 27 invalid values anyway, and yes it's way less than int, but it's still values you have to check. On top of that, this is very misleading, because when you use byte, people thinks you use this types to actually stores bytes, so if you use byte to store a score from 0 to 100, this will be very misleading to people who will try to understand to the link between a score and bytes...
And so, I think that you should only use byte when you actually need to stores bytes, period.

#

I answered that tho

#

of ?

#

let's say you want to store a byte

#

do you store it in a byte type or an int type

#

?

#

yes

#

wdym

#

I don't understand

#

if you want a value which can have values from 0 to 255 or from -128 to 127, you may want to use a byte

crystal summitBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍