Mensagens do FxCop

Para quem não conhece, o FxCop é uma ferramenta de análise de código que identifica pontos de melhoria em:

  • Design;
  • Localização;
  • Performance; e
  • Segurança.

Com base no Design Guidelines para desenvolvedores de Class Libraries, o FxCop identifica e exibe os pontos que podem e devem ser melhorados.

Vou destacar alguns pontos que classifico como interessantes e até mesmo curiosos. São eles:

  1. Do not catch general exception types – Explicação: You should not catch Exception or SystemException. Catching generic exception types can hide run-time problems from the library user, and can complicate debugging. You should catch only those exceptions that you can handle gracefully. Ou seja, trate apenas exceções específicas, que você consegue identificar de forma muito mais fácil ou simplesmente faça um Throw da exceção genérica. Essa é nova para mim;

  2. Specify CultureInfo – Explicação: Because the behavior of 'String.ToUpper()' could vary based on the current user's locale settings, replace this call in 'bus_proposta_leitura.LerAcessoControleBlocoInformacoes(Integer, String, String)' with a call to 'String.ToUpper(CultureInfo)'. If the result of 'String.ToUpper(CultureInfo)' will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'CultureInfo' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. De novo uma novidade para mim, o ToUpper e o ToLower usam as configurações da cultura em que a aplicação está rodando e essas configurações podem ser diferentes de uma cultura para outra.

  3. Identifiers should be cased correctly - Explicação: Type, namespace, and member identifiers are Pascal-cased. Parameter identifiers are camel-cased. Two letter acronyms within these identifiers should be upper-cased, for example, use System.IO instead of System.Io. Acronyms of three or more letters should be Pascal-cased, for example, use System.Xml instead of System.XML. The pascal-casing convention capitalizes the first letter of each word, as in BackColor. The camel-casing convention formats the first letter of the first word in lowercase and capitalizes the first letter of all subsequent words, as in backgroundColor. Although it may be common practice for some two letter acronyms to not be fully capitalized, violations of this rule should not be excluded for this reason. For example, 'DbConnection',is common but incorrect; use DBConnection. A violation of this rule might be required for compatibility with existing, non-managed symbol schemes. In general, however,these symbols should not be visible outside the assembly that uses them. Poxa, tudo bem que a nomenclatura deve ser seguida, mas, levar ao pé da letra assim, é sacanagem, apesar de ajudar muito, gostaria ver alguém que no dia-a-dia segue essas notações.

Esses são apenas algumas que apareceram aqui no meu projeto, dependendo do projeto de vocês podem aparecer algumas mais interessantes ainda. Qual mensagem “diferente” apareceu para vocês?

Ah, faça o download do FxCop 1.36 Beta aqui.

Abraços…

Chilá!@!

No Comments