93

Sometimes in a programming exercise, boilerplate generation, putting guide rails around the tasks for a junior programmer to implement, etc., it happens that the programmer is presented unimplemented code and told to "fill in the blank." For example, a unit test that may compile, but fails, or a class declaration with empty methods.

Is there a common term for this practice?

3 Answers3

176

You are referring to a stub or skeleton:

Stub

This is typically a method or function with a mostly-empty body that simply returns a dummy value so code will compile.

Skeleton

This is a method that has a high-level algorithm implemented, but individual parts are left unimplemented. They may be empty code blocks, or reference stub methods (see above) that will eventually perform subtasks. This is a good way to express a software design for a junior programmer who may struggle with the larger design effort, or for making sure you have the algorithm correct before investing too much time in the low-level details.


The practice of using these code elements would be called stubbing or creating a code skeleton.

  • 3
    Although I like your terms better, I think that the term 'scaffolding' in Ruby on Rails is the same concept. – dcorking Mar 09 '16 at 13:36
  • I also thought stub was the right word for this, but was not sure because I was getting push back from others at my job. Thank you. – Brandon Arnold Mar 09 '16 at 15:29
  • It's a "stub" if done in an academic context. Done in a professional/commercial context, it's "technical debt". – aroth Mar 10 '16 at 05:09
  • 10
    @aroth it is not technical debt if the code does not work - it must be implemented. Technical debt implies poorly written code that ends up being used in a production environment, meaning it requires significant effort to refactor correctly. A stub would ideally have a failing test case, so it must be implemented and tested before being set loose on production. –  Mar 10 '16 at 05:13
  • 2
    @BrandonArnold: When talking to your colleges, you should use words they understand. Unless you are the boss. – Stig Hemmer Mar 10 '16 at 08:39
  • @StigHemmer Well, if you're in a good working environment, especially when you're the boss :D – Luaan Mar 10 '16 at 13:39
  • @StigHemmer When talking to a stranger, you shouldn't give them social skills advice. Unless they ask you to do so. – Brandon Arnold Mar 10 '16 at 19:41
  • I think skeleton, not stub, matches the meaning OP is asking for. A skeleton is meant to be filled in. A stub is a non-functional implementation that's present to meet an interface requirement that's not actually needed or desired for the program at hand - it's a YAGNI phenomenon. – R.. GitHub STOP HELPING ICE Mar 11 '16 at 01:45
42

I've seen the term “stub” being used.

For example, I believe that Eclipse automatically inserts a comment

String getName() {
    // TODO: Auto-generated method stub
    return null;
}

into its infamous auto-generated, well, stubs.

Also note the usage of the term “stub” in the context of unit testing.

5gon12eder
  • 6,986
  • 2
  • 24
  • 29
17

In Visual Studio, when writing code intellisense will give you the option "generate a new method stub". When you choose this option, Visual Studio will generate a stub/skeleton of code exactly as you have described.

Microsoft refers to this as a stub, so I would also call these stubs.

Snoop
  • 2,748