comparison doc/v2_planning/API_coding_style.txt @ 1170:53340a8df1fa

coding_style: Started to write full code sample
author Olivier Delalleau <delallea@iro>
date Fri, 17 Sep 2010 14:37:00 -0400
parents 4f1b9e0a1377
children fe6c25eb1e37 10bc5ebb5823
comparison
equal deleted inserted replaced
1163:ec1e93663656 1170:53340a8df1fa
446 referring to Pylearn internals. 446 referring to Pylearn internals.
447 447
448 Code Sample 448 Code Sample
449 =========== 449 ===========
450 450
451 The following code sample illustrates many of the coding guidelines one should 451 The following code sample illustrates some of the coding guidelines one should
452 follow in Pylearn. 452 follow in Pylearn. This is still a work-in-progress.
453 453
454 .. code-block:: python 454 .. code-block:: python
455 455
456 #! /usr/env/bin python
457
458 """Sample code. There may still be mistakes / missing elements."""
459
460 __authors__ = "Olivier Delalleau"
461 __copyright__ = "(c) 2010, Universite de Montreal"
462 __license__ = "3-clause BSD License"
463 __contact__ = "Olivier Delalleau <delallea@iro>"
464
465 # Standard library imports are on a single line.
456 import os, sys, time 466 import os, sys, time
467
468 # Third-party imports come after standard library imports, and there is
469 # only one import per line. Imports are sorted lexicographically.
470 import numpy
471 import scipy
472 import theano
473 # Put 'from' imports below.
474 from numpy import argmax
475 from theano import tensor
476
477 # Application-specific imports come last.
478 from pylearn import dataset
479 from pylearn.optimization import minimize
480
481 def print_files_in(directory):
482 """Print the first line of each file in given directory."""
483 # TODO To be continued...
484
485 def main():
486 if len(sys.argv) != 2:
487 # Note: conventions on how to display script documentation and
488 # parse arguments are still to-be-determined.
489 print("""\
490 Usage: %s <directory>
491 Print first line of each file in given directory (in alphabetic order)."""
492 % os.path.basename(sys.argv[0]))
493 return 1
494 print_files_in(sys.argv[1])
495 return 0
496
497 # Top-level executable code should be minimal.
498 if __name__ == '__main__':
499 sys.exit(main())
500
457 501
458 Automatic Code Verification 502 Automatic Code Verification
459 =========================== 503 ===========================
460 504
461 Tools will be available to make it easier to automatically ensure that code 505 Tools will be available to make it easier to automatically ensure that code
470 514
471 Things still missing from this document, being discussed in coding_style.txt: 515 Things still missing from this document, being discussed in coding_style.txt:
472 - Proper style for C code and Mercurial commits 516 - Proper style for C code and Mercurial commits
473 - Enforcing 100% test coverage of the code base 517 - Enforcing 100% test coverage of the code base
474 - Providing ways to add type checking for function arguments 518 - Providing ways to add type checking for function arguments
475 519 - Conventions for script usage documentation and argument parsing
520