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
-
That developer must get paid by how many lines of code he writes... that's my only explanation.
-
spa691087yEven better than 11 if..else..statements.
(Although this code could be replaced by one if) -
What if, I'm not saying it probably is, but what if the different items aren't numbered in a nice order. Maybe Item 4 is the integer -847736, and item 5 is the integer 45, and maybe there are many more values in that item enum not visible to us...
Then it might, only saying it might, be easier to do it this way if you want to model the behaviour of always returning item 1 by default....
Staying humble has never failed me yet. -
I'm pretty sure this source code come from a class that extends RecyclerView. Adapter.
-
I think shortest way to do the same is
switch(position) {
case TYPE_ITEM_1:
case TYPE_ITEM_2:
...
case TYPE_ITEM_10:
return position;
default:
return TYPE_ITEM_1;
}
Anyways, ithat functions is a signal that you need a serious refactor -
jralph507yShortest way for the same result would be:
if (position > 10) {
return 1;
}
return position; -
@jralph cheers buddy! That's exactly what I added (but with index 0).
Yeah, they were integer constants only. 😅 -
Ah, OK...
No harm in double assigning, just in case, maybe it should be repeated with if statements in a try catch, just in case.
Then maybe create a unit test for that, just in case, just in case.
Did I say just in case? Just in case I'm going to say - just in case. -
I cringed when i saw this like the first time i googled trypophobia and saw an image of it.
I never believed in such posts until I saw this today.....
*Double face palm*
undefined