Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
dcad80a6
Commit
dcad80a6
authored
Jan 26, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update some things in coding guidelines.
parent
0e201c15
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletions
+38
-1
CODING_GUIDELINES.md
+38
-1
No files found.
CODING_GUIDELINES.md
View file @
dcad80a6
...
...
@@ -180,10 +180,13 @@ Exceptions
In the main body of the code, use typed exceptions where possible:
raise errors.AnsibleError("panic!")
versus:
raise Exception("panic!")
Similarly, exception checking should be fine grained:
...
...
@@ -205,7 +208,41 @@ List Comprehensions
In general list comprehensions are always preferred to map() and filter() calls.
However, they can be abused. Optimize for readability, and avoid nesting them
However, they can be abused. Optimize for readability, and avoid nesting them too deeply.
Regexes
=======
There is a time and place for them, but here's an illustrative joke.
"A developer had a problem, and used a regular expression to solve it. Now the developer had two problems".
Often regexes are difficult to maintain, and a trusty call to "find" can be a great solution!
Find
====
This expression:
if x.find('foo') != -1:
# blarg
Should be written:
if 'foo' in x:
# blarg
String checks
=============
To test if something is a string, consider that it may be unicode.
# no
if type(x) == str:
# yes
if isintance(x, basestr):
Cleverness
==========
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment