
Ask HN: I casually came up with chained unary operators, do you like them? - gioscarab
Working on a simple virtual machine and a new programming language, I have discovered that the interpreter I have developed can read chained unary operators nominally.<p>It seems a useful side effect...<p>$a = 0<p>print ++$a++<p># Prints &quot;1&quot; and sets a = 2 in memory<p>$a = 1<p>print --$a++<p># Prints &quot;0&quot; and sets a = 1 in memory<p>$a = 0<p>print ++++$a<p># Prints &quot;2&quot; and sets a = 2 in memory<p>$a = 0<p>print $a++++<p># Prints &quot;0&quot; and sets a = 2 in memory<p>$a = 10<p>print ++$a----<p># Prints &quot;11&quot; and sets a = 9 in memory<p>$a = 10<p>print ++--$a----++<p># Prints &quot;10&quot; and sets a = 9 in memory
======
tcbasche
I feel like when someone has to count plus signs to see what the code is doing
it's a bad sign.

------
quickthrower2
I’m not a fan of ++a and similar code golf constructs. I really only use a++
for loops. I like to keep code simple and readable. Well done on writing an
interpreter though. It’s not easy.

------
babygoat
I personally prefer that these operations be kept separate for clarity. An
extra line is justified.

------
sattoshi
$a = 2 $b = -------$a

What does $b equal? More importantly, how is this sane? I just wrote it and
I'm not quite so myself without taking my time and separating the dashes.

------
sloaken
Reminded me of this: [https://www.ioccc.org/](https://www.ioccc.org/)

~~~
Someone
Reminded me of
[http://www.eelis.net/C++/analogliterals.xhtml](http://www.eelis.net/C++/analogliterals.xhtml),
which starts with

    
    
      unsigned int a = 4;
      unsigned int b = I---------I;
      assert( a == b );
    

Moves on to 2D:

    
    
      unsigned int c = ( o-----o
                         |     !
                         !     !
                         !     !
                         o-----o ).area;
    
      assert( c == (I-----I) * (I-------I) );
    

and puts the cherry on the cake with 3D literals:

    
    
      assert( top( o-------o
                   |L       \
                   | L       \
                   |  o-------o
                   |  !       !
                   !  !       !
                   o  |       !
                    L |       !
                     L|       !
                      o-------o ) == ( o-------o
                                       |       !
                                       !       !
                                       o-------o ) );

------
Adamantcheese
Reminds me of good ol' APL.

