Redirected from Algorithms on Wikipedia
This is a draft of hints for good sample implementations of algorithms for Wikipedia. Further discussion is invited.
The main purpose of sample implementations is to help the reader understand the algorithm, not to provide ready-to-use code. Implementations should be easy to read and understand for average programmers or computer science students.
Programming languages which many people use or understand should be used. Suggested languages are C (especially where lower-level features are needed) Java or C++ (especially when demonstrating object-oriented algorithms or patterns), Perl, and Python. Languages with a small user base like Smalltalk or Eiffel are discouraged.
There is some controversy about sample implementations in Ruby and pseudocode. Ruby has an advantage of being very readable and a disadvantage of not being very popular. Some people prefer pseudocode, because an algorithm in pseudocode isn't obfuscated by implementation details. This is a major advantage as compared to some other languages (like C), but is a very small advantage as compared to other languages (like Python and Ruby). Other arguments against pseudocode are that it's not standardized and is hard to test.
Dialects of Pascal and BASIC can have considerable incompatibilities, so if those languages are used, care should be taken to use only their most universal features. It's good to avoid language-specific constructs in examples. For example, Perl code should avoid the use of that language's more unique and unusual features that programmers of other languages may find confusing.
Using iteration is usually preferred over using tail recursion because this is a more popular way of coding and because popular implementations of some languages do not support constant-space tail recursion.
In the case when these hints aren't sufficient to make decisions, it's okay to provide more than one sample implementation.
A list of algorithms is available.
Search Encyclopedia
|
Featured Article
|