martes, 26 de julio de 2016

Los dos formatos

Nuestro libro Algoritmos, Objetos y Estructuras de Datos puede adquirise en dos versiones ebook o impresa.
De esta manera se facilita el acceso a todos los que quieran utilizarlo como bibliografía de soporte para sus cursos o simplemente para aprender.

Support independent publishing: Buy this e-book on Lulu. Support independent publishing: Buy this book on Lulu.

martes, 4 de septiembre de 2012

Diseño por Contratos vs. Test-Driven Development (TDD)


Es común que aquellos que no tienen un conocimiento profundo de ambos temas tiendan a pensar que son enfoques intercambiables o incluso opuestos en el desarrollo de software.
Un interesante intercambio en el grupo de usuarios de Eiffel sobre el tema muestra una precisa distinción entre ambos que quería compartir.
Dice, Tomas Beale:

One thing I mentioned some time ago on this topic is the broad misunderstanding of DbC by people who should know better. I was looking at Scala blogs and wiki pages written by its designers, and they said that DbC was not really needed since Scala had TDD. That betrays a poor understanding of both.
Thinking about ways to explain the difference, I always understand the DbC pre- and post-condition specification for a routine F as a 'function' that maps a limited domain (the possible arguments + current object state) to a specific range (the answers, or behaviours in the case of a procedure) - it is therefore a mathematical requirement specification of the implementation of F (and it needs to be fully specificed to do this job properly - something we currently hardly ever do).
On the other hand, TDD to be a specification of specific members of the input domain + required correspondents in the range. So DbC is about functions, and TDD is about probing these functions with test data. Defining DbC in terms of these 'functions' offers possibilities for machine-verifiable software, which I know ETH and many others are working hard on.
But the outside world still doesn't seem to get this. And yet the original ideas come from Djikstra in the 60s!

Para profundizar un poco más otro usuario (Peter Gummer) recomienda el siguiente paper:
Para leer y reflexionar.

martes, 26 de julio de 2011

Contratos en C#. Parte 1.

En nuestro libro Algoritmos Objetos y Estructuras de Datos los algoritmos y ejemplos están realizados en C# y Eiffel.
Eiffel tiene el soporte nativo para contratos de software, es el lenguaje pionero en ese sentido. Pero también es posible realizar contratos en C# y en cualquier lenguaje sobre .NET usando  Microsoft Code Contracts.
Code Contracts provee un manera independiente del lenguaje de expresar precondiciones, poscondiciones e invariantes.  Hay algunas diferencias con los contratos en Eiffel fundamentalmente en el tema de la herencia pero igualmente son una poderosa herramienta de construcción de software confiable. Además de la librería hay una serie de herramientas que permiten la verificación de contratos:

  • ccrewrite: permite generar chequeos en tiempo de ejecución para los contratos
  • cccheck un verificador estático de contratos en tiempo de compilación
  • ccdoc que permite agregar los contratos a los archivos de documentación XML
En sucesivos artículos iremos describiendo mas en detalle esta herramienta de contratos de .NET. Para finalizar dejamos el código del ejemplo base de la librería, una clase que representa números racionales. Dicho ejemplo es fácil de leer y de comprender si se conoce el concepto de contratos, mas allá de los detalles de Microsoft Code Contracts.
  public class Rational {
    public int Numerator { get; protected set; }
    public int Denominator { get; protected set; }

    public Rational(int n, int d) {
      Contract.Requires(d != 0);

      this.Numerator = n;
      this.Denominator = d;
    }

    [ContractInvariantMethod]
    private void RationalInvariant() {
      Contract.Invariant(Denominator != 0);
    }

    public virtual void Add(Rational other) {
      Contract.Requires(other != null);
      int newN = this.Numerator * other.Denominator + other.Numerator * this.Denominator;
      int newD = this.Denominator * other.Denominator;

      this.Numerator = newN;
      this.Denominator = newD;
    }

    public static Rational operator +(Rational a, Rational b) {
      Contract.Requires(a != null);
      Contract.Requires(b != null);
      return new Rational(a.Numerator * b.Denominator + b.Numerator * a.Denominator, a.Denominator * b.Denominator);
    }
    public static Rational operator +(Rational a, int b) {
      Contract.Requires(a != null);
      return new Rational(a.Numerator + b * a.Denominator, a.Denominator);
    }

    public virtual void Divide(int divisor)
    {
      Contract.Requires(divisor != 0);

      this.Denominator = this.Denominator * divisor;
    }

    public int Truncate()
    {
      return this.Numerator / this.Denominator;
    }

    public virtual void Invert() {
      Contract.Ensures(Contract.OldValue(this.Numerator) == this.Denominator &&    Contract.OldValue(this.Denominator) == this.Numerator);

      int num = this.Numerator;
      int den = this.Denominator;
      this.Numerator = den;
      this.Denominator = num;
    }

  }

lunes, 27 de diciembre de 2010

Ofuscando .NET

La ofuscación de código tiene cómo objetivo proteger la propiedad intelectual del software. Se trata de un proceso por el cual se hace incompresible (o casi) a  los humanos comprender el código.
Dado que es muy fácil transformar el MSIL (el código intermedio que se general al compilar en los lenguajes de .NET y que es luego interpretado por el CLR) en por ejemplo C#, muchos programadores ven la necesidad de proteger su código mediante la ofuscación.
Hay diversas herramientas disponibles en el mercado a diversos precios, afortunadamente existe una herramienta muy potente, que se integra perfectamente con VisualStudio y que es gratuita. Se trata de Eazfuscator.Net.
Una intefaz sencilla y amigable sumado a la posibilidad de lo que se denomina ofuscación declarativa mediante atributos (Declarative Obfuscation Using Custom Attributes).



La figura anterior muestra la forma de ofuscar un proyecto mediante un simple drag and drop.
Para descargarlos, probarlo y ver mas pueden ir a: http://www.foss.kharkov.ua/g1/projects/eazfuscator/dotnet/Default.aspx