News for hackers. Stuff that matters.
Re:Beautiful Binary Search in D by theodpHN on Saturday February 18, 2023 @01:07PM (#34849293)
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-...
Re:Beautiful Binary Search in D by 2h on Saturday February 18, 2023 @01:40PM (#34849679)
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?

Re:Beautiful Binary Search in D by mhh__ on Saturday February 18, 2023 @01:42PM (#34849714)
> 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...

Re:Beautiful Binary Search in D by ternaryoperator on Saturday February 18, 2023 @04:52PM (#34851483)
> 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++.

Re:Beautiful Binary Search in D by mhh__ on Saturday February 18, 2023 @05:53PM (#34851935)
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.

Re:Beautiful Binary Search in D by btschaegg on Saturday February 18, 2023 @11:58PM (#34854601)
> 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.

Re:Beautiful Binary Search in D by alex_muscar on Saturday February 18, 2023 @02:14PM (#34850050)
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 :)