News for hackers. Stuff that matters.
Re:Brython – A Python 3 implementation for client-side web p... by mlthoughts2018 on Monday July 06, 2020 @08:20AM (#23747101)
100% this. When I write Javascript or Scala, I do this anyway just because it’s a better way to structure code.

Nested anonymous functions that contain complex bodies and rely on scope closure of args or local variables inside the complex bodies of exterior anonymous functions needs to stop being a thing, in any language, anywhere. It’s a massive antipattern.

Same for using functional programming constructs like map or filter or reduce with complex multi-statement nested anonymous functions. “Inlining” your anonymous function when it’s not just a simple statement is simply a terrible idea across the board.

It’s like living in crazy town to see that style defended as reasonable or treated like it’s valuable for a use case, etc.

Re:Brython – A Python 3 implementation for client-side web p... by pansa2 on Monday July 06, 2020 @08:37AM (#23747223)
> It’s a massive antipattern.

Yes! I used to be on-the-fence about this, but then had to try and decipher code like YDKJS’s `run` [0]. Four levels of nested functions!

Python’s syntax makes this sort of thing impossible, which I now consider to be a good thing.

[0] https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/async...

Re:Brython – A Python 3 implementation for client-side web p... by linkdd on Monday July 06, 2020 @08:52AM (#23747330)
Because you can write bad code using a pattern does not make it an anti-pattern.

Thanks to ES6, the async/await keyword for Promises help you get rid of the callback hell that Javascript can easily be.

Python support of asynchronous code is far behind Javascript and it is the basic requirement of frontend development.

Re:Brython – A Python 3 implementation for client-side web p... by jnwatson on Monday July 06, 2020 @09:37AM (#23747711)
Huh? Python async has been in the lead for quite a while now. The only thing it doesn’t have is anonymous inline function syntax.
Re:Brython – A Python 3 implementation for client-side web p... by linkdd on Monday July 06, 2020 @01:17PM (#23750087)
Node's design of Worker Thread, Promise and async/await makes an easier combo than Python + asyncio/trio which requires a lot of work to get it done.

But in the end, use what works for you, and if you need performance, you still have Go, Rust, and/or C++.

Re:Brython – A Python 3 implementation for client-side web p... by linkdd on Monday July 06, 2020 @08:48AM (#23747294)
Functional programming constructs helps you write simple code faster, and clarify the algorithm.

It is easier to rearrange, to test and to reason about, but it is harder to read.

Once your fast-written code works, you obviously need to optimize it where it's needed. And if you map/filter/reduce is your bottleneck, just get rid of it obviously.

But I highly doubt it will be your bottleneck.

Nested anonymous function that rely on scope closure is THE way to truly encapsulate your data, example: https://pastebin.com/JrAP6yGP

IMHO, the factory pattern is a clearer/easier pattern than Javascript's classes/prototypes.