Monday, February 25, 2008

Python Take II


Here is the verdict. Python simply rocks.
I am going to move one of my project from C/C++ to full Python.

There are a few things that makes Python a real magnet to programmers like myself :-

i - enforcement of readability and tabbings
ii - unit testing is naturally the way of python, each module is developed and tested easily
iii - rapid development for "engine" type of development is fast
iv - superior basic types, like list, and dictionaries that are iterable
v - oreilly python books are all pink (hehhaha, no relevance to edison chen pink mac)
6 - calling C dlls is a walk in the park
7 - works on both windows and linux

I have 3 books in my collection now, Learning Python, Programming Python and Python Cookbook. The cookbook series is a must if you are moving to a new language and you are an experienced programmer. It beats scavaging the internet for junks codes written by amatures, cookbook codes on the other hand are of excellent quality.

Saturday, February 9, 2008

Python From a Newbie Perspective

The Python support for Win32 comes in the form of PyWin32.
However the documentation is very weak and lacks the standard that one normally feels when using products from "de" Giant software company. This is the difference between a product that is made by a company with $$$$ and one that is of voluntary work. No amount of voluntary work could compete with highly paid dedicated people that is assigned to a task.
(activepython on the other hand gives an overall much better starting point)

Although i have the utmost respect for the work done as an open source product and the maturity of python as a programming language, i do feel that such low quality documentations only deters new programmers from fully adopting Python, especially those that have tasted something better like Visual Studios.

Python has been around for nearly 17 years now, but C# has covered more mileage and devotees in a few years than Python.

Here are some sane arguments, as trivial as it is, i felt it is important and is a stumbling block to convert anyone who has been using MS products

Python documentation lacks examples
What better way for seasoned programmers to learn than to just take a peek at how a function
is used? The standard docs that comes with Python 2.5 lacks useful examples. You end up buying a book from Oreilly (Mark Lutz) or scavaging the internet. Alternatively fireup the interactive session and try.
The 2.5 documentation is however much better than the pythonwin documentation, the indexing itself proved to be different.
If you were to use the "index" on the chm file provided for pythonwin, be amazed that one keyword you will have say 10 listing and u have no idea which one is the full description.
Lets take a look at one simple example : DeviceIoControl (win32file, phyton Win)


string = DeviceIoControl(hFile, dwIoControlCode , data , readSize , ol )
Call DeviceIoControl
hFile : int
Handle to the file
dwIoControlCode : int
IOControl Code to use.
data : string
The data to write.
readSize : int
Size of the buffer to create for the read.
ol=None :
An overlapped structure

Any windows programmer knows that there is supposed to be 2 buffers in the original windows "DeviceIoControl" , one for read and the other for write. So even if PyWin decideds to make life easier by using some smart detection on the parameters and selecting to "return the read buffer" as a return value (string), you can see from the documentation above, no hints is given. One can only be left wondering what is "string" supposed to be, things like "hFile" :int is not a int handle but rather the PyHandle, again hardly mentioned. Examples for using these apis (not just this one) are as scarce as water in the desert.

* the activepython documentation was better since it merges all necessary documentation into one place, however pythonwin docs for win32 stuff still sucks.

* the string return value is the replacement for the read buffer. If the values were actually c-integer , well, you have to figure out how to convert the python string with raw data representing the c-integer into phyton int. Yeah, for seasoned pythoners working with w32, this might be easy, for new comers even with java, c++ or c# background, they would be more productive sticking with their proven tools.

Python has some unjustified oddities (noob bugs?)

x = 0

class Hello :
def __init__ (self) :
global x
x = 100
def __del__(self) :
global x
x = 0

def DoNothing() :
xyz = 100

a = Hello()
b = DoNothing()
print x


What do you think the result would be? Run on a python and see for yourself, then comment out "DoNothing" and run it again .
Bug? By george, this is already Version 2.5 and if the garbage collector is still buggy with something as simple as this.....

*** The activeState Python however does NOT have this bug!!

