News for hackers. Stuff that matters.
Re:Esoteric C++ Contest 2018 by int_19h on Saturday March 23, 2019 @06:45PM (#19472746)
It looks like nobody managed to beat this one from 2015 yet:

http://b.atch.se/posts/non-constant-constant-expressions/

"Implementing f() to make the following snippet compile without the static_assert being fired looks impossible, doesn't it?

   // <insert solution here>
   int main () {
     constexpr int a = f();
     constexpr int b = f();
     static_assert (a != b, "fail");
   }
We all "know" that an expression that is usable in a constant-expression can neither depend on, nor change, the global state. This lack of dependency must inherently mean that it will yield the same value upon each invocation having the same set of arguments... right?

Up until about a week ago I "knew" this to be true, and I honestly thought the above was not possible to implement without triggering undefined-behavior (ie. writing a program that the ISO C++ Standard would consider ill-formed).

As it turns out, I was very wrong."

Re:Esoteric C++ Contest 2018 by the_duke on Saturday March 23, 2019 @09:00AM (#19470268)
Some of these are hilarious. I'm always astounded how easy it is to shoot yourself in the foot with C++.

It's such a important, transformative and widely used language, but due to the age and the "let's put everything in without ever removing anything because backwards compatability!" mentality has created a monster.

Re:Esoteric C++ Contest 2018 by mannykannot on Saturday March 23, 2019 @08:52PM (#19473320)
It's not just the number of things, but the way they combine, as in the rules for argument-dependent lookup (not to be mistaken for unqualified name lookup or template type deduction.) When you have pointers and two or arguably three types of references, and arrays that decay to pointers in some cases, there's a lot of different cases to be considered. It's quite an achievement that it often works the way you want.

https://en.cppreference.com/w/cpp/language/adl

Re:Esoteric C++ Contest 2018 by hughw on Saturday March 23, 2019 @02:24PM (#19471638)
Oh, they remove stuff. See "Deprecating Vestigial Library Parts in C++17" [1].

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p017...

Re:Esoteric C++ Contest 2018 by paulddraper on Saturday March 23, 2019 @02:59PM (#19471801)
To be fair, how many languages are as old and as widely used as C++?(Only one: C)

Anybody can create a some shiny new language or maintain a beautiful unused language.

Re:Esoteric C++ Contest 2018 by basementcat on Saturday March 23, 2019 @05:43PM (#19472514)
Fortran. Ok, maybe not as widely used :)
Re:Esoteric C++ Contest 2018 by rini17 on Saturday March 23, 2019 @03:39PM (#19471996)
Common Lisp :)
Re:Esoteric C++ Contest 2018 by bsder on Saturday March 23, 2019 @09:21PM (#19473468)
COBOL
Re:Esoteric C++ Contest 2018 by mschuetz on Saturday March 23, 2019 @08:35AM (#19470183)
Re:Esoteric C++ Contest 2018 by userbinator on Saturday March 23, 2019 @06:35PM (#19472703)
I've read the criticism of that post ( http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/ , discussed previously at https://news.ycombinator.com/item?id=18777735 ) but not the original, and now that I did, I have that strange feeling of not knowing whether it was satire or not --- and am unfortunately leaning towards the latter.

I made another comment here on this item, that it feels like a lot of the recent developments in programming languages are more along the lines of showing off how much complexity you can add, rather than solving the real problem itself. It's a "do less with more" mindset, the complete opposite of what I believe in.

Re:Esoteric C++ Contest 2018 by stagger87 on Saturday March 23, 2019 @09:55AM (#19470452)
I think this fits the definition of esoteric more than anything that was submitted.
Re:Esoteric C++ Contest 2018 by harias on Saturday March 23, 2019 @09:26AM (#19470349)
Somewhat off-topic, but how do you publicize your competitions better?

The author promised an iPad for the winner and got 40 entries.

What fraction of the money set aside for a competition should be spent on publicity and how much on the prize? Talking about programming/related competitions here.

Re:Esoteric C++ Contest 2018 by ycombonator on Saturday March 23, 2019 @11:19AM (#19470797)
Within C++, there is a much smaller and cleaner language struggling to get out. Stroustrup, Bjarne. The Design and Evolution of C++. pp. 207..
Re:Esoteric C++ Contest 2018 by mikeash on Saturday March 23, 2019 @12:13PM (#19471013)
That wouldn’t be so bad. The problem is that it’s five or six smaller and cleaner languages all struggling to get out.
Re:Esoteric C++ Contest 2018 by chubot on Saturday March 23, 2019 @01:17PM (#19471308)
Yeah I agree that nobody could agree on a single subset of C++.

I think that Bjarne might mean "modern C++", but I'm more a fan of "C with classes", and I think the latter is more appropriate for many domains. I would say those are the two main dialects (with modern C++ being split being library writers using templates and library consumers.)

The old Google C++ style guide is good, but it seems to be morphing more into modern C++ lately. It's basically C with:

- The ability to add methods to structs

- Basic single inheritance.

- Collection and string classes

- Scope based resource management.

https://stackoverflow.com/questions/3073642/official-c-langu...

No exceptions, no IO streams (except in one place), no implicit constructors, no operator overloading, multiple inheritance, etc.

So I woudn't say there are 5 or 6 languages, but it definitely feels like that sometimes. I think the lack of a single string type, single error handling mechanism, and single deallocation mechanism are the things that make it feel like more than one language in a single codebase.

Re:Esoteric C++ Contest 2018 by userbinator on Saturday March 23, 2019 @04:03PM (#19472094)
I agree, I'm definitely not a fan of the "Let's replace a simple and straightforward way with something that looks simpler at first but actually invokes a bunch of hidden complexity that's harder to debug and generates 10x more inefficient code. Why? Because that's the more 'modern' way." type of thinking I've seen from a lot of the "modern C++" advocates. They seem to be more interested in solving hypothetical or artificial problems that they themselves created, than the actual problem which needs to be solved.

Template libraries work well, until they don't, at which point you get many pages of confusing error messages containing absurdly long identifier names; and the cause is often something as simple as one missing, wrong, or extra character. Sometimes it even crashes the compiler...

Re:Esoteric C++ Contest 2018 by foobiekr on Saturday March 23, 2019 @03:22PM (#19471919)
with the exception of scope-based resourcing, that basically describes Go.
Re:Esoteric C++ Contest 2018 by chubot on Saturday March 23, 2019 @04:33PM (#19472209)
Yes I've heard people remark that Go is basically Google's C++ style guide distilled into a new programming language... It's not 100% true but there's definitely some truth to it :)

Not having exceptions is a big similarity. Go slices and StringPiece are essentially the same idiom. There's a lot of vector<> and map<> which leads to builtin arrays and maps, rather than having arbitrary user-defined data structures (i.e. no operator overloading). gofmt was definitely inspired by Google's code review process.

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

Re:Esoteric C++ Contest 2018 by ilovecaching on Saturday March 23, 2019 @02:01PM (#19471517)
The answer to C++ cruft always seems to be use the "modern" subset of the language. But there are three issues with that:

1. You have to interface with older libraries that overuse terrible behavior.

2. The hallmark of a junior developer is an overuse of features. Using a subset takes discipline.

3. Some things are just permanently broken or so hidden you don't even realize you are using a "feature".

That's why I'm just going to stick with Rust. I have no interest in the "let's put a wig and lipstick on the C++ pig" train.

Re:Esoteric C++ Contest 2018 by Rexxar on Saturday March 23, 2019 @02:16PM (#19471600)
We really don't need a rust comment on every c++ submission.
Re:Esoteric C++ Contest 2018 by Midnightas on Sunday March 24, 2019 @10:03AM (#19476389)
Knowing Rust, Go and Kotlin that's what we're going to get sadly.
Re:Esoteric C++ Contest 2018 by gdy on Sunday March 24, 2019 @03:47AM (#19475024)
An atheist, a vegan, and a Rust programmer walk into a bar. I only know because they told everyone within two minutes.

P.S. I'm an atheist.

Re:Esoteric C++ Contest 2018 by vkaku on Saturday March 23, 2019 @03:04PM (#19471836)
C++ is easily the next Perl:

With a cocktail of alphanumeric overloadable operators, lambdas, variadic templates and small identifiers, all badly spaced, It would not be difficult to achieve super unreadable code with it.

They just need to figure out a way to add implicit arguments like $@, $?, @_ and we'll get a more esoteric C++. Note that $_ is a valid identifier in C++.