Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have seen some horrible code in my time including people virtually duplicating the code in comments

// add 4 to x
x+=4;

// for each i in 0 to 9 
for (int i = 0; i < 10; i++) {
    // multiply x by i
    x *= i;
}

Taking this concept further, I'm curious whether prose to code compilers exist.

  • Is there a valid use case for English prose to code?
  • Do compilers exist that do this?

The distinction between this and auto generated code, is that auto generated code is generally always a subset of a project. Can we have complete projects auto generated from english prose?

I realise that this might overlap with the concept of declarative languages.

share|improve this question
1  
This is an odd question. You want to know if there are any, but don't want it for your own use. Is this like poison? Are you going to try to get someone else to use one? –  Matt Ellen Jul 1 '11 at 11:03
    
@Raynos: "curiosity" doesn't make a bad question suddenly good. What is a "comment to code" compiler? What would it do? What are the use cases? What would the inputs be? What would the outputs be? What are you talking about? –  S.Lott Jul 1 '11 at 11:44
    
@S.Lott @MattEllen thanks for your comments, I've cleaned up the question to be significantly more constructive. –  Raynos Jul 1 '11 at 11:48
    
1  
Guess you're going to write a compiler for the DeCSS haiku? www-2.cs.cmu.edu/~dst/DeCSS/Gallery/decss-haiku.txt –  SK-logic Jul 1 '11 at 12:53
show 6 more comments

4 Answers

up vote 7 down vote accepted

There are lots of prose to code compilers. It's even an entire class of tools. They are commonly called "programmers" or "software engineers".

Apart from that, writing software without knowing programming languages (which is what having a prose-to-code compiler would typically attempt to achieve) has fundamental problems. There is an entire field dedicated to dealing with these fundamental problems called Natural Language Processing. The biggest problem is that natural languages are typically extremely ambiguous (even short sentences can have thousands of potential parses).

share|improve this answer
    
Where can I get an automated programmer? One that compiles in minutes rather then months? –  Raynos Jul 1 '11 at 13:03
add comment

Wolfram|Alpha is able to calculate queries written in plain-English, so eventually they may be able to extend that to some more of programming. In general, even if you could get prose to be rigorous enough, it would be much too long, so regular programming would be much more efficient.

share|improve this answer
add comment

Is there a valid use case for English prose to code?

In some domains. For example Inform language for interactive fiction. Example program in Inform 7:

"Hello Deductible" by "I.F. Author"
The story headline is "An Interactive Example".
The Living Room is a room. "A comfortably furnished living room."
The Kitchen is north of the Living Room.
The Front Door is south of the Living Room.
The Front Door is a door. The Front Door is closed and locked.
The insurance salesman is a man in the Living Room. "An insurance salesman in a tacky polyester suit. He seems eager to speak to you." Understand "man" as the insurance salesman.
A briefcase is carried by the insurance salesman. The description is "A slightly worn, black briefcase." Understand "case" as the briefcase.
The insurance paperwork is in the briefcase. The description is "Page after page of small legalese." Understand "papers" or "documents" or "forms" as the paperwork.
Instead of listening to the insurance salesman for the first time:
say "The salesman bores you with a discussion of life insurance policies. From his briefcase he pulls some paperwork which he hands to you.";
move the insurance paperwork to the player.

For general purpose programming, COBOL was attempt to build a language, which would be as close to English prose as possible:

One of the design goals of COBOL was that non-programmers—managers, supervisors, and users—could read and understand the code. This is why COBOL has an English-like syntax and structural elements—including: nouns, verbs, clauses, sentences, sections, and divisions.

share|improve this answer
    
Note that this also means that COBOL code is very easy to read for a non-COBOL programmer. –  user1249 Jul 1 '11 at 13:06
1  
@ThorbjornRavnAndersen if COBOL is so easy to read, why do COBOL programmers get paid so well? –  Raynos Jul 1 '11 at 13:28
    
@Raynos: COBOL is supposed to be easy to read for non-programmers (another thing is it didn't quite achieve that goal). For programmer let's say i++ is easier to read than i + 1 YIELDS i –  vartec Jul 1 '11 at 13:36
1  
@Raynos, there is a vast difference between being able to read existing, working code, and write new code. –  user1249 Jul 1 '11 at 13:51
    
As a professional reader of COBOL code, the bulk of COBOL code written by professionals is opaque. The same would be true of the "comment-to-code" subset of English used by a "comment-to-code compiler". It would be opaque. –  S.Lott Jul 1 '11 at 19:05
add comment

Take a look at cdecl. It is a little tool which can convert C-declarations to English and vice versa. It is not exactly converting any code to English prose, but perhaps the closest you can get.

share|improve this answer
    
I wanted to convert english prose to code ;) It can of course go the other way too. Of course your example is a simple bijection, rather. I.e. C <-> Specific Subset of English. –  Raynos Jul 1 '11 at 12:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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