Assignment 7.2

posted Jul 2, 2010, 8:57 PM by Unknown user
Both the punctuation and call-and-response methods are useful in sending data between different programs (or in the case of object-oriented programming, different classes). Both work well in different situations, depending on what needs to be sent / received. In my experience, I've used the punctuation method in most cases due to its simplicity. The punctuation method involves inserting an arbitrary, preferably unique, character or sequence of characters at the end of each segment of code being sent. The receiver then parses it by separating it at each of these points. This method is convenient when the receiver does not need or is otherwise unable to send a message back. In addition, it requires less interaction between the receiver and sender, therefore being quicker and less processor intensive, so this method should be used whenever possible. mentions that the receiver could misinterpret a part of the message to be punctuation, however, this problem has been realized many times in the past, and the standard way to deal with this is using an escape, a unique character used to notify the receiver that the following character is part of the message - the most commonly recognized escapes are the backslash '\', used in C and similar languages in string formatting, and the %, used in html and similar web-based languages.

    However, sometimes the receiver needs to be synchronous with the sender in a way that cannot be hardcoded, or the receiver needs to send a message back to the sender. In this case the call-and-response method is an effective solution. It requires the receiver to send a message "asking" for a response, and the sender replies with one of the segments of data. However, for this to continue indefinitely is slightly more axing on the processor which may result in reduced speed, but when it is needed it can offer far more flexibility than the punctuation method - for instance the call could return a boolean value indicating whether the previous data was successful, eliminating the need to implement additional methods if this functionality is required.