Caruychen / 42Hive-Lem_in

Integrated smart ant colony transport system
2 stars 0 forks source link

Is a room alias starting with space valid? #5

Closed crl-n closed 2 years ago

crl-n commented 2 years ago

I'm writing this issue to highlight and document this specific corner case I'm a bit uncertain about.

In the pdf it is said that a room name/alias will never start with a '#' or a 'L'. This implies all other characters are valid starting characters. So, presumably ' ' (space) is a valid starting character. However, space is also used as the delimiter in the room lines, separating coordinates and the alias. Is space then a valid first character for a room line? And when a room name begins with a space, does the space become a part of the alias? Or should the alias be interpreted as being an empty string? Here's a couple examples.

Input: " abc 5 5" Does the alias become " abc" or "abc" or would this be an invalid line?

Input: " 5 5" This could be interpreted either as having a missing alias or having an empty string "" as alias.

Hope that makes sense. Let me know how you interpret this case.

Caruychen commented 2 years ago

That's an interesting question, and I think I understand what you mean. It's likely going to have different interpretations from everyone since it isn't explicitly stated. So I think it's a choice that we can make.

In my opinion, I feel that the rule is implied in its use. In that the space is reserved as a delimiter.

This is mainly because, if the space is allowed to be a valid name character at the start of a string, it leads to the logical mayhem you pointed to already. Is it a character? Is it a delimiter? Oh no, it's a conundrum!

It feels somewhat arbitrary to say that a space at the beginning is part of the name, and all other cases a delimiter. What about a space at the end of a name like "abc 5 5"? So it opens up a can of worms about how and why the space is interpreted differently for different cases. It also feels a bit "messy" if that makes sense. It's better to keep the rules simple and clean.

So the second example above " 5 5" would be error. The first example may or may not be an error (depending on whether our program would just trim leading spaces or not).

crl-n commented 2 years ago

Yeah I think you make a good point. Also, spaces in the middle of names would obviously just count as delimiters, so really any other interpretation than that names can't contain spaces would be in some way incoherent.

Good, because that also makes it far easier to code and validate.

Thanks Caruy!

crl-n commented 2 years ago

Another question. What about the dashes? Would they be valid characters in aliases? I just realized that makes validating link lines a bit more tricky. The reason is that the dash is the delimiter in the link lines. So if there are also dashes in the node aliases, it means there will be non-delimiter dashes in the link lines. Here's an example.

3
##start
start-node 0 0
middle-node 1 1
##end
end-node 2 2
start-node-middle-node
middle-node-end-node

As you can see this gets a bit more tricky.

What is your take on this?

Edit: I suppose it gets even trickier than that. For example...

3
##start
a 0 0
a-b 1 1
b 2 2
b-c 3 3
-b-c 4 4
##end
c 5 5
a-b        # From a to b
a-b-c    # This could be 'from a-b to c' or 'from a to b-c'
a--b-c  # From a- to b-c
b-c       # From b to c

This can be dealt with, but as the line 'a-b-c' shows, it creates some ambiguosity. But there really doesn't seem to be any clear indication that a dash would be a forbidden character in the aliases.

image