Ruby vs Python

  • Whitespace matters. Having to "end" everything in Ruby really sucks, especially since my code is always correctly aligned.
  • No ternary if. Seriously, I have to type this kind of crap in Ruby all the time:
    v = a.empty? ? a.shift : nil
    In Python this would be:
    if len(a) > 0:
                v = a[0]
                a = a[1:]
        else:
                v = None
    This is clearly less error-prone and more readable than Ruby's.
  • Better built-in methods. For example, you can simply do sum([1,2,3]) in Python, whereas you would have to do [1,2,3].inject(0) { |sum, i| sum += i } in Ruby. Seriously????? Why is it called inject anyways. Ruby's authors were clearly not well at English.
  • Faster. Because Python is so much simpler than Ruby, its VM is almost an order of magnitude faster to make up.
  • More production ready. I read somewhere that Google is using Python.
  • Better commenting. In Python you can do:
    def getTime():
            '''Returns a string timestamp in the form: 'Time hh:mm:ss' '''
                ...
    but in Ruby you're stuck with
    def get_time
            =begin doc
                Returns a string timestamp in the form: 'Time hh:mm:ss'
            =end
            ...
  • http://www.rossbeazley.co.uk/pablo-lorenzzoni-ruby-versus-python/open-source/

    Filed under  //  Python   Ruby  
    Comments (0)
    Posted

    Experiences Switching to Python

    We love most of Python, especially the clean, readable, minimal syntax. However, there are several Python gotchas, and we were bitten by almost all of them. Here are some of the major ones that confused either students or instructors:

    • There are no good GUI packages; Swing was at least teachable, but Tkinter has lots of warts and none of the others (e.g., wxPython, PyQt) seem to be usable on all three major OSes. We’ve dropped Tkinter this fall in favour of EasyGUI, which has major limitations but is much more teachable.
    • It’s hard to know when to stop. List comprehensions, for example, are really cool and natural, but they make a surprising number of problems too easy and allow students to avoid writing loops. We show them toward the end of our intro course but don’t require the students to use them.
    • Aliasing is surprising and comes up naturally and even accidentally, especially in lists. This is not necessarily Python-specific, but it sure comes up more in Python than it did in Java.
    • Default values for parameters are created once. Students (and some instructors) hate this.
    • Simple classes are harder to teach than in Java. Also, “self” confuses a large subset of the students. Since dictionaries are so accessible they do whatever they can to avoid using and understanding classes.
    • Global scope is hard to explain: it’s actually module scope and not global, and in the three examples below there are different behaviours; the last example in particular really confuses students. They do all of these things naturally, so we can’t prevent them getting confused.
      # Example 1
      i = 1
      def f():
          print i
      
      f()
      print i
      # Example 2
      i = 1
      def g():
          i = 2
          print i
      
      g()
      print i
      # Example 3
      i = 1
      def h():
          print i
          i = 2
          print i
      
      h()
      print i
    • More scope: nested functions baffle students.

      On the positive side, some students LOVE putting functions into dictionaries and getting rid of huge if/else statements. They also find passing functions as parameters to be natural; we introduce this idea to write a timing function that returns how long its argument runs. This is a lovely thing to do when we get to searching and sorting.

    Filed under  //  Python  
    Comments (0)
    Posted

    Python Versus C/C++

    The following is a list of differences between Python and C/C++:

    • Python's array constructs don't have the same number of problems that arrays written in C have.
    • Most of the memory allocation and reference errors that we easily get when coding C/C++ programs are eliminated as Python performs automatic memory management.
    • Python checks array references for boundary violations.
  • In many cases, developing an application in Python requires much less code than an equivalent application in C.
  • Filed under  //  C/CPP   Python  
    Comments (0)
    Posted

    Parallel Python

    PP is a python module which provides mechanism for parallel execution of python code on SMP (systems with multiple processors or cores) and clusters (computers connected via network). It is light, easy to install and integrate with other python software.  PP is an open source and cross-platform module written in pure python

     

    Filed under  //  Python  
    Comments (0)
    Posted

    MATLAB vs Python

    Actually, I have been thinking the same thing myself. Some of the things that make Matlab great are:
    (1) Easy scripting
    (2) Optimized for vector and matrix data types both in performance AND programming syntax.
    (3) Interactivity
    (4) Optimized libraries
    (5) A well designed and easy to use IDE.
    (6) Immediate accessibility to numerical data oriented actions: calculations, special functions, plotting, solving, etc.
    (7) Seamless integration between numerical and symbolic computation.

    It is probably not possible to have all of these things simultaneously with Python. However I think one could use the Eclipse RCP to recreate an IDE environment similar to Matlab. By using Sage as the standard interpreter, one would have mathematical operations at your finger tips.

    Direct, intuitive access to all the functions and operations one might want would still take some work and thought. This is particularly true for data display.

    I think Python does have some features that Matlab lacks that would be nice in a numerical environment:

    (1) Keyword Arguments. Since programming in Python, I've really come to hate
    set('linewidth', 5, 'color', red, ...) etc.

    (2) Operation Overloading. It would be nice to be able to create special data types that have operations not already planned out by Mathworks. For one example, I've had the idea of implementing some sort of "Einstein Notation" multiplication in which you could multiply and sum over a specified index.

    (3) Object oriented programming in general. Objects are great for preventing folders full of short functions.

    (4) Access to better GUI libraries.

    (5) OPEN SOURCE!!!!!!! If I want, I could modify standard algorithms (such as solving or fitting) instead of having to code my own. If optimization was done through SciLab and Cython, then I could modify builtin functions and recompile them to fast extensions.

    (6) Completely cross-platform. Combined with (5), whatever code I write can by run by anyone anywhere.

    Filed under  //  MATLAB   Python  
    Comments (2)
    Posted