r/programming • • Jul 30 '15

Code 'transplant' could revolutionise programming (Wired UK)

http://www.wired.co.uk/news/archive/2015-07/30/code-organ-transplant-software-myscalpel
0 Upvotes

14 comments sorted by

View all comments

22

u/Strilanc Jul 30 '15 edited Jul 30 '15

This article is garbage with no useful details beyond the terminology the researchers happened to use.

That being said, the underlying idea sounds really interesting. Use the implementation of feature X in program A to auto-implement X in another program B. After skimming the actual paper, here's the general idea:

  • The programmer marks the functionality-to-extract in the source program by marking a function with an /* OE */ comment. The function doesn't have to be pure; it can touch globals and have side effects.

  • The programmer annotates an /* IP */ at the desired insertion point in the destination program.

  • There must be a good existing test suite for the destination program's existing features.

  • The programmer must provide new tests that exercise the expected-to-be-inserted functionality in the destination program.

  • The tool tries to make the new tests pass, without breaking the old tests, by adding code at the insertion point. The "extraction point" function acts as a hint / code snippet source to help the process along.

You still have to write the tests, and the code that gets inserted probably isn't very clean, but in the ideal world where this worked perfectly it'd be a nice 2X speedup in dev time. Definitely interesting.

7

u/hu6Bi5To Jul 30 '15

It sounds cool, but I'm still skeptical about the utility of it, and definitely skeptical of any claims of increased productivity as a result of it.

So you need the source code of two pieces of software, in order to move some of A to B. But when would that happen?

  • In the open source world? Not likely, if only because each project is usually one (person/team)'s itch scratcher. Open source is very keen on duplication.

  • A closed source product stealing from open source? More likely... would make it harder to identify where the code came from too.

  • An "enterprise" trying to mangle to systems together after a merger? Hmm, this one is quite likely, I can see this angle taking off!

Still the claims in the original article are highly suspect:

The H.264 codec, which used to be lacking in VLC media player, was transplanted from x264. It took the automated system 26 hours to complete the transplant, while VLC's manual addition of the code happened over a period of 20 days.

Really? You're telling me it takes 20 days to add a new codec to a video player that already supports shedloads of codecs? If that's true that says more about VLC than anything else... but closer look shows that claim to be even worse:

took the automated system 26 hours to complete the transplant

That sounds like the runtime of the system itself. Did it work first time? Did this include all of the identifying and markup required? Did this include writing the additional tests required?

manual addition of the code happened over a period of 20 days

So not 20 person-days, but 20 elapsed days, when the developers could have been working on other things; or waiting for reviews, etc.? It could have easily been less than 26 actual working hours in total then?

It doesn't add up. And even if it did, the end result would be unmaintainable code. If there were a flaw in the original codec, you couldn't just apply a diff, you'd have to re-transplant the codec all over again.

Essentially this is an applied form of Genetic Programming, with all the same advantages and drawbacks of that technique.

1

u/crusoe Jul 31 '15

Would be more useful if it auto generated libraries from marked methods. That's the better way to make shared features. Like a super refactor.

This just sounds like a way to automate spaghetti code generation.

1

u/OneWingedShark Jul 31 '15

This just sounds like a way to automate spaghetti code generation.

We can't do that! Think of all the PHP jobs that will be lost!

0

u/[deleted] Aug 06 '15

[deleted]

1

u/Strilanc Aug 06 '15

Sometimes tests are harder to write, but sometimes they're easier. By allowing you to either ask for what you need or specify how to make it, you can try to always pick the easier route.

Also many programming tasks are ultimately a translation effort from user requests to working code. Since tests (and logic programming in general) are much closer in style to those requests ("it must do X when Y") than to imperative code, the translation should (hopefully, speculatively, with future more powerful tools that are more capable and effective than this one) become easier.