In colleges and in algorithm textbooks, it is quite common for the teacher and author to explain control flow in pseudo-code. With the advent of more expressive languages like Python and Haskell among others, is it reasonable that colleges switch to explain algorithms via one of these languages?
The only advantage of pseudo-code I can think of is that it's purportedly language-agnostic. But it is not. Some pseudo-code uses an imperative approach, other pseudo-code looks functional. Authors just borrow semantics from whatever programming language they are comfortable using, or worse just describe the semantics in natural language. So if pseudo-code isn't actually language-agnostic, what is the advantage of using it then? Wouldn't it be better to just use an existing language?
No. The point of pseudo-code is that it doesn't have to compile. I can quickly gloss over irrelevant details. In contrast, even languages that look like pseudocode at the first glance can have very non-intuitive details that would just detract from the algorithm. Let's take for example Quicksort in Haskell:
The advantage in both cases is that this is executable code, and as such can be tested, typechecked, and toyed with by students. However, they both include syntactic details that are distracting. Students would usually be better served by pseudocode that illustrates the intention of the algorithm, not implementation details:
The entire purpose of pseudo-code is to abstract away the details and complexities of individual languages so that you focus on what the program's supposed to do, rather than how it does it. With pseudo-code you can make up arbitrary rules that do not need to conform to actual implementation requirements the way that real-world languages do, but only to the requirements of the actual topic at hand.
Furthermore, if the logic is presented in a way that you (as the student) can't just copy/paste into a file, compile it and be done, then you are forced to implement the solution yourself even when the solution itself is described for you. This encourages individual thought over copy/paste cheating.
A simple VENN Diagram can highlight the problem easily. The set of all humans that are English And Mandarin Speakers is the subset of English Or Mandarin Speakers. Because it takes effort to obtain proficiency in any language the intersection is generally much smaller than the union.
The textbook on programming can presume that you understand at least one natural language, the language the textbook is written in. Its generally safe to presume this, as otherwise a different more legible textbook would have been selected. After all learning one language is difficult enough - two is harder.
This gives the first reason for using a pseudo code. It maximises the audience that could easily read the book. This is done by following established language conventions already found in the natural language. Say recipes from cooking, mathematical formulas, etc... Any gap can be bridged by a quick natural language explanation, or failing that a final recourse to our visual system with pictures.
As for why the common language could not be the programming language. I leave to you to consider how much Mandarin (or any language you do not already speak) you have learned by reading a book about programming written with examples given in a familiar programming language.
Most of this has nothing to do with the machines themselves, its mostly a discussion on how meat-ware should operate in order to bring about a program. That's pretty complex because it has to show why we would link our human space goals, to program space problems and strive to solve them.
The second textbook achievement is describing a Language. Now most programming languages can be described with a Grammar and a few semantic rules. On the shallow end are languages like JSON which can be defined fairly completely within three or so pages. More complex languages need a larger specification, but for the most part do not need a total understanding in order to be useful. What these descriptions are however are Pseudo Code. They specify the formal language in terms of a natural language. The difference is that these pseudo codes are specified in advance.
However, I'd also warn any authors and readers that when used in this context, this should be pseudo-version of the real language, and authors should be mindful not to be too strict about following the syntax and limitations of the language. Instead, authors should think carefully about what is it they're trying to communicate with the snippet, and hide irrelevant details behind function calls and/or comments rather than striving for a full, actually compilable implementation or code that's idiomatic for the chosen base language.
Authors should take some creative liberty on the language to get their point across so that even someone who knows just the basics of the language can still understand the gist of the snippet, while those seeking more exact semantic can refer to the language's documentation or fallback to their prior knowledge about the language to fill in the details.
Computer programs are written for machine reading. We have to write them in a certain format which will be compiled for the machine to understand. But often those written codes are not easy to follow for people other than programmers. In order to show those codes in an informal way so that humans can also understand, we prepare pseudocode. Though it is not an actual programming language code, pseudocode has similar structural conventions of a programming language. Since pseudocode does not run as a real program, there is no standard way of writing a pseudocode. We can follow our own way of writing a pseudocode.
Now, let us examine the pseudocode we have written. We are supplying a list of books and a name that we are searching. We are running a foreach loop to iterate each of the books and matching with the book name we are searching. If it is found, we are returning the position of the book where we found it, false otherwise. So, we have written a pseudocode to find a book name from our book list. But what about the other remaining books? How do we continue our search till all books are found and placed on the right shelf?:
Now we have the complete pseudocode for our algorithm of solving the book organization problem. Here, we are going through the list of ordered books and finding the book in the delivered section. If the book is found, we are removing it from the list and placing it to the right shelf.
This simple approach of writing pseudocode can help us solve more complex problems in a structured manner. Since pseudocodes are independent of programming languages and platforms, algorithms are expressed as pseudocode most of the time.
Let us now understand what is happening in the preceding code. First we have defined a new function, findABook at the beginning of the code. The function is defined with two parameters. One is Array $bookList and the other is String $bookName. At the beginning of the function we are initializing the $found to FALSE, which means nothing has been found yet. The foreach loop iterates through the book list array $bookList and for each book, it matches with our provided book name $bookName. If the book name that we are looking for matches with the book in the $bookList, we are assigning the index (where we found the match) to our $found variable. Since we have found it, there is no point in continuing the loop. So, we have used the break command to get out of the loop. Just out of the loop we are returning our $found variable. If the book was found, usually $found will return any integer value greater than 0, else it will return false:
This particular function placeAllBooks actually iterates through our ordered books $orderedBooks. We are iterating our ordered book list and searching each book in our delivered list using the findABook function. If the book is found in the ordered list ($bookFound !== FALSE), we are removing that book from the delivered book list using the array_splice() function of PHP:
These two lines actually shows two PHP arrays which are used for the list of books we have received, $bookList and the list of books we have actually ordered $orderedBooks. We are just using some dummy data to test our implemented code as shown:
The last part of our code actually calls the function placeAllBooks to perform the whole operation of checking each book searching for it in our received books and removing it, if it is in the list. So basically, we have implemented our pseudocode to an actual PHP code which we can use to solve our problem.
In computer science, pseudocode is a description of the steps in an algorithm using a mix of conventions of programming languages (like assignment operator, conditional operator, loop) with informal, usually self-explanatory, notation of actions and conditions.[1][2] Although pseudocode shares features with regular programming languages, it is intended for human reading rather than machine control. Pseudocode typically omits details that are essential for machine implementation of the algorithm. The programming language is augmented with natural language description details, where convenient, or with compact mathematical notation. The purpose of using pseudocode is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and scientific publications to document algorithms and in planning of software and other algorithms.
No broad standard for pseudocode syntax exists, as a program in pseudocode is not an executable program; however, certain limited standards exist (such as for academic assessment). Pseudocode resembles skeleton programs, which can be compiled without errors. Flowcharts, drakon-charts and Unified Modelling Language (UML) charts can be thought of as a graphical alternative to pseudocode, but need more space on paper. Languages such as HAGGIS bridge the gap between pseudocode and code written in programming languages.
b37509886e