C/Estrutura e estilo: Diferenzas entre revisións

Contido eliminado Contido engadido
Gallaecio (conversa | contribucións)
m →‎Liñas baleiras: Empezo a traducir
Gallaecio (conversa | contribucións)
Sigo a traducir
Liña 44:
*Entre novos camiños de código (por exemplo, declaracións de funcións ou bucles, ou tras o peche de chave "}").
 
<font style="color:#bc5ff8">#include</font> <font style="color:#ff48ff"><stdio.h></font>
'''<font style="color:#1b991b">int</font>''' main('''<font style="color:#1b991b">void</font>''')
int main(void)
{
'''<font style="color:#1b991b">int</font>''' i=<font style="color:#ff48ff">0</font>;
int i=0;
printf(<font style="color:#ff48ff">"Ola mundo!</font><font style="color:#ff48ff">"</font>);
printf("Hello, World!");
'''<font style="color:#bb2323">for</font>''' (i=<font style="color:#ff48ff">0</font>; i<<font style="color:#ff48ff">1</font>; i++)
for (i=0; i<1; i++)
{
printf(<font style="color:#ff48ff">"</font><font style="color:#a7a0d7">\n</font><font style="color:#ff48ff">"</font>);
80 printf("\n");
'''<font style="color:#bb2323">break</font>''';
90 break;
100 }
'''<font style="color:#bb2323">return</font>''' <font style="color:#ff48ff">0</font>;
110 return 0;
120 }
130
Based on the rules we established earlier, there should now be four line breaks added.
*Between lines 10 and 20, as line 10 is a precompiler declaration
*Between lines 40 and 50, as the block above it contains variable declarations
*Between lines 50 and 60, as it is the beginning of a new path (the 'for' loop)
*Between lines 100 and 110, as it is the end of a path of code
 
Seguindo as regras establecidas anteriormente, deberiamos de engadir catro liñas baleiras:
This will make the code much more readable than it was before:
 
<font style="color:#bc5ff8">#include</font> <font style="color:#ff48ff"><stdio.h></font>
The following lines of code have line breaks between functions, but not any indention.
<font style="color:blue">// Unha aquí, despois do que é unha declaración de precompilación</font>
 
'''<font style="color:#1b991b">int</font>''' main('''<font style="color:#1b991b">void</font>''')
10 #include <stdio.h>
11{
'''<font style="color:#1b991b">int</font>''' i=<font style="color:#ff48ff">0</font>;
20 int main(void)
<font style="color:blue">// Outra aquí, pois o bloque anterior contén declaracións de variables</font>
30 {
printf(<font style="color:#ff48ff">"Ola mundo!</font><font style="color:#ff48ff">"</font>);
40 int i=0;
<font style="color:blue">// Outra máis aquí, pois a continuación empeza un novo camiño (o bucle "for")</font>
41
'''<font style="color:#bb2323">for</font>''' (i=<font style="color:#ff48ff">0</font>; i<<font style="color:#ff48ff">1</font>; i++)
50 printf("Hello, World!");
51 {
printf(<font style="color:#ff48ff">"</font><font style="color:#a7a0d7">\n</font><font style="color:#ff48ff">"</font>);
60 for (i=0; i<1; i++)
'''<font style="color:#bb2323">break</font>''';
70 {
}
80 printf("\n");
<font style="color:blue">// E un cuarto aquí, xa que remata o camiño anterior</font>
90 break;
'''<font style="color:#bb2323">return</font>''' <font style="color:#ff48ff">0</font>;
100 }
}
101
110 return 0;
120 }
 
Isto fará o código móito máis fácil de ler que antes. Pero aínda pode ser máis lexible.
But this still isn't as readable as it can be.
 
=== Indentation ===