Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We say that we indent code. I'm writing a string builder which can add/remove tabs to indent code.

Sample:

builder.Add("<ul>");
builder.Indent();
builder.Add("<li></li>");
builder.Dedent(); // <-- what should this be named.
builder.Add("</ul>");   

What should I name the method?

share|improve this question

closed as primarily opinion-based by MichaelT, Thomas Owens May 2 at 12:33

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
It's somewhat off topic but : maybe you could avoid explicitly calling indent/dedent if you replaced Add("<ul>") and Ident() calls by a BeginElement("ul") that would include indent logic. (and also a EndElement method of course) –  David Sep 6 '11 at 7:49
    
@David: +1, but of course you'd want to take inline nested elements into account :) –  Demian Brecht Sep 6 '11 at 8:04
11  
What about outdent? –  Kevin Sep 6 '11 at 8:25
    
@Kevin: Great alternative, but why don't you add it as an answer? –  jgauffin Sep 6 '11 at 8:38
    
@David: It's used inside a framework and not exposed to the user (the class is public though so that user can use it for it's own purposes). Also it can be used for more than just markup, so BeginElement etc isn't appropriate. –  jgauffin Sep 6 '11 at 8:40
show 4 more comments

11 Answers

up vote 23 down vote accepted

Out is the opposite of in, everybody knows this. Why not use Indent() and Outdent()?

share|improve this answer
    
This is what I've always called it at least. –  Callum Rogers Sep 6 '11 at 10:26
    
Same here, I've always heard it called outdent. –  Brian Knoblauch Feb 6 '12 at 19:47
add comment
Indent
Dedent

To back up this, a quick google helps: unindent has 290,000 hits while dedent has 1,920,000 hits, giving a rough indication that the latter one is more widely used. Although this should be used as argument very cautiously.

Dedent is also the standart terminology used in the python docs.

share|improve this answer
2  
In fact "dedent" has only 321,000 hits when you put it in quotes and many of those hits haven't got anything to do with indentation, but are rather names or other things (dentist terms maybe?). "unindent" has 267.000 hits. –  Falcon Sep 6 '11 at 7:48
2  
Dedent is not an actual English word. A good API is clear and easily understood by anyone reading the source (as much as I love Python, this introduced me to a quirk that I'm not fond of at all). Next to each other, this makes sense, but might not otherwise (or to someone who is not quite fluent in English). –  Demian Brecht Sep 6 '11 at 7:54
5  
Well, "outdent" has almost 14 million hits. –  Mike Sherrill 'Cat Recall' Sep 6 '11 at 10:31
2  
@Demian Brecht: It's just a neologism. As a programmer, you're immersed in them daily. Get used to it. –  Jon Purdy Sep 6 '11 at 14:19
1  
@Jon Purdy: I'm quite used to it (been doing this for a while). Still doesn't make it a good idea and doesn't mean that there aren't better alternatives. –  Demian Brecht Sep 6 '11 at 15:28
show 4 more comments

For the opposite of indent, I would use unindent. From Wiktionary:

unindent

Etymology
un- +‎ indent; Originated in the 1980s when computers made it trivial for anyone to move text around on a page.
Verb
unindent (third-person singular simple present unindents, present participle unindenting, simple past and past participle unindented)
1. To remove the indentation; to move a block of text closer to the left margin.
I had to unindent the first line of each paragraph so that my essay would fit onto one side of paper.

According to the Online Etymology Dictionary, indent comes from:

early 15c., indenten/endenten "to make notches; to give (something) a toothed or jagged appearance," also "to make a legal indenture," from O.Fr. endenter "to notch or dent, give a serrated edge to," from M.L. indentare "to furnish with teeth," from in- "into, in, on, upon" (see in- (2)) + L. dens (gen. dentis) "tooth" (see tooth). Related: Indented; indenting. The printing sense is first attested 1670s. The noun is first recorded 1590s, from the verb. An earlier noun sense of "a written agreement" (late 15c.) is described in Middle English Dictionary as "scribal abbrev. of endenture."

So indenting is like to putting a "notch" in the source code. To remove that notch, you undo the indent: unindent.

share|improve this answer
add comment

Don't you mean indent?

Intend means something completely different.

Otherwise, maybe Unindent?

On a side note:

  • Using tabs to indent code is bad (imho) - spaces are more portable.
  • I wouldn't have this API exposed to the client. The builder should be smart enough to know what to and what to not indent.
share|improve this answer
4  
The post by Jeff Atwood doesn't say why using tabs is bad. It just throws out an insult to tab-users at the end. –  Peter Taylor Sep 6 '11 at 7:29
16  
"spaces are more portable": what the heck should that mean?!?!? ...also, I don't agree tabs are bad, actually, I personally find them good. It is cleaner, easier to parse, and enables the user to choose how spacy they should be represented in the view. I don't see any negative downside on them, in contrast to spaces which don't have the previously mentioned advantages. –  arnaud Sep 6 '11 at 7:38
3  
@arnaud: you should read up on tabs vs. spaces. it's largely a religious debate, but in my experiences, spaces have always prevailed (especially if you're working on an OS project or have multiple developers who use different editors). really, at the end of the day, the important thing is consistency. –  Demian Brecht Sep 6 '11 at 7:46
2  
The best is having an editor which automatically put X spaces when you press Tab. –  Jose Faeti Sep 6 '11 at 8:18
2  
@Konrad: Name one editor that does not support tabs? –  Callum Rogers Sep 6 '11 at 13:52
show 11 more comments

