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
		
- 
				
				really? Really?
 
 it's just
 
 if (final >= 1 && final <= 6)
 return final;
 return -1;
- 
				
				 -bgm-3159yTernaries would be fun here and look no less stupid. -bgm-3159yTernaries would be fun here and look no less stupid.
 
 (status == 5) ? return 4 : ((status == 4) ? return 5 : ((status > 0) ? return status : return -1))
- 
				
				 port2210999yThis really is the best solution. Take a close look, case 4 returns 5 and case 5 returns 4. You could use the ternary posted above but it's broken, the last conditional should be (status >= 1 && status <= 6) but now you have a ternary which is ugly and not inherently obvious what it does. Also your breaking convention by using a ternary operator > 80 characters. What happens when the spec changes and now 9 should return 14? If I'm using the ternary solution instead of just adding a case I have to interpret the ternary and realize I should put the new conditional before the last one. Shit on it all you want but the switch statement is the most maintainable and readable solution here. The one thing he/she could've done to improve it was added comments pointing out the 4 and 5 are switched and why. port2210999yThis really is the best solution. Take a close look, case 4 returns 5 and case 5 returns 4. You could use the ternary posted above but it's broken, the last conditional should be (status >= 1 && status <= 6) but now you have a ternary which is ugly and not inherently obvious what it does. Also your breaking convention by using a ternary operator > 80 characters. What happens when the spec changes and now 9 should return 14? If I'm using the ternary solution instead of just adding a case I have to interpret the ternary and realize I should put the new conditional before the last one. Shit on it all you want but the switch statement is the most maintainable and readable solution here. The one thing he/she could've done to improve it was added comments pointing out the 4 and 5 are switched and why.
- 
				
				Some PM obviously said "is it possible to switch place of the fourth and fifth item in the list?" And dev says "Sure, it is built with this kind of flexibility in mind, it's a oneliner!".
 Backs are patted and salaries are raised...
- 
				
				 achehab8399yIf you want to maintain this method, just add an annotation "please don't touch" because I would have changed this method as @rainmitchell said and fucked up the code xD (i didn't notice the 4 & 5 switch too). achehab8399yIf you want to maintain this method, just add an annotation "please don't touch" because I would have changed this method as @rainmitchell said and fucked up the code xD (i didn't notice the 4 & 5 switch too).
Related Rants
- 
						
							 arthurdent18 arthurdent18 Today on how to make money fast: Today on how to make money fast:
- 
						
							 hypervtechnics10I wrote a complex method for about 6 hours. Then I decided to test it via a console application... It didnt p... hypervtechnics10I wrote a complex method for about 6 hours. Then I decided to test it via a console application... It didnt p...
- 
						
							 ganapativs15 ganapativs15 By playing with Facebook source code in browser, you can enable GIF and Markdown, Tip Jar & many more options ... By playing with Facebook source code in browser, you can enable GIF and Markdown, Tip Jar & many more options ...












browsing application source, found this beauty of a method 😶
undefined
source
useful
method