开发者

What programming language is the most English-like? [closed]

开发者 https://www.devze.com 2023-01-04 02:24 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

I'm mainly a Python progra开发者_C百科mmer, and it is often described as being "executable pseudo-code". I have used a little bit of AppleScript, which seems to be the most English-like programming language I have ever seen, because almost operators can be words, and it lets you use "the" anywhere (for example, this stupid example I just came up with:

set the firstnumber to 1
set the secondnumber to 2
if the firstnumber is equal to the secondnumber then 
    set the sum to 5
end if

is a valid AppleScript program. Are there any programming languages that are even more English-like than these?


If you mean inconsistent in application of rules with lots of bizarre edge cases and sharp corners to injure the learner, there's very few programming languages more English-like than C++.


The Shakespeare answer reminded me of Inform 7, which is a serious programming language for writing interactive fiction. It's probably the language most closest to English that exists and has a well-defined semantics.

Here is a sample from Wikipedia:

"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.

The sample uses an extensive library of objects which is available for user. But the language itself is in fact Turing complete, and you can define objects with any behaviour in it.


At the risk of being a raging finger-wagger: I claim that natural-language-like is a bad goal for programming languages. Specifically, the goal of a natural language utterance is to influence the world so that other human beings want to kiss you rather than punch you; this is very different from the goal of a programming language utterance, which is intended as an unambiguous statement in a well-defined domain that a computer or another person can evaluate. A better question might be: which programming language makes it most difficult to accidentally shoot yourself in the foot?

... which is not at all what you asked, of course.


COBOL was always considered pretty "natural language". Here's an extract from the 99 bottles of beer page:

move spaces to buffer bb1                                 
move 1 to j                                               
divide i by 10 giving k remainder l                       
string bb8(k + 1) delimited space into bb1 pointer j      
if j > 1                                                  
   then move bb7(l + 1) to bb1(j + 1:)                    
   else move bb7(i + 1) to bb1                            
end-if

Of course, "natural language" is not always (often?) a virtue amoung programming languages, where preciseness is the order of the day (and natural language is almost always ambiguous - adding the preciseness required by a programming languages just makes it verbose).


How about the Shakesspeare programming language. Here's a part of the "hello world" source, out of wikipedia:

               Act I: Hamlet's insults and flattery.
               Scene I: The insulting of Romeo.

[Enter Hamlet and Romeo]
Hamlet:
You lying stupid fatherless big smelly half-witted coward! You are as
stupid as the difference between a handsome rich brave hero and thyself!
Speak your mind!
You are as brave as the sum of your fat little stuffed misused dusty
old rotten codpiece and a beautiful fair warm peaceful sunny summer's
day. You are as healthy as the difference between the sum of the
sweetest reddest rose and my father and yourself! Speak your mind!
You are as cowardly as the sum of yourself and the difference
between a big mighty proud kingdom and a horse. Speak your mind.
Speak your mind!
[Exit Romeo]

Seems like code highlighting doesn't work here. :/


VB.NET (though your AppleScript example beats VB.NET), SQL or COBOL (the source of this style). Lolcode is "language"-like but I'm glad English isn't like it.

VB.NET

If MsgBox("The process will be started", MsgBoxStyle.OkCancel, "Title") = DialogResult.OK Then 
   'ok was clicked
Else
  'cancel was clicked
 End If

COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
    RECORD CONTAINS 55 CHARACTERS
    DISPLAY 'Hello, world'.
    STOP RUN.

SQL

SELECT * 
    FROM Book
    WHERE price > 100.00
    ORDER BY title;

Lolcode

ON CATURDAY
    IM IN YR BED
        I IZ SLEEPIN!!10
        VISIBLE "Z!"
    KTHX
KTHXBYE


After reviewing all the answers, I'm convinced that AppleScript actually is the most natural language like.


Have you heard about Supernova. It's a natural programming language. Even you can create a window in Supernova by just saying I want window and the window title is hello.


I hate to plug my own stuff (well not really) but 7Basic has a pretty english-like syntax:

BEGIN FUNCTION (variable AS INTEGER) AS STRING
    PRINT "Hello!"

    RETURN "return value!"
END FUNCTION


I think a discussion of where Dijkstra-like programmatic precision is necessary vs where it is not would be interesting. In lower level programming where detail is needed, so is precision. As programming primitives are higher level, perhaps not so much ...


Maybe Common Lisp? Macros in Lisp allow you to define abstractions as "new words". That's as close to pseudocode or English as you want to get (because when describing program in our thoughts or discussions, we use a lot of abstractions from the mechanics of particular language).

An interesting example are anaphoric macros, which Paul Graham describes in his book On Lisp. Anaphoric macro is a macro that binds some expression to the symbol "it" inside it's body, so we can easily refer to it:

(aif (get-data) (do-something it)) 

In this line, the get-data is function which either returs some object or nil. If it returns the data, they are bind to "it" variable, which is the processed by "do-something" function. If the data returned are nil, the condition is not satisfied and the clause is not executed.

There are many other examples of anaphoric macros, like for loops, that bind the loop variable, and so on. In fact, you can even have macros that generate anaphoric macros for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消