tags:

views:

573

answers:

12

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  A: 

I've found Boo has become my "pseudocode" language when testing small bits of code for .NET. Very similar to a Python type syntax.

JTA
+10  A: 

I would rate Python first, over Lisp, just because most people don't write pseudocode using the prefix paren syntax :)

pgb
To be honest I've never written pseudocode in Lisp. I can just imagine how great it would be though, since I can pretty much write anything I want and turn it all into macros later.
Kai
I must agree with Kai. I've never ever seen pseudocode written in anything like Lisp (though, there aren't that many things that resemble Lisp in this world :-) They also say pseudocode is ment for human reading - I don't thing that many people could easily follow Lisp.
ldigas
Sounds like you agree with pgb to me :) Lisp is hard to swallow if the programs get too large, but its not meant for large team-oriented programming anyway. To the person who writes the code it tends to look much less confusing and my thoughts really flow when I do Lisp.
Kai
I remember a class I took at uni; our tutor gave us a sample of pseudocode and asked us to write it in our favourite programming language. I walked up to the board, added colons to the end of two lines, and sat down. "Oh... right... Python" our tutor remarked in a dry voice :-P
Smashery
+1  A: 

You already mentioned it but..

Python has a very clear syntax. It's very close to pseudocode and is easily readable.

GuiSim
I beg to differ. Python maybe has a clean syntax, but it is not fit that well as pseudocode. For pseudocode must be easily translatable into your language of choice, and python depends a lot on the back end libs, therefore translating it into some other language could prove difficult. It is better when writing pseudocode a language that has very little "in behind". Of course, all this is just IMHO.
ldigas
+3  A: 

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.

kmorris511
Beat me by a few seconds. Yes, expecially amongst mathematicians - most pseudocode I find when talking with them nowadays still looks like Pascal.
ldigas
+5  A: 

Pascal was relativery popular in that kind of pseudocode descriptions.

ldigas
+5  A: 

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

Bert F
Very interesting! I'll look into these for sure.
Kai
A: 

You can try Flash's Actionscript.

A: 

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!

RCIX
+2  A: 

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.

Soldier.moth
A: 

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.

dsteele
A: 

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.

marcush
+1  A: 

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 = [] ;
z5h