4

I built a prototype ("one to throw away") a while ago, and I'm rebuilding it now as an alpha. My goodness, it's been worth it.

I reused some of the prototype code by copy-pasting then modifying it, but I've fallen into a pattern of looking at the prototype for guidance, but writing the new code from scratch. This doesn't take too long for me because I'm a pretty fast touch-typist.

Right now I'm rebuilding a complex function, and I'm actually reading it line-by-line and typing equivalent code into my alpha version. I find it's better than copy-paste-refactor because I get reacquainted with the logic, and I don't miss parts of the code when I'm reading it. Is there a name for this kind of reuse? Any authoritative commentary on its benefits/drawbacks?

3 Answers3

7

IMHO the term that matches your activity best is just a rewrite.

This may sound trivial, but some commenters have already used that term, and if you search for the term here on PSE, you will find lots of postings dealing with the question when a rewrite is good or bad, or when you go better with refactoring (which is most times used in opposition to "rewriting" things). See, for example, here:

When is a BIG Rewrite the answer?

Doc Brown
  • 218,378
5

High quality code is typically supposed to be readable, in the sense that reading it is sufficient to understand and (re)use.

Given that your case is rather opposite, it looks like of one the "write-only" variety, in the sense as this term is used in Wikipedia article Write-only language:

In computer humor, a write-only language is a programming language with syntax (or semantics) sufficiently dense and bizarre that any routine of significant size is too difficult to understand by other programmers and cannot be safely edited. Likewise, write-only code is source code so arcane, complex, or ill-structured that it cannot be reliably modified or even comprehended by anyone with the possible exception of the author...

To avoid misunderstanding, above doesn't really prohibit justified compromises. For example, readability can be compromised when performance consideration force that, or code quality can be compromised in favor of fast prototyping / proof of concept development (like it probably was in your case).

gnat
  • 20,543
  • 29
  • 115
  • 306
3

I would call it implementation where basically your prototype acts as the design.

I often do the same, make a prototype and when useful implement that. What I do though is copy the relevant pieces of the source from the prototype, put it in my main source as comment and work from there.

Pieter B
  • 13,310