[prog] Passing data between modules

Dan Richter daniel.richter at wimba.com
Tue Jul 29 13:03:07 EST 2003


>Can you elaborate on this?  Why are the two sentences conflicting?  And
>why is C++ a better choice for futureproof?  Note, I'm not arguing against
>using C++.  I too think C++ is a better choice, but note below.

The main reason is objects. I don't see much need for 
inheritance/polymorphism in this project, but classes and objects still 
provide an easier way to structure and manipulate data.

One of the things I appreciate in Java is the way good structure makes it 
easy to code. If you open a Socket object, you pass it an InetAddress 
object. Everything fits together. And that means that if a change needs to 
be made in the future, you know exactly where to make it. The language is 
well designed. It's more than just the use of classes and objects, but the 
classes and objects help.

There are also more practical reasons. In C you can't return a struct from 
a function, and you have to remember to initialize all your data 
structures. You can get around all the limitations of C (e.g., return a 
pointer to a struct rather than the struct itself), but why make your life 
more difficult? C is great for kernel programming, but (I swear it's really 
true) there are other languages that are more appropriate for other tasks.

> >I recommend a higher-level interpreted language: the program will be done
> >five times faster and will be at least twice as readable, not to mention
> >easier to change and less buggy.
>
>Five times faster?  Even if you have to learn a new scripting language
>from scratch?

Fair enough.

>Can you elaborate?  Data passing is not a language specific operation.

Most data passing in large programs involves complicated data structures. 
Simply initializing these data structures is a pain in C because you have 
to remember to do it every time you declare a variable. Now consider what 
to do when you want to expand a part of the program, e.g., not only write 
data to a file, but decide which file to write to. You may have to add a 
new flag to the structure in addition to the "write to the file" flag, and 
this introduces the possibility of the flags getting out of sync. With C++, 
you pass an object, and the object makes sure that its data doesn't get out 
of sync.

>Is this because separate programs are intrinsically bad, or its bad only
>for this application?

It's not intrinsically bad, but it's more work, so there has to be a reason 
to justify it. A mail daemon has several components, but you don't have the 
option of running them individually. There's no reason to have the logger 
running if the daemon isn't accepting connections.

>Why is it more difficult to change the data structures in C?  As opposed
>to in any language that has to serialize the communication and have data
>structures?

Good point. I had forgotten that in C, you don't even need to serialize:
   write(fd, &big_structure, sizeof(big_structure));

-- 
  [Larry] Wall [inventor of Perl] believes that people think about
  things in different ways, that natural languages accommodate many
  mindsets, and that programming languages should too.
    - Jon Udell, in his essay, "A Perl Hacker in the Land of Python"



More information about the Programming mailing list