Friday, 10 August 2012

Python Code Design Descipline

We can analyze the rules that are to be followed while coding in python, through a step by step interpretation we can start from top that is from imports.

Imports should be seperated by lines
    For eg:  import os
                 import sys

    They should be put at the top of the file over all global module and constants.
They also should be grouped in following order.

    ** Standard library imports.
    ** Standard related library imports.
    ** Local application/specific imports.

White spaces should be not more than one space around an assignment (or other) operator to align it with another.
such as        
            x = 2          not         x      =      2

                                    Always surround the binary operators with single white spaces such as for assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).

                If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority. However, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator.

Use 4 spaces per indentation level.
For really old code that you don't want to mess up, you can continue to use 8-space tabs.
Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent. When using a hanging indent the following considerations should be applied; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line.

 foo = long_function_name(var_one, var_two, var_three,
                                            var_four)
hen invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors.

Comments should be complete sentences. If a comment is a phrase or sentence, its first word should be capitalized, unless it is an identifier that begins with a lower case letter.
    Block Comments generally apply to some (or all) code that follows them, and are indented to the same level as that code. Each line of a block comment     starts with a # and a single space.
    Inline Comments is a comment on the same line as a statement. Inline comments should be separated by at least two spaces from the statement. They  should start with a # and a single space.

Naming Conventions of Python's library are a bit of a mess, so we'll never get this completely consistent -- nevertheless, here are the currently recommended naming standards. New modules and packages (including third party frameworks) should be written to these standards.

joined_lower for functions, methods, attributes
joined_lower or ALL_CAPS for constants
StudlyCaps for classes
camelCase only to conform to pre-existing conventions
Attributes: interface, _internal, __private

 

Try not to use loops as much as possible instead you can use inbuilt functions or methods such as join() so to join all the list elements as an example.

Using TRUE in assignment and conditions is not encouraged.
for example you can use 

if x:
    print 'yes'

not 

if x=TRUE:
    print 'yes'

You can use a split in built method to extract words from paragraphs instead of using for or while loops nested. This decreases program readability.

>>>a='This is prasanth's program'.split()
>>>a
['This','is','prasanth's','program']

""""simple""""

All the conventions has to be followed thoroughly so as to improve readability to make yourself better while reading your own program.............


.................THANK YOU...................


Saturday, 4 August 2012

GIT Adding SSH keys....

As per the instructions in my previous post the final "push" may not be so simple as it looks. It may cause authentication failure using RSA encrypted key. So you have to upload ssh key to your repository by following steps:

In order to add ssh client and post your ssh key follow the instructions described in the link: https://help.github.com/articles/generating-ssh-keys

After posting ssh keys on a "push" you may prompt for password, this is the passphrase that you have given in the begining as in the previous link.

Now you've successfully authenticated.

The possible error may occur is:









! [rejected]        master -> master (non-fast-forward)
while a push into repository.

So first you have to pull the repository into your local machine by command:
$git pull [url]
Now you can push. The added files will be saved in your Github account repository.
Now you can explore Github and share your source codes..................

.............................................Thank you........................................


How to use Git?

Here are the STEP BY STEP instructions to use git to save your project into the local repository

To start with you should configure your git by command:
$git config --global user.name "your name"
Then you should configure your email address by which you have made GitHub account
$git config --global user.email "your_email@email.com" 
Initialize your git repository by using command:
$git init
these commands has to be entered by parsing on to your directory where your project is residing.

Next you have to add your file using:
$git add filename
Now your status is staged, your file not yet committed. You can add more file  by using same command recursively.

Now you can commit by:
$git commit -m 'revision version'
you can change your previous commit by using:(optional)
$git commit --amend
This command takes your staging area and uses it for the commit.
After commit you should add your remote repository for which you have made an account by using:
$ git add repositoryname [url]

 you can copy/paste url from your Github.com repository.

Finally to push your commited files   type:
$git push reponame url
Your account will be updated.
..........................................Thank you....................................................

Git Version Control System

Git is an Distributed Revision controls system(DRVS). DRVS  keeps track of software revisions and allows many developers to work on a given project without necessarily being connected to a common network.
              Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Git is free software distributed under the terms of the GNU General Public License version 2.

               
Git has two data structures: a mutable index that caches information about the working directory and the next revision to be committed; and an immutable, append-only object database.
The object database contains four types of objects:
  • A blob object is the content of a file. Blob objects have no file name, time stamps, or other metadata.
  • A tree object is the equivalent of a directory. It contains a list of file names, each with some type bits and the name of a blob or tree object that is that file, symbolic link, or directory's contents. This object describes a snapshot of the source tree.
  • A commit object links tree objects together into a history. It contains the name of a tree object (of the top-level source directory), a time stamp, a log message, and the names of zero or more parent commit objects.
  • A tag object is a container that contains reference to another object and can hold additional meta-data related to another object. Most commonly, it is used to store a digital signature of a commit object corresponding to a particular release of the data being tracked by Git.
Git stores each revision of a file as a unique blob object.

To install Git you may refer to link: http://git-scm.com/download/linux

After installing Git you have to create an account in Github.com which is a social coding website where you can host your projects, share your codes etc. 
         To create a free account go to https://github.com/signup/free and create a repository

If you are a software programmer or deeply interested in programming then be a part of GIT and start .....Gittiiiingggg.......