Re: overload operator<<



Hi Jon,

Your reaction about confusing symbols is understandable I think, what
I dont understand is the hidden agressive part. In my experience with
c++ I have had never any problem with the overloaded meaning of
operator << and >>.
Like most truths in a human world its overloaded with respect to some
context. I dont understand why your c# spec is the wholy grail when
compaired to a completely vendor independent c++ language spec and
comite.

Rick

On Sat, 7 May 2005 18:52:46 +0100, Jon Skeet [C# MVP]
<skeet@xxxxxxxxx> wrote:

>Steve Richter <StephenRichter@xxxxxxxxx> wrote:
>> > Just because an operator has been abused in one language doesn't mean
>>
>> > it should be abused in others too. You can get used to any number of
>> > things, but bad habits should be broken. << and >> are not "suck" or
>> > "blow" operators - they're bitshifting operators. Their purpose is in
>>
>> > the specification. That's what they should be used for, and all they
>> > should be used for.
>>
>> placing the emphasis on names to indicate what a statement does has two
>> problems. There is the obvious that if you dont know english the
>> meaning will not be apparent. ( yeah, yeah - keep the name simple and
>> consistent ). Another major problem is the designers of the .net
>> framework might make confusing choices.
>
>I think there are few choices as confusing as making a bitshifting
>operator effectively stream data, personally. That was a bad choice on
>the part of C++ library designers.
>
>> on friday I had to deal with converting strings to and from ebcdic
>> bytes. I am still new to .net and had not yet worked with the Encoding
>> and Decoding classes. ( still dont know the difference between an
>> Encoder and Encoding ).
>
>The difference is basically that an Encoding is stateless, and an
>Encoder/Decoder has state. For instance, if you are trying to read
>characters from a stream, you might only get part of a character, if
>you're reading a multi-byte character and only get the start of it. A
>Decoder remembers the bytes which have been read but haven't formed a
>full character yet, so that when the rest of the bytes turn up, the
>whole character can be returned.
>
>> I gave the MSDN documention 15 minutes and
>> none of the method names made sense to me. Without the examples I
>> found in google groups ( I think it was a post of Jon Skeets that was
>> the best example I found ), I would still be at it.
>>
>> Here is the code that translate a string to ebcdic bytes:
>> System.Text.Encoding encoding =
>> System.Text.Encoding.GetEncoding( 37 ) ;
>> byte[] bytes = encoding.GetBytes( InString ) ;
>>
>> "GetBytes" makes little sense to me. "TranslateTo" is more intuitive.
>> But why rely on either. In my c++ class framework masterpiece the code
>> reads:
>>
>> EbcdicBytes bytes( 37 ) ; // code page 37
>> std::string InString ;
>> bytes = InString ; // replace the contents of bytes with InString
>> bytes << InString ; // add InString to the contents of bytes
>>
>> I think this second example is much more readable. That is just my
>> opinion. What I dont agree with is the C# designers not allowing the
>> choice between the two styles. I prefer symbols over words.
>
>You find the above more readable, but I suggest that if you could write
>the above in C#, pretty much *anyone* who hadn't used C++ but had read
>the C# language specification would disagree - they'd wonder how on
>earth you were expecting to shift something by a string.
>
>The << and >> operators have a well-specified meaning, which has
>nothing to do with streaming data. Language allows one to be much more
>descriptive than symbols - symbols are just a shorter way of expressing
>things *when everyone knows what the symbols mean*. As soon as you
>start changing what the symbols mean, confusion enters.
>

>I'm very glad that I'll never have to read code like the above in C#.

.



Relevant Pages

  • Re: UPA board blog -- new post about observers for league play
    ... its just that i dont really trust it for one. ... is a little confusing  to me. ... i think you got me confused with jim parenella there. ... crying in ultimate in my world. ...
    (rec.sport.disc)
  • Re: how eval works?
    ... of execution. ... Also it confusing when it compiles the code & when not ... Moreover I still dont get, in function when it parses, why it dont ... therefore, during parsing, load every MAT-file that you try to load in your ...
    (comp.soft-sys.matlab)
  • Re: "Seven Weeks"
    ... The three views need to be separated by at least a character, ... Some letters are wierd, i.e the 'e'. ... I dont know though as I dont know much about java. ... good work on a unique game and playstyle. ...
    (rec.games.roguelike.development)
  • Re: simple serial string display help
    ... Now, just one more piece of help, if you dont mind. ... draw the string in the middle of the client rectangle, ... what you need to do is get the serial character that you want to ... Here we get into a long discourse on Unicode. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Tv series: Heroes and the ungay character
    ... I dont remembur waching it aftur we shuvuled lotz of blo up our nozzels. ... He's Zach, or at least the character is named Zach, ...
    (soc.motss)