|
| 1 | +How to Contribute to aima-python |
| 2 | +========================== |
| 3 | + |
| 4 | +Thanks for considering contributing to `aima-python`! Whether you are an aspiring [Google Summer of Code](https://summerofcode.withgoogle.com/organizations/5663121491361792/) student, or an independent contributor, here is a guide to how you can help: |
| 5 | + |
| 6 | +## Read the Code and Start on an Issue |
| 7 | + |
| 8 | +- First, read and understand the code to get a feel for the extent and the style. |
| 9 | +- Look at the [issues](https://github.com/aimacode/aima-python/issues) and pick one to work on. |
| 10 | +- One of the issues is that some algorithms are missing from the [list of algorithms](https://github.com/aimacode/aima-python/blob/master/README.md#index-of-algorithms). |
| 11 | + |
| 12 | +## Port to Python 3; Pythonic Idioms; py.test |
| 13 | + |
| 14 | +- Check for common problems in [porting to Python 3](http://python3porting.com/problems.html), such as: `print` is now a function; `range` and `map` and other functions no longer produce `list`s; objects of different types can no longer be compared with `<`; strings are now Unicode; it would be nice to move `%` string formating to `.format`; there is a new `next` function for generators; integer division now returns a float; we can now use set literals. |
| 15 | +- Replace old Lisp-based idioms with proper Python idioms. For example, we have many functions that were taken directly from Common Lisp, such as the `every` function: `every(callable, items)` returns true if every element of `items` is callable. This is good Lisp style, but good Python style would be to use `all` and a generator expression: `all(callable(f) for f in items)`. Eventually, fix all calls to these legacy Lisp functions and then remove the functions. |
| 16 | +- Add more tests in `_test.py` files. Strive for terseness; it is ok to group multiple asserts into one `def test_something():` function. Move most tests to `_test.py`, but it is fine to have a single `doctest` example in the docstring of a function in the `.py` file, if the purpose of the doctest is to explain how to use the function, rather than test the implementation. |
| 17 | + |
| 18 | +## New and Improved Algorithms |
| 19 | + |
| 20 | +- Implement functions that were in the third edition of the book but were not yet implemented in the code. Check the [list of pseudocode algorithms (pdf)](https://github.com/aimacode/pseudocode/blob/master/aima3e-algorithms.pdf) to see what's missing. |
| 21 | +- As we finish chapters for the new fourth edition, we will share the new pseudocode in the [`aima-pseudocode`](https://github.com/aimacode/aima-pseudocode) repository, and describe what changes are necessary. |
| 22 | +We hope to have a `algorithm-name.md` file for each algorithm, eventually; it would be great if contributors could add some for the existing algorithms. |
| 23 | +- Give examples of how to use the code in the `.ipynb` file. |
| 24 | + |
| 25 | +We still support a legacy branch, `aima3python2` (for the third edition of the textbook and for Python 2 code). |
| 26 | + |
| 27 | +# Style Guide |
| 28 | + |
| 29 | +There are a few style rules that are unique to this project: |
| 30 | + |
| 31 | +- The first rule is that the code should correspond directly to the pseudocode in the book. When possible this will be almost one-to-one, just allowing for the syntactic differences between Python and pseudocode, and for different library functions. |
| 32 | +- Don't make a function more complicated than the pseudocode in the book, even if the complication would add a nice feature, or give an efficiency gain. Instead, remain faithful to the pseudocode, and if you must, add a new function (not in the book) with the added feature. |
| 33 | +- I use functional programming (functions with no side effects) in many cases, but not exclusively (sometimes classes and/or functions with side effects are used). Let the book's pseudocode be the guide. |
| 34 | + |
| 35 | +Beyond the above rules, we use [Pep 8](https://www.python.org/dev/peps/pep-0008), with a few minor exceptions: |
| 36 | + |
| 37 | +- I have set `--max-line-length 100`, not 79. |
| 38 | +- You don't need two spaces after a sentence-ending period. |
| 39 | +- Strunk and White is [not a good guide for English](http://chronicle.com/article/50-Years-of-Stupid-Grammar/25497). |
| 40 | +- I prefer more concise docstrings; I don't follow [Pep 257](https://www.python.org/dev/peps/pep-0257/). In most cases, |
| 41 | +a one-line docstring suffices. It is rarely necessary to list what each argument does; the name of the argument usually is enough. |
| 42 | +- Not all constants have to be UPPERCASE. |
| 43 | +- At some point I may add [Pep 484](https://www.python.org/dev/peps/pep-0484/) type annotations, but I think I'll hold off for now; |
| 44 | + I want to get more experience with them, and some people may still be in Python 3.4. |
| 45 | + |
| 46 | + |
| 47 | +Contributing a Patch |
| 48 | +==================== |
| 49 | + |
| 50 | +1. Submit an issue describing your proposed change to the repo in question (or work on an existing issue). |
| 51 | +1. The repo owner will respond to your issue promptly. |
| 52 | +1. Fork the desired repo, develop and test your code changes. |
| 53 | +1. Submit a pull request. |
| 54 | + |
| 55 | +Reporting Issues |
| 56 | +================ |
| 57 | + |
| 58 | +- Under which versions of Python does this happen? |
| 59 | + |
| 60 | +- Is anybody working on this? |
| 61 | + |
| 62 | +Patch Rules |
| 63 | +=========== |
| 64 | + |
| 65 | +- Ensure that the patch is python 3.4 compliant. |
| 66 | + |
| 67 | +- Include tests if your patch is supposed to solve a bug, and explain |
| 68 | + clearly under which circumstances the bug happens. Make sure the test fails |
| 69 | + without your patch. |
| 70 | + |
| 71 | +- Follow the style guidelines described above. |
| 72 | + |
| 73 | +Running the Test-Suite |
| 74 | +===================== |
| 75 | + |
| 76 | +The minimal requirement for running the testsuite is ``py.test``. You can |
| 77 | +install it with:: |
| 78 | + |
| 79 | + pip install pytest |
| 80 | + |
| 81 | +Clone this repository:: |
| 82 | + |
| 83 | + git clone https://github.com/aimacode/aima-python.git |
| 84 | + |
| 85 | +Fetch the aima-data submodule:: |
| 86 | + |
| 87 | + cd aima-python |
| 88 | + git submodule init |
| 89 | + git submodule update |
| 90 | + |
| 91 | +Then you can run the testsuite with:: |
| 92 | + |
| 93 | + py.test |
| 94 | + |
| 95 | +# Choice of Programming Languages |
| 96 | + |
| 97 | +Are we right to concentrate on Java and Python versions of the code? I think so; both languages are popular; Java is |
| 98 | +fast enough for our purposes, and has reasonable type declarations (but can be verbose); Python is popular and has a very direct mapping to the pseudocode in the book (but lacks type declarations and can be slow). The [TIOBE Index](http://www.tiobe.com/tiobe_index) says the top seven most popular languages, in order, are: |
| 99 | + |
| 100 | + Java, C, C++, C#, Python, PHP, Javascript |
| 101 | + |
| 102 | +So it might be reasonable to also support C++/C# at some point in the future. It might also be reasonable to support a language that combines the terse readability of Python with the type safety and speed of Java; perhaps Go or Julia. I see no reason to support PHP. Javascript is the language of the browser; it would be nice to have code that runs in the browser without need for any downloads; this would be in Javascript or a variant such as Typescript. |
| 103 | + |
| 104 | +There is also a `aima-lisp` project; in 1995 when we wrote the first edition of the book, Lisp was the right choice, but today it is less popular (currently #31 on the TIOBE index). |
| 105 | + |
| 106 | +What languages are instructors recommending for their AI class? To get an approximate idea, I gave the query <tt>[\[norvig russell "Modern Approach"\]](https://www.google.com/webhp#q=russell%20norvig%20%22modern%20approach%22%20java)</tt> along with the names of various languages and looked at the estimated counts of results on |
| 107 | +various dates. However, I don't have much confidence in these figures... |
| 108 | + |
| 109 | +|Language |2004 |2005 |2007 |2010 |2016 | |
| 110 | +|-------- |----: |----: |----: |----: |----: | |
| 111 | +|[none](http://www.google.com/search?q=norvig+russell+%22Modern+Approach%22)|8,080|20,100|75,200|150,000|132,000| |
| 112 | +|[java](http://www.google.com/search?q=java+norvig+russell+%22Modern+Approach%22)|1,990|4,930|44,200|37,000|50,000| |
| 113 | +|[c++](http://www.google.com/search?q=c%2B%2B+norvig+russell+%22Modern+Approach%22)|875|1,820|35,300|105,000|35,000| |
| 114 | +|[lisp](http://www.google.com/search?q=lisp+norvig+russell+%22Modern+Approach%22)|844|974|30,100|19,000|14,000| |
| 115 | +|[prolog](http://www.google.com/search?q=prolog+norvig+russell+%22Modern+Approach%22)|789|2,010|23,200|17,000|16,000| |
| 116 | +|[python](http://www.google.com/search?q=python+norvig+russell+%22Modern+Approach%22)|785|1,240|18,400|11,000|12,000| |
0 commit comments