News for hackers. Stuff that matters.
Re:What’s New in Python 3.8 by kolinko on Monday October 14, 2019 @06:50PM (#21253705)
I actually found an immense use for Walrus - used it to hack Python into doing pattern matching that is way more readable than without it:

https://github.com/eveem-org/panoramix

(source code for Eveem.org, which is arguably the best decompiler for Ethereum smart contracts out there. you can see a lot of pattern matching in pano/simplify.py , and I found no way to do it without extending the language/walrus while maintaining the readability)

Re:What’s New in Python 3.8 by onlyrealcuzzo on Monday October 14, 2019 @07:15PM (#21253898)
Just a suggestion...

I went to your repo, and it wasn't clear to me what Panoramix actually is or does. So I checked out Eveem.org, and even on the about page, it wasn't clear to me what Eveem was.

But with that context, coming back to your GitHub page, I was able to get the gist of it.

It might be helpful to have a section above the installation section that gives a little context / tells about the project.

And in your example section -- again, I literally don't know anything about decompilation so maybe I'm not your target demographic... but if I understand the gist of it, kitties is an example function or binary. It might be better to use something more concrete (and provide the context).

Re:What’s New in Python 3.8 by kolinko on Tuesday October 15, 2019 @04:51AM (#21256679)
Thank for the feedback! My first open-source project. I will improve this :)
Re:What’s New in Python 3.8 by gizmo385 on Monday October 14, 2019 @06:57PM (#21253756)
After a quick read through, I personally find this syntax much harder to read using operator overloads than it would have been using a series of comparison functions. Tilde is a very obtuse operator and I don't know that this really buys you anything.

Feels like a case of preferring cleverness over readability/usability/maintainability.

Re:What’s New in Python 3.8 by MichaelMoser123 on Tuesday October 15, 2019 @01:33AM (#21255800)
Python is adding features, maybe they want to be as expressive as perl, when they grow up; however that comes with the price of decreased readability.
Re:What’s New in Python 3.8 by kolinko on Tuesday October 15, 2019 @04:58AM (#21256708)
I actually had a series of comparison functions initially, but those weren't that readable.

To give you an example, let's look at this statement:

if exp ~ ('mask_shl', int:size, int:offset, -offset, :e): ...

It is the same as writing: if type(exp) == tuple and len(exp) == 5 and exp[0]=='mask_shl' and type(exp[1])==int aand type(exp[2])==int and exp[3] == -exp[1]: size, offset, e = exp[1], exp[2], exp[4] ...

If you can figure out syntax that makes this sort of matches more readable, I'll gladly use it :)

Re:What’s New in Python 3.8 by kolinko on Tuesday October 15, 2019 @07:05AM (#21257319)
Fixing formatting for above:

    if exp ~ ('mask_shl', int:size, int:offset, -offset, :e): ...
vs

    if type(exp) == tuple and len(exp) == 5 and exp[0]=='mask_shl' and type(exp[1])==int aand type(exp[2])==int and exp[3] == -exp[1]: 
        size, offset, e = exp[1], exp[2], exp[4] 
        ...
Re:What’s New in Python 3.8 by mark-r on Monday October 14, 2019 @08:24PM (#21254351)
Exactly the road C++ tries to go down. How's that for a ringing endorsement?
Re:What’s New in Python 3.8 by wolco on Monday October 14, 2019 @08:56PM (#21254548)
C++ is one of the most successful languages.
Re:What’s New in Python 3.8 by nine_k on Monday October 14, 2019 @10:45PM (#21255134)
Despite its flaws, not due to them.

Same can be said about e.g. Cobol.

Re:What’s New in Python 3.8 by eru on Tuesday October 15, 2019 @02:18AM (#21255972)
Despite the flaws, and because of being in the right place at the right time.

Cobol also was a good idea back in the day. And some of the ideas in Cobol we know recognize as bad _had_ to be tried to gain that recognition.

Re:What’s New in Python 3.8 by otabdeveloper4 on Tuesday October 15, 2019 @03:02AM (#21256170)
False.

There have been dozens of working C++ competitors over the years, each one technically as good as C++.

They all failed because their authors are good at writing languages, but very bad at knowing how languages are used in the real world.

The C++ committee really knows what it's doing, you're not going to do anything useful in this space without actually understanding the problem domain.

TL;DR - yes, C++ is complex, but that is because programming is complex. Your attitude of "programming is hard, let's go (language) shopping" will not displace C++.

Re:What’s New in Python 3.8 by nine_k on Tuesday October 15, 2019 @09:04AM (#21257913)
C++ made a number of... unfortunate decisions early in its development, which resulted in a much worse language than it could have been. (Hindsight is 20/20, of course.)

I totally agree that C++ of 21st century is way better than C++ from 1998, and is becoming better. The problem is that maintaining backwards compatibility requires to keep a number of footguns in place, and some of them are cornerstones of the language :(

I have high hopes for Rust becoming the more sane competitor in the space traditionally occupied by C++. Its authors seem to understand the problem domain from a very practical standpoint, and are proficient in C++, to begin with. They also strive to apply reasonable design principles, and some actual math hopefully will keep the core of the language from logical pitfalls.

Another example of hitting a sweet spot is Go. I dislike many Go's language decisions. (Some are definitely great, though, e.g. the whole OOP approach lifted from Oberon.) But its authors definitely understand both the problem domain, and the target audience.

This is what I mean by talking about success despite the flaws. C++ has both flaws and merits, and merits outweighed the flaws. But the flaws are still painful.

Re:What’s New in Python 3.8 by mark-r on Tuesday October 15, 2019 @10:59AM (#21259120)
How much of that success can be attributed to the features that were added in the last 10 years?
Re:What’s New in Python 3.8 by raobit on Tuesday October 15, 2019 @01:42AM (#21255834)
Rust:- Am i a joke to you?
Re:What’s New in Python 3.8 by cortesoft on Monday October 14, 2019 @10:29PM (#21255063)
Pretty good?
Re:What’s New in Python 3.8 by Tommah on Monday October 14, 2019 @08:50PM (#21254500)
There is a similar trick that you can use without the walrus operator. I wrote the code many years ago and I am reproducing this from memory, so the code below may be a little off. Define this class:

    class Any:
        def __eq__(self, other):
            self.value = other
            return True
Then you can use an instance of it as the hole in a pattern. My use case was performing peephole optimizations in a simple 6502 assembler. For example, if the LDA operation (load value from memory location into accumulator) occurs twice in a row, the first load is redundant. So I did this test:

    x, y = Any(), Any()
    if L[i:i+2] == [('LDA', x), ('LDA', y)]:
        L[i:i+2] = [('LDA', y.value)]
(Note that the last line changes the length of the list, so it may be slow on large lists.)

I was going to write a blog post about this back then, but I never did. If anyone is interested, I can write it now.

Re:What’s New in Python 3.8 by eru on Tuesday October 15, 2019 @02:19AM (#21255976)
But that breaks normal equality tests for your type?
Re:What’s New in Python 3.8 by heavenlyblue on Tuesday October 15, 2019 @04:46AM (#21256656)
Wouldn’t parent’s code simply copy into Any every time it’s compared in a list?

It is some spooky action at a distance.

Re:What’s New in Python 3.8 by eru on Tuesday October 15, 2019 @06:11AM (#21257065)
Probably. I found it a bit confusing in any case.
Re:What’s New in Python 3.8 by ohazi on Monday October 14, 2019 @07:17PM (#21253915)
You should link to a snippet that actually uses := rather than to the top level project.
Re:What’s New in Python 3.8 by kolinko on Tuesday October 15, 2019 @05:03AM (#21256737)
Ah yes, sorry:

https://github.com/eveem-org/panoramix/blob/bc55be84a9a6abb1...

It uses "~" custom operator, but implementing it would not be possible without ":=" operator (see /tilde directory).

Re:What’s New in Python 3.8 by closed on Monday October 14, 2019 @07:10PM (#21253862)
This is super interesting! I've never seen codecs used to introduce language features like this... Do you have any good references for getting started with using codecs?

Also, I wonder if there's an easy way to implement this in a jupyter notebook, without fiddling with the kernel...

(issues of whether it's a good idea aside, definitely seems useful to know about.. )

Re:What’s New in Python 3.8 by kolinko on Tuesday October 15, 2019 @05:02AM (#21256729)
Thanks! The idea for using codecs is not mine - found it on StackOverflow somewhere. Googling for "how to add custom language statements python" should give you some results, this included :)

Also, in my case I had to use Codecs because a new operator causes AST-parser to not go through. But if you have some kind of syntax that will be compatible with Python AST, then you can implement it even easier.

You can google Python AST to get a lot of useful information :)

Re:What’s New in Python 3.8 by m463 on Tuesday October 15, 2019 @12:19AM (#21255525)
I thought regex matching was one of the strongest arguments for it.