Foros - Stratos

Stratos => Off-topic => Mensaje iniciado por: samsaga2 en 22 de Septiembre de 2004, 08:29:33 AM

Título: Situaciones Reales
Publicado por: samsaga2 en 22 de Septiembre de 2004, 08:29:33 AM
 Echadle un ojo:

http://rinkworks.com/stupid/cs_programming.shtml

La que mas me ha hecho gracia:

This little bit of Java was written as part of a group project at university. The friend who passed it to me has been bouncing off the walls about the quality of the guilty party's code (silly things like defining error and success codes with the same value so you don't know what the return code means and stuff like that), but this is the most obviously stupid bit.

public int convertItoi(Integer v)
{
   if (v.intValue()==1) return 1;
   if (v.intValue()==2) return 2;
   if (v.intValue()==3) return 3;
   if (v.intValue()==4) return 4;
   if (v.intValue()==5) return 5;
   if (v.intValue()==6) return 6;
   if (v.intValue()==7) return 7;
   return 0;
}  
Título: Situaciones Reales
Publicado por: zxs en 22 de Septiembre de 2004, 03:53:00 PM
 es mejor ésta:

if (value == 0)
   return value;
else
   return 0;


menuda joya!!!
Título: Situaciones Reales
Publicado por: Sacrifai en 22 de Septiembre de 2004, 03:58:48 PM
 
CitarI found this comment in some code I had to maintain:

    /* This function is BOOL but actually returns TRUE,
    FALSE and -2 because I've no time to change it
    to int */

Didn't it take more time to write the comment?

Supongo que el gringo tiene razón XDDDD.
Título: Situaciones Reales
Publicado por: sés en 22 de Septiembre de 2004, 04:35:24 PM
 
Citarif (a)
{
    /* do something */
    return x;
}
else if (!a)
{
    /* do something else */
    return y;
}
else
{
    /* do something entirely different */
    return z;
}
Este tampoco está mal :P