He estado programando durante mucho tiempo. Generalmente programo en algunos lenguajes como PHP, ASP.net, Java, JavaScript y otros. En todos los idiomas, tengo que usar una gran cantidad de declaraciones if else. Al igual que si el valor = 10, entonces ... si reviso mi código, entonces encontraré un montón de condiciones. Entonces me gustaría minimizarlos pero no estoy seguro.Cómo evitar si ... else y cajas de conmutadores
un momento estaba usando clases tanto minimizadas pero aún así son más ...
como tarea, gato, sec y tipo:
if task = 'add' then
if cat = "animal" then
if sec = "man" then
if type = "male" then
'do the following stuffs
else
'do the following stuffs
end if
elseif sec = "horse" then
if type = "run"
'do the following stuffs
else
'do the following stuffs
end if
elseif....
end if
elseif cat = "plant" then
if sec = "land" then
if type="tree" then
'do the following stuffs
elseif type = "grass" then..
'do the following stuffs
elseif...
end if
elseif sec = "water" then
...
...
...
más n más los que siguen n continuar
así que me pregunto cómo puedo minimizarlos y escribir algunos códigos eficientes?
Lo sentimos informar de que últimamente hay muchos valores para task, cat, sec y type. Mis sentencias if van anidadas n anidadas.
Más explicativo mi código también se parece a la misma como:
http://thedailywtf.com/Articles/Coding-Like-the-Tour-de-France.aspx
agregué un código a mi respuesta – Mchl
Una nota al margen: intente codificar con la intención de que una función/sub nunca sea mayor que puede ver toda la función/sub en una pantalla (pantallas giratorias no incluidas:]). De esta manera se verá obligado a dividir este código en fragmentos más pequeños y esto, a su vez, hará que sea más fácil ver y entender – Default