可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
As I write code from now on, I plan to first lay out everything in beautiful, readable pseudocode and then implement the program around that structure.
If I rank the languages that I currently know from easiest to most difficult to translate, I'd say:
Lisp, Python, Lua, C++, Java, C
I know that each language has its strength and weaknesses but I'm focusing specifically on pseudocode. What language do you use that is best suited for pseudocode-to-code? I always enjoy picking up new languages. Also, if you currently use this technique, I'd love to hear any tips you have about structuring practical pseudocode.
Note: I feel this is subjective but has a clear answer per individual preference. I'm asking this here because the SO community has a very wide audience and is likely to suggest languages and techniques that I would otherwise not encounter.
回答1:
You may be interested in Literate Programming, where the "source code" you write is more like writing a book, but its a book that can be "tangled" into real code or "woven" into formatted documentation.
See the examples provided at http://www.literateprogramming.com/cweb_download.html.
You may also find Eiffel interesting:
"... Eiffel shuns coding tricks or coding techniques intended as optimization hints to the compiler. The aim is not only to make the code more readable, but also to allow programmers to concentrate on the important aspects of a program without getting bogged down in implementation details. ..."
回答2:
I would rate Python first, over Lisp, just because most people don't write pseudocode using the prefix paren syntax :)
回答3:
Pascal was relativery popular in that kind of pseudocode descriptions.
回答4:
I think it depends exactly on the pseudocode flavor. A lot of the pseudocode I've seen in Algorithms text books looks like Pascal ironically. Pascal was always considered a good teaching langauge.
回答5:
Here is a link to what I believe is the first reference to python as "executable pseudo-code." The article is Reprinted from the August 2001 issue of PC Update, the magazine of Melbourne PC User Group, Australia.
回答6:
I've found Boo has become my "pseudocode" language when testing small bits of code for .NET. Very similar to a Python type syntax.
回答7:
You already mentioned it but..
Python has a very clear syntax. It's very close to pseudocode and is easily readable.
回答8:
I think you've got this backwards, kind of. The problem with this question is that you tend to write pseudocode in an approximation of the language that you are planning on using for your actual code. Hands up anyone who wants to create a pseudocode language which (like Esperanto?) is an amalgam of commonly used programming languages.
回答9:
TCL syntax is easily the most like pseudo-code. Commands trump functions for readability and for expressing lower-level operations more typical of assembly code. At the same time, high-level algorithms are also very easy to read. The uniformity of the syntax allows the user to focus on the steps rather than on language artifacts. I would even say that the "expr" keyword for mathematical operations is an advantage, because it clearly delineates the math parts of the program from the algorithmic parts. Fewer symbols are overloaded, and words like "set" are used in their place. This is another win for pseudo-code. More than any other syntax, TCL spans the divide between functional and imperative styles.
回答10:
You can try Flash's Actionscript.
回答11:
I'd say that lua is the best for translation from pseudocode (in most cases). As long as the variables are well named, lua can be easily read by most programmers and its pretty fast as well!
回答12:
I Agree with Nosredna's comment that Ada looks very much like pseudocode.
If you don't mind all the extra typing that Ada requires, I think it's a great language, as the code really does mean what it says.
回答13:
Prolog is something you may not otherwise encounter. It sidesteps the issue of pseudocode all together. In a sense, there is no code. There are only facts and rules.
For example, the append predicate is just things we know about lists, as follows:
Appending a list Y to an empty list yields Y.
append([], Y, Y).
If appending Xs to Ys yields Zs, then we can prepend the same value to Xs and Zs and the relation will still hold.
append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).
We haven't actually written code that does stuff. We've just said what we know about appending lists. But now we can ask Prolog to append 2 lists:
?- append([1,2],[3,4],Z).
Z = [1, 2, 3, 4].
Or give Prolog a list and ask it to show us what lists we could append to get the target list:
?- append(X,Y,[1,2]).
X = [],
Y = [1, 2] ;
X = [1],
Y = [2] ;
X = [1, 2],
Y = [] ;