views:

257

answers:

8

http://example.com/foo.aspx?foo=bar

I'm refactoring and need to name the constant which will hold only the question mark character of this string. I'm not sure what best to name the variable, as I've never known what the proper name of that question mark was.

What should I name the constant? Or... is there something in .NET that's the wiser choice here (something built-in whose value is already that question mark -- or that builds a querystring for me automatically given a name/value pair collection)?

+7  A: 

In URIs the separator between hierarchical and query part always is a question mark, so why pull it into a constant?

Possible names:

  • QuerySeparator
  • QueryStartCharacter
  • QuestionMark
  • CurlyThingWithDotBelow
Joey
+1 for CurlyThingWithDotBelow
Matt Joslin
"why pull it into a constant?": I try to avoid having any one value located two or more places in my code, especially in strings. The exceptions (things that /truly/ don't change, ever) are few enough that it's fairly reasonable making no exceptions in that practice when I'm coding. Generally, I don't have freeform strings in my code. If it's a string, it's in a constant, resource file, or configuration file. It's an arguably unreasonable extreme which is very effective at keeping code clean.
lance
hm, for dealing with things like URIs I can imagine strictly adhering to this might reduce readability. At least the characters ``/`, `?` and `#` are known to everyone and you would expect them in the source somewhere. If they are named `HierarchyIdentifier`, `QueryIdentifier` and `FragmentIdentifier` it might not be immediately obivous what the heck is going on. For strings or character literals which will really never change I consider this not the greatest idea.
Joey
I concur, really. Maybe I'll make a rare exception here. Alternatively, I might make this issue moot by using the UriBuilder class to which Scott Anderson has introduced me in his answer.
lance
A: 

In JavaScript it is called "search"

Jeremy
That's the question mark **and** the search part, not just the question mark.
David Dorward
+1  A: 

Well, that question mark just indicates that it was a GET request and the parameters sent follow. Call it query or something, but it seems a waste of time since you can safely hard code that in. It will never change for a GET request

Simonw
Even without the question mark, the browser wil send an GET request. It's not because of the question mark the request will become a GET request.
Ikke
Sorry, I didn't mean it was necessary for any get request, I just meant it was necessary for a GET request which was passing parameters
Simonw
+1  A: 

Query string identifier? I don't recall seeing any named specific for the character.

Perhaps QUERYSTRING_ID

Pat
+1  A: 

It doesn't have an official name, but you could call it searchpart seperator (since it separates the searchpart from the previous part of the URI).

David Dorward
+5  A: 

There's no need to name this. .NET has a UriBuilder class that can assist you in building your URL's. Check this article to see how it works and to make it a little more intuitive:

http://codeidol.com/csharp/csharpckbk2/Web/Using-the-UriBuilder-Class/

Scott Anderson
+1  A: 

As far as I can find in RFC 3986, there is no specific name for that. "Fragment segment separator", nothing more.

naivists
@Johannes Thanks for noticing - yes, it was segment separator.
naivists
+10  A: 

In this document, it's literally called the "question-mark" (hyphen included) (http://www.ietf.org/rfc/rfc2396.txt -- scroll down to 3.2 Authority Component).

I agree it's a bad name. The hash (#) is called the "Fragment Identifier" (scroll down to 4.1). So maybe it should be called the "Query Identifier".

Keltex
When I think "ID" (or "Identifier"), I think "unique value that distinguishes one instance of something from another". How does QueryDesignator sound? Is the "ID" language used elsewhere (anywhere) when not uniquely identifying something from another?
lance
@lance. Valid point. I like designator.
Keltex