Talk:Parse an IP Address

From Rosetta Code
Revision as of 16:21, 28 September 2011 by Rdm (talk | contribs) (→‎Sloppy)

Hm. I'm thinking the decimal number requirement isn't necessary. Removing. --Michael Mol 12:35, 27 September 2011 (UTC)

Sloppy

This task currently seems sloppy.

First, it requires that extra data (the port) be ignored. In practical use, if the port is being passed to a routine that parses ip addresses, this probably means the data is being mishandled. So good practice suggests that this be treated as an error case. This is a minor but annoying complexity in the task.

Second, it asks us to mix ipv4 and ipv6 addresses but ipv4 addresses have a representation as ipv6 addresses (see rfc 2373, for example) but the example implementation mixes them in the same data structure without labeling the type and without using a consistent mapping.

I can think of several ways to go here:

  1. Discard the port parsing requirement
  2. Ask for ip,port to be reported as a pair
  3. Ask for ipv4 and ipv6 address results to be distinguished (or put them in separate tasks)
  4. Ask for the ipv4 addresses to be encoded as ipv6 addresses (127.0.0.1 becomes ::127.0.0.1 to distinguish it from ::7f00:1).
  5. change the task to make some of these issues moot

But I am not sure which way to go here. --Rdm 13:58, 28 September 2011 (UTC)

The trouble is, connection targets (IP/port combinations) are frequently passed around in string format with the version undeclared. Many programs which need to operate with IPv4 and IPv6 addresses actually have difficulty with it, even though the standardized formats are documented. Correctly converting that string representation into a logical representation is what this task is intended to be about. The inclusion of both IPv4 and IPv6 notation, as well as the inclusion ":portNumber", is intentional, to attempt reflect the full complexity of the problem. So what remains is likely a poorly chosen task title and an an insufficiently-described task. I have extreme difficulty being clear on the latter point, though. --Michael Mol 14:27, 28 September 2011 (UTC)
The string format is unambiguous. But result format is ambiguous, here. --Rdm
Ah, I see now. I only saw the output format of the task to be relevant in that it required comprehension of the input format to generate. The internal representation (in particular, correct distinction of host and port addresses) was what I was more interested in. Requiring the port address in the output helps a reviewer understand how the port number was understood. Change the requirements for the output format however you see fit, with that requirement in mind. (I'd try changing it, but I've been without my glasses for a week, and doing things on the computer has been very, very error-prone--even trying to write coherently. )--Michael Mol 15:15, 28 September 2011 (UTC)

The 'bit specifying if port was given' doesn't seem necessary, how about just use port 0? --Ledrug 15:37, 28 September 2011 (UTC)

Specifying port 0 means "any available", but only in some contexts. A more general solution should be preferred, IMO. I took the "bit specifying" bit as "an indicator", rather than as an explicit like-formatted boolean bit. The way I read it, it could be equally (and possibly more clearly) written as "a note specifying if port was given". --Michael Mol 15:40, 28 September 2011 (UTC)
I have (after several not-so-good attempts) done my best making the result format unambiguous and complete for this task. Let me know what you think.
Meanwhile, as Michael Mol points out, port 0 can be different from no port specified. --Rdm 15:47, 28 September 2011 (UTC)
The only part I don't understand is "In languages where variant result types are clumsy". --Michael Mol 15:48, 28 September 2011 (UTC)
How would you represent the required results in C, for example? --Rdm 15:49, 28 September 2011 (UTC)
How would it be any different from a console-output-capable language that wasn't C? --Michael Mol 15:50, 28 September 2011 (UTC)
In languages which have variable length tuples as a native time (like Pico Lisp) returning a port number or omitting a port number is trivial. You can either return (addr-family ip-address port) or (addr-family ip-address). In a language like C, it's much more natural to use something like a struct with a fixed memory layout. Of course, whether this issue propagates to a textual representation of the result is a different issue... But currently the task is asking for a result and a textual representation of that result would be for illustrative purposes. --Rdm 16:21, 28 September 2011 (UTC)