News for hackers. Stuff that matters.
Re:Esoteric C++ Contest 2018 by Something1234 on Saturday March 23, 2019 @08:38AM (#19470195)
Try raja, or any pile of templated mess. I hate templates so much.
Re:Esoteric C++ Contest 2018 by lasagnaphil on Saturday March 23, 2019 @09:16AM (#19470314)
I googled RAJA and found it was a HPC (High performance computing) library for running GPU code in C++. This couldn't be that bad, right? Turns out I was terribly wrong.

Behold, I present you this fucking monstrosity (Directly from the RAJA matrix multiplication tutorial):

  using EXEC_POL9 =
    RAJA::KernelPolicy<
      RAJA::statement::CudaKernel<
        RAJA::statement::Tile<1, RAJA::statement::tile_fixed<CUDA_BLOCK_SIZE>, RAJA::cuda_block_y_loop,
          RAJA::statement::Tile<0, RAJA::statement::tile_fixed<CUDA_BLOCK_SIZE>, RAJA::cuda_block_x_loop,
            RAJA::statement::For<1, RAJA::cuda_thread_y_loop, // row
              RAJA::statement::For<0, RAJA::cuda_thread_x_loop, // col
                RAJA::statement::Lambda<0>,   // dot = 0.0
                RAJA::statement::For<2, RAJA::seq_exec,
                    RAJA::statement::Lambda<1> // dot += ...
                >,
                RAJA::statement::Lambda<2>   // set C = ...
              >
            >
          >
        >
      >
    >;
And that's just for matrix multiplication. I cannot imagine how fucking terrifying it will to write something more complicated than that. If I were to write (and debug) this mindfucking mess of templated code, I would rather escape this trainwreck and go back to writing CUDA/OpenCL code...
Re:Esoteric C++ Contest 2018 by pjc50 on Saturday March 23, 2019 @01:38PM (#19471411)
That's .. not actually too bad. Obviously it's going to generate a lot of code, but I can almost understand what it's trying to do and it doesn't look like it relies too heavily on type resolution surprises.

If you want a template challenge, try (without looking it up) writing your own iostream class. iostream is one of those things that's present in even beginner examples but when you look at how it works a whole load of complexity unravels.

Re:Esoteric C++ Contest 2018 by Something1234 on Saturday March 23, 2019 @09:38AM (#19470395)
And I was dumb enough to accept an independent study to add openacc support to the library.
Re:Esoteric C++ Contest 2018 by ycombonator on Saturday March 23, 2019 @11:15AM (#19470785)
Take a look at C++ AMP https://docs.microsoft.com/en-us/cpp/parallel/amp/cpp-amp-cp.... It’s smooth as melted butter.
Re:Esoteric C++ Contest 2018 by otabdeveloper2 on Saturday March 23, 2019 @10:22AM (#19470541)
> Behold, I present you this fucking monstrosity

It's just a Lisp-like language with a slightly different syntax for S-expressions. Ugly, like all Lisps, but nothing 'monstrous'.

Re:Esoteric C++ Contest 2018 by bjoli on Saturday March 23, 2019 @11:22AM (#19470816)
How far down the rabbit hole must one be to not think that is monstrous?
Re:Esoteric C++ Contest 2018 by otabdeveloper2 on Saturday March 23, 2019 @11:40AM (#19470884)
The cognitive dissonance required to believe that C++ templates are 'monstrous' while Lisp S-expressions are awesomely useful and productive is enormous.

C++ templates are far from user-friendly, but they're literally (literally) just Lisp S-expressions with a Lisp syntax and semantics.

Re:Esoteric C++ Contest 2018 by pjc50 on Saturday March 23, 2019 @01:35PM (#19471389)
The semantics of template resolution are important, and unlike anything I'm aware of in Lisp.
Re:Esoteric C++ Contest 2018 by stagger87 on Saturday March 23, 2019 @12:20PM (#19471050)
Short of writing your own DSL, how would you solve the problem the above code snippet is attempting to solve in C++?

I understand complaining about templates like the ranges example also posted in this thread, but I am curious to hear what you think is the alternative for this specific example.

Re:Esoteric C++ Contest 2018 by krapp on Saturday March 23, 2019 @09:44AM (#19470414)
I think templates are fine as long as they're not abused. Unfortunately, since C++ templates are Turing complete, people will inevitably go overboard with them.

My personal rule is to never nest more than two templates. You can have a template inside a template, but anything deeper than that should be refactored or at least split up into typedefs for readability.

Re:Esoteric C++ Contest 2018 by colmvp on Saturday March 23, 2019 @09:30AM (#19470367)
Why hate templates?
Re:Esoteric C++ Contest 2018 by mianos on Saturday March 23, 2019 @05:18PM (#19472408)
Compilation times? Obfuscation? Bloat? I like them but these are valid negatives.
Re:Esoteric C++ Contest 2018 by llukas on Saturday March 23, 2019 @09:50PM (#19473608)
Those are problem only if templates are misused (imho).
Re:Esoteric C++ Contest 2018 by Something1234 on Saturday March 23, 2019 @10:27PM (#19473783)
Which is pretty much anything outside of the STL library's basic usage.
Re:Esoteric C++ Contest 2018 by mianos on Saturday March 23, 2019 @11:37PM (#19474108)
Yes I agree. I would not have been so down-voted so much if I had said the use of templates in the std:: libraries and some others, not all, is fantastic. But, the use of templates to make generic code when it does not need to be leads to the same functionality as specialised classes with longer compile times and obfuscation.
Re:Esoteric C++ Contest 2018 by llukas on Sunday March 24, 2019 @03:47AM (#19475027)
I agree that putting templates where they not belong causes problems (even more than just longer compile times and obfuscation).

However, properly designed templates with enough attention put into exposing functionality beat non-templated approaches right off the bat.

Example: http://eigen.tuxfamily.org/dox/TopicInsideEigenExample.html