News for hackers. Stuff that matters.
Re:Python’s tug of war between beginner-friendly and advance... by smitty1e on Thursday February 04, 2021 @08:23PM (#26031956)
> Creating a new language sounds ideal

I seriously cannot think of anything I could do to exceed Python.

Does it do everything? No. But name a tool with significantly greater overall reach. Some compete, but seriously. . .

Re:Python’s tug of war between beginner-friendly and advance... by pansa2 on Thursday February 04, 2021 @09:02PM (#26032207)
Python is great if you’re writing code to run on your own computer(s). But it’s terrible for packaging into executables to give to others (compared to Go), for embedding in applications (compared to Lua) and for running in the browser (compared to JS).

There’s no reason a new scripting language couldn’t excel in all three of those areas. But AFAIK none currently come close.

Re:Python’s tug of war between beginner-friendly and advance... by andi999 on Thursday February 04, 2021 @11:28PM (#26033113)
And small things. Like your function wants to know if a parameter was not used when calling it. The ideom if par=None breaks if called with arrays. Ending scripts with a command early would also be great (for interactive programming)

Also what is wrong in having a switch statement? (I`d like one with range cases 1<x<10..)

Accesing dicts with a struct syntax.

'Inline' C functions.

JIT, especially for loop acceleration.

Re:Python’s tug of war between beginner-friendly and advance... by LostJourneyman on Friday February 05, 2021 @08:23PM (#26043259)
Quick note, the more pythonic way of checking par in this case would be just to:

  if par:
    do_stuff()
Python does some really cool, if slightly unintuitive, checks for "truthiness" where 0, [], {}, false, '' and None (could be other cases too, brain's a little foggy today) all evaluate as false. This controls for:

  if par = None:
    do_stuff()
not catching empty lists, empty dicts, etc.
Re:Python’s tug of war between beginner-friendly and advance... by andi999 on Saturday February 06, 2021 @09:04AM (#26046534)
How do you define the function in that case?
Re:Python’s tug of war between beginner-friendly and advance... by LostJourneyman on Sunday February 07, 2021 @10:46AM (#26055750)
So, a more complete example might help:

  def myFunc(par=None):
    if par:
      # do whatever is needed when the parameter exists
    pass
    #finish processing
This allows you to pass in [], {}, None, '', or omit par all together, which will all behave as if par=None, or pass in data and use it appropriately. You can also use

  if not par:
    pass
if you want to do the inverse.
Re:Python’s tug of war between beginner-friendly and advance... by vasachi on Friday February 05, 2021 @01:25AM (#26033668)
I believe the idiom to check, if a parameter wasn’t set is to use an object() instance as default value.

  _notset = object()

  def foo(x=_notset):
      if x is _notset:
          print("foo was called as foo()")
Re:Python’s tug of war between beginner-friendly and advance... by andi999 on Friday February 05, 2021 @06:29AM (#26035198)
Thats nice. Thanks. Where did you find it.
Re:Python’s tug of war between beginner-friendly and advance... by vasachi on Saturday February 06, 2021 @06:36AM (#26045885)
I think it is from somewhere in standard library.
Re:Python’s tug of war between beginner-friendly and advance... by maxs on Friday February 05, 2021 @02:50AM (#26034070)
I don't understand what you mean by arrays.

    if par is None: ...
As for accessing dicts with a struct syntax, I prefer keeping dicts and objects different things (unlike Javascript).

And for JIT, there's numba!

Agreed on the switch statement...

Re:Python’s tug of war between beginner-friendly and advance... by Wowfunhappy on Thursday February 04, 2021 @10:23PM (#26032705)
Pyinstaller seems to work pretty damn well for packaging standalone binaries. Or at least it does on macOS, I haven't tried it on other platforms.
Re:Python’s tug of war between beginner-friendly and advance... by MikeTheGreat on Friday February 05, 2021 @02:36AM (#26034008)
I'm using PyInstaller on Win10. It works well, although the single-file binaries get slower as I add more libraries because it starts by extracting that single file out into a temporary directory and then running it.

It's a personal project so I like to experiment, but it's also a CLI program that accepts command line arguments, runs, and then exits, so a 3-5 second delay _each_time_ it runs is pretty painful.

Luckily for me there's a 'single directory' option, which puts everything (uncompressed) into a folder. Snappy start because there's no decompression step, and while I like the idea of a single file .exe it turns out I don't really need that (I'm not copying the program from computer to computer).

So - thumbs up for PyInstaller!

Re:Python’s tug of war between beginner-friendly and advance... by sireat on Friday February 05, 2021 @02:50AM (#26034068)
Pyinstaller is nice for packaging projects with smaller libraries. Hello world is about 7MB.

Try including pandas with a few other popular libraries.

Suddenly you have 500MB blobs. Not very practical for passing around multiple projects.

I suppose that is not worse than Electron apps...

Re:Python’s tug of war between beginner-friendly and advance... by dagw on Friday February 05, 2021 @07:15AM (#26035475)
I know you are being factious, but it is much worse than Electron apps. One advantage of JavaScript's focus on smaller libraries and aggressive tree shaking at build time is that it is pretty good at only shipping code that is actually called.

In the python world you have to do all the work by hand. I've literally spend time copying and pasting code out of libraries and into my code just so that my build wouldn't balloon by 100MB because I wanted to call a 100 line function.

Re:Python’s tug of war between beginner-friendly and advance... by Wowfunhappy on Friday February 05, 2021 @11:35AM (#26038113)
Is Python actually so poor though?

This is an extremely unscientific comparison, because I don't feel like creating custom binaries specifically to test with. But I happen to have a copy of youtube-dl on my hard drive, and it's 1.8 MB. I'm not sure whether youtube-dl creates their binaries with PyInstaller, but youtube-dl is written in Python, and the binary is a single file that can be run without a Python installation.

I also have a copy of docker-compose, which I know for a fact is created with Pyinstaller. That one clocks in at a significantly worse 10.8 MB (so perhaps Pyinstaller is the culprit and youtube-dl is doing something unique), but that's still relatively small for a considerably complex program.

Lastly, I have a binary called "toggle-switchmate3", which I created myself some years ago. I have a set of Switchmate light switches set up in my apartment, and the best way I could find to control them from a Mac was via this Node package: https://www.npmjs.com/package/node-switchmate3. NPM's dependency mess freaks me out, so I set everything up in a virtual machine, and then created a binary with "pkg", the Node equivalent of pyinstaller.

"Toggle-switchmate3" is 36.1 MB. And it's not a standalone binary—it requires a separate "binding.node" file to be in the same directory.

Re:Python’s tug of war between beginner-friendly and advance... by dagw on Friday February 05, 2021 @05:13PM (#26041885)
Is Python actually so poor though?

Perhaps not in the general case, but in many cases it absolutely is. The problem isn't python itself but libraries. While JavaScript tends towards dozens of small libraries that do only one thing, python tends towards one library that does everything. Which is really handy in most cases, but very painful when you want to package something that just uses one of those functions.

In a concrete case I had a small script that ran a particular edge detection algorithm on an image and returned the edges in geojson format. The whole script was less than 300 lines. But the built dist weighed in at several hundred MB as it pulled in the entirety of numpy, scipy, scikit-image, fiona, shapely and rasterio, despite needing only maybe a couple of percent of the functionality of each library.

Re:Python’s tug of war between beginner-friendly and advance... by vram22 on Friday February 05, 2021 @01:50AM (#26033796)
I have tried PyInstaller some, on Windows, for both CLI and GUI (wxPython) apps, and what I tried worked fine, including single-file EXEs.
Re:Python’s tug of war between beginner-friendly and advance... by CraigJPerry on Thursday February 04, 2021 @11:46PM (#26033237)
>> for embedding in applications

I did this before and found it really easy to integrate. The provided C API surface is really easy to integrate with. It was literally just a case of detailing my types, calling the Py runtime and then querying the results/side effects.

Having never done something like that before, i was full of trepidation - i was amazed at how easy it was.

Re:Python’s tug of war between beginner-friendly and advance... by pjmlp on Friday February 05, 2021 @03:23AM (#26034220)
Packing Python into single packages has been a thing since 2002.
Re:Python’s tug of war between beginner-friendly and advance... by jshen on Thursday February 04, 2021 @09:02PM (#26032208)
There are a lot of things python could do to be much better. Two examples, 1) dependency management in python is a train wreck compared to most modern languages. 2) the way package paths are done for imports is far more confusing than it should be.
Re:Python’s tug of war between beginner-friendly and advance... by jtdev on Thursday February 04, 2021 @08:58PM (#26032180)
Agreed. I’ve always felt that the following sums up why Python is my preferred language:

Python is the second-best language for everything.

Re:Python’s tug of war between beginner-friendly and advance... by monsieurbanana on Thursday February 04, 2021 @09:37PM (#26032424)
With the big, big, notable exception: targeting the browser.
Re:Python’s tug of war between beginner-friendly and advance... by folkrav on Thursday February 04, 2021 @10:36PM (#26032797)
To be perfectly fair, unless you count WASM or other compiles-to-JS-but-not-quite-native langs (which, outside TS, are pretty niche), this is the case with literally every language except JS.
Re:Python’s tug of war between beginner-friendly and advance... by monsieurbanana on Friday February 05, 2021 @03:40AM (#26034299)
> unless you count WASM or other compiles-to-JS-but-not-quite-native langs

As a happy user of clojurescript, or seeing the popularity and adoption rate of typescript, I do not count them out.

Re:Python’s tug of war between beginner-friendly and advance... by folkrav on Friday February 05, 2021 @12:48PM (#26039051)
Not counting them out either, but outside TS, they're still quite marginal, at best.
Re:Python’s tug of war between beginner-friendly and advance... by jtdev on Friday February 05, 2021 @08:10AM (#26035881)
JavaScript and it’s variants are 1st place for the browser (shoe in on a technicality) ... but like 213th for everything else.
Re:Python’s tug of war between beginner-friendly and advance... by Izkata on Thursday February 04, 2021 @11:36PM (#26033167)
Possibly not for long: https://www.brython.info/
Re:Python’s tug of war between beginner-friendly and advance... by mkl on Friday February 05, 2021 @07:33AM (#26035625)
Brython has been around since 2014.
Re:Python’s tug of war between beginner-friendly and advance... by peterkelly on Friday February 05, 2021 @01:54AM (#26033820)
> I seriously cannot think of anything I could do to exceed Python.

Just off the top of my head:

- Pattern matching

- Multi-line lambdas

- Proper variable capture in lambdas and inner functions (as was fixed with the 'let' keyword vs 'var' in recent versions of JavaScript)

- Support for cyclic imports (a bad pattern in general but necessary in some cases)

- A well-defined C API for extensions that doesn't get them too entangled in the internals of CPython. This would make it possible for other implementations to reach the level of library support that CPython enjoys.

Re:Python’s tug of war between beginner-friendly and advance... by kazinator on Friday February 05, 2021 @04:45PM (#26041615)
Pattern matching is in PEP 635, created Sep 12, 2020.

Multi-line lambdas can be sort of obtained in Python by defining a progn function:

https://news.ycombinator.com/item?id=19933223

Re:Python’s tug of war between beginner-friendly and advance... by maxs on Friday February 05, 2021 @02:52AM (#26034075)
I would say proper variable scoping in general. It would be awesome to have let variables in python!
Re:Python’s tug of war between beginner-friendly and advance... by zo1 on Friday February 05, 2021 @03:08AM (#26034149)
Variables are scoped just fine from my point of view. What do you mean by proper?
Re:Python’s tug of war between beginner-friendly and advance... by maxs on Friday February 05, 2021 @03:17AM (#26034185)
I meant to say block scoped. Variables in python have function or global scope but no global scope. E.g. you can say

   for x in ...:
and then use x outside of the loop.
Re:Python’s tug of war between beginner-friendly and advance... by knighthack on Saturday February 06, 2021 @07:47AM (#26046169)
I have no idea why you would want to declare an x in the loop, and then use it outside the loop. There are better ways of doing things.

The fact that you can do such a thing in JavaScript is exactly why JavaScript is such a mess of a language with its globally-declared and hoisted variables.

That sort of practice has never made sense, and is not a language design that Python should follow.

Re:Python’s tug of war between beginner-friendly and advance... by didibus on Thursday February 04, 2021 @11:47PM (#26033243)
I'm not sure what you mean by reach? But Clojure given one definition has more reach. It can make use of Python libraries, Java libraries, C# libraries, JavaScript libraries, Erlang libraries, C libraries, and can run on desktop, mobile and browser.
Re:Python’s tug of war between beginner-friendly and advance... by javajosh on Thursday February 04, 2021 @09:06PM (#26032234)
JavaScript has greater reach. ES6 in a modern browser with native modules, and if you avoid classes and this, focus on object literals and pure functions, and pick a decent utility library, its a very good environment with max reach.
Re:Python’s tug of war between beginner-friendly and advance... by jimbob45 on Thursday February 04, 2021 @08:48PM (#26032126)
Better main method calling, better chaining, multiple constructors, and better reflection.