07 July 2009

Django using Eclipse with pydev extension

This article helps you configure eclipse so that you do web app development using django framework. Eclipse can be used for python programming using pydev plugin. The same plugin will be used for working with django framework also.

I assume you already have pydev plug-in for your eclipse. If not you can download it here. I assume that you have already installed django. If not you can download it here. Django installation instructions are here.
  1. Create your django project folder using the command line method as illustrated in the django tutorial. I assume you have used the project name as "mysite". For reference, I will consider it as located at "documents/mysite".
  2. In eclipse go to windows>preferences and then select Pydev>Interpreter-Python. Select the python interpreter (python dot exe). In the System PYTHONPATH section, please select the django folder you installed. Click Apply. Then click OK.
  3. Create a pydev project called "mysite" with src folder. For reference I will assume the project folder will be at "eclipse_workspace/mysite".
  4. Copy the entire "mysite" folder from "documents/mysite" and paste it into "eclipse_workspace/mysite/src" folder. Refresh your view in eclipse. You should now be able to see mysite package and polls package in the eclipse package explorer.
  5. Lets set up some run configurations. Go to Run>Run Configurations... In the Run Configuration window, select Python Run on the left. Right click and select New. Name it as "manage_config". Select the project as "mysite" and Main Module as "manage.py". In "arguments" tab, add "runserver --noreload" in Program Arguments section. In "environments" tab, add variable DJANGO_SETTINGS_MODULE with value mysite.settings. You can add new variables by clicking on "New..." button. Now you can run the manage.py module, and this will start the django inbuilt development server. If you want to debug the app, run the manage.py module in debug mode. Just right click on manage.py and then select debug>debug configurations and select manage_config. Click on debug. Or right click on manage.py select debug as> python run, if you have only one run configuration defined for manage.py

  6. Create a package called "test" and a module called "test". Use this module to play with your Django API. Lets set up some run configurations for test module. Go to Run>Run Configurations... In the Run Configuration window, select Python Run on the left. Right click and select New. Name it as "test_config". Select the project as "mysite" and Main Module as "test.py".

    In "environments" tab, add variable DJANGO_SETTINGS_MODULE with value mysite.settings. You can add new variables by clicking on "New..." button. Now you can run the manage.py module, and this will start the django inbuild dev .

    Now you can run or debug the test.py module and play with the Django API to your hearts fill.

    Please feel free to test drive and let me know if you run into issues. This set up is pretty much independent of version numbers. If you have any specific problem with any specific version combination, please leave a comment.

23 June 2009

Unable to update Avira Antivir

Since couple of days, I found my Avira Antivir Personal edition (free) not updating properly, or taking for ever to do an update. I thought something might be wrong with my program or worse, my computer might be affected. After searching the web, I found that sometimes when the update files are big and if the update server get over burdened, you will not be able to automatically update.

Solution: Do a manual update. To do that, download the latest virus definition file (VDF) from Avira VDF update. After the file is downloaded, use your Avira Antivir program to do a manual update by clicking "Update" > "Manual Update".

Let me know if this works for you.

16 June 2009

Paul Graham - Great Hack

Here is an article from Paul Graham. This is a gem of an article. Great Hackers by Paul Graham.

29 May 2009

Python is faster than Java!

I wanted to pitch Java and Python against each other and see how they perform. So I put in a simple program that puts some stress on the system. Data Structures would also be used. Both the programs should be run on same machine. There shouldn't be any other Java or Python process running in background. I wrote a simple program in both Java and Python and ran them.

Java Program (JVM version - 1.6.0_11-b03)

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;


