Wednesday, August 26, 2009

Wisdom of Experts: Programming in vs. Programming into a language

David Gries (1981)  pointed out that “your programming tools don’t have to determine how you think about programming”. He also made a distinction between programming in a language vs. programming into a language.

Programmers who program “in” a language limit their thoughts to constructs that the language directly supports. If the language tools are primitive, the programmers thoughts will be also be primitive.

Programmers who program “into” a language, first decide what thoughts they want to express, and then they determine how to express thoughts using the tools provided by their specific language.

So, try as much as you can to program into the language you use. If your language lacks constructs that you want to to use or is prone to other kinds of problems, try to compensate for them. Invent your own coding conventions, standards, class libraries, and other augmentations.

Saturday, August 15, 2009

Using Python Scripts with IIS 7

Here are the steps you should make if you want to use python scripts on IIS 7:

  • Please make sure Python is installed properly or refer to Python Notes – 1 : Setup for installation steps.
  • Make sure CGI module is installed in IIS 7.

Control Panel -> Programs -> Program and Features -> Turn Windows features on and off -> Internet Information Services -> World Wide Web Services -> Application Development Features -> CGI module (Ensure that it is selected).

Screenshot Studio capture #1

  • Add web application for Python, In IIS Manager, right click Sites –> Add Web Site..

Screenshot Studio capture #2

  • In the Add Web Site dialog box, set Site name e.g.: PythonTest, and make it pointing to some folder like C:\PythonTest, then click OK

Screenshot Studio capture #4

  • In Features View, open Handler Mappings

Screenshot Studio capture #5

  • On the left pane click Add Script Map ...

Screenshot Studio capture #7

  • In Request path, put "*.py" as the script files extension, In Executable select "C:\Python25\Python.exe %s %s", or change it according to your Python installation path. (The two "%s" after the executable are required for console-based script interpreters but would not be required for an Internet Server API [ISAPI]-based script interpreter). Then give the script mapping an appropriate Name, like Python. Click OK.

Screenshot Studio capture #8

  • Create a test.py into the virtual directory (C:\PythonTest), and copy the following script into it.

print

print 'Status: 200 OK'

print 'Content-type: text/html'

print

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>' print '<BODY>'

print '<H1>This is a header</H1>'

print '<p>' #this is a comment

print 'See this is just like most other HTML'

print '<br>'

print '</BODY>'