Live data from Hacker News

Homogenization of scientific computing – Python is eating other languages’ lunch

r-bloggers.com

171–180 of 184 posts

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#171
post #72

Earlier quoted context omitted.

"That said, I do wonder at times what it is about Lua that makes so many people not-interested in it, when .. from my naive point of view .. its an almost perfect language for rapid development." Probably because the core language is only a small part of what determines a language's usefulness. Python has heaps of tools and libraries, is used in many software packages as the scripting language, and is generally well-…

Thats why I find it curious that more hackers don't adopt Lua, and the Lua VM, for a lot of projects - you can put the VM anywhere. ANY. Where. It takes less than a day to get the Lua VM inserted in a project, and from that point on you have a powerful engine for productive development..

...

They don't adopt it because the ecosystem is so much smaller, as I said. Chicken and egg, and Python had the first mover advantage. I embedded Python from C++ in less than a day too, that is not the problem. It's the design of the API for the integration which takes the work.

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#172
post #160

Earlier quoted context omitted.

2) It's cramping my style. My code is art, and restricting how I can structure my code is an affront to my very being. To be fair, there are quite a few common cases where Python's syntax is rather inelegant. The need to break out if-then statements into multiple lines, the need for explicit 'return' statements which also have to go on their own line. These things are only indirectly related to whitespace but do some…

> To be fair, there are quite a few common cases where Python's syntax is rather inelegant Now we're stepping out of the realm of "semantic white space" though. The people I've known to get (literally) red in the face over Python haven't actually used the language and can't do much more than regurgitate stuff like, "but white space!" > The need to break out if-then statements into multiple lines, the need for explici…

Actually after a quick search I realized my problem was ignorance. I did not know about PEP 308 (conditional expressions) which is a workaround for the issue I described.

And yes technically it's a statement/expression issue not a whitespace issue, though they're indirectly related.

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#173

Earlier quoted context omitted.

I like this one. Though I would do it like this to keep the lines under 80 characters: words=open('test.txt').read().lower().split() for word, count in Counter(words).most_common(): print word, count (edited per child comment)

Yeah, those are nice -- and may actually be more efficient on smaller files, as you're only doing the lower() once on a big string. However, for big files you don't necessarily want to read the whole thing in at once. One nitpick: it's Pythonic (I think) to just name the list of words "words" rather than "word_list".

Yes that's a classic tradeoff, a proficient programmer will have to pick one.

Personally I always read entire files into memory first unless I have reason to believe memory will be an issue or need to program defensively against malicious/careless input. The code is always much cleaner and easier to read and if you need to do a second pass on the data you don't need to re-read it from disk.

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#174
post #48

Earlier quoted context omitted.

> Yeah, but that's Perl 101. Grabbing an element of array @a is $a[0], which is wholly different than plain $a. > > That's not really a style thing, it's a Perl thing, for better or for worse. That code confused me after working in nothing but Perl for 4 years. It was confusing because I wasn't used to people having an array (@_ in this case) and a scalar ($_) named the same thing, and used in close approximation. Th…

> For example, what is 'shift' intended to be? "shift->method()" a very standard Perl idiom for OO code. If you presume the code was called via a blessed reference, then "shift" == "this".

I don't think I've ever come across Perl code that uses "shift->method()" to access "this" but once. Maybe I just haven't look at enough code on CPAN, or maybe I just remember that instance because it was an entire file that was meant to be production code that could have been an entry into a Perl golf competition.

I understand that in Perl OO code, the first argument is 'this', but most code I've come across takes the time to actually name variables because the aim isn't write-once, read-never.

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#175

Earlier quoted context omitted.

You don't have to simulate multidimensional arrays in C. It's just easier than wrapping your head around the weird syntax required to pass them around: http://pastebin.com/JTjQMfxr

That's all well and good until the dimensions of the array are dynamic. Which they are in all real code.

C has variable sized arrays. http://pastebin.com/BEgDNAhu That's no longer backward-compatible to C89, though.

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#177

Earlier quoted context omitted.

Re: setting up environment, I love Anaconda for that reason. Wget the installer, run it, all done - you have a fully featured Python environment ready to go, including Numpy, Scipy, Scikit-learn and much more. Running IPython and the IPython Notebook is then trivial. If you need anything else, you can use their own Conda package manager, or you can just use pip as usual.

@dkersten What happens in the scenario where you have other Python distributions on your system? Does Anaconda keep things nicely compartmentalized like a virtualenv?

Yes, Anaconda is completely self-contained (you can actually install it anywhere you like, for example, your home directory) and does not interfere with the rest of your system at all. You can also run virtualenv from Anaconda too, if you want to have isolated Anaconda environments without installing it multiple times (which you could also do, if you wanted..)

I like using it to make sure I have a very easy to install consistent environment between the various computers I use (including EC2 instances).

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#178
post #93

Earlier quoted context omitted.

What does this have to do with Scientific Computing? I don't think there is anyone would say that in the realm of Scientific Computing there is a problem with slow in python.

I would argue that many Scientific Computing problems involve large amounts of data and/or computation.

Have you ever worked with MatLab or other "Scientific Computing Languages"? They are like 10 times slower then Python.

I am guessing you are against dynamic languages?

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#179

Earlier quoted context omitted.

That's all well and good until the dimensions of the array are dynamic. Which they are in all real code.

C has variable sized arrays. http://pastebin.com/BEgDNAhu That's no longer backward-compatible to C89, though.

I was not aware of that. Is this a GCC extension, or is it part of C99 and/or C11?

Re: Homogenization of scientific computing – Python is eating other languages’ lunch

#180
post #95
post #86

Earlier quoted context omitted.

python is a deliberately-straightforward language. i don't see how anyone couldn't become highly proficient in it after writing one or two scripts

Deliberately-straightforward -- agreed. But "highly proficient" after writing one or two scripts? That's quite a stretch. For instance, one of the questions I give in phone screens is for the candidate to write a program to count the number of occurrences of unique words in a text file. The "after writing one or two Python scripts" approach is something like this: counts = {} f = open('test.txt') lines = f.read().spl…

Here's mine for what it's worth, since this is one of the Google python assignments. Admittedly, i'm not very proficient at all.

   def get_file_words(filename):
     file = open(filename, 'rU')
     words = {}
     for line in file:
       for word in [word.lower() for word in line.split()]:
         if not word in words.keys():
           words[word] = 1
         else: words[word]+=1
     return words


   def print_words(filename):
     wordcount = get_file_words(filename)
     for word in wordcount:
       print word, wordcount[word]
Post reply on HN