I am faced with the usual case of retrieving some information on a remote server using an HttpPost request. Imagine that we are dealing with a weather application that receives some weather information.
The server sends the input stream long , and we are interested in extracting some information from this stream. Keep in mind that we are in a memory related environment.
We have two options:
1) We use a JSON or XML parser to retrieve information.
This is the recommended method, but it has some disadvantages:
This is painfully verbose, especially if we want to get a little information from a large stream.
It should be faster and more convenient for garbage collection, but I'm not sure if this is the case for the above case (some information from a large stream).
2) We use simple string manipulation (SSM):
We reduce the size of the input stream by roughly trimming useless information, and then extract the information from the compact line. For this purpose, we can create filters using static methods to reduce the work of the garbage collector.
Also this method has some disadvantages:
- I think this method is very discouraged
- The more information we extract, the slower this method. I think the performance curve is a critical point where SSM is getting slower.
- It may be less flexible than JSON or another parser.
But also some important advantages:
- Short, readable code.
- It may be difficult to modify an existing filter, but it is much easier to create a new one.
To summarize, the question arises:
1) Is simple string manipulation big no-no, or is it wise to consider using it? 2) If you answered yes (big no-no) to the previous question, could you explain your reason?
cheers :)
source share