News for hackers. Stuff that matters.
Re:Brython – A Python 3 implementation for client-side web p... by ascar on Monday July 06, 2020 @06:04AM (#23746251)
Javascript came a long way and despite its legacy quirks is actually quite enjoyable with ES6. We also added tons of good tooling (like TypeScript, React or Vue) to improve the web development experience.

While I still think, it would be nice to use a language that doesn't need 3 equal signs for sane comparisons, I wonder if Python with its strong whitespace to code-block correlation is actually a good choice for transmission and remote execution?

It definitely increases the size of transmitted code (tho probably by not so much because I think files are usually transmitted gzip compressed to modern browsers).

Are there other issues anyone can think of? It somehow gives me an uneasy feeling even tho technically a semicolon or repeated 0x20 don't make a difference except size.

Re:Brython – A Python 3 implementation for client-side web p... by alexchamberlain on Monday July 06, 2020 @08:00AM (#23746975)
I (professional Python developer) tried writing some ES6 over the weekend. I acknowledge I'm out of the loop/practice, but I can handle ===. I do, however, struggle with 1) the lack of a reasonable standard library and 2) the lack of a well defined object model. In general, the fact that objects and mappings are the same thing, and that keys have to be strings, is tough for me to understand.
Re:Brython – A Python 3 implementation for client-side web p... by azangru on Monday July 06, 2020 @08:58AM (#23747387)
> In general, the fact that objects and mappings are the same thing,

What do you mean? What would you like to see in an object? ES6 has classes (syntactic sugar over prototypes, but does it really matter?) if that's what you are after.

> and that keys have to be strings

ES6 has a Map constructor[0] that can have any type of value as key. Usually, though, having keys as strings is quite sufficient.

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:Brython – A Python 3 implementation for client-side web p... by IshKebab on Monday July 06, 2020 @09:37AM (#23747710)
"Any type of value as key" is quite misleading since anything other than primitive types (number, bool, string) is compared by reference. Observe:

  > const m = new Map();
  undefined
  > m.set([1], "one");
  Map(1) {Array(1) => "one"}
  >m.get([1])
  undefined
C++ and Rust don't stand for this nonsense. You can't even define a custom hashing function, which means if you want a useful map for anything other than numbers and strings you have to write a wrapper around `Map` that hashes the objects to numbers or strings, and then you're more or less back to raw objects.

It's definitely better than raw objects because it doesn't mix up data and methods, but it's not much better.

Re:Brython – A Python 3 implementation for client-side web p... by gilnaa on Monday July 06, 2020 @10:35AM (#23748310)
I was quite surprised to read that you can't set a custom hasher in C++/Rust, and I even went and made sure that it's possible.

But then I re-read your comment and realized you've meant that you can't do this in JS.

Re:Brython – A Python 3 implementation for client-side web p... by temporarysdwvit on Monday July 06, 2020 @11:06AM (#23748703)
Oh you can, just implement toString and js will use it for hashing
Re:Brython – A Python 3 implementation for client-side web p... by IshKebab on Tuesday July 07, 2020 @08:31AM (#23758486)
No it won't.
Re:Brython – A Python 3 implementation for client-side web p... by yqot on Tuesday July 07, 2020 @01:59PM (#23762083)
Map, no. Plain object, yes.
Re:Brython – A Python 3 implementation for client-side web p... by IshKebab on Saturday July 11, 2020 @08:06AM (#23801492)
It doesn't "use `toString` for hashing", it just converts the key to a string. That is not the same (e.g. you can't recover the original key).
Re:Brython – A Python 3 implementation for client-side web p... by alexchamberlain on Tuesday July 07, 2020 @01:13AM (#23755913)
> ES6 has classes

To clarify, I miss having an object model that allows customisation of hashing, equality etc

> ES6 has a Map

Thanks for this; I'll check it out. One simple example of a key that is hard to use strings with is a composite key of 2 strings. OK, you could concatenate them using a character you know won't be used in either string, but what if it's user input? The code is then littered with in/out concatenation/splitting my this extra character etc. (And that's the simple case without other types etc.) It's much easier to have a clear way to customise the hash function IMHO.

Re:Brython – A Python 3 implementation for client-side web p... by Drew_ on Monday July 06, 2020 @11:57AM (#23749221)
Most programming languages have a nice delineation between a dictionary and an object but they are one and the same in JS and that'll throw plenty of traditional programmers for a loop.
Re:Brython – A Python 3 implementation for client-side web p... by andybak on Monday July 06, 2020 @02:12PM (#23750883)
To be fair Python has the concept of "everything is a dictionary" running pretty deep in its DNA. To a certain extent everything in Python is syntactic sugar over dictionaries.
Re:Brython – A Python 3 implementation for client-side web p... by jccooper on Monday July 06, 2020 @03:12PM (#23751577)
Yeah, but that's implementation. Top level syntax, an object and dictionary are distinct.
Re:Brython – A Python 3 implementation for client-side web p... by throwaway894345 on Monday July 06, 2020 @08:52PM (#23754468)
I’m a professional Python developer as well and JS objects are one of the things I envy. Python objects are still opaque to me after more than a decade. I couldn’t tell you all of the magic methods nor could I describe the functions of those that I do know. Many of the things that Python objects support, such as inheritance, strike me as overtly undesirable (it would be much better to use composition in all cases, IMO), and the meta type system seems far more complicated than it needs to be (partly because inheritance confounds things)—although I was relieved to discover that you can call type() to generate new types instead of using the meta type class syntax.

On the other hand, as far as I am aware, JS objects are just bags of attributes with relatively few special magic attributes. There also seems to be less of an obsession with inheritance in JS, probably because the syntax makes a functional style more ergonomic although perhaps also because prototype inheritance is relatively cumbersome.

In general, JS’s object system feels more transparent to me, although I wish they would go further and preclude the special syntaxes for creating types. There’s nothing wrong with a function that returns types (which are either objects or closures depending on your religion). But I suppose I’m well on my way to reinventing lisp at that point.

Re:Brython – A Python 3 implementation for client-side web p... by heavyset_go on Monday July 06, 2020 @11:45AM (#23749098)
> In general, the fact that objects and mappings are the same thing, and that keys have to be strings, is tough for me to understand.

JavaScript takes object.__dict__ literally.

Re:Brython – A Python 3 implementation for client-side web p... by goffi on Monday July 06, 2020 @06:15AM (#23746307)
White I agree with you about modern JS, using Python in the browser has a few advantages:

- it can be the same language as the backend, that's a huge advantage (no need to change context, you can more easily have the team for backend and frontend)

- if you use Python elsewhere (like it's my case for multi-frontends XMPP client), you can factorize the code

- it's a really popular language, notably among scientists

- I have no numbers, but I suspect that once the initial download is done and cached, Python code should be smaller than JS equivalent

- there is a huge ecosystem (of course JS is even bigger, but the neat thing is that you can use both)

And probably other things I'm not thinking of right now.

Re:Brython – A Python 3 implementation for client-side web p... by zaro on Monday July 06, 2020 @06:19AM (#23746327)
> - it can be the same language as the backend

This is already the case for Javascript :) Also you get much bigger collection of ready to use opensource libraries, and better performance.

Re:Brython – A Python 3 implementation for client-side web p... by KaiserPro on Monday July 06, 2020 @06:37AM (#23746430)
> you get much bigger collection of ready to use opensource libraries,

bigger number, but that's because there is no (useful) standard library in JS. Datetime for example, there are loads of libs for that in JS, some of which are complete.

In python you just use the built in one. You bust out to a non standard lib when you want something fancy.

Re:Brython – A Python 3 implementation for client-side web p... by zaro on Tuesday July 07, 2020 @02:32AM (#23756333)
> bigger number, but that's because there is no (useful) standard library in JS.

I was thinking more about higher level libraries like frameworks.

> Datetime for example, there are loads of libs for that in JS, some of which are complete. Ahm, and if you need to work with Timezones(not much fancy IMO) you still need an external library.

Re:Brython – A Python 3 implementation for client-side web p... by speedgoose on Monday July 06, 2020 @07:36AM (#23746798)
Like doing a http request asynchronously?
Re:Brython – A Python 3 implementation for client-side web p... by JonAtkinson on Monday July 06, 2020 @07:51AM (#23746907)
`import asyncio` is a standard part of Python.

`aiohttp` is a a 3rd party package if you want a more succinct expression of the same functionality.

Re:Brython – A Python 3 implementation for client-side web p... by rrrix1 on Monday July 06, 2020 @12:33PM (#23749576)
Important footnote: the creator of Node.js is also the creator of Deno. One of his key reasons for "starting over" with Deno is that the lack of a standard library in Node.js is one of it's biggest pitfalls. That is also one of Denos biggest features (among many other awesome things). Unfortunately there is still a long way to go for Deno to "catch up" to node.js.

As an experienced JS/TS and Python developer, I can confidently say that the Node.js / npm / yarn ecosystem sucks compared to what you get with Python and PyPi.

Re:Brython – A Python 3 implementation for client-side web p... by nawgszy on Monday July 06, 2020 @05:30PM (#23752999)
>the lack of a standard library in Node.js is one of it's biggest pitfalls

>npm / yarn ecosystem sucks compared to what you get with Python and PyPi

So you claim Python has a better standard library AND a better package ecosystem? That's bold. Care to expand on why you feel this?

I ask because of this. From the perspective of a JS dev who helps Python devs at work, pip seems pretty weak, its publishing story even weaker, and then both languages seem to have all their strength in their package ecosystems (Python: tf, django, dataframes, etc; JS: react, typescript, etc). So now to see you say "npm ecosystem sucks compared to pip" has me wondering what I'm missing.

Re:Brython – A Python 3 implementation for client-side web p... by zenhack on Monday July 06, 2020 @09:58PM (#23754864)
As someone who's done a lot of python and a fair bit of JavaScript, I'll agree with the preference for the python ecosystem. I guess my perception of the difference is a quantity vs quality thing. My experience has been that python packages tend to be more stable, better documented, and frankly more reasonable in scope. There's less framework churn (Django has been around for what feels like forever, as have lighter solutions like Flask) and libraries tend to include enough functionality to seem with adding a dependency for; the number of transitive dependencies on a typical JS project is alarming. Also much less of the ecosystem feels like it's just trying to make up for an absent standard library. You don't see stuff like underscore in python land.

Both languages suffer from patchwork build infrastructure; interpreted languages are great when you have one file and no dependencies, but as soon as you grow a bit beyond that rules about where to find modules make things complicated. Both languages have developed tooling around this that suffers from being an afterthought, and I'm not sure which is worse.

Re:Brython – A Python 3 implementation for client-side web p... by nawgszy on Tuesday July 07, 2020 @04:43AM (#23757022)
I guess this might not strictly belong to "the package ecosystem", but I strongly disagree that you can compare the npm packaging story to the pip packaging story. Publishing to npm, hosting your own npm instance, configuring npm to look behind proxies for certain packages, an opinionated `package.json` with real functionality beyond dependencies, a unified entrypoint, wow it actually boggles my mind to hear Python people say pip is even in the same room as npm.

Definitely let's be clear - babel & webpack and the associated ecosystem are a pain, but those are mostly borne of necessity to transpile HTML/CSS/JS from frameworks, and not because node.js itself isn't a decent language.

Finally, I don't really follow all this business about the lack of standard library. Can you explain to me what you mean? What parts of the Python standard library are a part of your everyday toolkit? I've built a lot of web apps over the years and the only time I've ever used lodash is for throttle and debounce.

Re:Brython – A Python 3 implementation for client-side web p... by pseudalopex on Wednesday July 08, 2020 @04:26AM (#23767990)
What's the matter with publishing to PyPI or hosting your own instance?

The Python ecosystem makes publishing binary packages easy. node-pre-gyp might come close if you use S3.

The most used NPM packages[1] overlap with Python's argparse, datetime, glob, os, shutil, uuid, and xml modules.

[1] https://www.npmjs.com/browse/depended

Re:Brython – A Python 3 implementation for client-side web p... by nawgszy on Wednesday July 08, 2020 @01:00PM (#23771787)
>What's the matter with publishing to PyPI

This is a succinct guide to publishing a PIP package: https://medium.com/@joel.barmettler/how-to-upload-your-pytho...

An npm publish requires you to run `npm publish`, assuming your `package.json` points to the entrypoint of your code. Remember: `package.json` is pre-populated when you start your project with `npm init`.

Also, I was able to run my own NPM instance with a zero-config tool, I expect Python has parity there.

Anyways, pip... Just the other day, I went to use a Python project I had been regularly using, and without any changes to Python, my OS, pip, or the project, it completely started failing. Some errors that the `ssl` module wasn't available. How can a module not be available? There was no easy solution, all to something triggered by nothing. This install was literally done thru a source-controlled script too. It's a pretty awful situaton.

Anyways, NPM has never so wholly failed me, and in the worst cases where it fails it usually has helpful messages directing the user what to do.

That plus tools `npx` make it pretty clear to me, Python is literally version and dependency hell. NPM has had this all on lock for years now

Re:Brython – A Python 3 implementation for client-side web p... by zaro on Tuesday July 07, 2020 @01:57AM (#23756143)
Indeed, pip feels like a joke after using npm.

Not that npm doesn't have flaws, but it gets much more things right.

Re:Brython – A Python 3 implementation for client-side web p... by zaro on Tuesday July 07, 2020 @02:28AM (#23756315)
> As an experienced JS/TS and Python developer, I can confidently say that the Node.js / npm / yarn ecosystem sucks compared to what you get with Python and PyPi.

I can say the same. As an experienced Python and TS/JS developer, I confidently state that Python ecosystem sucks compared to what you get with typescript and npm. And if we take only type systems TS is on another level compared to Python.

Re:Brython – A Python 3 implementation for client-side web p... by britbull on Monday July 06, 2020 @06:36AM (#23746427)
Although Javascript has a bigger collection, Python is often the go-to for Data Science, ML and AI, and Web dev backends. It's nice to reduce the complexity of the stack I'm using by being able to use Python for both.

Also, Python is one of the most loved and fastest growing languages: https://insights.stackoverflow.com/survey/2019#most-loved-dr...

Re:Brython – A Python 3 implementation for client-side web p... by zaro on Tuesday July 07, 2020 @02:52AM (#23756442)
Yet, in the same survey it is on par with Typescript.

Also for me always the question is loved by who. Of course junior/beginner level people will prefer simplistic language like Python, because that's the main target audience for Python as a language.

Re:Brython – A Python 3 implementation for client-side web p... by britbull on Tuesday July 07, 2020 @07:22AM (#23757997)
Yes it is on par but isn't Typescript an attempt to address the shortcomings of Javascript? I'm not saying Typescript is bad but it's a strange example to reach for when arguing for Javascript.

> - loved by who

Python is used by a huge number of professional developers for commercial applications, it is not targeted specifically towards beginners. Also, I don't see how it being a go-to language for a lot of beginners is a bad thing. A language being more complicated doesn't inherently make it better.

At the end of the day there are use cases for Javascript just as there are Python. The people using Brython will have their own reasons, just like you have yours for using Javascript for your applications.

Re:Brython – A Python 3 implementation for client-side web p... by _fourzerofour on Monday July 06, 2020 @06:33AM (#23746402)
True on your first point, but I imagine GP was considering a case where you've already got a backend in Python.
Re:Brython – A Python 3 implementation for client-side web p... by Supermancho on Monday July 06, 2020 @12:07PM (#23749307)
> that's a huge advantage

It's a small advantage, practically. There's a limited set of circumstances where this is leveraged in the rare cases that client/server languages are matching (usually the ability to directly copy specific algorithmic implementations). The "advantage" always feels overstated...especially on the web where the frameworks are disparate because the underlying data models are different, ie the DOM.

Re:Brython – A Python 3 implementation for client-side web p... by jidiculous on Monday July 06, 2020 @05:13PM (#23752818)
I'd say the advantage is less on the architectural side and more on the team efficiency side – you could possibly have a full-stack team that only needs to do most of their work in 1 language. The benefits of easing task-switching could make it worthwhile as a stack choice.
Re:Brython – A Python 3 implementation for client-side web p... by ascar on Monday July 06, 2020 @08:23PM (#23754322)
The thing is that for anything more complex than simple CRUD either side (frontend and backend) is such an inherently different problem domain that I don't see that the programming language is the relevant factor.

Because frontend and backend need a very different skillsets and both need a lot of knowledge and training to become good, there are very few true fullstack engineers. And I would bet that most if not all of those can handle work in multiple different programming languages.

Re:Brython – A Python 3 implementation for client-side web p... by nawgszy on Monday July 06, 2020 @05:32PM (#23753029)
Sure, but that's being positioned as a "huge advantage" vs. JavaScript, which I hope I do not need to explain to you the irony of
Re:Brython – A Python 3 implementation for client-side web p... by hombre_fatal on Monday July 06, 2020 @04:35PM (#23752455)
It would be nice to use the same BBCode parser on the server and client to give the client accurate previews. Why not just compile that one little module into Javascript and sent it over the wire?
Re:Brython – A Python 3 implementation for client-side web p... by mekster on Monday July 06, 2020 @06:59PM (#23753743)
> - it can be the same language as the backend, that's a huge advantage (no need to change context, you can more easily have the team for backend and frontend)

Having used TypeScript for both frontend and backend for several projects, I say this isn't as necessary as you might imagine.

The real context is whether you're coding for your frontend or your backend and that context will happen even if the languages are the same.

You can use same set of libraries but usually they don't really overlap either.

Re:Brython – A Python 3 implementation for client-side web p... by IshKebab on Monday July 06, 2020 @09:39AM (#23747731)
> I have no numbers, but I suspect that once the initial download is done and cached, Python code should be smaller than JS equivalent

You have to download 750 kB of Python interpreter. No way the terseness of Python can make up for that unless you have so much code you definitely shouldn't be using Python. Plus how do you minify Python? All those spaces...

Re:Brython – A Python 3 implementation for client-side web p... by devxpy on Monday July 06, 2020 @07:44AM (#23746854)
Bytecode.