News for hackers. Stuff that matters.
Re:Why Python is more fun that Java by globalrev on Saturday August 16, 2008 @09:29PM (#278107)
I'd wish people stop post all crappy blogposts about shallow language-comparisons.

Saying language X does Y in 4 lines instead of language Zs 5 lines just doesn't say much unless you put it in a bigger perspective.

(And I like Python very much and hate Java).

Re:Why Python is more fun that Java by fauigerzigerk on Sunday August 17, 2008 @04:34AM (#278272)
That's true, and I also like Python more than Java. What's missing in these comparisons are some important architectural consequences of using Python (or ruby or PHP) for web apps. The one reason why I haven't been using Python as much as I like is the GIL (global interpreter lock).

The GIL requires that you use multiple processes to make use of multiple CPUs or cores. And that means you cannot keep much data in memory as it would be duplicated in each process. Some applications benefit a lot from keeping much of the data in memory most of the time, and if you have complex data structures (like graphs) memcached (or similar solutions) is no replacement as you have to rebuild those data structures on each access. Any solution that invalidates process relative adresses incurs a huge overhead in order to access that data.

I know the debate around threads and how problematic they are and how much better a multi process model scales. That's all very well, but threads are the only way to use multiple cores and access in memory data structures fast.

So using Python, for me, means having to write much of my application in C++ (or Java or C#) and access that backend process from the Python web frontend. This approach comes with a lot of complexity and it's a lot more work than using Java or C# in the first place.

On the other hand, keeping a lot of data in memory isn't necessary for most applications as the data structures and the parallelism lives in the DBMS, which is written in C/C++ anyway.

It's also questionable whether Java is a good solution for my scenario. Java and C# need about twice as much memory as C++ for the exact same data structures, and the garbage collector gets slower the more memory a process allocates.

I know there are more options but this post is getting lengthy :-)

Re:Why Python is more fun that Java by anewaccountname on Sunday August 17, 2008 @12:41PM (#278438)
If the data structures are static, you can build them, then fork off a bunch of python processes. They will all have the data, but it will only be in memory once. Just make sure to never invoke GC after that point... (unless python's GC isn't compacting). Also make sure to never reference anything, or you will increment it's reference count and trigger copy-on-write...
Re:Why Python is more fun that Java by fauigerzigerk on Sunday August 17, 2008 @02:50PM (#278503)
The data structures are not static. It's effectively an in memory database, so the data keeps changing.
Re:Why Python is more fun that Java by anthonyrubin on Sunday August 17, 2008 @01:55PM (#278469)
PostgreSQL is not multi-threaded and uses System V IPC. Threads are certainly not the only option.
Re:Why Python is more fun that Java by fauigerzigerk on Sunday August 17, 2008 @03:04PM (#278511)
So how would you do it? I have a large graph on which a number of clients run queries, complex analyses and updates at the same time. I've been pondering various solutions like shared memory, memory mapped files, relying on the disk cache, memcached, etc. But they're all either not performing well because they cause a lot of serialisation in and out of process memory, or they cause overly complex designs or both. I do appreciate any advice I can get...

[edit] Traditional DBMS architectures like that of postgres ,to my knowledge, rely on shared memory or memory mapped files (I'm sure this varies). They swap on disk pages in and out of memory and those pages retain their on-disk structure. There is little if any translation into in-memory data structures. Yes I could do that, but it's incredibly complex. Every single data structure basically has to be implemented on top of a byte array. I wouldn't be able to use any existing libraries for trees, lists, sets, hashtables, etc.

Re:Why Python is more fun that Java by ii on Sunday August 17, 2008 @04:19PM (#278576)
Try ZODB/ZEO, you will be able to access native python data structures (possibly cached in memory) from multiple python processes.

http://www.zope.org/Products/ZEO/ZEOFactSheet

Re:Why Python is more fun that Java by rbanffy on Sunday August 17, 2008 @05:15PM (#278617)
This does not solve the GIL problem - it reduces it just a little.

ZEO and ZODB are nice, but using them also does not solve the problem - there is still one serialization for every update and one de-serialization for every independent client/dirty-read. I love Zope and Plone and use them for a lot of situations (I won't think twice when someone wants a CMS for their intranet), but I sure would like to be able to set "zserver-threads" to 64, buy a Sun Niagara-based server and just live happy with it watching how all thread units get their fair share of usage.

Re:Why Python is more fun that Java by atl2008 on Saturday August 16, 2008 @10:58PM (#278144)
So write something that gives that bigger perspective.
Re:Why Python is more fun that Java by waldrews on Saturday August 16, 2008 @10:35PM (#278135)
It's a little surprising how many of the Python-favoring features are already present in C# 3.0; closures, syntactically clean properties, and a nicer array syntax; between the yield keyword and LINQ, you get something close to generator syntax; reflection is pretty painless; and while there's no dynamic typing, there's a convenient type inference mechanism.

My personal pet peeve against Java is the lack of multiline string literals, also available in both Python and C#.

Java has some syntactic catching up to do.

Re:Why Python is more fun that Java by gojomo on Saturday August 16, 2008 @10:54PM (#278142)
I share your peeve. A request for multiline string literals is over 7 years old...

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4472509

Reading the Sun bug database, it's clear who's held back Java's functionality and stability over the years: xxxxx@xxxxx, who on this issue back in 2001 wrote "This is yet another request for a syntactic sugar to save some user from typing. It's not worth it."

I hope for the good of the platform xxxxx has been let go since then.

Re:Why Python is more fun that Java by michaelneale on Saturday August 16, 2008 @11:16PM (#278149)
Agreed. If I ever find xxxxx@xxxxx in a dark alley, he/she better watch out.
Re:Why Python is more fun that Java by michaelneale on Saturday August 16, 2008 @11:17PM (#278150)
Not just string literals - but a better literal syntax for maps and arrays would be really nice.
Re:Why Python is more fun that Java by michaelneale on Sunday August 17, 2008 @02:42AM (#278230)
Interesting article on how to kinda sorta do it using varags, generics and static imports (looks more like scala): http://gleichmann.wordpress.com/2008/01/13/building-your-own...
Re:Why Python is more fun that Java by 13ren on Sunday August 17, 2008 @03:36AM (#278254)
multiline string literals... also available in C (using \).
Re:Why Python is more fun that Java by babul on Saturday August 16, 2008 @08:38PM (#278088)
Deja vu.

(http://news.ycombinator.com/item?id=260014)

p.s. I thought a dupe post got credited to its predecessor. Is there a time limit on this check?

Re:Why Python is more fun that Java by qqq on Saturday August 16, 2008 @08:58PM (#278096)
the URL is different
Re:Why Python is more fun that Java by babul on Saturday August 16, 2008 @09:39PM (#278112)
URL is same (http://brizzled.clapper.org/id/75).

Also, I have experienced this myself. Submitted an article and found it had been submitted ~1-2hr before/after by another (so usually would delete article I submitted).

Re:Why Python is more fun that Java by aneesh on Saturday August 16, 2008 @09:45PM (#278114)
No, the url is different, which is why it got past the dupe-detection.

The original post's url is actually (http://www.clapper.org/bmc/blog/id/75), which just redirects to the current post's url. Same content, different url.

But yeah, it's a dupe. There should be a way to report this (similar to "flag"), and then the admins can merge the two topics.

Re:Why Python is more fun that Java by babul on Sunday August 17, 2008 @04:10PM (#278567)
Re:Why Python is more fun that Java by babul on Sunday August 17, 2008 @08:54AM (#278339)
You are right. Thanks.
Re:Why Python is more fun that Java by axod on Saturday August 16, 2008 @08:29PM (#278085)
Sorry but I stopped reading here...

System.exit(0);

It's hardly going to be fair and balanced with things like that in it.

Re:Why Python is more fun that Java by paul on Sunday August 17, 2008 @02:41AM (#278229)
His StringBuffer example is also wrong (the java compiler would automatically use a StringBuffer in his example).
Re:Why Python is more fun that Java by chrisbroadfoot on Sunday August 17, 2008 @01:49PM (#278468)
StringBuilder?
Re:Why Python is more fun that Java by paul on Sunday August 17, 2008 @03:45PM (#278547)
Oh yeah, that's right, since jdk1.5. It used to be StringBuffer.
Re:Why Python is more fun that Java by chrisbroadfoot on Saturday August 16, 2008 @09:11PM (#278099)
TRWTF is this:

  for (String s : args[0].split("\\s+"))
      System.out.println(s);
which is exactly the same as:

  System.out.println(args[0]);
(redacted)
Re:Why Python is more fun that Java by jdale27 on Saturday August 16, 2008 @09:38PM (#278111)

  [jdale@localhost ~]$ java -cp . Test "foo bar baz"
  foo
  bar
  baz
Re:Why Python is more fun that Java by chrisbroadfoot on Saturday August 16, 2008 @09:55PM (#278117)
Oh, good point. Cheers.

I then submit my Groovy solution:

  args[0].split().each { println it }
Re:Why Python is more fun that Java by duane on Sunday August 17, 2008 @01:44PM (#278465)
What, no decorators mentioned?