Express Refactoring
Las nuevas versiones express de VisualStudio tienen muy buena pinta. Visual C# Express Edition ocupa tan solo 28MB y puedes ponerte a desarrollar en un entorno que está muy pero que muy bien organizado. Actualmente es versión beta, y funciona de maravilla.
Hoy veremos una agradecida y esperada funcionalidad: Refactorización. Veamos como ejemplo un trozo de código que dado un String, le da la vuelta:
string hello = "Hello world!!";Ahora toca algo de magia. Seleccionamos de este trozo las líneas 3, 4 y 5. Botón derecho y "Extract Method", tal como aparece en la siguiente figura:
char[] charArray = hello.ToCharArray();
Array.Reverse(charArray);
String reversedString = new String(charArray);
Console.WriteLine(reversedString);

static void Main(string[] args)
{
string hello = "Hello world!!";
String reversedString = ReverseString(hello);
Console.WriteLine(reversedString);
}
private static String ReverseString(string hello)
{
char[] charArray = hello.ToCharArray();
Array.Reverse(charArray);
String reversedString = new String(charArray);
return reversedString;
}




1 comentarios
Paper sobre refactorización:
Introduction to Refactoring (variant.ch)
10:35 AM
Publicar un comentario en la entrada
Links to this post:
Crear un enlace
<< Volver