Hacker News new | ask | show | jobs
by rbanffy 5050 days ago
You can always do the speed-critical parts in C and link that from your Python code. Or, if your analysis is something already done, use a library already written in C (such as NumPy).

Another approach could be Jython (or any other JVM language closer to the desired level of abstraction) and Java.

I don't have much love for Java the language. It's not much easier to program than with C, isn't faster and is very verbose. Still, what you are doing looks like a good match for it. And all the respect I don't have for the language, I have for the JVM.

I wouldn't use if for web app development as there are much more productive options around.

1 comments

I noticed a lot of criticism of Java's verbosity in the comments and I'm a bit curious what people are referring to? I work primarily in Java, but also do quite a bit of Javascript and Perl, and I don't notice Java being especially verbose. Maybe internally I'm giving it a break because it isn't a scripting language? I'm honestly curious to see what you guys think.
The two areas that most frequently annoy me are processing collections and (lack of) first-class functions.

Java:

  List<String> firstNames = new ArrayList<String>();
  for(Person p : people) {
    firstNames.add(p.getFirstName());
  }

  addCallback(new Runnable() {
    public void run() {
      doSomething();
    }
  });
Python:

  first_names = [p.first_name for p in people]

  add_callback(do_something)
Scala:

  val firstNames = people.map((p) => p.firstName);

  addCallback(() => doSomething());
  
The Python and Scala versions do exactly what they say, while the Java code has a bunch of boilerplate that you have to mentally filter out before you can understand what it's doing. And the Scala code is fully typesafe; the compiler infers types rather than making you continually repeat them.
This is, because you can't Java. How you will find out, where you use

   first_names = [p.first_name for p in people]
? More verbose, but right way in Java is like (you can do this better with enums and/or guava, it's just example):

    class PersonTransformer implements Transformer {
        public Object transform(Object o) {
            return ((Person)o).getFirstName();
        }
    }
and then:

    Collection<String> firstNames = CollectionUtils.collect(people, new PersonTransformer());
You can reuse it and, more important, you can search for it. Same for second example.
Why would you want to reuse a construction so trivial? Why would you want to search for it?

A couple days back I commented Java, by making some things harder than needed, induces programmers to over-engineer and build things for needs they don't have and to think that's perfectly normal. Think about what you just wrote.

Because it's DRY-Principle. It's doesn't matter trivial or not. If you distribute you 'trivial' constructions over whole application, you doesn't have any chance to have consistent, robust processing. If you collect/group things logically, you can easy find out where you (re)use constructions and what you can break, if you change it.

It's not over-engineering, it's just how to deal with >300 People and >6 years projects and not to have "design dead software".

It's just a list comprehension. Do you imply I should use a function instead? Why not use a very nice syntax feature every Python developer can understand?

Because if you do, I'd advise you not to add integers with the "+" operator, but, instead, build a class with various add methods for different types of arguments or, better yet, build add methods into every class you define so that you can better search for them. This approach would allow you to add things that aren't integers or even not the same type on both sides of the operator.

Are you really arguing that the 'java' way in your example is superior to Scala's
orangecat example is type safe, your example trades a "compile time" error for a runtime error.
Python isn't type safe (but Scala). Especially for you I wrote "you can do this better with ... guava, it's just example" :)
Curious enough in fact, to do some research. I found an interesting article: http://www.informit.com/articles/article.aspx?p=1824790

I also forgot about file i/o, which I don't do much of in web applications.