Live data from Hacker News

Python has brought computer programming to a vast new audience

economist.com

221–230 of 268 posts

Re: Python has brought computer programming to a vast new audience

#221
post #201

Earlier quoted context omitted.

sum(x > 3 for x in iterable) True == 1, False == 0, so this counts how many items in iterable are greater than 3. But I think that's the only non-dirty way I've used it, and if that wasn't possible a trivial count() function could do the job. If I remember correctly, bool subclasses int mostly for compatibility with pre-existing conventions. People were already defining their own "True = 1" and "False = 0" constants…

If it wasn't possible you could still do: sum(x > 3 for int(x) in iterable) And avoid a class of errors in other places.

That code is invalid, because you're using "int(x)" as an assignment target. What would you expect it to do?

Re: Python has brought computer programming to a vast new audience

#223
post #178

Someone else said this on HN: Python is the second best language in almost every field of computing. That's why there's a library for everything in Python. It's limitations are also not terrible for most people. If you want super fast, you will know how to do that some other way. If you just want simple and easy to read, you use Python.

> Someone else said this on HN: Python is the second best language in almost every field of computing. It isn't. Frankly, it isn't even top 3 in any "field of computing" depending on how you define "field of computing". What python has going for it is the evangelists who do a great job of spreading the word and of course funding - they have lots of money backing the language. Also, being an interpreted language, it h…

how do you define "field of computing"?

It's taught in most beginning CS courses, has wide adoption for scientific computing and business. It seems like most apps are prototyped in R/Python before functions get ported to c or parallelized with dask/spark/scala

python was never intended to be a functional language, but it has lambdas. ruby and C++ are both "functional, OO, imperative" in the same way.

C with classes and first class functions is probably the best language

Re: Python has brought computer programming to a vast new audience

#224

Earlier quoted context omitted.

Here are some examples from the Python standard library: multiprocessing/pool.py: self._number_left = length//chunksize + bool(length % chunksize) test/test_math.py: tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1) From NumPy and SciPy: numpy-1.11.0/tools/swig/test/testArray.py:385: sys.exit(bool(result.errors + result.failures)) scipy/scipy/signal/signaltools.py:2003: n_out = n_out // down + bool(n_out % d…

>Here's one from my own code, where I allow a query to be specified through --query , or as a hex-encoded query through --hex-query or as an input file through --queries, but I only allow one of them This would be better written as a mutually exclusive argument group. Assuming you're using argparse: https://stackoverflow.com/a/13310109

"Better" only if you want the default error message. As the second rated answer for the question comments: "If you like to have more control about error message and the like, you can of course check the results later"

For example, this code:

    import argparse
    parser = argparse.ArgumentParser()
    g = parser.add_mutually_exclusive_group()
    g.add_argument("--queries",help="queries help")
    g.add_argument("--hex-query",help="hex-query help")
    g.add_argument("--query",help="query help")
    args = parser.parse_args()
    print(args)
When passed the command-line arguments "--hex-query AB --query CD --queries ASDF" it gives:

  error: argument --query: not allowed with argument --hex-query
My code gives:

  error: Can only specify at most one of --query, --hex-query, or --queries

Re: Python has brought computer programming to a vast new audience

#225
post #130

Earlier quoted context omitted.

Agree. I can't understand people praising the lightness and readability while at the same time stuffing their code with underscores. Also it seems often inconsistent. Like some functions are used as prefix (len(x)) while other are suffix (x.clear()), I assume for historical reasons. Or like the "b if a else c" which reverse the logical order (you evaluate the condition then you can tell if you go one way or another).…

Those are all valid gripes, but for most use-cases (where performance isn't critical), I haven't found anything better than Python yet. Ruby is an aesthetically nicer language and doesn't have those issues you mentioned in the first paragraph, but the Python ecosystem is amazing and better than Ruby's IMO. And compared to most other languages Python still feels very clean, terse, and pretty to me. >multi-threading Mo…

> There are 2 kinds: bytes and unicode.

No I mean single quote, double quote, triple double quotes, r prefix, u prefix, f prefix, combinations, etc

> Can you give some examples

The one I have in mind is the os library, which I use a lot (like why st_mtime?).

Re: Python has brought computer programming to a vast new audience

#227
post #15

Python is a great language to start programming in. My biggest frustration with traditional programming languages (well, C/Java mostly) was just how much upfront effort and understand is required to do useful stuff. Whereas with python it is pretty easy to whip up a script, read input and transform it into output in real time etc. That said, I think its also important for Python programmers to dabble at least a littl…

There is not an Universal OOP specification to follow.

In Java's case, a lot OOP flavor's design patterns are created due to Java's lacking of some primitives like closure/lambda and higher-order functions back in its old days.

In short, Java's OOP solves many problems that are unique to Java and could be easily avoided in other languages.

Re: Python has brought computer programming to a vast new audience

#228
post #126

Earlier quoted context omitted.

I gather the exact opposite opinion of you: when something is aesthetically pleasing people will come up with rationalizations for why they like it, even if the real reason is difficult to describe. Similar to how in a focus group you can judge people's overall opinion but you should not focus on their specific feedback.

I am involved in many, many language communities. I've shipped software to production audiences of varying sizes in C, C++, Perl5, Common Lisp (Allegro), Common Lisp (SBCL), Ruby, Python, Scala, Ocaml, Java, JavaScript, Clojure, Haskell, F#, Typescript, Purescript, and Pony (finally!). I've used many more languages for non-trivial projects, including some now some defunct but really beautiful contenders like Nim, Io,…

To avoid confusion: Perl 6 is not (anymore) on the defunct list, it is still on the "beautiful contenders" list.

Re: Python has brought computer programming to a vast new audience

#229
post #126

Earlier quoted context omitted.

I gather the exact opposite opinion of you: when something is aesthetically pleasing people will come up with rationalizations for why they like it, even if the real reason is difficult to describe. Similar to how in a focus group you can judge people's overall opinion but you should not focus on their specific feedback.

I am involved in many, many language communities. I've shipped software to production audiences of varying sizes in C, C++, Perl5, Common Lisp (Allegro), Common Lisp (SBCL), Ruby, Python, Scala, Ocaml, Java, JavaScript, Clojure, Haskell, F#, Typescript, Purescript, and Pony (finally!). I've used many more languages for non-trivial projects, including some now some defunct but really beautiful contenders like Nim, Io,…

Uh? Is Nim defunct? I wouldn't say so!

Re: Python has brought computer programming to a vast new audience

#230

Earlier quoted context omitted.

:set ts=8 sts=0 sw=8 expandtab I have secrets.

Thank you for this. I've been typing out: :set tabstop=4 :set shiftwidth=4 :set expandtab Like a pleb for years. What's sts?

Put them in your .vimrc, and put your dotfiles in git.

Hint: searching GitHub for "dotfiles" can be a fun and productive way to spend a Friday afternoon :-)

Post reply on HN