16
Radioh
8y

Got to admit. Got a little surprised when stream.ReadByte() returned an integer instead of a byte.

Comments
  • 4
    I believe so that they can return an EOF value
  • 0
    @DrEmann I'm not familiar with C# (Java instead and come C) but I think it would be better to just throw and EOFException and allow checking with something like stream.available() before?
  • 0
    You can represent an byte as int8
  • 0
    @LinusCDE you should not use exceptions for program flow - at least for "expected" cases like "end of file".
    Exceptions are expensive in many languages.
  • 0
    @hawkes Not really in Java. Also if you take C, there you are required to check for stream.available(). And in Java you probably will put data streaming always in a try-catch because of e.g. IOException which is thrown if the connecting wasn't successful.
  • 1
    @hawkes it's Java

    It uses exceptions for *everything* (even where they're not appropriate at all)
  • 0
    @hawkes it's Java
    (hey, I thought I'd mention it)
  • 0
    Like parsing an integer. C# gets it right there, at least, thanks to out parameter support.
Add Comment