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
    Sounds to me like you're just refactoring/improving code. The fact that you're using a new inode to do it is irrelevant. – idoby Aug 27 '13 at 12:26
  • 2
    There is no canonical term for rewriting without pasting, but it is a pretty distinct activity from the more common copy+hack until it compiles, and I'm pretty certain that it contributes to maintaining your familiarity with the code much more. (And it isn't limited to programming either. There are whole sections of Shakespeare's plays where he clearly had Holinshed's Chronicles of England, Scotland, and Ireland open on his desk and just versified away - so you're in the very best company!) – Kilian Foth Aug 27 '13 at 12:30
  • 3
    copy-paste-refactor – ratchet freak Aug 27 '13 at 12:36
  • @ratchetfreak - yeah, that's better :) – Excrubulent Aug 27 '13 at 14:44
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?

  • No, it's not really trivial - I was thinking the question itself was kind of trivial, but I figured this is the place for asking questions about fiddly little ideas & practices like this. – Excrubulent Aug 27 '13 at 15:05
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).

  • 2
    +1. I don't see why this got a downvote. If code is not even good enough for copy pasting it, then what you're doing is just a plain old rewrite of bad code. – back2dos Aug 27 '13 at 12:55
  • 2
    Implementation of a proof of concept. Often prototype code isn't good enough for production code, but good enough to prove a concept which you can then implement. – Pieter B Aug 27 '13 at 13:12
  • It was originally written two years ago in Javascript when I was a student - I've improved a lot since then, and ported the code to a more feature-rich language (C#). I'm kind of appalled at some of my design choices. Some were just naive, or rushed, and some were encouraged by the language. I'm amazed I did so little commenting when I knew it would be reviewed by my teacher - I comment more than that now just for myself! – Excrubulent Aug 27 '13 at 14:40
  • @Excrubulent so, you were basically reviewing former, much less experienced self. This happened to me too, and have to admit, in my case "kind of appalled" would be a bit of understatement of what I felt (in my case, it was more like what an idiot wrote that crap:) – gnat Aug 27 '13 at 15:07
  • 2
    @gnat if you didn't feel that way about reviewing your own code, then that would mean you have not grown intellectually. It is a good sign. – emory Aug 27 '13 at 16:53
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.

  • 1
    In software development, implementing/coding is always designing, too, that's why don't feel well with your suggestion. I guess the new implementation is an even better design than the prototype, from what the OP writes his prototype had a very bad design, and now he "does it right". I mean this in the sense of Jack W. Reeves, see here developerdotstar.com/mag/articles/reeves_design_main.html – Doc Brown Aug 27 '13 at 12:57
  • This may be a nice thought experiment, but when I talk to colleagues about designing functionality vs implementing it, the distinction is very clear. – Pieter B Aug 27 '13 at 13:07
  • It's an interesting answer, but I'm much more comfortable with the rewrite term myself. I was leaning towards it while reading the answers/comments. – Excrubulent Aug 27 '13 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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