public class PerformanceTester {

private final static int SIZE = 500000;

public static void main(String[] args) {

long start_time = System.currentTimeMillis();

Hashtable build_hash = new Hashtable();
for(int i=0; i build_array = new ArrayList();
for(Iterator it = build_hash.keySet().iterator(); it.hasNext();){
Integer value = build_hash.get(it.next());
it.remove();
String strValue = (value.intValue()+8)+"add more";
build_array.add(strValue);
}

long stop_time = System.currentTimeMillis();
System.out.println("Total Time = "+((stop_time - start_time)/1000.0000));

}

}


Multiple Run Result
Total time = 1.391
Total time = 1.375
Total time = 1.344
Total time = 1.422
Total time = 1.484


Python Program (CPython version 2.6.1)

import time

start_time = time.clock()
SIZE = 500000

build_hash = {}

for a in range(1,SIZE):
build_hash[str(a)] = a

build_array = []

for key in build_hash:
build_array.append(str(build_hash[key]+8) + "add more")
build_hash[key] = None

stop_time = time.clock()
print "total time = ", (stop_time - start_time)


Multiple Run Result

Total time = 0.888883333612
Total time = 0.878249380963
Total time = 0.991458537034
Total time = 0.850523498354
Total time = 0.860505161151

I see Python showing a huge advantage when it comes to speed of execution. Java is slow! Thats bad news for Java. I would like you to try same or similar program and let me know how it performs. If you run the same above programs, try increasing the hash size for both the programs. You will be surprised with what you see! I can't believe Java is not only slow, but also uses more memory. Python is not only simpler, but faster, more powerful and uses lesser memory than Java.

28 May 2009

Java is loosing the grip while Python and Ruby gaining ground


We have come accross many instances that Java/J2EE is trying to get rid of its complexities, yet not very successful at it. First the misfortunes EJB 2, and then the obliteration of XML files in a large application. Finally the tedious and daunting task of putting all the types of frameworks and to make them work together for every new application. There has been a huge improvement in EJB 3, but
architects and managers still dread the name EJB.

The management hates it when we tell them that we are throwing away code. They panic, as if we are throwing away used furniture. Why throw it, can't we re-use them somewhere! This statement looks very logical from the management perspective, but when it comes to we super technologists, it sounds ridiculous. For us, old code is like old milk. You refactor it and continually improve it or just throw the freaking thing away. Old code has a shelf life, just like milk. We are involved in developing and maintaining code, we know how bad it stinks. The smell is a good indicator that the application is deteriorating in quality and increasing in quantity.

If you are worried about your job prospects, Java/JEE is still a hot bed as of May 2009. The ecosystem is complex enough that you need people who are bright enough to make sense from it. Many companies still stick to Java as their primary web technology, but things might be changing soon.


Sun is now acquired by Oracle and I do not know what future holds for new Java apps. Oracle is big and they will push the Java technology to upper management in many large corporations. These companies have lot of money to invest and they are always more comfortable when they know that they are in company with large corporation such as Oracle. If you are very enthusiastic about web application development, and are willing to take some risks in the job market, you should try Rails or Django. Job prospects are improving for both, so you might not be in loss. But you will enjoy your work much better because I see either Ruby or Python to be much better programming languages than what Java is or going to become. After being with Java for this long, I see that Java has this inferiority complex with C# and does a catch up. I am in big favor of open source and you might know how I might feel about C#.

Ruby on Rails or Python with Django provide very powerful combination for web development. Job demands will come, but will come as the industry adoption grows. Both Python and Ruby are mature and have good community of users. The new features in the languages come from key persons. Just like Linus Torvalds drives Linux kernel development, Yukihiro Matsumoto will drive Ruby language development and Guido van Rossum will drive Python language development. I feel this is much better than a language being driven through a community similar to JCP.

21 March 2009

Ruby on Rails IDE for beginners

I have been a Java programmer for a long time and a big fan of eclipse. Lately I have been very interested to try out Ruby on Rails and Python with Django. I am not the guy who wants to program using text editors. I found that we have these following choices. I have listed here some IDEs and simple test editors which can turn into powerful programming environments for you as a new RoR explorer.

Programming environments listed in Alphabetical order
Note: If you are already using a tool for Ruby on Rails development, please leave a comment and let us know about it.

Eclipse based RadRails - If you are coming from Java shop and are already heavily into eclipse as your IDE, then you might want to check this out. It installs on Linux, Mac OSX and Windows. Because eclipse is java based, you will need jvm installed before you install RadRails with eclipse. RadRails can also be installed with Aptana Studio, an IDE bundle by RadRails creators.

JEdit - JEdit is a powerful programming tool for those who are good with using just a text editor for their coding requirements. Here are couple of good guidlines from Eric and Eadz for working with JEdit for RoR.

Komodo - This is an excellent IDE from ActiveState developers for scripting languages. You can program in Python, Perl, PHP, Ruby, and even HTML, CSS and javascript using Komodo. If you are also programming in other mentioned languages, then this IDE would be worth a look.

NetBeans- This is a java based IDE which has a good support for RoR. Comes bundled with Glassfish V3 Prelude. They provide RoR learning trails that can help you if you are a beginner.

TextMate - For all Mac enthusiasts, this is the editor of choice for RoR. This is pretty powerful and highly customizable. You defenitely want to check this out if you are on a Mac. If you use windows, there is a similar editor called eTextEditor, which is equally powerful.

20 March 2009

Ruby, JRuby, Rails, Python, Django, J2EE

As an experienced Java/J2EE developer for more than 4 years, and after successfully leading Java projects, we are missing something. It takes too much time to even just set up a rough draft of what we want. Even to provide a small demo for the client, we had to set up the whole mixture of frameworks, make sure the jar files don't conflict with new versions, and tedious manipulations trying to figure out how each framework will talk to each other... and so on. What a pain. Programming should be better than this. Web programming has so much capabilities and yet getting simple things in and out shouldn't be such a trouble. Python with Django and Ruby with Rails are beginning to solve most of these problems.

There are talks for Sun being acquired by IBM. Bad news for Java. I don't see much innovation happening due to Java Community Process. The web and open source shall remain the first and last place for free spirited innovation. If you are someone like me who wants to explore and find solutions where Java is failing, then you should definitely give Python or Ruby a try. There is no harm in learning a new language. Infact it will flex your cranium further, and you will be a better programmer, whether you program in Python, Ruby or Java.