Bob Lindquist

 

            If I were to make an addition to a language, it would be to make sockets like butter in C++.  What I mean by this is to implement them as streams so you could throw any object down one or into one.  Using operator overloading, your classes could communicate naturally with one another across multiple systems.  I guess that is simplifying things more than real life but hey, what can you do?   It would probably not be that difficult.  This will make working with sockets more natural and integral in the process of designing programs. Who needs to use read and write anyway?  There could possibly be a negative effect in that there may be confusing syntax to deal with blocking and nonblocking.  These changes would benefit any program that uses sockets in that it would make the code easier to read and easier to debug.  It would also aid in the synchronization of data across multiple realms.  It would be nice if it could work like magic.

            This change could theoretically work in some other languages except some languages, such as Java, do not support operator overloading.  The implementation of streams in C++ is very unique and I do not think it would be evenly matched in many languages.

Current C++

s=MakeSocket(“Euclid.nmu.edu:25”);

len=read(s,buf,BUFSIZE);

strcpy(buf,"helo fakemail.nmu.edu\n");

len=write(s,buf,strlen(buf));

 

Modified C++

socketStream host(“Euclid.nmu.edu”);

host >> buf >> host;

 

            As can be seen from the code example, data from sockets could be tossed around like any other stream.  The code to read a line and send it back to the host that sent it is remarkably short.  It is also much easier to read.  There would not be much of an effect on performance except for the slight overhead of operator overloading.  Never mind latency.  One of the key benefits of this change would be that it would be easy for people to learn or relearn as most already have basic familiarity with streams from using cin and cout,

            Since normal socket operation would remain unchanged, backwards compatibility would be maintained.  Code could be converted at one’s leisure to the new form.  I am unaware of any language that currently implements sockets as streams (unless of course C++ already does).  This will be useful to make sockets less “scary” for people who are not used to using them and will enhance readability of code.  I do not believe that any programs could be written with this change than without it.