What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

I understand the importance of formatting. The more solidified the format, the more difficult it is to read. So when I need a portion of text that is program related but not code, I tend to use the code block to have it partially stand out.

My question is that correct? Or is it really preference? I want to ensure simplicity for reading and understanding. So I want to get those proper habits going.

Example:

You can implement an Interface by defining one like this:

public interface IName
{
    // Code Here
}

The I tends to go infront of the name to make an Interface stand out when working with it. Keep in mind an Interface doesn't perform any physical logic.

Or should it be more like this:

You can implement an Interface by defining one like this:

public interface IName
{
    // Code Here
}

The I tends to go infront of the name to make an Interface stand out when working with it. Keep in mind an Interface doesn't perform any physical logic.

Or does it even matter, does it just boil down to preference? I'd like to do what is easiest for the community and I'm not quite sure the proper way.

share|improve this question
    
I use it the way you had stated in your example for few things to stand out but I have read quite a few answers on Meta where other users don't like backticks being used on non-code related terms. I guess that it depends on your comfort level of how you want to present the answer. –  user213400 Mar 6 '13 at 18:25
    
@Siva Thank you for clarification. I asked because I saw someone said "By the way you have it, it is hard to read the answer." Which got me thinking am I using it correctly? –  Greg Mar 6 '13 at 18:28
    
So far no one has complained about the formatting that I use in my answers but I am really not the right person to answer your question. I just stated what I have been doing. –  user213400 Mar 6 '13 at 18:30
    
I guess your doing it right then. –  Greg Mar 6 '13 at 18:30

2 Answers 2

up vote 4 down vote accepted

It boils down to preference.

Just make sure you don't use the backticks for non-code terms (not even for coding-related names such as JavaScript or SQL Server). When using an example interface name, backticks are more than fine.

share|improve this answer
    
@Martijin Pieters Thank you for clarification. I asked because I saw someone said "By the way you have it, it is hard to read the answer." Which got me thinking am I using it correctly? –  Greg Mar 6 '13 at 18:28

A good guide is to have you answer look like good documentation:

...
onCreateContextMenu()
From View.OnCreateContextMenuListener. This is called when a Context Menu is being built (as the result of a sustained "long click"). See the discussion on context menus in the Menus developer guide.

These methods are the sole inhabitants of their respective interface. To define one of these methods and handle your events, implement the nested interface in your Activity or define it as an anonymous class. Then, pass an instance of your implementation to the respective View.set...Listener() method. (E.g., call setOnClickListener() and pass it your implementation of the OnClickListener.)

The example below shows how to register an on-click listener for a Button.

// Create an anonymous implementation of OnClickListener
private OnClickListener mCorkyListener = new OnClickListener() {
    public void onClick(View v) {
      // do something when the button is clicked
    }
};
...

Conventions might vary from one language to another, but a common rule of thumb is that code formatting should be used for words from source code: variable names, function names, keywords, etc. In your example, there's even the potential for differentiating usage via formatting:

A Java interface defines the interface via which an object can be manipulated. The name of an interface often starts with 'I', e.g., IOnClickListener, to differentiate them.

share|improve this answer

You must log in to answer this question.

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