Is there a human readable programming language? [c

2019-01-29 20:07发布

I mean, is there a coded language with human style coding? For example:

Create an object called MyVar and initialize it to 10;
Take MyVar and call MyMethod() with parameters. . .

I know it's not so useful, but it can be interesting to create such a grammar.

标签: nlp grammar
30条回答
Explosion°爆炸
2楼-- · 2019-01-29 20:15

Being more human-readable than most was one of the early selling points of Ada. I find it a silly argument these days, as any sufficently complex task in any language is going to require a competent practicioner to understand. However, it does beat the bejeezus out of C-syntax languages. Its dominant coding styles can enhance this effect too. For example, comparing loops in an if statement: Ada:

if Time_To_Loop then
   for i in Some_Array loop
      Some_Array(i) := i;
   end loop;
end if;

C:

if (timeToLoop != 0) {
   for (int i=0;i<SOME_ARRAY_LENGTH;i++) {
      someArray[i] = i;
   }
}

The C code would look even worse if I used Hungarian notation like Microsoft, but I'm trying to be nice. :-)

查看更多
我命由我不由天
3楼-- · 2019-01-29 20:16

HyperTalk and its descendant AppleScript were designed to be similar to the English language.

查看更多
Evening l夕情丶
4楼-- · 2019-01-29 20:17

COBOL is a lot like that.

SET MYVAR TO 10.
EXECUTE MYMETHOD with 10, MYVAR.

Another sample from Wikipedia:

ADD YEARS TO AGE.
MULTIPLY PRICE BY QUANTITY GIVING COST.
SUBTRACT DISCOUNT FROM COST GIVING FINAL-COST.

Oddly enough though, despite its design to be readable as English, most programmers completely undermined this with bizarre naming conventions:

SET VAR_00_MYVAR_PIC99 TO 10.
EXECUTE PROC_10_MYMETHOD with 10, VAR_00_MYVAR_PIC99.
查看更多
太酷不给撩
5楼-- · 2019-01-29 20:17

GradStudent

It only has one statement: "you - write me a program to do x"
It's valid for all values of X and has the advantage that x doesn't have to be defined and can be changed after the program is written.

A commercial dialect is available called intern: development cost is lower but it isn't guaranteed to work

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-29 20:18

Inform 7

Inform 7 is perhaps the language I feel is most appropriately designed in a human language fashion. It is quite application specific for writing adventure games.

It is based on rule-based semantics, where you write a lot of rules describing the relationship between objects and their location. For instance, the section below is an Inform 7 program:

"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. The description is "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: 
    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.

Example cited from Wikipedia

查看更多
再贱就再见
7楼-- · 2019-01-29 20:18

Sure, Erlang.

-module(listsort).
-export([by_length/1]).

 by_length(Lists) ->
    F = fun(A,B) when is_list(A), is_list(B) ->
            length(A) < length(B)
        end,
    qsort(Lists, F).

 qsort([], _)-> [];
 qsort([Pivot|Rest], Smaller) ->
     qsort([ X || X <- Rest, Smaller(X,Pivot)], Smaller)
     ++ [Pivot] ++
     qsort([ Y ||Y <- Rest, not(Smaller(Y, Pivot))], Smaller).

I'm a human, it's a programming language, and I can read it. I don't know what any of it means, but I see a lot of English words in there, I think.

(Tongue firmly in cheek.)

查看更多
登录 后发表回答