Skip to content

reapply some improvements to code style section in different branch #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/writing/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ One statement per line

While some compound statements such as list comprehensions are
allowed and appreciated for their brevity and their expressiveness,
it is bad practice to have two disjoint statements on the same line.
it is bad practice to have two disjoint statements on the same line of code.

**Bad**

Expand Down Expand Up @@ -86,7 +86,7 @@ Function arguments

Arguments can be passed to functions in four different ways.

**Positional arguments** are mandatory and have no default values. They are the
1. **Positional arguments** are mandatory and have no default values. They are the
simplest form of arguments and they can be used for the few function arguments
that are fully part of the functions meaning and their order is natural. For
instance, in ``send(message, recipient)`` or ``point(x, y)`` the user of the
Expand All @@ -99,7 +99,7 @@ and, doing so, it is possible to switch the order of arguments, calling for inst
reduces readability and is unnecessarily verbose, compared to the more straightforward
calls to ``send('Hello', 'World')`` and ``point(1, 2)``.

**Keyword arguments** are not mandatory and have default values. They are often
2. **Keyword arguments** are not mandatory and have default values. They are often
used for optional parameters sent to the function. When a function has more than
two or three positional parameters, its signature will be more difficult to remember
and using keyword argument with default values is helpful. For instance, a more
Expand All @@ -121,7 +121,7 @@ principle, it is often harder to remove an optional argument (and its logic insi
function) that was added "just in case" and is seemingly never used, than to add a
new optional argument and its logic when needed.

The **arbitrary argument list** is the third way to pass arguments to a
3. The **arbitrary argument list** is the third way to pass arguments to a
function. If the function intention is better expressed by a signature with an
extensible number of positional arguments, it can be defined with the ``*args``
constructs. In the function body, ``args`` will be a tuple of all the
Expand All @@ -139,7 +139,7 @@ it explicitly: ``send(message, recipients)`` and call it with ``send('Hello',
the recipient list as a list beforehand, and it opens the possibility to pass
any sequence, including iterators, that cannot be unpacked as other sequences.

The **arbitrary keyword argument dictionary** is the last way to pass arguments
4. The **arbitrary keyword argument dictionary** is the last way to pass arguments
to functions. If the function requires an undetermined series of named
arguments, it is possible to use the ``**kwargs`` construct. In the function
body, ``kwargs`` will be a dictionary of all the passed named arguments that
Expand All @@ -166,9 +166,13 @@ Avoid the magical wand

A powerful tool for hackers, Python comes with a very rich set of hooks and
tools allowing to do almost any kind of tricky tricks. For instance, it is
possible to change how objects are created and instantiated, it is possible to
change how the Python interpreter imports modules, it is even possible (and
recommended if needed) to embed C routines in Python.
possible to do each of the following:

* change how objects are created and instantiated

* change how the Python interpreter imports modules

* it is even possible (and recommended if needed) to embed C routines in Python.

However, all these options have many drawbacks and it is always better to use
the most straightforward way to achieve your goal. The main drawback is that
Expand All @@ -181,7 +185,7 @@ way. However, knowing how to use them and particularly when **not** to use
them is the most important.

Like a Kungfu master, a Pythonista knows how to kill with a single finger, and
never to do it.
never to actually do it.

We are all consenting adults
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down