Live data from Hacker News

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

r-bloggers.com

161–170 of 184 posts

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

#161
post #122
post #32

Earlier quoted context omitted.

Getting the indentation right should be the least of your worries if you have a good editor (and don't do something like mix spaces and tabs, which I think everyone is in general agreement with across all languages). When was the last time that you manually typed out 4 (or 2, or 8, etc) spaces to indent a line of code vs. just hitting tab and letting the editor handle inserting those spaces (or the editor automatical…

It's easy enough if you have only one editor on one computer that you use with only one language. If you mix and match a half-dozen editors on multiple computers running different OSes coding in different languages, then it gets messier. Especially when all of the editors have different ways to set preferences for whether to use spaces or tabs, how much space per tab/indent, and whether those preferences are for this…

One of my pet peeves with Emacs is the way that it indents things (at least by default), so you won't find me using it. :-P

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

#162

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

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

#163
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…

I'd like to jump in with a little R here- it not all that difficult in "that" either!

open(con text = readLines(con, n= -1L) # n is number of lines to read, -1L means read all of it

words = strsplit(text,split = " ")

counts = table(unlist(words))

I put this in because the good thing about R is that it provides functions for many such mathematical operations. And along with this, I'll say something any self-respecting pythoner will know- Less is better than more.

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

#164
post #99

Earlier quoted context omitted.

Actually that's not 'highly proficient'. This is: def read_words(words_file): return [word for line in open(words_file, 'r') for word in line.split()] len(set(read_words('test.txt')))

R version for comparison (; length(unique(scan('test.txt',character(),sep=" ")))

Very clean. 1 small change to make it count of frequencies-

table(scan('test.txt',character(),sep=" "))

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

#165

Earlier quoted context omitted.

Actually that's not 'highly proficient'. This is: def read_words(words_file): return [word for line in open(words_file, 'r') for word in line.split()] len(set(read_words('test.txt')))

smashing tons of crap together isn't necessarily "highly proficient". In some cases it makes things harder to read and/or harder to maintain and many times certainly harder to edit.

True that. But there is also another side to this story, where such nested calls translates naturally to what we are thinking, i.e.

length(unique(text)) comes from the thought "How many(length()) unique (unique()) words are there in this text(text)?"

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

#166

Earlier quoted context omitted.

Edit: in response to "why isn't there a movement around using JavaScript for scientific computing", which I thought was an excellent question (which has crossed my mind on occasion). Typed arrays and real support for integers are crucial features for scientific computing. Although JavaScript recently got some support for typed arrays, they are pretty awkward to use and there still isn't any support for 64-bit integer…

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.

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

#167
post #91

Earlier quoted context omitted.

Indeed that is a problem when you are copy-pasting huge blocks of code. In deeply nested code it can be difficult to determine whether the nesting should be say 28 or 32 spaces. In practice, most people shy away from writing such code because to many levels of nesting is hard to follow. People also prefer to write atomic 5-15 line functions in which keeping track of the nesting levels is trivial. Many C# and Java-hea…

Many C# and Java-heads complain that Python lacks support for auto-completion. Which is true Isn't that an IDE issue and not a language issue? I have no problem with the auto-completion in ipython for instance, though even ipython notebook is only useful for writing simple amounts of code. PyDev though works well too for larger projects albeit a bit sluggishly.

No, Pythons dynamicness means it is in general impossible to find all available completions:

    m = type('', (), {})()
    setattr(m, 'foo', 123)
    m.f
Without actually running the code (which is unsafe), no editor could at that point figure out what the completion should be.

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

#168
post #72

I find Lua more interesting than Python. It has all the simplicity, all of the power, none of the indentation, and is quite a nice portable tool. 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. I don't have that feeling about Python, quite so much ..

"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..

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

#169
post #48

Earlier quoted context omitted.

> The two '$_'s in the map block actually refer to two different variables 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. > I'm sorry, but I can't get worked up about not being able to write code like that. Why? It looks more or less reasonable to me. Most of the weirdness there…

> 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".

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

#170
post #124
post #103

Earlier quoted context omitted.

For me, Tcl does what Lua does, but much better. In fact given Tcl, it's hard to see why Lua was created.

I hope you're wrong about Lua, which I've never used. But allow me to say that I have to use Tcl, and I hate it. I want to like it, the syntax is clean and code has a nice look to it. But the everything-is-a-string [1] semantics is awkward to deal with. As with shell scripting, a lot of what you do amounts to solving problems with quoting. I find Tcl hard to debug, and I don't like the scoping (upvar!). I'd much rath…

I think Lua improves on the Tcl "everything-is-a-string" semantics a great deal: everything is a table, or a string, or a number.

The great thing about Lua is that tables - or, rather, metatable programming - is really, really powerful. I'm finding it difficult to think of an example of a common, powerful data structure that we all know and love, which can't be implemented with Lua tables/metatables. Lists, hashes, arrays, tries, trees, all of these basic things work so well in the context of the Lua table.

However, you have to learn what a table is, in Lua. You have to learn how to use it effectively. A lot of times, folks don't take the effort to understand how metatables can be used to turn your average Lua table into .. objected-oriented constructs (classes), queues, stacks, etc. But if you do make at least this milestone in learning Lua: watch out! You won't want to use any other language, ever again! :)

Post reply on HN