Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Ewwwwwwwwwwwwwww.
Can we just erase people from the gene pool for psychopathically wrong code? -
@ThatPerlDeb The biggest switch I've found in this "code base" is 3600 lines of code. One big switch with some smaller ones within... ⚰️⚰️⚰️
-
How does anyone even come up with this idea.
What happens if multiple cases are true? -
sleek34483y@IntrusionCM sometimes you write a lot of consecutive if conditions, then u think to yourself, hmmm this looks too ugly, maybe theres a nice way to wrap that logic up.
then i googled it and someone suggested it online and I tried it.
Looking at it now it looks horrible, i feel bad, and im sorry -
@sleek At least progress is made.
Maybe as a hint: The easiest solution would be an associative array binding a callback.
With newer PHP versions, lambdas are possible.
For a more pimped functional style, look at e.g. functional-php:
https://github.com/functional-php/... -
-
@theabbie 2 ifs are not quite the same as an if-elseif. In the latter, only one block may ever be executed, just like in switch-case. But other than that, you're absolutely right, an if-elseif would have veen much cleaner.
@ all:
My assumption why they wrote this is that they wanted to show which variable was being checked for each case block...
But then again, there are wayyyy cleaner ways of doing this lol -
bosi5083yWell... this looks like several copy n paste stack overflow snippets combined into one piece of code.
At least I think it will work but working code is not the only but just the first requirement of code. I assume that this wasn't written by a professional. -
satibel303y@electrineer afaik a string cannot be equal to two different strings at the same time.
Also, the switch will go in order, so the first being equal will trigger and the break will end the switch. -
@satibel what prevents you from using any other condition than string comparison if that is allowed. Interesting that anything is allowed.
-
satibel303y@electrineer I just assumed it was copy pasted and all the same, but yeah there may be different comparisons within the switch. Still the first match will do its thing and then break the switch (assuming a break is used).
If conditions like starts with or contains are used, and the first match priority is used, I'm not sure if there's a much cleaner way to do dispatch (a db might work but it'll be much slower).
That's basically chained if/else except you can be sure there's not an end somewhere with a forgotten else or one purposefully put there (though there's the same-ish thing with break) -
@Lucky-Loek true but turd coders will still fetch redundant data from outside systems at every opportunity they can get. O(n²) for the win 😄
Related Rants
You wanna know why PHP has such a poor reputation?
It's because of imbeciles who code like this:
rant
retards
code of doom
php