Python PyWin32 GUI needs refinement
The autocomplete feature for example will come as a shock to many VS users, instead of the
natural convenience of pressing "enter" to select the autocomplete listing, you need to press "tab". The logic behind "enter" is simple, your right hand is already bz with pressing the "up" and "down" arrows and it won't be doing anything else so using that same hand to press the "enter" key which is just above those arrow keys is fast and easy. Pressing "Tab" on the other hand requires your left hand to move from its natural typing position while the "right" hand which is stuck doing nothing at the arrow keys . I don't think this could be modifed from the config.cfg file for the keyboard layouts.

Its hard to explain but that is what ergonomics is all about, refinement over routine habits that yields comfort and productivity as the goal.

Somehow VS just got it right, even Eclipse misses a mark. For eg, using the php plugin to Eclipse, when you enter [', as a corrective fix to ur expression, the ide will rudely add in ']', without any smart detection that you are typing between the expressions (eg correcting _GLOBAL$(hello'])

When you add up all the "annoyances" in phyton ide, its obvious they need to learn from MS. is an excellent ide for free.

Python needs a proper image
You will likely see a lot of python related stuff using "snake" icons and images as though that was the real meaning of the language. Unfortunately its actually named after "monty python" a comedy show. On the other hand you have O'reilly, the most respected programming book publisher using all kinds of images for its Python books, ironically "Learning Python" uses a "mouse" as its front cover and pink color as the scheme.

Ok, maybe Python theme is a humorous one, but many programmers would prefer if their career and livehood tools are serious cause not everyone gets employed by Google or use programming for academic purposes. (if u can find a company in Malaysia or Sg that will hire you for using lisp and fortran, pls post a comment here, i need to know why some languages i considered "offline" are still commercially viable)

So what are you trying to say ...

So, does this mean that python sucks and we should avoid it?

I suggest you take up this language when you are on some vacation and see for yourself.
The language survived for many years and it does have some really fun and powerful factors
such as list, tuples and dictionary built in types and i love the fact that the tabs/whitespaces are enforced into the language itself.
The interactive session also makes learning fun and unlike the VS that we all "had to love", the size and implementation dont experience the same "bloat" that you get from .Net.
I must say its a very unique programming language that kept me sleepless for few days playing with it, the sheer fun and joy of learning a new language.
I do recommend that you use ActivePython and not (See the bug above, tested on windows vista, python 2.5)

Tuesday, February 5, 2008

Wifi Hell and Acer 4520 (open suse 10.3)

Chinese New Year is just tomorrow and i was walking around tesco and i saw some really cheap notebooks, RM 2k for various brands. HPs. compaqs and Acers were the models displayed. The same offer you can find in Carrefour.

I notice it comes with "Linpus Linux", a fedora based linux that is shipped by a taiwan company and Acer is putting it in these low cost notebooks.

So i grabbed one since i am playing with phyton nowadays and i plan to have a dedicated Open Suse 10.3 instead of running it via my Vista vmware (ouch!). There is where the hell begins...

The Wifi wouldn't work and this is not some newbie problem. Although some manage to get it working perfectly on Mandriva and Ubuntu, it seems that the Wifi that comes with this ACER Aspire 4520 has a string of problem when it comes to getting it to work on 32 bit Open Suse.

The said wifi is Atheros Wifi.

The following are things that DON'T work :-

- using ndiswrapper and getting the Atheros wireless driver for XP
- latest drivers and via ndiswrapper
- madwifi default packages and latest build (up to this blog entry, so feel free to try)
- any vista/xp driver attempting to be used via the ndiswrapper (ndisgtk + related stuff)

There was one Ubuntu forum that shows how this was done successfully on the Ubuntu, and somewhere else a guy in malaysia copied the instruction and posted it as his own...with no credits given. However, the exact steps doesnt work on Open Suse 10.3 even after i mapped the correct differences.

Finally 12 hours of non sleep attempt, here is your ANSWER :

1. Download the following files and transfer to ur linux via USB drive.

Read the How to Apply from here :

2. Read the following and do :-

3. Run the "yast2 lan" or via ur yast2 (my computer, administrator setting) and set ur configuration from there, setting via the iwconfig etc won't work. After that use the icon on ur system tray and connect to ur SSID (router), re enter the WEP key if needed.

There. I just saved you 12 hours.

As for Nvidia drivers, just download
and do the sh NVIDIA* instead of depending on the yast.