-3

This might be (or seem to be) a minor question. But it might also have a considerable impact on searchability.

Is there any consensus about how class- or method names should be written in the title of a question?

Updated, to justify this question, partially in response to the comments:

There may have been doubts that this is relevant, so here is an example that shows the difference: When entering "table view cell image is" as a (partial) title for a new question, then the results are the shown in the "Similar Questions" popup are completely different than those that appear when entering "tableViewCell image is". So the whether class names in the title are spelled as individual words or written in CamelCase obviously does have an effect.


Further examples could be whether it is preferable to write

How to set the kernel initializer for a keras layer?

or whether the specific entity (which is a kernel_initializer) should be written using snake_case:

How to set the kernel_initializer for a keras layer?

One could even go so far to include the specific class name, like this:

How to assign a color to a UITableViewCell?

Even if it may look ugly or less readable at the first glance, it might have a positive effect on searchability.

Note that I don't propose any solution here. This this is really about whether the community prefers one or the other style, or whether there any real technical pros and cons. For example, I could imagine that it is easier to match a search query like "table view cell" against the word "tableViewCell", via some sub-word-matching, than to match a query like "tableViewCell" against the words "table view cell": There is no reasonable way to tokenize the word "tableviewcell" so that the tokens can match the individual words...


I recently saw an edit in the review queue where someone essentially (mainly) replaced the words "table view cell" in a question title with "tableViewCell". I wasn't sure whether this is an edit that is worth being accepted or whether it might even have a negative effect. That's one of the reasons of why I'm bringing this up here.

6
  • I don't think labeling questions with classes like tableview to UITableView and tableViewCell to UITableViewCell helps the search engine. If you have evidence that it improves then do mention it
    – weegee
    Aug 10, 2019 at 14:28
  • Downvotes on meta are different. They don't indicate that your question is badly formatted or they affect your reputation. They just indicate that people don't like your idea or disagree with your question.
    – weegee
    Aug 10, 2019 at 14:33
  • What puts users off is probably the phrase formatting ... in titles as there is no formatting in titles. Maybe better is: "How should class or method names be spelled". And then overall: assume we agree on what is "best" what are you/we supposed to do with that consensus? Edit all titles? Tell users to update their questions with a link to this post? Ask SE to better handle technical terms for searchability? Something else?
    – rene
    Aug 10, 2019 at 15:02
  • @rene Yes, I hesitated with "formatting" (we don't want markdown in titles, for sure). But "spelling" doesn't seem to capture it either (they should be spelled correctly :-/). Do you think that "What are the coding/naming conventions..." could do it? (I'll address the other points in an edit)
    – Marco13
    Aug 10, 2019 at 15:09
  • I'm not a native speaker so I wouldn't rely too much on my gut feeling but conventions has a better ring to it then formatting.
    – rene
    Aug 10, 2019 at 15:18
  • @rene I went for "conventions" now, because it more closely resembles "coding conventions" and thus might be less ambiguous. I also addressed the question about "What to do with this consensus?": For me, it will at least have an effect on whether I accept EDITs in the review queue that (only) change the title according to one form to the other...
    – Marco13
    Aug 10, 2019 at 15:31

1 Answer 1

4

There may be cases where one option is better than the other but it is highly dependent on context. I don't think it can be boiled down to a simple, concrete, and generally applicable rule.

Are there any real technical pros and cons? Or is this entirely subjective, to be decided on a CaseToCase_basis?

Both. There are technical constraints, but the technical constraints do not always entail that there is a single correct way to do it.

For instance, if you are asking for help about a project produced by others, the choice between snake_case and CamelCase has already been made, and this should constrain how you refer to identifiers defined in the project. If the project you refer to uses kernel_initializer as an identifier, and you want to refer to that specific identifier, then don't change the convention that the authors of the project used to name their variable.

However, I don't see much value in generally insisting that people use an identifier instead of the name of the concept they are referring to.

For instance, a question about alternating the styles of rows in an HTML table could go:

How can I alternate table row styles?

How can I alternate tr styles?

How can I alternate HTMLTableRowElement styles?

In isolation, the first title does not make it clear that HTML tables are the topic but the tag fixes that. Searches that pertain only to HTML tables can use that tag to find relevant questions. For the example I gave above, I'd say between tr and HTMLTableRowElement, tr seems to be the identifier that would generally be the most appropriate, seeing 99% of the time the issue is how to setup a proper CSS stylesheet, and CSS refers to table rows as tr, not HTMLTableRowElement. Then again, there can be exceptions. For instance, there could be a question where the OP needs to add the style at run time, uses TypeScript and there's a typing problem that the OP is facing, in which case HTMLTableRowElement would be the appropriate focus of the question rather than tr.

Having a requirement that identifiers must be used can even have perverse effects in some cases. The HTML identifier for a paragraph is p. I tried a few searches. What I got varied a lot depending on what keywords were used alongside "p", but I got some results where the hits for "p" were mostly garbage. The problem that p is a stock element likely to appear in just about any HTML example, even those that don't focus on paragraphs. Doing the same search with the word "paragraph" was more likely to produce relevant hits, probably because authors who are having trouble with p specifically are more likely to say "paragraph" in their question.


There may have been doubts that this is relevant, so here is an example that shows the difference: When entering "table view cell image is" as a (partial) title for a new question, then the results are the shown in the "Similar Questions" popup are completely different than those that appear when entering "tableViewCell image is". So the whether class names in the title are spelled as individual words or written in CamelCase obviously does have an effect.

I see this search as a last ditch effort on the part of the site to get the OP to consider that maybe the question has been answered. It is not perfect, but I don't think its imperfections should start determining how we write. The result list is severely truncated and is ordered by relevance, so it does not take a lot of change to the title to get lists of results that don't overlap.

1
  • (Sorry for the edit that I did in parallel, in response to the comments - the core should remain the same, though). Sure, there's probably no one-fits-all solution, and the examples of tr and p are probably extreme: These are not words, and thus, notoriously difficult to handle in search queries anyhow. Sometimes, "Common Sense©" can help, e.g. calling a "button" a "JButton" will make clear that it's Java/Swing. As such, the more specific question is whether to prefer "camel case word" or "CamelCaseWord" (also, whether a corresponding EDIT should be accepted)
    – Marco13
    Aug 10, 2019 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .