Hacker News new | ask | show | jobs
by theodpHN 1224 days ago
Beauty is in the eye of the beholder. While clever, this is (IMO) far less understandable and more error-prone than say COBOL's positively ancient built-in SEARCH ALL binary search statement. Here's an example of a 3-key binary table search from IBM's COBOL documentation that includes options for found and not found conditions.

   SEARCH ALL TABLE-ENTRY
     AT END PERFORM NOENTRY
     WHEN KEY-1 (INDX-1) = VALUE-1 AND
          KEY-2 (INDX-1) = VALUE-2 AND
          KEY-3 (INDX-1) = VALUE-3
       MOVE PART-1 (INDX-1) TO OUTPUT-AREA
   END-SEARCH 
https://www.ibm.com/docs/en/cobol-zos/6.1?topic=all-example-...
2 comments

That's right. The Cobol version has its own beauty because it's built into the language. Also, this is my TIL nugget of the day. Thanks :)
Agree. This just screams of being too clever. It's OK to repeat things sometimes. If you DRY to the point that the code is not even readable, is that really an improvement?

Also I physically shuddered when I saw the word template. Did no one learn from C++ mistakes?

> Also I physically shuddered when I saw the word template. Did no one learn from C++ mistakes?

While we might disagree on a lot of semantical things on this, I'd argue that D very much learned from those mistakes. There's a strong argument for D's templates to be "templates done right" (which C++'s most certainly aren't).

So I encourage you to read more into this topic. To me, this question seems just about as uninformed as someone complaining about a LISP tutorial on macros, asking "did no one learn from the mistake that is the C preprocessor?".

If/where there are other models better suited for metaprogramming would be another (interesting) discussion (full of tradeoffs, I'm sure), but the notion of proper (hygienic?) templates not being adequate anywhere can certainly not be inferred from C++'s implementation alone.

> Did no one learn from C++ mistakes?

D was designed by Walter Bright (who played a large role in inflicting C++ on the world) and Andrei Alexandrescu so you could say that...

> D was designed by Walter Bright (who played a large role in inflicting C++ on the world)

That's a rather unfair characterization. He wrote the Datalight/Zortech C++ compiler. He was never--that I recall--a big flag-waver for C++.

His company originally was a C++ toolchain shop.

Anyway, I was joking — Walter did one of the first (if not the first?) "Proper" C++ compilers, so the idea of not learning from C++ is rather ironic.