concise and confusing code

So I just fell in love with concise code and I’m sure I’m not the only one so post the single most confusing and concise line of code you have and maybe an explanation. You get 10 bonus points if I don’t understand the line of code :slight_smile:

Brainf*ck: Not a line of code, but a programming language. Look it up.
Basically it has 8 commands: < > , . + - ]
and it has a data array that can be manipulated with those commands.
It can be fun. Very difficult to program in. Requires knowledge of binary/ASCII in order to program text.
Have fun.

The Fibonacci Sequence in a single line of Brainf**k. It’s pretty confusing.


+++++++++++>+>>>>++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++<<<<<<>>>>>>>+>+<<<<<<<-]>>>>>>><<<<<<<+>>>>>>>-]<>++++++++++-<->>+>+<<<-]>>><<<+>>>-]+<>-]<-]]><<>>>+<<<-]>>-]]<<]>>>>>+>+<<<-]>>><<<+>>>-]+<>-]<-]]><<+>>-]]<<<<<<<]>>>>>++++++++++++++++++++++++++++++++++++++++++++++++.-]]++++++++++<->-<]>++++++++++++++++++++++++++++++++++++++++++++++++.-]<<<<<<<<<<<<>>>+>+<<<<-]>>>><<<<+>>>>-]<->>.>.<<<-]]<<>>+>+<<<-]>>><<<+>>>-]<<<+>-]><+>-]<<<-]

Almost 3 years ago i wrote this beutiful IRC bot:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-
----.------.++++++++.-------------------------------------------.+++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++.-----------
------.++++++++.+++++.--------.--------.++++++++++++++++++++++++.-----------.-]
++++++++++.-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++.--.--------------.+++++++++++++.----------------------------
----------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++.++++++++++++++++.-----------------.++++++++.+++++.--------.--------.++
++++++++++++++++++++++.-----------.---------------------------------------------
------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++.----------------------------------
------------------------------------------------------------.+++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----
--------------------------------------------------------------------------------
----------.++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++
++++.---.----.+++.---.++.+++++.---.-]++++++++++.-]>+ -]-------------+++++++
++++++>,-------------],-]<<]>>        >-<+>]>-<<+>>]>-<<<+>>>]<<<  --------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------<-]>-<+>]<]-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++.-.-.-------.---------------------------------------.-]>>
>>>.>]++++++++++.<]>-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++.+++++.------.+++++.-----------------------------------------
-----.+++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++.-------.+++++++++++++++.-------------------.+++++++.-]++++++++++.-]+
-]-------------+++++++++++++>,-------------],-]<<]>>       >-<+>]>-<<+>>]
>-<<<+>>>]<<<  ----------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------<-]>-<+>]<]     -]+++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++.-.-.-------.----------------
-----------------------.-]>>>>>.>]++++++++++.<]>-]+]

Unfortunuty I have lost the original commented out version so even for me its hopeless to try to understand how this works anymore

All of the above get 10 points :slight_smile: did some research on brainf**k and my brain… So yeah I’m not touching that language until I recover :wink:

I tried writing a Text Based RPG a while back. I ~never~ use comments. I’ve written 3 in the entire time I’ve known how to code. I took a week break from the RPG for fall break, and when I got back, I couldn’t read my own code. I also don’t like using any more lines of code than I have to (I answered practice APCS FRQs in one line). If I could post more than one line, or even an entire loop, it would be more confusing, but some of my worst lines are:
This beginning to a for loop:


for(Item i: this.inventory.keySet().toArray(new Item[this.inventory.keySet().toArray().length]))

This line:


findName(commandArray[0],attackers).inventory.use(findName(commandArray[0],attackers).inventory.getItem(commandArray[2]), findName(commandArray[0],attackers),findName(commandArray[4],targets));

This line:


giver.inventory.inventory.keySet().toArray(new Item[giver.inventory.inventory.keySet().size()]);

And a worse programming language: Malbolge!

You should see Malbolge, it took a guy years just to write hello world:

 ('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#"
 `CB]V?Tx<uVtT`Rpo3NlF.Jh++FdbCBA@?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${z@>

I have only been able to generate up to 5 character words, it seems like you need to write them by hand to get any more than that

A quite fun one is named Befunge, its two dimensional and there are a bunch of variants

Looked up malbolge, got even more scarred :wink: with your text RPGs, you REALLY need to make variable names (Like hp, ad) instead of functions and arrays… Unless you don’t want the user to touch your code and I totally get that…

I’m just lazy, as all programmers are. At one point I had variables named True, False, NullTrue, and TrueFalse, because I was too lazy to come up with real names. true, false and null (lowercase) are reserved, so I just capitalized.

Speaking as somebody who is now working in the real world, writing code that has to understandable by other people, and working with code originally written by other people, an obsession with “concise” code at the expense of readability is a terrible habit that you should break now. Also, for the love of all that is good, comment your code.

Just for VEX, what happens if you’re sick the day of the tournament and for whatever reason you need to change how long your robot goes forward for in autonomous? If nobody else can understand your code to make that change, well, your “concise” code just cost you the tournament.

If you want to mess around with unnecessarily complicated unreadable code, stuff like Malbogle is awesome for that, but please don’t intentionally make your robot code unreadable.

So the two languages noted above are “toy languages”, they’ve never been used for any kind of business system.

I win, I worked on a billing system written in APL.

Research on APL is left to you, the casual programming Roboteer.

I am the only programmer. I understand what you’re saying, but if I’m sick, no changes are being made to that code that day.

I can comment, and will should I ever need to share code with someone, but for now, I’m ok with obfuscated code.

Just for the irony, I must say this: Eschew obfuscation!

I did not think it was possible to find the first N prime numbers with 17 characters.

you still should comment your code even if you are the only programmer, because 1) its a good habit to get into and 2) its always good to make code understandable, that way you never get confused about what each line does, and it make it better for others, for example, I am the only programmer on my team but I have shared my code extensively to help other teams

I always make sure I explain what a line or block of code does, and why I wrote it that way. I’ve found that when I revisit code, it still makes sense to me, but I have no idea why I did it that way. It also makes putting the code into our engineering notebook far easier, and a few of my teammates who understand the concepts of code but aren’t fluent in RobotC can explain it to judges, in case I’m away from the pit for some reason.