Posts Tagged ‘programming’

The JVM Crowd

March 1st, 2010

The JVM is an industry-proven environment for enterprise applications development and it has been receiving lots of updates especially after moving to be open source. The only problem was the Java programming language in my opinion. Java is an excellent language for its simplicity and consistency (people may argue) but it’s not a “modern” language and lacks most of the features that the current modern crowd is looking for.

For those who tie the JVM (Java Virtual Machine) with the (Java Programming Language), I’m sorry to say, but you are absolutely wrong. The Java programming language is the first language that supported the byte-code generated for the JVM and it’s the most famous one so far but the virtual machine is an environment (a very stable one actually) and many programming languages (literally; many) is now supported on top of the JVM, you can write Jython (Python implementation in Java) and your code will run seamlessly over the JVM with your old Java code/classes. » Read more: The JVM Crowd

Design Patterns Last Call

February 21st, 2010

The course will start next Friday, If you are interested in the course you must register before next Wednesday 24th Feb. No registrations will be accepted after that date.

If you are interested in the first professional software design course, send email to course+design@ahmedsoliman.com

Design Patterns Course Details

February 11th, 2010

As I’ve announced earlier, I’m going to launch a Software Design Patterns course isA.

I’ve been receiving a huge number of emails regarding that course and I had to wait till I find the suitable timing to launch the course, and today I’m announcing that the course will run on 5 Fridays , 6 Hours per session with 1 hour break. The course contains more than 12 of the most important design patterns for those interested in enterprise software design.

The course will take place in Mansoura (Egypt) and no intentions to launch this course elsewhere at the moment.

The course samples will be written in Java/Python, and the outlines of the course are:

  • Introduction to Software Design
  • Observer Pattern
  • Decorator Pattern
  • Factory Patterns
  • Adapter Pattern
  • Singleton Pattern
  • Command Pattern
  • Facade Pattern
  • Template Method Pattern
  • Iterator and Composite Patterns
  • Proxy Pattern
  • State Pattern
  • Compound Patterns

It’s  comprehensive, interesting and professional contents that you don’t want to miss if you aim to be a real software engineer, not to mention the presents and giveaways in the end of the course.

If you are truly interested and serious about joining the course, please contact me on my mail course+design@ahmedsoliman.com to apply for the course, and I’ll mail you back with further details.

All the samples are done by me on a data projector and you will have exercises to run at home and I’ll be reviewing your code personally. The course is not hands-on, this means that there are no in-lab practice but there will be a very good space between sessions to review and do the exercises at home.

Limited Seats, first confirmed first served.

Common Mistake about Python default parameter value

October 1st, 2009

I know it’s a little bit long title but didn’t find a better one :) It’s one of the common mistakes a python beginner does and even more experienced programmers can fall into the same mistake so I thought it might be useful if I illustrated that out here so you can know the concept.

you can easily fall into writing code that look like that:

def get_me_bad_list(arg1, myList=[]):
    myList.append(arg1)
    return myList

In [1]: get_me_bad_list(“hello”)
Out[1]: ['hello']

In [2]: get_me_bad_list(“world”)
Out[2]: ['hello', 'world']

Interesting, no?

The issue here is that the default value for function parameter is evaluated at function definition time (i.e, module import?) and as list objects are mutable they allow you change the value so you keep having the same default object for every function call and you modify it and return it back and even worse the caller can change it and it’ll reflect the list inside the function like the following

In [3]: x = get_me_bad_list(“Assalam”)

In[4]: x.append(“Alaykum”)

In[4]: get_me_bad_list(“Ya Shabab”)

Out[4]: ['hello', 'world', 'Assalam', 'Alaykum', 'Ya Shabab']

So, what’s the right way to do that? (if you are not doing that intentionally and you just want the plain default function parameters) that you define the initial value inside the body of the function (execution time)

def get_me_good_list(arg1, myList=None):
    myList = [] if myList is None else myList
    myList.append(arg1)
    return myList

In [1]: get_me_good_list(“hello”)
Out[1]: ['hello']

In [2]: get_me_good_list(“world”)
Out[2]: ['world']

and I’ll leave the rest of the tests to you, but generally the explanation is that everytime you call the function we create a new list (if you didn’t supply one explicitly) and that list is populated and returned so you won’t see any nasty behavior.

It’s interesting that you see that the deep you understand how the python interpreter scan and execute the code can really affect the way you fall into mistakes because if you are good enough then you will be somehow safe :)

Design Patterns Course

September 25th, 2009

I’m planning to launch a software design patterns course in Mansoura on Fridays for 5 days that would introduce the most important patterns (8 Patterns) to those who are interested in software design.

The course is comprehensive and will have hands-on example using Java 5. The course is also considered the first professional design patterns course in Mansoura, if you are interested please post because I’m collecting votes.

Mercurial 2

September 16th, 2009

Session 2 of Mercurial Tutorial in Arabic

http://www.vimeo.com/6597676

التسجيل كان قبل الافطار بنص ساعه فعذراً لو كان فيه لخبطه بسيطه في الكلام :)

