Live data from Hacker News

Why People Should Learn Python

iluxonchik.github.io

121–130 of 329 posts

Re: Why People Should Learn Python

#121
post #117
post #72

Earlier quoted context omitted.

Huh? Can you provide an example? Well he did mention numpy and obviously doing something that can be done in numpy with nested loops will be much much slower. However that is as much a case of numpy being really fast as python being slow. For example, just tested elementwise multiplication of two 10kX10k matrices and with numpy and numpy arrays it took ~350 ms vs ~15 seconds with a nested for loops and python lists.…

Could you post the Julia code? Unfortunately, you do have to make sure that the types are correctly inferred by the compiler in high-performance loops. Or maybe you used a global. http://docs.julialang.org/en/release-0.4/manual/performance-...

I'll admit I don't really know that much Julia and basically wrote naive MATLAB code (and I wanted to make it as close as possible to my python code):

  s=10000;
  a=ones(s,s);
  b=ones(s,s);
  c=zeros(s,s);

  tic();
  for i in 1:s
    for j in 1:s
      c[i,j]=a[i,j]*b[i,j]
    end
  end
  toc();
Obviously in real code I'd simple write

  c=a.*b 
and get basically the same performance as numpy

Re: Why People Should Learn Python

#122
post #30

Earlier quoted context omitted.

