Dirty-equals
Languages and libraries
testing library
SHOW HN2022
25points
6comments
#1,352of 2,570 in 2022
Top 53%of 2022 by points
How HN took it
QuietFewer than 5 comments about the project
1 positive, 0 neutral or asking, 0 mixed, 1 critical, out of 2 comments about the project.
Design: 0 for, 1 againstIdea: 1 for, 0 against
The thread, comment by comment
Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.
positive neutral or mixed critical about another commenter or something else the maker
What HN said
What people liked
Useful functionality for flexible comparisons
From 2 comments
``` assert user_data == { 'id': IsPositiveInt, 'avatar_file': IsStr(regex=r'/[a-z0-9\-] {10}/example\.png'), ``` > Without dirty-equals, you'd have to compare individual fields…
quietbritishjim on HNthis is pretty neat!
high_byte on HN
Objections
Overloading the equals operator is a gimmick and less clear
From 1 comment
``` assert user_data == { 'id': IsPositiveInt, 'avatar_file': IsStr(regex=r'/[a-z0-9\-] {10}/example\.png'), ``` > Without dirty-equals, you'd have to compare individual fields…
quietbritishjim on HN
Questions
Why not use a separate dirty_check function instead of ==
From 1 comment
``` assert user_data == { 'id': IsPositiveInt, 'avatar_file': IsStr(regex=r'/[a-z0-9\-] {10}/example\.png'), ``` > Without dirty-equals, you'd have to compare individual fields…
quietbritishjim on HN
Alternatives named
Raku smart-match operator
From 2 comments
Raku has this feature by design. While there technically is a general equality operator `eqv`, you rarely see it used. Instead, you use the matching operator, `~~`, which can…
pie_flavor on HNThe operator is called "smart-match". When you do: ``` $a ~~ $b ``` You are in fact doing: ``` $b.ACCEPTS($a) ``` So any object can determine how it will interpret any other…
lizmat on HN