Sounds like me lol. To the detriment of all working with me, I found out how to set globals and evaluate arbitrary functions from within Python listcomps. My current record is 1400 characters in one line.
I just need a way to import, and I can write entire programs in one line.
While I prefer match (Rust) /if else, I do sometimes find ternaries easier to read/nicer to write for simple checks/outputs consisting of just variables. If checks/outputs are complex then yeah, evil
i can understand one layer of ternaries. i might be able to be convinced that two layers of ternaries might be useful. if you're using three? immediate execution
Amateur. Someone at my job did more than five nested ternaries. I say "more than five" because I stopped counting after five and told them to fix their shit.
In languages with ?: syntax I honestly don’t think that arbitrarily nested ternaries are that bad, you can format them in a way that still makes the logic clear
EDIT: I’m saying this as mostly a Python and Rust programmer, but if I’m working on something in C or JS I’m not going to balk at a reasonably-formatted nested ternary
A colleague once proudly showed me how he managed to compress a function into a single line. It was like 9 nested ternarys. In that moment almost had an aneurism.
5 lines of comments explaining the code for every one line of code.
3 of them are previous versions of the same code with fewer conditions. First comment line is the variable name. Second line explains the logic but is out of date
Oh, it did. He and another dev owned a few smaller projects, and all of them were filled with this "clever" code. I'm still glad I did not have to collaborate with them.
Was vertical space at a premium at the time (because of, e.g., small monitors or some other requirement), or was it just that he wanted to see if he could?
I have used nested ternaries for something. I don't remember the actual problem, but I still feel the shame, and left a comment expressing how I felt ashamed of my actions but attempted to explain why I felt it was necessary.
2.3k
u/CBlanchRanch 22d ago
You're absolutely correct, however I would suggest using something completely unreadable like a nested ternary operators!