Introduction to Mercurial

September 12th, 2009

This is an introduction to mercurial distributed SCM published as part of my contributions to CAT H4c3krZ, the video is in arabic and all the next sessions will be in arabic also.

http://www.vimeo.com/6519247

Let me hear your opinion….

Python recursion performance test

July 15th, 2009

That’s really shocking, I even tried several ways to optimize performance without touching the code and still performance sucks!

Fibonacci simple recursion solution takes 3 seconds to execute with C code and about 2 minutes in python!

Here is the code I used for the python version

def fib(x):
    if x == 0 or x == 1: return x
    return fib(x-1) + fib(x-2)

if you called fib(40) it will take about 2 minutes! the C code is exactly the same and it’s compiled with normal optmizations (-O0)

I compiled the python to pyc and used the pyc and still around 2 minutes (slightly less)

the impressive thing is that the dynamic programming solution works perfectly in no time, try this

def fib(x):
    t = [0, 1]
    for i in xrange(x):
        t.append(t[-1] + t[-2])
    return t[-2]
 

call it for fib(40) and see the performance gain.

the bottomline is that you shouldn’t use recursion in python.

If you have any suggestions to make this goes faster (I thought about trying stackless python here) I’m really happy to discuss them.

Python or Java

May 10th, 2009

I’ve been enjoying working with C++ and Python for 6 months now in a very interesting project that might change the way people look at storage in data-centers and the mix of using such extremes is because sometime you want fine control over memory and CPU instructions and sometime you just want to get things to work with less headache.

I’ve also been using Java for quite sometime now and I’m using java these days in my project CAT-SCMP that I’m really happy with it and with its progress, and I was thinking about the differences between python and java and when/where to use any of them, after some thoughtful thinking and practical experience, I’ll tell you :)

Java is quite amazing and I like lots of things in Java as a C++ programmer, the language has small vocabulary and consistent thinking in almost all of its API and the performance is stunning even if you are writing I/O programming you can still achieve performance that can really compete with what you can do with C++, especially, while using Java NIO.

Also, it’s platform independent so compile-once, run-any-where is a bless specially for people like me who take care of the differences between operating systems behaviour and different system calls / API. Java is excellent in portability and does lots of healthy emulation for things that are not available in the operating systems and uses the direct calls to the system calls if they are available.

Python is really amazing too but for different reasons, it’s an amazing language for prototyping in general, so you can get something that can really work in one third the time  you will spend on Java doing the same thing, and the dynamic typing is really cool, you don’t have to worry much about types and you can hackingly use the duck-typing that is pythonic, easy, and fast.

However, python will really encourage you to break the rules and does encourage design-less programming which I don’t really like, some people say that iterative programming means that you don’t have to design before you start, this is WRONG, you might want to read the legendary article from Martin Fowler (Is Design Dead?)first before you say that again.

Python will also help you to do more while typing less, but the performance is 1/50 of java, it’s not bad if you are writing something that is small but I really can’t see that it’s good for large systems, Java is really superior in the overall performance compared to python.

Also, python is not so much compile-once, run any-where thing, because some of its standard library methods are not even available on all platforms, so you have to be sure that you write code that is portable (it’s your responsibility) or you may want to involve a continuous integration system to make sure that you have your system running all the time on all the systems that you are targeting.

Conclusion:

  • Java is for larger, well designed, portable, and highly scalable systems.
  • Java achieves excellent performance for overall system performance.
  • Python provide much faster development and allows less thoughtful designs.
  • Python is really excellent for small systems, Gui’s, system administrators.
  • You can still do some enterprise work with python, but you have to create your own boundaries and enough documentation.
  • Java is not very good in GUI and generally slower than python in that particular area because of the platform independent windowing it’s using, while Python is much faster because it has no windowing and it uses whatever native library you choose like PyQt, or PyGTK for example.

Talk to GTalk from Python

April 27th, 2009

Some friend of mine asked me today if I can help him to communicate with google talk from python as he wants to send notifications about some network usage over the chat service. In fact, that was pretty interesting and it just inspired me with tons and zillions of ideas that you can do with that, things like getting security alters, usage logs, any simply feedback that you want to receive while being online and without being irritated with the fact that you have to refresh what you are monitoring every while.

It’s not a hard trick at all, but looks like all of the scripts on the internet are written wrong! and he have been trying to use all of them with no luck, so I helped him as I have some good experience with python-xmpp (xmpppy) module in python.

The idea is that we want to send a message to a Google Apps. User and use another account on the same domain to chat and here comes the trick about it and of course this script is released under the BSD License so you can do whatever you want to do with it :)

import xmpp

client = xmpp.Client('ahmedsoliman.com')
client.connect(server=('<a href="http://talk.google.com/" target="_blank">talk.google.com</a>', 5222))
client.auth(user='myUser', password='myPassword', resource='myResource', sasl=0)

client.send( xmpp.Message('anotherUser@ahmedsoliman.com', 'Hello World'))

Of course you can download the python-xmpp package manually or if you are using fedora, simply use the magical yum install python-xmpp