I sure hope so, i stumbled upon more bad code while checking out my old projects. But i fear eye damage from bad code isn't covered by most insurances.
So there is a lot of things wrong here, but the ternary if inside an if is the one I despise the most. That if(cnt != 3 ? string.length != 2 : string.length != 4) should definitely be if((cnt == 3 && string.length != 4) || string.length != 2)
This is not a ternary if though. Ternary ifs were an invention of Fortran, where if(condition) could return 3 possible values: -1, 0, and 1, and so you would have three branches after if.
21
u/onichama Jan 11 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
22
u/worldpotato1 Jan 11 '22
Ternary is nice!
But don't stack them, don't use them in conditions etc.
Just usw them to simple set variables.
6
u/Dr-Rjinswand Jan 11 '22
I’m actually guilty for this, I fucking love ternary ifs.
2
u/DeepRobin Jan 13 '22
Will my eye doctor bill be covered by your insurance?
27
u/[deleted] Jan 11 '22 edited Jan 12 '22
I always get wary when I see a variable named “cnt” 😂
1
u/Not_Sugden Jan 12 '22
bad tenary if
breakexistssometimes omitting {} when unnessercary, but sometimes keeping it even when its unnessercary
jesus
3
u/[deleted] Jan 11 '22
Bro what the fuck. Are you allergic to && || logic
3
u/pyker404 Jan 11 '22
The only bad thing i see is you are using camelCase for C# methods instead of PascalCase
3
u/CynicalGroundhog Jan 12 '22
How to format a simple date string in O(n³) complexity...
2
u/youngbull Jan 11 '22
So there is a lot of things wrong here, but the ternary if inside an if is the one I despise the most. That
if(cnt != 3 ? string.length != 2 : string.length != 4)should definitely beif((cnt == 3 && string.length != 4) || string.length != 2)2
u/[deleted] Jan 11 '22
This is not a ternary if though. Ternary ifs were an invention of Fortran, where if(condition) could return 3 possible values: -1, 0, and 1, and so you would have three branches after if.
1
u/[deleted] Jan 11 '22
What is "res" supposed to mean?
Edit: typo
1
u/maryP0ppins Jan 11 '22
i ONLY chain ternary operators. make sure the strong are the ones working on it.
1
u/youngbull Jan 11 '22
There is just so much wrong here, why does it default on "11.11.1111"? Ever heard of throwing an exception?
1
u/MaheuTaroo Jan 11 '22
G E N I U S
1
u/D34TH_5MURF__ Jan 13 '22
Nice variable name, cnt.