News for hackers. Stuff that matters.
Re:Python has brought computer programming to a vast new aud... by riazrizvi on Thursday July 19, 2018 @05:15PM (#17570345)
The thing I love most about the language is its conciseness, on several levels.

It's syntactically concise because of its use of whitespace and indentation instead of curly braces.

Expressions are often concise because of things like list slicing and list expressions.

It can be linguistically concise, because it is so easy to fiddle with the data model of your classes, to customize their behavior at a deeper level. For example, it is so quick to design a suite of classes that have algebraic operators, which leads to elegant mathematical expressions of your custom GUI objects for example. But you can also change the way classes are instantiated by overriding Class.__new__ which I've used to make powerful libraries that are a joy to use.

Further elegance can be added through creative use of the flexible argument passing machinery, and the lovely way that functions are also objects.

Your application architecture tends to be concise because there are so many existing libraries, you can often design your application at a more interesting higher level. For example, you don't have to worry about the size of int's.

My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded.

Besides the odd gripe here and there, the language really gives me a warm glow.

Re:Python has brought computer programming to a vast new aud... by throwaway5752 on Thursday July 19, 2018 @05:22PM (#17570400)
"Besides the odd gripe here and there, the language really gives me a warm glow."

That's a perfect summary of my feeling towards it, too. If the PSF puts up a GoFundMe for sending Guido on a nice vacation of his choosing, I will be happy to chip in a few bucks. Same goes for Linus when he hands over the reins, and a few other maintainers who probably cannot be adequately compensated for the impact of their work.

Re:Python has brought computer programming to a vast new aud... by stevesimmons on Thursday July 19, 2018 @08:21PM (#17571494)
I agree. I came to Python in 2000, after Perl (1996-1998), PHP (1999), Matlab (1992-1996), C++ (1990), Fortran (1989), C (1988), Pascal (1988), Assembly (1984-86) and Basic (1981-83).

After all those, I found Python, as the saying goes, really does "fit your brain" [1]. Since discovering Python 18 years ago, I have looked at Haskell, successfully avoided Java, and promised myself to "one day" do more JS. Still, Python remains 95% of what I do, and I don't see a problem with that :)

[1] "Python fits your brain" was the theme of the 9th International Python Convention in 2001.

Re:Python has brought computer programming to a vast new aud... by dorfsmay on Thursday July 19, 2018 @08:45PM (#17571607)
> "Python fits your brain"

For me, I find using python is like touching both data and code with my hands.

As much as it's trendy to bash Object Oriented languages, the way python allows to lookup all variables and method on a class or an object makes it like using your hands:

dir(MyClass) help(MyClass) dir(my_object) help(my_object)

etc...

Re:Python has brought computer programming to a vast new aud... by opnitro on Thursday July 19, 2018 @09:41PM (#17571825)
If you'd like to go further along that path, and I'd really recommend trying to learn a lisp. How to Design Programs[0] is good gentle introduction if you're new to the ideas of lisp or functional programming, and SICP[1][2] is the old classic.

[0] http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html

[1] http://web.mit.edu/alexmv/6.037/sicp.pdf

[2]https://www.youtube.com/watch?v=2Op3QLzMgSY&list=PLE18841CAB...

Re:Python has brought computer programming to a vast new aud... by dorfsmay on Friday July 20, 2018 @01:00PM (#17576779)
Which one though?

I have looked at LISPs, but it's difficult to pick one to invest time in. Because I am so restricted on time I have to stick to languages which are used in the industry (so my fun has real-life ROI), which I think boils down to CL which is often touted as old-fashion and its market seems to shrink slowly, and Clojure which means the JVM and mainly Java libraries and high mem requirements.

For pure fun and practicality, Racket does seem up on the "list", but not used at all in the industry. A lot of languages (Python, Rust) are adopting the good parts of lisp (except for the minimal syntax, sadly), and I'm getting better mileage from spending time learning and becoming better at those than starting from scratch in a language that I won't be able to use during work hours.

Re:Python has brought computer programming to a vast new aud... by opnitro on Sunday July 22, 2018 @10:08AM (#17586811)
So, I really like How To Design Programs, because the thing it got across for me is how to appropriately think in a functional way. It walks you through building data structures and full programs in a really nice method. I've now been going through SICP, and nothing has seemed out of place as the notation is almost identical, and the few places that it isn't are not hard to translate.
Re:Python has brought computer programming to a vast new aud... by dorfsmay on Sunday July 22, 2018 @03:02PM (#17588257)
My question was more about which program language, which Lisp to choose in 2018?
Re:Python has brought computer programming to a vast new aud... by opnitro on Tuesday July 31, 2018 @08:42PM (#17658668)
Oh, so How To Design Programs uses "teaching" languages, which are sub-languages of Racket. Going from that book to learning the full features of Racket has been fun.
Re:Python has brought computer programming to a vast new aud... by vgy7ujm on Friday July 20, 2018 @08:19AM (#17574377)
Totally the other way around for me. Perl fits my brain. Python I can't comprehend.
Re:Python has brought computer programming to a vast new aud... by bb88 on Thursday July 19, 2018 @08:10PM (#17571459)
Ask Naomi Ceder who is the chair of the PSF. She's super nice.
Re:Python has brought computer programming to a vast new aud... by eigenvalue on Thursday July 19, 2018 @05:46PM (#17570592)
It's also nicely self-contained, especially if you use a distribution like Anaconda. You don't have to spend hours fighting with the configuration and tooling. It's also very easy to debug and step through code using Spyder, which is similar to MATLAB. It makes it easy for someone who is smart and generally competent with computers to be productive in a short amount of time without first amassing huge amounts of arcane knowledge-- knowledge that isn't actually helpful to making working code!
Re:Python has brought computer programming to a vast new aud... by sidlls on Thursday July 19, 2018 @09:03PM (#17571689)
I've found it very difficult to "self-contain" python projects that are even of modest size. Anaconda is a mediocre solution that is the best among other terrible options.
Re:Python has brought computer programming to a vast new aud... by Barrin92 on Thursday July 19, 2018 @06:40PM (#17570972)
agreed with all the posts above, the only real letdown for me was always the difficulty to produce standalone executables. I would really love a python equivalent to uberjars or go's build tool.
Re:Python has brought computer programming to a vast new aud... by StavrosK on Thursday July 19, 2018 @07:22PM (#17571222)
I recently used PyInstaller to wrap Black (the code formatter) and it worked perfectly in two minutes. Literally one command to take the whole script and produce a standalone executable. There's also something like this: https://build-system.fman.io/
Re:Python has brought computer programming to a vast new aud... by talltimtom on Friday July 20, 2018 @07:58AM (#17574257)
The thing about pyInstaller is that it works absolutely perfectly... until it doesn’t. In which case you are stuck spending days on trying to kick everything in your project into shape with the hope of it working.

That is what I hate most about Python, there is only one sure-fire way of doing packaging and that’s setting it up even before you write your first line of code and the testing constantly as your project evolves.

Myself and others have absolutely no trust in the several build pathways because they all fail horrible for a wide range of reasons. To the counter, if I have a C++ or C# project I’m very confident that it will almost always be a breeze to package it up.

Re:Python has brought computer programming to a vast new aud... by devmacrile on Friday July 20, 2018 @12:15PM (#17576320)
This was circulating around HN a few days ago: https://github.com/facebookincubator/xar
Re:Python has brought computer programming to a vast new aud... by riazrizvi on Friday July 27, 2018 @08:05PM (#17630565)
CORRECTION: My regret was referring to a problem where this code worked in Python 2 but not Python 3:

    x = 100
    y = [x+i for i in range(2)]
In Python 3 I kept seeing

    NameError: name 'x' is not defined
However, after working around this problem with fixes like this -

    x = 100
    y = (lambda x=x: [x+i for i in range(2)])()
    
I have just discovered that the different scope treatment was due to a problem with IPython when using it in embed mode, for example by calling it with the following command:

    $ python -c "import IPython;IPython.embed()"
It goes away when you call ipython directly

    $ ipython

I mistakenly attributed this problem to Python 3 for years, I guess I introduced the problem because I had a different way of invoking Python 2 and Python 3 - yeesh.
Re:Python has brought computer programming to a vast new aud... by UncleEntity on Thursday July 19, 2018 @06:39PM (#17570962)
> My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded.

Ironically, the PEP to add this to py3k is what's causing all the fuss in pythonland lately.

Re:Python has brought computer programming to a vast new aud... by riazrizvi on Thursday July 19, 2018 @07:32PM (#17571283)
Actually I think it was 'fixed' as a syntax change in Python 3, https://docs.python.org/3/whatsnew/3.0.html#changed-syntax "List comprehensions no longer support the syntactic form..."
Re:Python has brought computer programming to a vast new aud... by kjeetgill on Thursday July 19, 2018 @08:41PM (#17571584)
He's talking about something a little different. Python is introducing assignment expressions (vs assignment statements).
Re:Python has brought computer programming to a vast new aud... by hellofunk on Thursday July 19, 2018 @05:20PM (#17570389)
> My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded.

Can you elaborate? I'm not sure what this is referring to.

Re:Python has brought computer programming to a vast new aud... by eesmith on Thursday July 19, 2018 @05:48PM (#17570608)
In Python 2.x the loop variable is part of the containing scope:

  >>> a
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'a' is not defined
  >>> [a*2 for a in (1,2,3)]
  [2, 4, 6]
  >>> a
  3
In Python 3.x, it is not:

  >>> a
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'a' is not defined
  >>> [a*2 for a in (1,2,3)]
  [2, 4, 6]
  >>> a
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'a' is not defined
It is sometimes useful to know why something failed. The following Python 2 code will not work in Python 3:

  >>> import math
  >>> try:
  ...   values = [math.sqrt(x) for x in (1, 2, -3, 4)]
  ... except ValueError:
  ...   print("cannot compute sqrt(%r)" % x)
  ...
  cannot compute sqrt(-3)
I have mostly found this feature of Python 2 to be useful on the interactive shell, when trying to diagnose what caused an error in my list comprehension. Eg.

  >>> with open("tmp.dat") as input_file:
  ...   fields = [line.split()[3] for line in input_file]
  ...
  Traceback (most recent call last):
    File "<stdin>", line 2, in <module>
  IndexError: list index out of range
  >>> line
  'one two three\n'
Oops, there are only 3 columns, not 4.
Re:Python has brought computer programming to a vast new aud... by w-m on Thursday July 19, 2018 @06:19PM (#17570841)
When you use iPython you can just drop into the context of the error with %debug after it occurred, and then print the line there. No need for the bleeding scope on the language level.
Re:Python has brought computer programming to a vast new aud... by kozlovsky on Friday July 20, 2018 @07:11AM (#17574008)
In Python 3.8 you will be able to use assignment expressions:

    [a := x*2 for x in (1, 2, 3)]
See PEP 572 -- Assignment Expressions: https://www.python.org/dev/peps/pep-0572/
Re:Python has brought computer programming to a vast new aud... by aidos on Thursday July 19, 2018 @06:26PM (#17570886)
I’m the same, I would never use that side effect in production code but I do miss having it in ipython though my use is slight different.

I often did:

    >>> [d for d in drawings]
    >>> [d.<tab> ...]
Because I’m lazy and I want the autocomplete to be there for me. It’s actually the only thing I miss from python 2 and I will admit that a couple of times the sideffects have caught me out in production code so I’m happy with the change.

It’s worth noting that the latest python pep is going to give you a way to assign the variables in the outer scope again:

https://www.python.org/dev/peps/pep-0572/#simplifying-list-c...

Re:Python has brought computer programming to a vast new aud... by duckerude on Thursday July 19, 2018 @05:28PM (#17570448)
In Python 2, "[x for x in range(10)]; print(x)" prints 9. x is available outside the list comprehension.

In Python 3, it raises a NameError, because the x in "print(x)" is not defined. It's contained in the list comprehension.

But I don't know a good use of the Python 2 behavior.

Re:Python has brought computer programming to a vast new aud... by iscrewyou on Thursday July 19, 2018 @05:39PM (#17570537)
I went through a course in python about a decade ago and I enjoyed it! Then along the way, I picked it up here and there. Then used it at work for a few months to sort through a lot of data.

Recently I started trying to learn swift through the Stanford course. And the curly brackets confused the heck out of me. They still do! They just seem to pop up out of nowhere. All to say , I completely agree with your second paragraph. Python is very concise.

Re:Python has brought computer programming to a vast new aud... by jplayer01 on Friday July 20, 2018 @07:20AM (#17574050)
Curly brackets fulfill the exact same function as indenting a code block in Python - it defines scope and ties code together.
Re:Python has brought computer programming to a vast new aud... by bb88 on Thursday July 19, 2018 @08:13PM (#17571469)
Usually braces define the scope (or lifetimes) of variables.

C/C++/Java use them quite a bit.

Re:Python has brought computer programming to a vast new aud... by nikofeyn on Thursday July 19, 2018 @08:45PM (#17571609)
do you know an ML language like sml, ocaml, or f#? if not, you should really give one a go, especially f#. the conciseness and cleanliness is just as good if not better than python, and there are far more options for data modeling and expression.