The long arrow operator in C++
cukic.co
cukic.co
while (x --\
\
\
\
> 0)
printf("%d ", x); assert( ( o-------------o
|L \
| L \
| L \
| o-------------o
| ! !
! ! !
o | !
L | !
L | !
L| !
o-------------o ).volume == ( o-------------o
| !
! !
! !
o-------------o ).area * int(I-------------I) );
http://www.eelis.net/C++/analogliterals.xhtml #include <stdio.h>
int main()
{
int x = 10;
while (x --> 0) /* x goes to 0 */
{
printf("%d ", x);
}
}
(prints 9 8 7 6 5 4 3 2 1 0)https://stackoverflow.com/questions/1642028/what-is-the-oper...
I blame Haskell, Scala, and Ruby.
Thompson, Ritchie and Kernighan admit that Unix was a prank
while (a -->> k --> 0 <-- b <<-- c)
and you can have dashed arrows too: k = a <- - - - - b; int a=0, b=4;
while(a < - - - - --b) {
printf("b: %d\n", b);
} Morse m;
cout << (++++m) << (+m) << (+-++m) << (+-++m) << (---m) << ", "
<< (+--m) << (---m) << (+-+m) << (+-++m) << (-++m) << "!\n";
Damn you, C++! Why won't you let me overload the . operator? ;-)What is the equivalent term or expression for being in the spirit of C++?
The article, while a joke (just like C++ originally, look it up), feels very C++y.
Idiomatic might be fuzzy, but it definitely does not include active attempts obfuscation, malice or jokes. The code in the article could be any of these depending on context.
An example of non-idiomatic C++ might be
for (int I = 0; I < c.size(); I++) {
Total += c[I].foo;
}
...instead of using std::accumulate. The code from the article is (humorously pointing out) something else entirely.Not so much with C++. There is no one way to do things. Depending on your needs, you will use the language differently. Code focused on performance (ex: game engine) will look very different from server code, or a GUI, or embedded software. And none will be more C++y than the other.
The typing is getting stronger, the library richer and hard things easier. If you know about or can google RAII and are willing to lookup things on occasion to pick algorithms or just the right member function, code gets very clean. After not too long the looking stops because the std lib is still pretty small compared to other languages.
But if you have already moved to Rust I can't make an objective argument for it.
That may be true, but all you are seeing is C++ copying from every other language in an effort to once again become relevant.
IMHO in this modern day and age there are so many easier, better, more expressive, easier to use languages than C++ to choose from.
And that is coming from someone who spent a lot of time coding C++ some 15 years ago.
To be fair, that's what every other language does too. There are few truly novel ideas in industry programming languages.
I was unaware that being the 2nd and 3rd most popular language made it not relevant when I guess nothing is relevant except Java. (Per the Tiobe index)
If you need high level abstractions and the ability to tweak for performance at the lowest levels the it is either C++ or Rust, and if you need a mature ecosystem that really only leaves C++. Game devs, Google, Facebook, HPC and tons of stuff and now with emscripten and WASM we get to compete with JS devs for in browser games too!
Considering that C++ is perhaps the most popular programming language ever designed (in TIOBE's index it ranks 3rd, right after C and Java), you sound that you nurtured an irrational hatred for a programming language. That says more about you than the language you are trying to criticise.
Designing classes that distinguish & and && properly makes writing new types more difficult. You need even more boilerplate stuff now. Like: I define a '-' operator, but I don't automatically get a '-=' operator, WTF. And now I need to add a && version of the -= and += and = and to invoke move() correctly so the type system is pleased AND it won't crash. This is supposed to be used for application code, so why do we need so much brain capacity to handle it?
And I would really be interested in a survey to find our how many professional C++ programmers know the intricate rules behind overloading with template functions, template classes, inside and outside class scope, with namespaces, with & and &&, with const, with auto and lambda and maybe more etc. This is just too much!
Using classes is a bit better now (if they are written properly), but once you start defining your own types, its no fun anymore.
The nicest I can say about C++ is that it is fun if you want to experiment. But for a production system, it is not a good choice, because it is too complex.
As for the old and new stuff both being there, yes it us but that doesn't mean you need or should use all of it. The new should replace the old or at least let you clean it up.
It sounds like the code you were forced into was super sloppy. Making move increment and decrement operator is an micro-optimization in the extreme. You can probably safely remove that non-sense and not see any difference if your class implements something like sane value semantics and use RAII. But of course like any language someone can make a big ball of mud when misusing the tools.
I agree there is complexity but I think most of the complexity you have needed to deal with is because of bad code. I could write you some Python or Ruby that is equally impossible to parse and deal with. Watch as I overload methods on Method class and Class class.
Also enjoying elm for frontend.
8==>[1] https://stackoverflow.com/questions/7825055/what-does-the-c-...