STL vs your own

Started by
96 comments, last by doodah2001 22 years, 2 months ago
quote:Original post by DrPizza
No, like a fundamental bit of english grammar.

"optimum" is the superlative form of "best". It cannot take any qualifiers like "more" or "less". It's an absolute.

Er... actually optimum is a synonym for best. Best cannot have a superlative form since it is already a superlative itself: it's the superlative form of the adjective "good". ("Better" is the comparative form.)

Why am I saying this? Because people are getting pedantic about the language used when we rarely use it 100% accurately ourselves.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Edited by - Kylotan on February 6, 2002 6:34:55 PM
Advertisement
*replies to give opinion about English grammar just to feel included*
optimum noun - the best out of a number of possible outcomes or choices.

As DrPizza pointed out, "best" is already superlative. Houdini''s post would have been correct had he said "the most optimal," keyword: optimal. However, he missed the best part - DrPizza had a grammatical error in his correction of Houdini''s grammatical error:

quote:Original post by DrPizza

Ugh. "optimum" is already a superlative, it doesn''t not need qualifying.


Double negative: doesn''t not.

(I sure hope no one pays attention to my grammar. )
quote:Original post by null_pointer
What are chain and filter streams? Aren't they just streams who are themselves "buffers" for streams? As in:


Note: I prefer to call chain/filter streams "modifier streams", so from here on out that's what I'll be calling them.

Modifier streams modify data before writes, and modify data after reads. Modifier streams can also be chained or connected to other modifier streams, but the start of the chain must be a physical stream.

For example, let's say you want to send data over a network stream, but first you wanted to encrypt it, then compress it. This could easily be done using modifier streams, like so:

      int main (){   NetworkStream net_stream("153.211.32.145");    GZipStream gzip_stream(net_stream);   EncryptionStream encrypt_stream(gzip_stream);   encrypt_stream.Write("This text will be encrypted first, "     "then the result sent to the gzip stream which will zip "     "it, then that result it will passed to the network "     "stream which finally sends it across the network");}      


In Java and C# streams aren't buffered, instead you must attach a BufferStream to it. A BufferStream is just a modifier stream which buffers data until the buffer is full before sending it off to the physical stream, just like normal buffers. I personally like your way much better because you'd normally want your streams buffered by default.


- Houdini

Editted by Stoffel: changed code so it didn't kill the rest of the thread by running past the end of the line between source tags.

Update: Damn you were faster than me Stoffel

Edited by - Houdini on February 6, 2002 7:56:22 PM
- Houdini
quote:Original post by Kylotan
Er... actually optimum is a synonym for best. Best cannot have a superlative form since it is already a superlative itself: it''s the superlative form of the adjective "good". ("Better" is the comparative form.)

Doh. Yes, I know that.

I was too busy thinking back to learning latin at school... (bonus, melior, optimus). I had the ''b'' stuck in my head. Too much useless junk.

char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
quote:It''s not even close to the same as a gobal. Nothing outside that .c file would have access to it. It''s the C equivilent of a class member.

It very much *IS* close to the same as a global.

In particular:
It can be modified by multiple threads simultaneously
It can be modified by multiple functions simultaneously

It is these two features that make globals dangerous (there are other _annoyances_ with globals, like name clashes, but these aren''t _dangerous_), and file-level globals have those exact same issues.

quote:BTW, I find it also noteworthy that no other recent object oriented languages (Java, C#) use a function to convert types to strings.

What the hell are you talking about?

Let''s just see.

Java: Every class derives from Object, and Object has a method called... toString(). And that method''s purpose is, let''s see... oh my god, it''s to convert that object to a string.

I''ll grant you that much of the time it''s called implicitly, which hides its existance, but it''s very much there (so, if you want, write yourself a C++ class hierachy that implements a similar mechanism).

C# has no library or class hierarchy at all. If you mean the classes of the CLR/CLI, then, oh me oh my. We have the Object class and its ToString() method.

References:
Java: ttp://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html#toString()
.NET: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemobjectclasstostringtopic.asp
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
You''d ought compress before you encrypt, less you be mighty disappointed

The iostream implementation on MSVC is about an order of magnitude slower (maybe half-an-order) than the xprintf flavor.
IME, both are entirely way to @#$@#% slow to use in a speed critical section of code.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by DrPizza
It very much *IS* close to the same as a global.

In particular:
It can be modified by multiple threads simultaneously
It can be modified by multiple functions simultaneously


Nothing outside that module can touch that variable. Nothing else can see it. Sure you could create multiple threads in that same file to mess with it, but that is your business. Nothing outside this module can do this.

quote:Original post by DrPizza
What the hell are you talking about?

Let's just see.

Java: Every class derives from Object, and Object has a method called... toString(). And that method's purpose is, let's see... oh my god, it's to convert that object to a string.

I'll grant you that much of the time it's called implicitly, which hides its existance, but it's very much there (so, if you want, write yourself a C++ class hierachy that implements a similar mechanism).


It's part of a class so you can call ToString on any object to get the string equivalent. The same thing can be accomplished in C++ by overloading a ToString function.

My point is this: I can write a set of functions using sprintf to achieve the exact same thing as stringstream, minus the state information. Hell, most iostream classes use sprintf to convert the types! These set of functions will also produce slightly faster code and take up less memory.

So once again, if speed and memory constraints are a major concern, and you don't plan on keeping state information, then you would you use the class over the functions ?

That is my point, a point you seem to be missing entirely.

quote:Original post by DrPizza
C# has no library or class hierarchy at all. If you mean the classes of the CLR/CLI, then, oh me oh my. We have the Object class and its ToString() method.


Sigh, yes, I meant the CLR and you knew exactly what I was talking about. Yet, you still try to insist on pointing out grammatical errors and misused terms instead of focusing on the debate.

Since you like doing this so much:

quote:Original post by DrPizza
It very much *IS* close to the same as a global.


The definition of global in the American Heritage dictionary:
global 3. Comp. Sci. Of an entire program or document.

By definition something that only spans one file is not global. It's not even close .

Of course, I knew what you had really meant, which is that you believe the consequences of using a file scope instance is similar to that of a global instance. But since we are nit picking...


- Houdini


Edited by - Houdini on February 6, 2002 10:09:12 PM
- Houdini
Houdini:

Hmm...I do not think that it would be possible to make a stream that could be both a general purpose stream and a modifier stream, without using some kind of wacky syntax. But making the stream I/O type parameter (i.e., file, mp3, encrypted, compressed) work with both could be done. A user could distinguish between the two by looking at the word - if it's obviously a past-tense verb then it is a modifier stream, whereas if it is a noun then it is a target...

  // compressed, encrypted, socket input and output streams: stream < compressed < encrypted < socket, output > > > out;stream < compressed < encrypted < socket, input  > > > in;  


If the modifier stream requires extra template parameters (or could simply put them to good use), then you could add extra template parameters to its class definition, supply defaults, and tack them onto the end like so:

  /* a compressed, encrypted, socket input stream making use of md5 encryptionand gzip compression, using the default buffering schemes */ stream < compressed < encrypted < socket, input > default_buffering, md5 > gzip, default_buffering >  


Of course, that's a little unwieldly. I wonder if there is a way to clean up that "default_buffering" name with a class template named "default" that was explicitly specialized streams as the third parameter. Then we could call it "default" and rely on stream's template template parameters and buffer interface specification to perform the appropriate specialization...

(Six more days! But then there's also shipping time... )

Edited by - null_pointer on February 7, 2002 1:10:26 PM

This topic is closed to new replies.

Advertisement