Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/07/2014, 16:45
Avatar de stramin
stramin
 
Fecha de Ingreso: marzo-2008
Ubicación: Cubil felino
Mensajes: 1.652
Antigüedad: 16 años, 1 mes
Puntos: 336
Respuesta: Como indentar/tabular un switch?

El estilo de Patriarka es parecido al "Cortador" pero indentado, supongo que llamaré a este estilo "Patriarka".

Entonces jc_moj prefiere la indentación de php.net

No me quedo claro como lo hace pateketrueke :(

He estado buscando más información por ahí y he encontrado que originalmente los case: eran etiquetas y por lo tanto nunca deberían tabularse, o sea como el "económico".

Cita:
When a label in a switch follows a "break" statement, the two are separated by a blank line. If the preceding statement is not a break, there is no blank line.

Blank lines separate each of the main sections in a file, including prologue comment (with copyright or version information, etc.), package declaration, imports and interface or class. Within a class, at least all constructors, methods and inner classes should be separated from each other and from any other fields by blank lines (always before the prologue comment, of course).

A blank line may optionally be inserted anywhere to improve readability but the use of two or more contiguous blank lines is unnecessary and should be avoided.
Sin embargo otras fuentes dicen que todo lo que está entre {llaves} debería indentarse.

Sin embargo en otro foro un usuario publicó este código:

Código PHP:
Ver original
  1. switch (1) {
  2.     case 1:
  3.         break;
  4.     case 2:
  5.         break;
  6.     case 3:
  7.         break;
  8.     default:
  9.         break;
  10. }

y un corrector de scripts lanzó esta salida:

Cita:
line 3, col 5, Expected 'case' to have an indentation at 1 instead at 5.
line 4, col 9, Expected 'break' to have an indentation at 5 instead at 9.
line 5, col 5, Expected 'case' to have an indentation at 1 instead at 5.
line 6, col 9, Expected 'break' to have an indentation at 5 instead at 9.
line 7, col 5, Expected 'case' to have an indentation at 1 instead at 5.
line 8, col 9, Expected 'break' to have an indentation at 5 instead at 9.
line 9, col 5, Expected 'default' to have an indentation at 1 instead at 5.
line 10, col 9, Expected 'break' to have an indentation at 5 instead at 9.
Por lo tanto también apoya a estilo "económico".

Al parecer, no hay una forma "correcta" o "incorrecta", pero esta encuesta me sirve para elegir un estandar :)

Y ustedes como hacen el switch?
__________________
El objetivo de este foro es orientar al usuario como un favor y no como una obligación.

Yo soy de los que dan puntos por aporte :D