Saturday, December 31, 2011

Python IDEs/Editors

If you're getting into developing in python, then you're going to ask yourself the question 'Which IDE / code editor should I use?'  Although this is obviously a subjective issue, let me weigh in with my personal experience.
Ignoring VI/Emacs.
If you're a MicroSerf / Windows developer, then one good option is NotePadPlusPlus (NPPP).   NPPP is light-weight - and so snappy and responsive, but at the same time VERY extensively featured.  On the downside, it's really a Windows-only product, and so if you like me want to be able to use the same python dev platform across both Windows and Linux, then NPPP is disqualified.  Other detractors are a lack of code completion, and no class / solution explorer.  (At least no built-in code completion, and the one or two attempts  I made to equip it with a plug-in failed.)
Which brings us to Scintilla-derivative Geany, a long-time personal favourite of mine.  It's a light-weight code editor which bests NPPP by coming off-the-shelf with some code completion, and a class/solution explorer.  OS-wise, Geany binaries compiled for both Linux and Windows are available.  On the down-side, the feature-set that Geany offers is quite limited compared to NPPP, although most of the essentials are there.  The upside of the limited feature set, is that the IDE/editor itself is not resource hungry.
Finally, the PyDev extension for Eclipse.  I've just recently started using this, so its a bit early in the game for comment, but it's obviously a fully featured IDE, with code completion, a solution/class explorer, test-infrastructure integration, cross-platform and is open-source.  The only disadvantage of this option is that Eclipse is clearly not a light-weight application itself, and so if your development box is spec-light, then you may want to go with either NotePadPlusPlus or Geany.

Note Pad Plus Plus
+ V.Fast, light-weight
- Windows only (Linux version runs under Windows emulator [Wine], and is horrible)

Geany
+ Cross OS - identical Windows & Linux versions
+ Code completion
+ Class / solution explorer
+ Light-weight
- Relatively limited feature-set

Eclipse PyDev
+ Cross OS - identical Windows & Linux versions
+ Code-completion
+ Refactoring support
+ Class / solution explorer
+ Test integration
+ Integrated debug support
- Requires decent machine specs

Post Script - Aptana Studio 3

In the two months or so since I wrote this post up, I've started using Aptana Studio 3.

Aptana Studio 3is a customisation of Eclipse developed and maintained by Aptana, who via some convoluted corporate cannibalism, has absorbed the original PyDev team.  So, in short, Aptana is the heir apparent to PyDev for Eclipse.

What you get is an all-in-one download, which short-circuits the previous two-stage download, for a grade-A user-experience.  The IDE itself is snappy, and seems faster than PyDev under Eclipse Indigo.  In addition, Aptana features support for Django projects, although I haven't actually done any Django work in the interim, so more to come on that...

FINAL VERDICT

Aptana Studio 3 by a Knock-Out !





Wednesday, December 7, 2011

Sieve of Eratosthenes in F# - Attempt # 1

sieve.fs :
namespace sieve
  module sieve = 

(*
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself.
To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method:
*)

    let shake (n : int) = 

      printfn "Applying Sieve of Eratosthenes to First %i Natural Numbers" n |> ignore
      
      // 1. Create a list of consecutive integers from 2 to n: (2, 3, 4, ..., n).
      let matrix = Array.init n (fun x -> true)

      // 2. Initially, let p equal 2, the first prime number.
      let mutable p = 2

      let mutable set_exhausted = false
      while (set_exhausted = false) do
      
        //  3. Starting from p, count up in increments of p and mark each of these numbers greater than p itself in the list.
        //  These numbers will be 2p, 3p, 4p, etc.; note that some of them may have already been marked.        
        let mutable i = p + p
        while (i <= n) do        
          matrix.[i - 1] <- false
          i <- i + p

        //  4. Find the first number greater than p in the list that is not marked; let p now equal this number (which is the next prime).        
        p <- p + 1
        while ((p <= n - 1) && (matrix.[p - 1] <> true)) do
          p <- p + 1      
        
        //  5. If there were no more unmarked numbers in the list, stop. Otherwise, repeat from step 3.
        if (p >= n - 1) then
          set_exhausted <- true

      //  6. When the algorithm terminates, all the numbers in the list that are not marked are prime.
      matrix
Program.fs :
namespace effsharp
module Main =
    open System
    open sieve
        []
        let main args =         
            
            printfn "Sieve up to what natural number ? [Max %i]" Int32.MaxValue
            let nStr = Console.ReadLine()
            let n = Int32.Parse(nStr)

            let primes = sieve.shake n

            for i = 1 to n do              
              if (primes.[i - 1] = true) then
                printfn "%i" i |> ignore

            printfn "any key to exit..."
            let endofapp = Console.ReadKey()
            0