News for hackers. Stuff that matters.
Re:First Impressions of Python from a Java Developer by stevelosh on Monday November 08, 2010 @02:02PM (#1883515)
The thing that really made my jaw drop the first time I saw it was list comprehensions.

    allowed_usernames = [user.username for user in all_users if user.is_admin()]
This Stack Overflow answer makes it seem like Java developers should be at least impressed with them as I was: http://stackoverflow.com/questions/899138/python-like-list-c...
Re:First Impressions of Python from a Java Developer by swannodette on Monday November 08, 2010 @02:47PM (#1883704)
This feature is of course lifted from Haskell - another jaw dropping language.
Re:First Impressions of Python from a Java Developer by stevelosh on Monday November 08, 2010 @03:27PM (#1883847)
Yep. Python has a wonderful habit of taking the awesome features of other languages and expanding on them.

List comprehensions were added in 2.0, generator comprehensions were added in 2.4, and dictionary comprehensions came in 2.7

Re:First Impressions of Python from a Java Developer by nickbarnwell on Monday November 08, 2010 @03:49PM (#1883943)
Just found a reason to upgrade to 2.7...
Re:First Impressions of Python from a Java Developer by stralep on Monday November 08, 2010 @03:42PM (#1883911)
"Haskell is a scripting language inspired by Python."

:)

http://www.haskell.org/pipermail/haskell-cafe/2010-November/...

(joke)

Re:First Impressions of Python from a Java Developer by whakojacko on Monday November 08, 2010 @04:10PM (#1884021)
You can do similar in scala, either

  val allowed_usernames = all_users.filter(_.is_admin()).map(_.username)
or

  val allowed_usernames = for(user <- all_users if user.is_admin()) { yield user.username }
And still get all the of goodness of Trivial jvm/java compatability...
Re:First Impressions of Python from a Java Developer by jcromartie on Monday November 08, 2010 @05:15PM (#1884261)
Or Clojure... (or... or... or...)

    (map :username (filter admin? all-users))
Re:First Impressions of Python from a Java Developer by Scriptor on Monday November 08, 2010 @06:19PM (#1884477)
Or Clojure again

    (for [username all-users] :when (admin? username))
Re:First Impressions of Python from a Java Developer by moshezadka on Monday November 08, 2010 @05:11PM (#1884246)
Nothing against scala, but you can program in Python and get all the goodness of JVM compat by simply running your programs in Jython...
Re:First Impressions of Python from a Java Developer by lusis on Tuesday November 09, 2010 @01:20AM (#1885585)
Jython is behind current python implementations. If you're comfortable with being compatible up to python 2.5 then go right ahead. But if you need 2.6 or 2.7 compatibility, Jython is sadly not an option.
Re:First Impressions of Python from a Java Developer by DanielRibeiro on Monday November 08, 2010 @02:36PM (#1883662)
In Ruby, with ruby underscore (http://bit.ly/9dwWAX), you can write it as:

    all_users.select(_.is_admin).map _.username
Other languages have similar ways to write it concisely as well (http://bit.ly/a6QmgL). Coffeescript (which compiles to javascript, and therefore, can run on Rhinon inside the jvm) in particular:

    allowed_usernames = user.username for user in all_users when user.is_admin()
Yeah. Reminds me of http://gag.googlecode.com/svn/trunk/javadoc/com/google/gag/a...
Re:First Impressions of Python from a Java Developer by generalk on Monday November 08, 2010 @02:51PM (#1883717)
In Ruby 1.9, or Ruby 1.8 w/ ActiveSupport, you can use the & operator, which coerces it's argument (in this case, a symbol) to a Proc:

    all_users.select(&:is_admin).map(&:username)
This is a common idiom with a fantastic writeup at http://weblog.raganwald.com/2008/02/1100inject.html
Re:First Impressions of Python from a Java Developer by DanielRibeiro on Monday November 08, 2010 @03:57PM (#1883981)
Actually on ruby 1.8.7 the proc coercion is default. No need for active support. And yeah, ruby underscore is overkill for this trivial example.
Re:First Impressions of Python from a Java Developer by RyanMcGreal on Monday November 15, 2010 @09:00AM (#1906230)
This blew my mind when I first came across it:

    deck = ['%s%s' % (n, s) for s in 'HDCS' for n in '23456789XJQKA']
It creates a deck of cards.

Also, you can easily shuffle the deck using the standard library.

    import random
    random.shuffle(deck)
Re:First Impressions of Python from a Java Developer by m_myers on Monday November 08, 2010 @11:58PM (#1885387)
Yes, terseness is definitely not among Java's virtues. Your way looks a lot more fun to write than mine -- it's amazing what a little well-placed syntactic sugar can do.
Re:First Impressions of Python from a Java Developer by th0ma5 on Monday November 08, 2010 @02:30PM (#1883636)
one the few reasons i like jython too!
Re:First Impressions of Python from a Java Developer by InclinedPlane on Monday November 08, 2010 @03:10PM (#1883782)
.NET languages (C#, powershell, for example) have list comprehensions as well. They seem to be unappreciated languages amongst the "cool kids" due to their Microsoftian origin.
Re:First Impressions of Python from a Java Developer by patrickaljord on Monday November 08, 2010 @03:16PM (#1883805)
Or maybe it's because powershell and C# only run on windows and are not open source and we're not interested in using a technology that is playing catch up with a moving target (mono).
Re:First Impressions of Python from a Java Developer by InclinedPlane on Monday November 08, 2010 @05:07PM (#1884234)
Since you claim C# only runs on Windows and yet mention mono in the same sentence I'll pretend you said instead that mono is not production ready (which I think I could buy, at least for SaaS).

As far as "playing catch up with a moving target", I don't see how that's terribly relevant, the end result is still a platform that continues to improve and advance. If the C# code that runs on Windows and mono is still more advanced than, say, Java or Perl, and continues to advance (even though not as fast as C# on Windows alone) then that's still a benefit. Given the advent of monotouch and the coming of monodroid it seems like even a hard-core MS hater could come to appreciate C#.

Re:First Impressions of Python from a Java Developer by patrickaljord on Monday November 08, 2010 @05:15PM (#1884258)
> If the C# code that runs on Windows and mono is still more advanced than, say, Java or Perl

The problem is that it's not. You can do anything you want when it comes to SaaS using python, ruby, php, node or java. Actually those have huge open source communities with tons of libs available to make work faster. This is not the case of C# and if it ever gets there, it probably won't be any better. So again, I don't see any reason to use it, and plenty of reasons not to and being a "hard-core MS hater" would probably come at the bottom of the list of reasons not to use C#, don't try to justify the lack of interest in MS by some kind of imaginary persecution. But to each his own , if you're happy with it go for it.

Re:First Impressions of Python from a Java Developer by Tomek_ on Monday November 08, 2010 @06:42PM (#1884549)
Seriously? I mean, I'm doing my job using the, let's call them, open-source languages: javascript, php, bit of python, java and perl, but, still, I would say that C# is better than most of them, both in terms of the lanuage syntax, features and such, as well as in terms of the quality of libraries. That it's sort of Microsoft-platforms-only keeps me away, but I have to give a credit where it's due: C# is a great piece of technology.
Re:First Impressions of Python from a Java Developer by patrickaljord on Monday November 08, 2010 @11:14PM (#1885296)
Seriously. C# syntax looks too much like Java, python and ruby have much better syntax IMO and they have way more libraries than C#. But again, to each his own.
Re:First Impressions of Python from a Java Developer by Tomek_ on Tuesday November 09, 2010 @04:42AM (#1885936)
well, ruby and python, in your original post you've said c# is no better than java or perl, that makes "a bit" of a difference...
Re:First Impressions of Python from a Java Developer by patrickaljord on Tuesday November 09, 2010 @08:04PM (#1888730)
In my original post I said everything you can do with c# you can also do with perl when it comes to building a SaaS. Is there some kind of website that can only be built with c# but not perl? I'm curious.
Re:First Impressions of Python from a Java Developer by thibaut_barrere on Monday November 08, 2010 @04:15PM (#1884041)
It's mostly a "niche vision" effect. I know a lot of cool kids that do use C#, list comprehensions, Linq, and appreciate .Net a lot.

Some of them also believe Python, Ruby etc are for kiddies :)