What about SetIndentLevel(int level).

Removing an indent is then just setting the level to 0. Afaik there's no term for the opposite of this operation.

share|improve this answer
    
+1 - That's a better approach than two function calls to increment & decrement the indent level. –  mcottle Sep 6 '11 at 7:37
6  
Not sure it's better than 2 methods. Using a setIndentLevel methods means it's your responsibility to remember how deep indentation has gone in case of nested elements in the document. That would mean keeping a counter. No, definitely that should be builder's responsibility, not yours. –  David Sep 6 '11 at 7:46
1  
@David: You can easily create two wrapper methods to keep track of it. In some cases it may be better or easier to use while in other cases its not. With an other interface you'd have to call an increase/decrease method multiple times or in a loop. So I'd probably want all three versions: Set/Increase/Decrease –  Falcon Sep 6 '11 at 8:02
1  
@David setIndentLevel(1 + getIndentLevel()) - the best of both worlds. –  Izkata Jul 20 '13 at 22:45
add comment

The word "indent" doesn't actually mean "insert whitespace" - it means "adjust whitespace so that things line up". As such, indenting can mean both adding or removing tabs; just like there is no opposite to "walk", conceptually speaking there is no opposite to "indent". You can remove indentation, undo the indenting, or change the indentation level, each of which are operations that somehow revert or alter the effects of indenting, in different ways, but none of them is "the" opposite of indenting. The popular "dedent" and "unindent" are wrong the same way as "unwalk" or "defest". (BTW, this might make a good question for english.se)

In your case, I'd go with IncreaseIndentationLevel and DecreaseIndentationLevel.

share|improve this answer
1  
english.se isn't very fond of discussing programming terms. –  jgauffin Sep 6 '11 at 8:15
    
It's more a typesetting term than a programming term, but OK. –  tdammers Sep 6 '11 at 8:28
    
"Indention", not "indentation". –  Mike Sherrill 'Cat Recall' Sep 6 '11 at 10:29
1  
Agreed, "Increase Indent" and "Decrease Indent" are the correct terms, strictly speaking. I would expect that to be language that programmers would use and understand. You do use "negative acceleration" when you talk about bringing your car to a halt, don't you? –  StevenV Sep 6 '11 at 12:46
add comment

I've seen the word "outdent", for example at Wikipedia Template:Outdent page

For outdenting a reply on a talk page when indention gets too deep. Indenting on talk pages is done using a colon character (:) to produce tabs; this template produces a connector bar and initial text to indicate an outdent, based on the number of colons used in the previous indent...

share|improve this answer
add comment

I've seen Dedent in Fowler's book on DSLs.

share|improve this answer
add comment

FWIW Google Docs and MS Word uses "Increase Indent" and "Decrease Indent". I forget which editor (maybe it was TinyMCE, been working with that lately) but I know I once saw "Indent" and "Outdent"

share|improve this answer
add comment

Definition of Indent:

Start (a line of text) or position (a block of text, table, etc.) further from the margin than the main part of the text

There is not really an opposite of this, rather you are indenting the main text further than the specified line.

I think a better term would be RemoveIndent() or ReduceIndent()

Having said that, a google search for the term "opposite of indent" reveals the following term: Outdent. http://www.urbandictionary.com/define.php?term=indent This may also be suitable.

share|improve this answer
    
Outdent is just as ugly as dedent. The "in-" in "indent" is not a prefix, really, replacing it as if it were is an abuse of English grammar. –  tdammers Sep 6 '11 at 7:54
    
@tdammers - in a sense it is. You are denting the paragraph inwards, so the opposite would be to dent it outwards - Outdent. Personally I prefer Remove/ReduceIndent() though for a function name... –  Gavin Coates Sep 6 '11 at 8:07
1  
@tdammers: Apparently the "in-" in indent is a prefix ("into, in, on, upon" – etymonline.com/index.php?term=indent). Not that it matters – I don't see anything "abusive" about folk etymology (en.wikipedia.org/wiki/Folk_etymology); it's part of language evolution. And I disagree that outdent is as ugly as dedent. I'm not even sure which syllable to stress in dedent; it's very ugly either way. But outdent is nice and obvious. It's a perfect complement to indent. The two words create a nice pair that define one another with a very visual contrast. I like it. –  callum Sep 6 '11 at 12:34
    
Sorry, I've just realised I've failed to read this question or its answers properly... I was assuming it was about the automatic display of wrapped lines in a text editor. In which case, outdent (meaning the option of displaying a line further left than the line above it) would be perfect in my opinion. But this question is actually about removing an indent that already exists – like what happens when you press Shift+Tab. In which case, I agree with reduceIndent(), or even unindent(). –  callum Sep 6 '11 at 12:43
    
Did my own research; yes, the "in-" is actually a prefix, but as callum states, "outdent" would mean a line that starts left of the left edge. IIRC, such a thing is called a negative indent in typesetting, not an outdent, and it's not what we're talking about here anyway. –  tdammers Sep 6 '11 at 18:30
add comment

I know I'm a bit late to the party, but just had the same problem finding the opposite for Indent. As here are several different answers to that question, I asked an English colleague (UK) what he would choose: His first tip was IncreaseIndent and DecreaseIndent. But Indent and Detent would also work.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.