Agreed. That, the explicit self argument (which no other major OO language needed) and the : at the end of lines where you would need a { in other languages. If you google you find that there are good reasons for all of those choices but IMHO they are wrong solutions to the problem they solve and make Python look ugly. At least in 2016 they could make the colon optional. The colon is so ironic for a language that tak…

> how about an almost Erlang-like full stop? This is just brackets/braces in disguise, at which point you might as well follow convention and use {}. This is obviously a very personal issue, but for me, the whitespace has less cognitive load. E.g.: in languages with brackets, people usually still indent the code for readability. I've also found that when teaching people to program, consistency works well. I think thi…

For those languages is not people who reindent code but it's the editor or the IDE. There is usually a key to force reindentation. That is possible because {} or even the end in Ruby are easy markers for the block (there are multiple markers for a block start in Ruby). Is there any automatical indentation function in some editor for Python? If not, it's Python the unfortunate language where people has to indent code to feed the compiler. I always hated doing the compiler's job.

I'm asking because I'm using Python little and only for short scripts, so I didn't bother investigating much. Still I've been bitten a couple of times by bugs introduced by moving code around and not noticing that a line was not indented correctly. That in Python and in Haml (http://haml.info/) If somebody knows about those tools I will appreciate and it will make my life easier. BTW, I'm fixing somebody's else Python scripts right now :-)

Re: Why People Should Learn Python

#123
post #72
post #54

Earlier quoted context omitted.

> Try running a nested loop on a non-trivial example, and you can end up spending minutes in what would take milliseconds in any other language. Huh? Can you provide an example? There's nothing about writing nested loops in Python that is qualitatively different from other languages. > If you want to program in Python, you must get used to the functional paradigm. Not "should", "must". This is incorrect, much to my c…

Huh? Can you provide an example? Well he did mention numpy and obviously doing something that can be done in numpy with nested loops will be much much slower. However that is as much a case of numpy being really fast as python being slow. For example, just tested elementwise multiplication of two 10kX10k matrices and with numpy and numpy arrays it took ~350 ms vs ~15 seconds with a nested for loops and python lists.…

I've been using Julia a lot lately so these results really surprised me, and I wrote my own test. Punchline: it takes about 0.4 seconds on Julia 0.4.6, on my machine which is several years old. Check it out:

julia> include("elmult.jl")

eachindex

0.42587028

outer loop over rows

8.923323015

outer loop over cols

0.516270241

Code:

    function elmult(m1, m2)
       result = zeros(m1)
       for i in eachindex(m1)
           result[i] = m1[i] * m2[i]
       end
       return result
    end

    function elmult_rowmajor(m1, m2)
        result = zeros(m1)
        nr = size(m1, 1)
        nc = size(m1, 2)
        for i in 1:nr, j in 1:nc
            result[i,j] = m1[i,j] * m2[i,j]
        end
        return result
    end

    function elmult_colmajor(m1, m2)
        result = zeros(m1)
        nr = size(m1, 1)
        nc = size(m1, 2)
        for j in 1:nc, i in 1:nr
            result[i,j] = m1[i,j] * m2[i,j]
        end
        return result
    end

    elmult(rand(3,3), rand(3,3))
    elmult_colmajor(rand(3,3), rand(3,3))
    elmult_rowmajor(rand(3,3), rand(3,3))

    m1, m2 = rand(10000,10000), rand(10000, 10000);

    println("eachindex")
    println(@elapsed elmult(m1, m2))
    println("outer loop over rows")
    println(@elapsed elmult_rowmajor(m1, m2))
    println("outer loop over cols")
    println(@elapsed elmult_colmajor(m1, m2))

Re: Why People Should Learn Python

#124
post #99

Earlier quoted context omitted.

As my PHP fluent colleague said to me - don't bother learning PHP or you will end up having to fix (our) Wordpress sites and thats a nightmare. We have a Python application, and while its not written well, the PHP sites we have seem to be a fair bit worse even the ones not done in Wordpress.

Wordpress is horrible. Never going to touch that again (Senior PHP Dev myself) or anything else like it (Magento, Drupal,...). And yes there is a lot of horrible PHP code out there, writting by bad developers. I guess newer or not as accessible languages don't have as many bad devs as PHP/JS. But if you have good devs, I prefer a good PHP codebase to any other language that I have come across (I tried a lot of them).

Could you elaborate a bit on what you prefer about it? I've heard this from a few people and would be curious to hear it fleshed out a bit.

Re: Why People Should Learn Python

#125
post #52

I use python on daily basis for 5 years now. It's a really cool language, but: * Packaging is horrible * Releasing python code is a non-standarised nightmare. Every solution has it's own flaws * Big and complex projects in python are really hard to reason about * Poor support for concurrency (fixed in py3) Don't get me wrong, python is really cool as a proof-of-concept scripting language. But for mature and complex s…

I've programmed in a few other languages than Python. I'm curious to know which languages you think have an easier time managing mature and complex stuff?

Re: Why People Should Learn Python

#126
post #121
post #117

Earlier quoted context omitted.

Could you post the Julia code? Unfortunately, you do have to make sure that the types are correctly inferred by the compiler in high-performance loops. Or maybe you used a global. http://docs.julialang.org/en/release-0.4/manual/performance-...

I'll admit I don't really know that much Julia and basically wrote naive MATLAB code (and I wanted to make it as close as possible to my python code): s=10000; a=ones(s,s); b=ones(s,s); c=zeros(s,s); tic(); for i in 1:s for j in 1:s c[i,j]=a[i,j]*b[i,j] end end toc(); Obviously in real code I'd simple write c=a.*b and get basically the same performance as numpy

It looks like this was done at global scope. It's important to wrap things in a function for maximum performance - AFAIK, because method dispatch and precompilation happen at the function level, functions are much much faster than not functions.

Julia also stores its arrays column major, so put the outer loop over columns for another order of magnitude performance increase. (I'm not sure I love this feature, but presumably there's a reason...maybe for better performance on matrix operations?) My reply to your grandparent comment has a simple implementation that runs in 0.4 seconds on an aging machine.

Re: Why People Should Learn Python

#127
post #52

I use python on daily basis for 5 years now. It's a really cool language, but: * Packaging is horrible * Releasing python code is a non-standarised nightmare. Every solution has it's own flaws * Big and complex projects in python are really hard to reason about * Poor support for concurrency (fixed in py3) Don't get me wrong, python is really cool as a proof-of-concept scripting language. But for mature and complex s…

Do you really think packaging is still horrible? I tend to agree with Glyph Lefkowitz [0]. What issues are you still having?

[0] https://glyph.twistedmatrix.com/2016/08/python-packaging.htm...

Re: Why People Should Learn Python

#128

Why you shouldn't learn Python: 1. In-consistant syntax. 2. The language uses exceptions to control flow of logic. 3. Divided community, since Python 3+ included breaking changes to the standard. 4. Un-discoverable APIs. You better hope the documentation is bulletproof else the API could change in any which way during runtime. 5. Poor error messages. If an import goes wrong you are not told why, and so on. 6. Ultimat…

Reasons to learn Python:

Sklearn, tensorflow, pandas, Sqlalchemy, requests, Beautifulsoup, numpy, scipy, pulp.

If you have a language that had equivalent libraries that cover all these domains I'd love to hear it. Until then I can build really cool stuff in Python very easily thanks to the amazing hardwork and generosity of these library creators.

Re: Why People Should Learn Python

#129
Addressing some criticism from various comments:

> Python 2 vs 3

It is mostly over. All important libraries are accessible on 3. It is clear that if you are starting from scratch you should go with 3. There are good tools to help with the migration (e.g. six). Some libraries start dropping python 2 support.

> Bad tooling

Having used Emacs with jedi for a while I switched to PyCharm to leverage optional typing. PyCharm beats my tooling experience in all languages I used expect Java:

- Auto imports work well.

- Code completion works very well, especially on optionally typed code.

- Even refactoring works very well, failing short only to my experience with Java, but beating C++ or even Scala.

- Debugging is actually a highlight - I can drop into full fledged REPL at break point. "Evaluate expression" in C++ or Java didn't come close.

Profiling is indeed not as advanced as what I was used to on the JVM, but IMO it is sufficient for 95% of use cases. For that 5% it is clear from the start that you shouldn't go with python. Language specific performance monitoring in production becomes less of an issue when you start running inside containers and it starts to make more sense to monitor containers rather than individual processes.

> Maintainability at scale

I am using Python 3.5 optional typing and I feel my project is much more maintainable as a result. Among others, refactoring in PyCharm works very well.

> Packaging and deployment

As mentioned in another comment, personally I moved away from relying on language specific tools to do more than just "install version X of library Y" and manage my deployment and dependencies using docker. It have it's own problems, but so far it works very well, and it's quickly improving.

> Performance

In domain of scientific computing by using correct libraries and things like Cython or Numba you can come close to C++ performance levels. In other domains it's becoming more common to be disk/network bound, and then it doesn't matter if you use Assembler or Python. Also JITs are coming to Python: https://lwn.net/Articles/691070/.

> Syntax/libraries/language features/etc.

It is the most subjective section, but my experience with python in this regard is highly superior to Scala/Java/C++/JS.

Re: Why People Should Learn Python

#130
post #51

Earlier quoted context omitted.

Not all - note the always relevant: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

Nobody said all.. and your link is just some guy's rant. He mentions at the end that he doesn't have any conclusions and he just assumes that people who read the article agree with him. Sure, PHP has it's faults, but as your article points out, it's designed to give people who aren't full time programmers tools with which to build websites or scripts to perform tasks, and there is a large market for that sort of thin…

> it's designed to give people who aren't full time programmers tools with which to build websites

And just like that, the cyber-security profession was born.

Post reply on HN