Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Re-usable vs Re-editable

npsimons (32752) writes | more than 5 years ago

Programming 1

Given the recent controversy over Prof. Knuth's comments, I'm left pondering one (of many) questions: why can't code be both re-usable and re-editable? (no, I haven't read the article)

Are re-usable and re-editable code fundamentally opposed? Would it just take too much time (or genius) to make code both re-usable and re-editable? Or is Knuth just calling designing for re-usability a waste of time like unit tests?

Given the recent controversy over Prof. Knuth's comments, I'm left pondering one (of many) questions: why can't code be both re-usable and re-editable? (no, I haven't read the article)

Are re-usable and re-editable code fundamentally opposed? Would it just take too much time (or genius) to make code both re-usable and re-editable? Or is Knuth just calling designing for re-usability a waste of time like unit tests?

To me, the re-usableness and re-editableness of code seem orthogonal. You can write code that is re-usable but completely un-editable (it's usually unreadable at that point). If you're writing code properly, it seems to me that re-editable is a given. Re-usable is more difficult to do, but it seems like a good idea, and a best practice that most programmers should try to get into the habit of (just like writing re-editable code).

Maybe I'm just missing something here, but I always aim to make my code re-editable and re-usable, and one doesn't seem to get in the way of the other, other than competing for my time. Thoughts?

cancel ×

1 comment

Sorry! There are no comments related to the filter you selected.

Really ought to read ;) (0)

Anonymous Coward | more than 5 years ago | (#23269616)

If you don't read the article, you probably won't understand Knuth's background, or where he's coming from when he's talking about "re-editable".

Knuth is a big proponent of "literate programming", which is basically about telling a story, and within that story is the code that makes up the application. This can be done for pretty much any mostly-linear application. Take, for instance, e-voting:

1. A person walks into my booth and identifies him or herself as privileged to vote here by providing a code that matches one of the codes that were recently given to me by the master controlling terminal connected on port X.
2. I ask the user whether they would like to vote straight ticket. To keep things moving, I ask them if they want to vote straight ticket Republican, straight ticket Democratic, or if they wish to vote on each race individually. If they choose straight ticket, I select the candidates labeled as Republican or Democratic and go to 4.
3. I display each race from the list of races, and the user selects the candidate that they wish to elect to that position from the list of candidates for that position. I repeat this step until all of the races have been voted for or the user decides to stop and undervote the remaining races.
4. I display the choices the user had selected, and ask them if they wish to make changes or confirm their vote. If they wish to make changes, I will return to step 3.
5. I record the selected candidate for each race by incrementing that candidate's counter in permanent storage.
6. If the printer is enabled, I send the selected candidates to the printer for it to print.
In literate programming, the actual program would start from there, with each of those paragraphs filled out (not replaced) with the actual code to use. Knuth wasn't afraid of GOTO, Knuth didn't care for x=x+1; /* Increase the value of x by 1 */... the narrative the code was within would explain exactly what you were doing. If the code didn't match the narrative, it wasn't the comments that were wrong, it was the code.

So where does re-editing come in? Let's say you decide to re-use some code you had laying around from working on a few other projects:

1. A user logs into the web site.
2. I ask the user whether they would like to vote straight ticket. To keep things moving, I ask them if they want to vote straight ticket Republican, straight ticket Democratic, or if they wish to vote on each race individually. If they choose straight ticket, I assemble the selected product using the list of parts and go to 4.
3. I display each race from the list of races, and the user selects the desired shirt size and color from the available stock for each item. I repeat this step until all of the races have been voted for or the user decides to check out.
4. I display the user's shopping cart, and ask them if they wish to make changes or continue to the checkout page. If they wish to make changes, I will return to step 3.
5. I record the list of pieces used to make the product in order to ensure that they can be reordered when inventory gets low.
6. If the printer is enabled, I send the selected candidates to the printer for it to print.
It loses its meaning. If the meanings don't match, how can one be sure the code does?
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>