News for hackers. Stuff that matters.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by titzer on Tuesday March 11, 2025 @02:50PM (#43335774)
SELECT DISTINCT author FROM books WHERE pageCount > 1000;
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by __mharrison__ on Tuesday March 11, 2025 @04:04PM (#43336465)
Folks don't seem to have a problem when SQL does it. Only when code like Pandas does it...
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by mont_tag on Tuesday March 11, 2025 @07:39PM (#43338332)
Hi Matt! I've observed this phenomenon as well.

When the SQL and Pandas examples are isomorphic except for shallow syntactic differences, the root cause of the complaint must either be:

* that the judgment was emotional rather than substantive * or that the syntactic differences (dots and parens) actually matter

Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by __mharrison__ on Wednesday March 12, 2025 @12:14AM (#43339900)
Folks really like their intermediate dataframes... for "debugging".
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by beryilma on Tuesday March 11, 2025 @05:11PM (#43337046)
This is 5 times more readable than FP example above for the same computation. The FP example uses variable book(s) five times, where using it once was sufficient for SQL. Perhaps FP languages could have learned something from SQL...
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by xigoi on Wednesday March 12, 2025 @03:50AM (#43340792)
Now modify the SQL to support books having multiple authors. (In the FP example, you would just change map to flatMap.)
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by YesBox on Tuesday March 11, 2025 @06:29PM (#43337806)
Scrolled to find the SQL. Such an elegant, powerful language. Really happy I chose SQLite for my game/project.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by pif on Wednesday March 12, 2025 @09:14AM (#43342896)
Just add strong types, with verification at something-like-compile-time, and you'll have a sane language.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by odyssey7 on Tuesday March 11, 2025 @07:47PM (#43338399)
Notably this example is declarative, the original is functional, and neither is imperative.
Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by 101011 on Tuesday March 11, 2025 @11:24PM (#43339671)
In fairness, if this was in a relational data store, the same code as above would probably look more like...

SELECT DISTINCT authors.some_field FROM books JOIN authors ON books.author_id = authors.author_id WHERE books.pageCount > 1000

And if you wanted to grab the entire authors record (like the code does) you'd probably need some more complexity in there:

SELECT * FROM authors WHERE author_id IN ( SELECT DISTINCT authors.author_id FROM books JOIN authors ON books.author_id = authors.author_id WHERE books.pageCount > 1000 )

Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by titzer on Wednesday March 12, 2025 @12:15AM (#43339907)
The last one is better as:

SELECT * FROM authors WHERE author_id IN (SELECT author_id FROM books WHERE pageCount > 1000);

But I think you're missing the point. The functional/procedural style of writing is sequentialized and potentially slow. It's not transactional, doesn't handle partial failure, isn't parallelizable (without heavy lifting from the language--maybe LINQ can do this? but definitely not in Java).

With SQL, you push the entire query down into the database engine and expose it to the query optimizer. And SQL is actually supported by many, many systems. And it's what people have been writing for 40+ years.

Re:What Makes Code Hard to Read: Visual Patterns of Complexi... by 101011 on Wednesday March 12, 2025 @12:50PM (#43345179)
agreed on the revised SQL!

But I don't think I missed the point, the original text talks about measuring complexity as a function of operators, operands, and nested code. The true one to one mapping is more complex than the original comment I replied to