C/Estrutura e estilo: Diferenzas entre revisións

Contido eliminado Contido engadido
Gallaecio (conversa | contribucións)
m Empezo a tradución
 
Gallaecio (conversa | contribucións)
Empezo a tradución, déixoo por hoxe
Liña 1:
{{Navegador|Compilación|Manexo dos erros}}
 
Este capítulo trátase dunha introdución básica de cara á produción de estruturas de código efectivas na linguaxe de programación C. Pensouse para explicar como usar de xeito efectivo as tabulacións, comentarios, e demáis elementos que farán que o teu código en C sexa máis doado de ler.
==C Structure and Style==
This is a basic introduction to producing effective code structure in the C Programming Language. It is designed to provide information on how to effectively use indentations, comments, and other elements that will make your C code more readable. It is not a tutorial on actually programming in C.
 
Os programadores que estén a empezar probablemente non entendan a grande utilidade que supón crear estruturas no código dos seus programas, pois a miúdo pensan que o código créase simplemente para ser lido por un compilador. A miúdo isto non é certo, pois para un programador que leva meses sen traballar no código, lelo e editalo será máis doado se éste está ben escrito e estruturado.
New programmers will often not see the point of creating structure in their programs' code, because they often think that code is designed purely for a compiler to read. This is often not the case, because well-written code that follows a well-designed structure is usually much easier for programmers (who haven't worked on the code for months) to read, and edit.
 
Nas vindeiras seccións, tratarase de explicar as técnicas de "boa programación" que farán os teus programas máis efgectivos.
In the following sections, we will attempt to explain good programming techniques that will in turn make your programs more effective.
 
== Introduction Exemplo==
Os seguintes dous bloques de código son básicamente o mesmo: ambos os dous conteñen exactamente o mesmo código, e compilaranse e executaranse co mesmo resultado. Aínda así, hai unha direfencia esencial.
The following two blocks of code are essentially the same: Both of them contain exactly the same code, and will compile and execute with the same result; however there is one essential difference.
 
Cal dos dous pensas que é máis doado de ler?
Which of the following programs do you think is easier to read?
 
<source lang="c">
<code><font style="color:#bc5ff8">#include</font> <font style="color:#ff48ff"><stdio.h></font><br>'''<font style="color:#1b991b">int</font>''' main('''<font style="color:#1b991b">void</font>''') {printf(<font style="color:#ff48ff">"Ola mundo!</font><font style="color:#a7a0d7">\n</font><font style="color:#ff48ff">"</font>); '''<font style="color:#bb2323">return</font>''' <font style="color:#ff48ff">0</font>;}</code>
#include <stdio.h>
 
int main(void) {printf("Hello, World!\n");return 0;}
ou
</source>
 
or
<code><font style="color:#bc5ff8">#include</font> <font style="color:#ff48ff"><stdio.h></font>
<source lang="c">
#include <stdio.h>
'''<font style="color:#1b991b">int</font>''' main('''<font style="color:#1b991b">void</font>''')
int main(void)
{
printf(<font style="color:#ff48ff">"Ola mundo!</font><font style="color:#a7a0d7">\n</font><font style="color:#ff48ff">"</font>);
printf("Hello, World!\n");
'''<font style="color:#bb2323">return</font>''' <font style="color:#ff48ff">0</font>;
return 0;
}</code>
 
</source>
O mero uso de tabulacións e saltos de liña pode mellorar e moito a facilidade de lectura do código. Ao termos un código máis lexible, é moito máis doado ver onde rematan as funcións e operacións, e que liñan son parte de que bucles e operacións.
The simple use of indents and line breaks can greatly improve the readability of the code; without making any impact whatsoever on how the code performs. By having readable code, it is much easier to see where functions and procedures end, and which lines are part of which loops and procedures.
 
Este libro centrarase no anterior fragmento de código, e como melloralo. Nótese que durante o transcurso do tutorial, aparecerán moitos anacos de código aparentemente redundantes. Estes están simplemente para servir de exemplo de técnicas que serán explicadas, sen romper co fluxo global de código que o programa logra.
This book is going to focus on the above piece of code, and how to improve it. Please note that during the course of the tutorial, there will be many (apparently) redundant pieces of code added. These are only added to provide examples of techniques that we will be explaining, without breaking the overall flow of code that the program achieves.
 
==Saltos de liña e tabulacións==
== Line Breaks and Indentation ==
Engadir espazos en branco no teu código podería dicirse que é a parte máis importante da boa estrutura de código. O seu uso efectivo pode crear un indicador visual de como flúe o teu código, o cal pode resultar moi importante á hora de volver ao código para o seu mantemento e revisión.
The addition of white space inside your code is arguably the most important part of good code structure. Effective use of it can create a visual gauge of how your code flows, which can be very important when returning to your code when you want to maintain it.
 
===Saltos Line Breaksde liña===
 
10 #include <stdio.h>