<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gustavo Dutra &#187; Dicas</title>
	<atom:link href="http://gustavodutra.com/categoria/nerd/dicas-nerd/feed/" rel="self" type="application/rss+xml" />
	<link>http://gustavodutra.com</link>
	<description>Um pouco de tudo, nada de pouco</description>
	<lastBuildDate>Thu, 29 Jul 2010 22:57:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introdução a testes unitários com CakePHP e SimpleTest</title>
		<link>http://gustavodutra.com/post/377/introducao-a-testes-unitarios-com-cakephp-e-simpletest/</link>
		<comments>http://gustavodutra.com/post/377/introducao-a-testes-unitarios-com-cakephp-e-simpletest/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 16:22:50 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[aumentar produtivade]]></category>
		<category><![CDATA[extreme programming]]></category>
		<category><![CDATA[fdd]]></category>
		<category><![CDATA[feature driven development]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[produtividade]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[simpletest]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[teste de software]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=377</guid>
		<description><![CDATA[Há tempos eu venho lendo sobre XP (eXtreme Programming), Scrum e Feature Driven Development (FDD). São metodologias ágeis de desenvolvimento de software. O engraçado é que praticamente, ao meu ver, fazem a mesma coisa, porém de forma diferente. E todas elas frizam a importância dos testes unitários e, mais especificadamente, testes unitários antes do desenvolvimento, [...]]]></description>
			<content:encoded><![CDATA[<p>Há tempos eu venho lendo sobre XP (eXtreme Programming), Scrum e Feature Driven Development (FDD). São metodologias ágeis de desenvolvimento de software. O engraçado é que praticamente, ao meu ver, fazem a mesma coisa, porém de forma diferente. E todas elas frizam a importância dos testes unitários e, mais especificadamente, testes unitários antes do desenvolvimento, o chamado TDD (Test Driven Development). Como nunca havia trabalhado desta forma, ainda não tinha uma opinião sobre isso. Apenas comentários e depoimentos de que usa. Somado a isso, veio aquele senso de desafio, de inovação e curiosidade.</p>
<p>Faz alguns meses, e decidimos, eu e o <a rel="nofollow" href="http://ezabka.wordpress.com">Emanuel Zabka</a>, implantar o TDD no desenvolvimento na empresa em que trabalhamos. Academicamente é falado muito em <em>refactoring</em> e <em>mudanças de requisitos</em>, mas na prática, eu nunca havia notado a quantidade de modificações que um mesmo código/classe/arquivo é modificado num curto período de tempo e a longo prazo.</p>
<p>Os testes me ajudaram a enxergar, não só as dependências do sistema, como também, <strong>acoplamentos desnecessários</strong>; a qualidade dos códigos; do design do projeto; e, consequentemente, diminuiu muito os bugs mais corriqueiros, como validação de campos. Mesmo tendo várias coisas boas, há coisas ruins, como aumento do tempo de desenvolvimento &#8211; o que, apesar de nunca ter medido, diminui o retrabalho e tempo utilizado no futuro em correções de bugs -, aumento da complexidade da arquitetura &#8211; a fim de manter uma maior coesão com baixo acoplamento, entre outros menos relevantes.<br />
<span id="more-377"></span></p>
<h2>Unit Test</h2>
<blockquote><p>
The basic concept of unit testing is write more code which will test the main code we’ve written, by “throwing” sample data at it and examining what it gets back.
</p></blockquote>
<p>Harry Fuecks</p>
<p>Enfim, uma boa definição de testes unitários é esta supracitada. São escritos mais códigos para testar o código principal, utilizando dados de testes para analisar o comportamento e o retorno do código sendo testado. </p>
<h2>CakePHP</h2>
<ul>
<li>Framework de desenvolvimento rápido pra Web com PHP</li>
<li>Utiliza padrões MVC e ORM</li>
<li>Extensível para desenvolvimento, manutenção e deploying.</li>
<li>OpenSource / Comunidade muito ativa e amigável   </li>
<li>Orientada a Objetos</li>
<li><a rel="nofollow" href="http://www.cakephp.org/pages/features" target="_blank">Mais detalhes sobre o CakePHP</a></li>
</ul>
<h2>SimpleTest</h2>
<ul>
<li>Praticamente mesma coisa que JUnit, JMock e PHPUnit.</li>
<li>Guiado através de asserções</li>
<li>Possibilidade navegação em requisições HTTP para testar interface gerada (HTML)   </li>
<li>OpenSource</li>
<li>Orientada a Objetos</li>
<li><a rel="nofollow" href="http://www.simpletest.org/en/overview.html" target="_blank">Mais detalhes sobre o SimpleTest</a></li>
</ul>
<h2>CakePHP e SimpleTest</h2>
<ul>
<li>Startup (criação do arquivo, casos de testes básicos) dos testes unitários automaticamente</li>
<li>Customizações no template de Report (Web com template padrão)</li>
<li>Rápida execução de testes individualizados</li>
<li>Rápida execução de grupos de testes (execução de vários testes unitários sequencialmente)</li>
<li>Pode-se usar Mock para objetos internos do CakePHP ou da aplicação</li>
<li>Pode-se testar aplicação toda (APP + Plugins)</li>
<li>Pode-se testar somente a aplicação (APP)</li>
<li>Pode-se testar plugins separadamente</li>
<li>Pode-se testar em modo batch</li>
<li><a rel="nofollow" href="http://book.cakephp.org/view/354/Preparing-for-testing" target="_blank">Integração dos dois frameworks</a></li>
</ul>
<h2>Convenções e Padrões</h2>
<p>Para o SimpleTest não há padronização no nome dos arquivos, mas o CakePHP estabelece um a partir da convenção das classes utilizados por ele. Ex: respectivamente as classes de controller e model de um Post:</p>
<dl>
<dt><strong>PostController</strong></dt>
<dd>tests/cases/controllers/post_controller.test.php</dd>
<dt><strong>Post</strong></dt>
<dd>tests/cases/models/post.test.php</dd>
</dl>
<ul>
<li>O nome da classe contida no arquivo é derivado a partir do nome do mesmo.</li>
<li>Esta classe deve extender a classe CakeTestCase ou CakeWebTestCase</li>
<li>A assinatura dos métodos que contém asserções (métodos de teste) devem iniciar com “test”, como em testPostControllerAddPost().</li>
<li>Métodos que são executados como eventos:
<dl>
<dt><strong>start()</strong></dt>
<dd>Primeiro método chamado. Executado quando se iniciam os testes</dd>
<dt><strong>end()</strong></dt>
<dd>Último método chamado. Executado quando se concluí todos os casos testes</dd>
<dt><strong>startCase()</strong></dt>
<dd>Executado antes do caso de teste começar a ser testado (lembrando que um teste pode ser composto de um ou mais casos de teste)</dd>
<dt><strong>endCase()</strong></dt>
<dd>Executado depois que o caso de teste foi testado por completo</dd>
<dt><strong>before($method)</strong></dt>
<dd>Anuncia o início de um método de teste</dd>
<dt><strong>after($method)</strong></dt>
<dd>Anuncia o término de um método de teste</dd>
<dt><strong>startTest($method)</strong></dt>
<dd>Executado antes de um caso de teste iniciar</dd>
<dt><strong>endTest($method)</strong></dt>
<dd>Executado depois que um caso de teste termina</dd>
</dl>
</li>
</ul>
<p><a rel="nofollow" href="http://book.cakephp.org/view/362/Creating-tests" target="_blank">Mais detalhes sobre as convenções</a></p>
<h2>Fixtures</h2>
<p>Fixtures são uma forma de utilizar dados de teste. São matrizes de dados que correspondem à registros em um banco de dados.<br />
Cada Model possui uma Fixture, que irá não só ter os dados como a representação dos campos que compõe a tabela do banco, pois a partir destes dados o framework irá:</p>
<ol>
<li>Criar uma tabela prefixada (por padrão) de “test_suite_” no banco de dados para cada fixture necessário (ou seja, cada model utilizado).</li>
<li>Inserir os dados de teste na tabela de teste</li>
<li>Executar os testes em cima destes registros</li>
<li>Remover os dados da tabela de teste</li>
<li>Remover a tabela no banco de dados.</li>
</ol>
<p>Ou seja, assim é garantido que os dados serão sempre os mesmos e que não comprometerá a base de dados atual com sujeira, podendo-se executar<br />
estes testes a qualquer momento atrás de problemas. Testes que envolvem banco de dados com índices únicos, chaves primárias ou outras constraints<br />
estão livres de erros (erros não propositais) durante os testes.</p>
<p><a rel="nofollow" href="http://book.cakephp.org/view/358/Preparing-test-data" target="_blank">Veja mais sobre Fixtures</a></p>
<h2>Asserções</h2>
<ul>
<li>assertTrue($x)</li>
<li>assertFalse($x)</li>
<li>assertNull($x)</li>
<li>assertEqual($x, $y)</li>
<li>assertIsA($object, ‘ClassName’)</li>
<li>assertIdentical($x, $y)</li>
<li>assertPattern(’/REGEX/’, $x)</li>
<li>expectError();</li>
</ul>
<p>Se você se interessou, para mais detalhes sobre os testes unitários no CakePHP, recomendo a leitura deste post da <a rel="nofollow" href="http://debuggable.com">Debuggable</a>: <a rel="nofollow" href="http://debuggable.com/posts/unit-testing-in-cakephp-part-1---introduction-to-unit-testing:48102610-c5d0-4398-a010-76974834cda3" target="_blank"><cite>Unit Testing in CakePHP Part 1 &#8211; Introduction to Unit Testing</cite></a></p>
<p>Agradecimentos especiais a <a rel="nofollow" href="http://twitter.com/wmute">André Leitzke</a> e <a rel="nofollow" href="http://vivids.com.br">Viviane de Souza</a> por terem me ajudado com a caracterização e descrição do framework!</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/377/introducao-a-testes-unitarios-com-cakephp-e-simpletest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Acessando a freenode.org por SSL no Irssi</title>
		<link>http://gustavodutra.com/post/370/acessando-a-freenode-org-por-ssl-no-irssi/</link>
		<comments>http://gustavodutra.com/post/370/acessando-a-freenode-org-por-ssl-no-irssi/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 20:59:15 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[archlinux]]></category>
		<category><![CDATA[como]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[irssi]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=370</guid>
		<description><![CDATA[Bom, recentemente a FreeNode.org adicionou suporte a conexões SSL. Não que eu faça questão, porém meu irssi perdia a conexão com o server. Fui para o google e decidi postar a dica de como resolvi o problema e habilitei a conexão SSL.

Primeiro, eu baixei um script que a própria FreeNode.org disponibiliza para o irssi, o [...]]]></description>
			<content:encoded><![CDATA[<p>Bom, recentemente a <a rel="nofollow" href="http://freenode.org">FreeNode.org</a> adicionou suporte a conexões SSL. Não que eu faça questão, porém meu <a rel="nofollow" href="http://irssi.org" rel="nofollow">irssi</a> perdia a conexão com o server. Fui para o google e decidi postar a dica de como resolvi o problema e habilitei a conexão SSL.</p>
<p><span id="more-370"></span></p>
<p>Primeiro, eu baixei um script que a própria <a rel="nofollow" href="http://freenode.org">FreeNode.org</a> disponibiliza para o irssi, o instalei e depois algumas dependências.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>.irssi<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>autorun <span style="color: #666666; font-style: italic;">#Se o diretório não existir, crie-o</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.freenode.net<span style="color: #000000; font-weight: bold;">/</span>sasl<span style="color: #000000; font-weight: bold;">/</span>cap_sasl.pl</pre></div></div>

<p>Como maioria das dependências não estavam nos repositórios oficiais do <a rel="nofollow" href="http://archlinux.org">Arch Linux</a> nem do <a rel="nofollow" href="http://aur.archlinux.org">AUR</a>, eu tive que as instalar separadamente e ai já aproveitei pra fazer um script de instalação com todas as dependências. Esse script funciona em qualquer distro. São necessários os seguintes módulos: <strong>Math::BigInt, Math::BigInt::FastCalc, Math::BigInt::GMP, Math::BigInt::Pari, Crypt::DH e Crypt::OpenSSL::BigNum</strong>.</p>
<p>Abra um novo arquivo e cole as linhas abaixo, será nosso script de instalação.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">packages</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>Math-BigInt-<span style="color: #000000;">1.89</span> Math-BigInt-FastCalc-<span style="color: #000000;">0.19</span> Math-BigInt-GMP-<span style="color: #000000;">1.24</span> Math-BigInt-Pari-<span style="color: #000000;">1.13</span> Crypt-DH-<span style="color: #000000;">0.06</span> Crypt-OpenSSL-Bignum-<span style="color: #000000;">0.04</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>cpan-comp
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>cpan-comp
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.cpan.org<span style="color: #000000; font-weight: bold;">/</span>authors<span style="color: #000000; font-weight: bold;">/</span>id<span style="color: #000000; font-weight: bold;">/</span>T<span style="color: #000000; font-weight: bold;">/</span>TE<span style="color: #000000; font-weight: bold;">/</span>TELS<span style="color: #000000; font-weight: bold;">/</span>math<span style="color: #000000; font-weight: bold;">/</span>Math-BigInt-1.89.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.cpan.org<span style="color: #000000; font-weight: bold;">/</span>authors<span style="color: #000000; font-weight: bold;">/</span>id<span style="color: #000000; font-weight: bold;">/</span>T<span style="color: #000000; font-weight: bold;">/</span>TE<span style="color: #000000; font-weight: bold;">/</span>TELS<span style="color: #000000; font-weight: bold;">/</span>math<span style="color: #000000; font-weight: bold;">/</span>Math-BigInt-FastCalc-0.19.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.cpan.org<span style="color: #000000; font-weight: bold;">/</span>authors<span style="color: #000000; font-weight: bold;">/</span>id<span style="color: #000000; font-weight: bold;">/</span>T<span style="color: #000000; font-weight: bold;">/</span>TE<span style="color: #000000; font-weight: bold;">/</span>TELS<span style="color: #000000; font-weight: bold;">/</span>math<span style="color: #000000; font-weight: bold;">/</span>Math-BigInt-GMP-1.24.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.cpan.org<span style="color: #000000; font-weight: bold;">/</span>authors<span style="color: #000000; font-weight: bold;">/</span>id<span style="color: #000000; font-weight: bold;">/</span>T<span style="color: #000000; font-weight: bold;">/</span>TE<span style="color: #000000; font-weight: bold;">/</span>TELS<span style="color: #000000; font-weight: bold;">/</span>math<span style="color: #000000; font-weight: bold;">/</span>Math-BigInt-Pari-1.13.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.cpan.org<span style="color: #000000; font-weight: bold;">/</span>authors<span style="color: #000000; font-weight: bold;">/</span>id<span style="color: #000000; font-weight: bold;">/</span>B<span style="color: #000000; font-weight: bold;">/</span>BT<span style="color: #000000; font-weight: bold;">/</span>BTROTT<span style="color: #000000; font-weight: bold;">/</span>Crypt-DH-0.06.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.cpan.org<span style="color: #000000; font-weight: bold;">/</span>authors<span style="color: #000000; font-weight: bold;">/</span>id<span style="color: #000000; font-weight: bold;">/</span>I<span style="color: #000000; font-weight: bold;">/</span>IR<span style="color: #000000; font-weight: bold;">/</span>IROBERTS<span style="color: #000000; font-weight: bold;">/</span>Crypt-OpenSSL-Bignum-0.04.tar.gz
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> pkg <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$packages</span>; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pkg</span>.tar.gz&quot;</span> ;
	<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pkg</span>&quot;</span> ;
	<span style="color: #c20cb9; font-weight: bold;">perl</span> Makefile.PL ;
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ;
	<span style="color: #7a0874; font-weight: bold;">cd</span> .. ;
<span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p>OK, o <a rel="nofollow" href="http://garotosopa.wordpress.com/">garotosopa</a> tirou toda a graça do meu script, me alertando uma coisa da qual não sabia, para instalar um módulo do perl, basta digitar:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cpan <span style="color: #660033;">-i</span> Math::BigInt Math::BigInt::FastCalc Math::BigInt::GMP Math::BigInt::Pari Crypt::DH Crypt::OpenSSL::Bignum</pre></div></div>

<p>Inicie o irssi e digite:</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">/sasl set freenode Seu_nick Sua_Senha DH-BLOWFISH
/sasl save
/save
/quit</pre></div></div>

<p>Agora, é só ajeitar o config do irssi.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> ~<span style="color: #000000; font-weight: bold;">/</span>.irssi<span style="color: #000000; font-weight: bold;">/</span>config</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">servers <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#123;</span>
		address <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;irc.freenode.org&quot;</span><span style="color: #339933;">;</span>
		chatnet <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;freenode&quot;</span><span style="color: #339933;">;</span>
		port <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;7000&quot;</span><span style="color: #339933;">;</span>
		use_ssl <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #339933;">;</span>
		ssl_verify <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #339933;">;</span>
		ssl_capath <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;/etc/ssl/certs&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Entre no irssi novamente e pronto! Só usar o /connect freenode !</p>
<p>E ai, gostou? </p>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/370/acessando-a-freenode-org-por-ssl-no-irssi/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>50 Cheat Sheets e Quick Refs para salvar sua pele</title>
		<link>http://gustavodutra.com/post/336/50-cheat-sheets-e-quick-refs-para-salvar-sua-pele/</link>
		<comments>http://gustavodutra.com/post/336/50-cheat-sheets-e-quick-refs-para-salvar-sua-pele/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 17:46:11 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[bazaar]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[cheat sheets]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gvim]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=336</guid>
		<description><![CDATA[Estou disponibilizando algumas Cheat Sheets que estavam nos meus favoritos. Sempre são úteis em algum momento!!! Espero que aproveitem pelo menos 1 delas!
Controle de Versão

SVN Cheat Sheet
Git Cheat Sheet
Mercurial Cheat Sheet
Bazaar Cheat Sheet

Frameworks

Prototype Cheat Sheet
MooTools Cheat Sheet
jQuery Cheat Sheet
Ruby On Rails
Django Cheat Sheet
CodeIgniter Cheat Sheet
CakePHP Cheat Sheet
Mais de 12 Symfony Cheat Sheets

Programação

Bash Script Quick Refences
AWK [...]]]></description>
			<content:encoded><![CDATA[<p>Estou disponibilizando algumas Cheat Sheets que estavam nos meus favoritos. Sempre são úteis em algum momento!!! Espero que aproveitem pelo menos 1 delas!</p>
<h2>Controle de Versão</h2>
<ul>
<li><a rel="nofollow" href="http://www.cs.put.poznan.pl/csobaniec/Papers/svn-refcard.pdf">SVN Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://ktown.kde.org/%7Ezrusin/git/git-cheat-sheet-large.png">Git Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://edong.net/2008v1/docs/dongwoo-Hg-PDF.pdf">Mercurial Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://doc.bazaar-vcs.org/latest/en/_static/en/bzr-en-quick-reference.png">Bazaar Cheat Sheet</a></li>
</ul>
<h2>Frameworks</h2>
<ul>
<li><a rel="nofollow" href="http://thinkweb2.com/projects/prototype/downloads/Prototype%20Cheat%20Sheet%201.6.0.2">Prototype Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://mediavrog.net/blog/wp-content/uploads/2008/08/mootools-12-cheat-sheet-pf.pdf">MooTools Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/Jquery-Cheat-Sheet-1.2.pdf">jQuery Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.addedbytes.com/cheat-sheets/download/ruby-on-rails-cheat-sheet-v1.pdf">Ruby On Rails</a></li>
<li><a rel="nofollow" href="http://www.mercurytide.co.uk/media/whitepapers/django-cheat-sheet/django10-cheat-sheet.pdf">Django Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://codeigniter-1-7-1-quick-reference-cheatsheet.googlecode.com/files/CodeIgniter_Cheatsheet_DesignFellow_v2.zip">CodeIgniter Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://cakephp.org/files/Resources/CakePHP-1.2-Cheatsheet.pdf">CakePHP Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://trac.symfony-project.org/wiki/CheatSheets">Mais de 12 Symfony Cheat Sheets</a></li>
</ul>
<h2>Programação</h2>
<ul>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/bash_ref.pdf">Bash Script Quick Refences</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/image/saved.copy.gif">AWK Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/HTML5_Canvas_Cheat_Sheet.png">HTML5 Canvas Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/php_cheat_sheet.png">PHP Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.zenspider.com/Languages/Ruby/QuickRef.html">Ruby Quick Refence</a></li>
<li><a rel="nofollow" href="http://www.scottklarr.com/topic/106/perl-cheat-sheets/">9 Perl Cheat Sheets</a></li>
<li><a rel="nofollow" href="http://rgruet.free.fr/PQR24/PQR2.4.html">Python Quick Refence</a></li>
<li><a rel="nofollow" href="http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/">Regular Expression Cheat Sheet</a></li>
</ul>
<h2>Web Design</h2>
<ul>
<li><a rel="nofollow" href="http://www.reeddesign.co.uk/test/points-pixels.html">Font Size Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.blooberry.com/indexdot/css/propindex/all.htm">Propriedades CSS</a></li>
<li><a rel="nofollow" href="http://www.addedbytes.com/cheat-sheets/html-character-entities-cheat-sheet/">HTML Char Entities Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.scottklarr.com/topic/114/designers-color-chart-cheat-sheets/">6 Design Colors Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.seomoz.org/user_files/SEO_Web_Developer_Cheat_Sheet.pdf">SEO Web Developer Cheat Sheet</a></li>
</ul>
<h2>Bancos de Dados</h2>
<ul>
<li><a rel="nofollow" href="http://www.xml.dvint.com/docs/SchemaStructuresQR-2.pdf">XML Schema Structure Quick Refence</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/MySQL_QuickRef.pdf">MySQL Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.alberton.info/downloads/postgresql-cheat-sheet.png">PostgreSQL Cheat Sheet</a></li>
</ul>
<h2>Ferramentas</h2>
<ul>
<li><a rel="nofollow" href="http://www.google.com/help/cheatsheet.html">Google Search Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://duvet-dayz.com/firebug-cheatsheet/">Firebug Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/dhffkc6q_97fsjrgmd7.gif">Vimperator Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/latexsheet-0.png">LaTeX Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/vim-cheatsheet.png">Vim Cheat Sheet</a></li>
<li><a rel="nofollow" href="http://www.cheat-sheets.org/saved-copy/vimqrc.html">Vim Quick Refence</a></li>
<li><a rel="nofollow" href="http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/">mod_rewirte Cheat Sheet</a></li>
</ul>
<p>Alguma que eu tenha esquecido? Posta ae nos comentários!</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/336/50-cheat-sheets-e-quick-refs-para-salvar-sua-pele/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Buscas eficientes no Vim com vimgrep</title>
		<link>http://gustavodutra.com/post/296/buscas-eficientes-no-vim-com-vimgrep/</link>
		<comments>http://gustavodutra.com/post/296/buscas-eficientes-no-vim-com-vimgrep/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 20:23:37 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[aumentar produtivade]]></category>
		<category><![CDATA[busca]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[exemplo]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[gvim]]></category>
		<category><![CDATA[produtividade]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[vimgrep]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=296</guid>
		<description><![CDATA[A busca efetiva pode ajudar muito, caso bem usada, tanto no ganho de tempo como na efeciência de substituições ou refactories. Seguem alguns outros exemplos de finalidades para a busca utilizando o Vim:

Certeza de encontrar todas as incidências
Ficam visualmente destacadas (com :set hlsearch)
Testar substituições
Verificar a ortografia atrás de erros de digitação
Encontrar variáveis ou funções não [...]]]></description>
			<content:encoded><![CDATA[<p>A busca efetiva pode ajudar muito, caso bem usada, tanto no ganho de tempo como na efeciência de substituições ou refactories. Seguem alguns outros exemplos de finalidades para a busca utilizando o Vim:</p>
<ul>
<li>Certeza de encontrar todas as incidências</li>
<li>Ficam visualmente destacadas (com :set hlsearch)</li>
<li>Testar substituições</li>
<li>Verificar a ortografia atrás de erros de digitação</li>
<li>Encontrar variáveis ou funções não utilizadas, só declaradas</li>
<li>Encontrar rapidamente algum termo</li>
<li>Verificar a existência de algum termo</li>
</ul>
<p>Além da conhecida / (barra) para buscar, existe o :vimgrep. É dele que quero falar.</p>
<p><span id="more-296"></span></p>
<h2>Vimgrep</h2>
<h3>Comando</h3>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>vim<span style="color: #000000;">&#91;</span>grep<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">!</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">/</span><span style="color: #000000;">&#123;</span>pattern<span style="color: #000000;">&#125;</span><span style="color: #000000;">/</span><span style="color: #000000;">&#91;</span>g<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span>files<span style="color: #000000;">&#125;</span></pre></div></div>

<ul>
<li>Busca inscidências de <em>pattern</em> nos <em>files</em> listados.</li>
<li><em>pattern</em> pode ser uma expressão regular ou não</li>
<li>A exclamação (<em>!</em>) ignora as alterações já feita no arquivo atual</li>
<li><em>g</em> procura por todas as inscidências, não só a primeira, em cada arquivo</li>
<li><em>j</em> pula para o primeiro resultado ao executar o comando</li>
<li><em>files</em> podem conter <em>wildcards</em>, como *, ? e **</li>
<li>Os resultados são abertos na <strong>quickfix list</strong></li>
</ul>
<h3>Exemplos</h3>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>vimgrep<span style="color: #000000;">!</span> <span style="color: #000000;">/$</span>var<span style="color: #000000;">/</span> arquivo<span style="color: #000000;">.</span>pl</pre></div></div>

<p>Pesquisa pela primeira inscidência de $var no arquivo.pl</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>vimgrep <span style="color: #000000;">/</span>texto<span style="color: #000000;">/</span> <span style="color: #000000;">*.</span>rb</pre></div></div>

<p>Busca por <em>texto</em> em todos os arquivos com a extensão .rb do diretório atual (para descobrir qual o diretório atual, use :pwd. Para mudar :cd <em>dir</em>)</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>vimgrep <span style="color: #000000;">/</span>TeXtO<span style="color: #000000;">/</span> <span style="color: #000000;">*.</span>py dir<span style="color: #000000;">/*.</span>py</pre></div></div>

<p>Busca com case-sensitive em todos os arquivos .py do diretório atual e dos dentro do diretório dir/.</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>vimgrep <span style="color: #000000;">/</span>minhaFuncao<span style="color: #000000;">/</span>g <span style="color: #000000;">**/*.</span>c</pre></div></div>

<p>Busca recursiva dentro da árvore de diretórios do diretório atual cuja extensão seja .c</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>vimgrep <span style="color: #000000;">/&lt;</span> \<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">^</span> <span style="color: #000000;">&#93;</span>\<span style="color: #000000;">+</span>\<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">^&gt;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">*&gt;.</span>\<span style="color: #000000;">+&lt;</span> \<span style="color: #000000;">/</span>\<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&gt;/</span> <span style="color: #25BB4D;">index</span><span style="color: #000000;">.</span>html</pre></div></div>

<p>Busca usando expressões regulares também são permitidas!</p>
<h2>Navegando na QuickFix List</h2>
<ul>
<li>:copen</li>
<li>:cfirst</li>
<li>:cprevious</li>
<li>:cnext</li>
<li>:clast</li>
<li>:cclose</li>
</ul>
<p>Como nosso foco é a eficiência, podemos criar mapeamentos para andar pela quickfix list!</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #25BB4D;">map</span> <span style="color: #000000;">&lt;</span>F9<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span>copen<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;</span>
<span style="color: #25BB4D;">map</span> <span style="color: #000000;">&lt;</span>F10<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span>cclose<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;</span>
<span style="color: #25BB4D;">map</span> <span style="color: #000000;">&lt;</span>A<span style="color: #000000;">-</span>j<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span>cnext<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;</span>
<span style="color: #25BB4D;">map</span> <span style="color: #000000;">&lt;</span>A<span style="color: #000000;">-</span>k<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span>cprevious<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;</span></pre></div></div>

<div id="attachment_305" class="wp-caption aligncenter" style="width: 546px"><a href="http://gustavodutra.com/wp-content/uploads/2009/11/vimgrep1.jpg"><img src="http://gustavodutra.com/wp-content/uploads/2009/11/vimgrep1.jpg" alt="Exemplo de uso do vimgrep" title="Exemplo de uso do vimgrep" width="536" height="875" class="size-full wp-image-305" /></a><p class="wp-caption-text">Exemplo de uso do vimgrep</p></div>
<h2>Conclusão</h2>
<p>Esse recurso não parece ser muito abordado por ai, mas é extremamente importante. Seja criativo e descubra onde melhor usar o :vimgrep! Tenho certeza de que vai lhe ajudar! E quando encontrar, comente ai!</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/296/buscas-eficientes-no-vim-com-vimgrep/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Usando Screen e Vim para Pair Programming remoto</title>
		<link>http://gustavodutra.com/post/276/usando-screen-e-vim-para-pair-programming-remoto/</link>
		<comments>http://gustavodutra.com/post/276/usando-screen-e-vim-para-pair-programming-remoto/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 22:09:59 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Engenharia de Software]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[engenharia de software]]></category>
		<category><![CDATA[extreme programming]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[pair programming]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[skype]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=276</guid>
		<description><![CDATA[Bem, é notável o crescimento das metodologias ágeis de desenvolvimento de software. Uma das práticas que me agrada muito, é a programação em pares (pair programming). É bem perceptível, a um longo prazo, a diferença que faz essa prática. Navegando pela internet, como um marujo sem rumo, encontrei um post falando sobre Remote Pair Programming. [...]]]></description>
			<content:encoded><![CDATA[<p>Bem, é notável o crescimento das <strong>metodologias ágeis de desenvolvimento de software</strong>. Uma das práticas que me agrada muito, é a programação em pares (<em>pair programming</em>). É bem perceptível, a um longo prazo, a diferença que faz essa prática. Navegando pela internet, como um marujo sem rumo, encontrei um post falando sobre <em>Remote Pair Programming</em>. Parece meio estranho, porque o XP (<a rel="nofollow" href="http://www.extremeprogramming.org/">eXtreme Programming</a>) faz alusão a uma dupla programar em um único computador, com um único teclado e um único mouse.<br />
<span id="more-276"></span><br />
Então, vamos tentar simular este ambiente utilizando 4 ferramentas simples:</p>
<ul>
<li>screen</li>
<li>ssh</li>
<li>vim</li>
<li>skype</li>
</ul>
<p>Destas, só o <em>skype</em> não é <em>open-source</em>. Mas é interessante manter uma conversa verbal, pois conversas escritas podem desviar o foco da programação, que é bem mais rápida e precisa do que a escrita, que pode deixar brechas para má interpretações. A conversa verbal consegue interromper o programador ao mesmo tempo em que escreve, corrigindo-o ou questionando-o.</p>
<p>Conectados no skype, basta decidir em qual máquina será o desenvolvimento. Esta, por sua vez, terá que ter um servidor <strong>ssh</strong>. Ela será o <em>host</em> da programação. Será necessário, também, nesta máquina, ter instalado o <em>screen</em>, que é um programa que possibilita criar &#8217;sessões&#8217; no terminal.</p>
<h2>Host</h2>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #660033;">-S</span> PairProgramming</pre></div></div>

<p>Parece que nada mudou, mas você está numa sessão do <strong>screen</strong> chamada <em>PairProgramming</em>.</p>
<p>Precione CTRL+a e digite:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:multiuser on</pre></div></div>

<p>Pressione CTRL+a novamente e digite:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:acladd usuarioclient</pre></div></div>

<p>Tudo que você ver nesta sessão, será visto pelo outro usuário (<em>usuarioclient</em>) que se conectará nela.</p>
<p>Então, abra o <strong>vim</strong>, pois será necessário um edito de textos de verdade <img src='http://gustavodutra.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> , e se divirta:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>caminho<span style="color: #000000; font-weight: bold;">/</span>arquivo</pre></div></div>

<h2>Client</h2>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> usuarioclient<span style="color: #000000; font-weight: bold;">@</span>host
<span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #660033;">-x</span> usuariohost<span style="color: #000000; font-weight: bold;">/</span>PairProgramming</pre></div></div>

<p>Pronto! Agora você está acessando a mesma seção! Tudo que o <em>usuáriohost</em> fizer, o <em>usuárioclient</em> enxergará e <strong>vice-versa</strong>.</p>
<p>Agora, basta descutir a tarefa via Skype e programar. As atualizações são em tempo real, ou seja, aparecem ao mesmo tempo que são escritos, digo&#8230; depende da conexão, mas não é um grande problema.</p>
<p>Caso seja necessário que o usuarioclient não possa modificar o código, apenas assitir e dar pitacos, o usuáriohost deve pressionar CTRL+A e digitar:</p>
<pre>:aclchg usuarioclient -w #</pre>
<p>Eu ainda vou programar assim, depois digo a experiência.</p>
<h2>Referências</h2>
<ul>
<li><a rel="nofollow" href="http://www.linux.com/archive/feature/56443">Linux.com</a></li>
<li><a rel="nofollow" href="http://haruska.com/2009/09/29/remote-pair-programming/">Jason Haruska</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/276/usando-screen-e-vim-para-pair-programming-remoto/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Várias Dicas Simples de Legibilidade de Códigos PHP</title>
		<link>http://gustavodutra.com/post/236/varias-dicas-simples-de-legibilidade-de-codigos-php/</link>
		<comments>http://gustavodutra.com/post/236/varias-dicas-simples-de-legibilidade-de-codigos-php/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 01:52:19 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[aumentar produtivade]]></category>
		<category><![CDATA[código limpo]]></category>
		<category><![CDATA[como]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[ligibilidade]]></category>
		<category><![CDATA[manutenção]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[produtividade]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=236</guid>
		<description><![CDATA[Faz um tempo que venho observando códigos que considero estranhos. Apesar de entendê-los, são necessários um esforço e um tempinho disponível. Alguns ainda exigem uns debugs ou até mesmo perguntar ao autor qual foi a intenção daquele trecho.
Baseado nisso e no comentário que recebi recentemente e inspirado pelo post de um amigo, vou fazer uma [...]]]></description>
			<content:encoded><![CDATA[<p>Faz um tempo que venho observando códigos que considero <strong>estranhos</strong>. Apesar de entendê-los, são necessários um esforço e um tempinho disponível. Alguns ainda exigem uns debugs ou até mesmo perguntar ao autor qual foi a intenção daquele trecho.</p>
<p>Baseado nisso e no <a rel="nofollow" href="http://gustavodutra.com/post/222/schemaspy-ferramenta-para-modelagem-literaria/#comment-55">comentário que recebi recentemente</a> e inspirado pelo <a href="http://blog.flyonthe.net/geral/boas-praticas-de-desenvolvimento/">post de um amigo</a>, vou fazer uma lista de coisas que proponho. São coisas simples, mas que facilitam na manutenção.</p>
<p>Umas das coisas que aprendi com <a rel="nofollow" href="http://butunclebob.com/ArticleS">Uncle Bob (Robert C. Martin)</a>, no seu livro <a rel="nofollow" href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1250297519&#038;sr=8-1"><em>Clean Code</em></a> foi: escrevemos o código apenas uma vez, porém o mesmo é lido várias vezes. Então, não custa usarmos 5min a mais documentando alguma coisa ou escrevendo variáveis legíveis, que nos pouparão tempo mais tarde!</p>
<p><span id="more-236"></span></p>
<h2>1. Clareza e objetivadade nos nomes das variáveis</h2>
<p>É incrível como as pessoas conseguem dar nomes criativos para variáveis. O alfabeto tem tantas letras que formam tantas palavras, por que insistem em usar apenas <strong>1 letra como nome de variável</strong>? Pior, <strong>Por que usar sempre as mesmas?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dias</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span></pre></div></div>

<p>A primeira variável simplesmente não diz nada. Olhando ela não se consegue ter noção nenhuma do que ela representa, o que é o 3? Do mesmo modo se aplica a segunda variável, sabemos que são 2 dias, mas 2 dias não nos diz nada também. Olhando assim, só sabemos a unidade de medida!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dia_vencimento</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$qtde_dias_para_pagamento</span>  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span></pre></div></div>

<p>Há quem reclame do tamanho das variáveis. Mas hoje em dia, que editor não auto-completa para você? Se o seu não, por favor, considere trocar =).</p>
<p>O que se deve cuidar ao se nomear uma variável, é não por algum nome que venha a ter mais de uma possibilidade de significado. Por exemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$valor_frete_desconto</span> <span style="color: #339933;">=</span> <span style="color:#800080;">11.3</span><span style="color: #339933;">;</span></pre></div></div>

<p>O valor acima citado, é referente ao desconto dado ao frete, ao valor do frete a ser descontado ou o valor do frete com o desconto? Eu não afirmo nenhuma hipótese à partir do nome dado. Se me perguntarem, eu diria que olharia o código para afirmar. Por tanto, seja <strong>CLARO E OBJETIVO</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$valor_frete</span> <span style="color: #339933;">=</span> <span style="color:#800080;">13.4</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$valor_desconto_frete</span> <span style="color: #339933;">=</span> <span style="color:#800080;">2.3</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$valor_frete_descontado</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$valor_frete</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$valor_desconto_frete</span><span style="color: #339933;">;</span></pre></div></div>

<p>Caso o desconto do frete seja aplicado com porcentagem:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pct_desconto_frete</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$valor_frete</span> <span style="color: #339933;">=</span> <span style="color:#800080;">13.4</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$valor_desconto_frete</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$valor_frete</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pct_desconto_frete</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$valor_frete_descontado</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$valor_frete</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$valor_desconto_frete</span><span style="color: #339933;">;</span></pre></div></div>

<p>A melhor coisa em relação às variáveis é justamente o fato de omitir o valor atrás de um nome inteligível. Por tanto, sempre que possível, esconda os valores, a legibilidade aumenta muito!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$arr_usrs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$arr_usrs</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$arr_usrs</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Pergunto:</p>
<ul>
<li>$arr_usrs é uma lista gerada à partir de que dados?</li>
<li>O que é o índice 3 do array usado no if ?</li>
<li>O que diabos quer dizer == 4?</li>
<li>O que devo esperar que $arr_usrs contenha?</li>
</ul>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;STATUS&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ATIVO&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$contatosAtivos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$contatos_do_usuario</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$contato</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contatos_do_usuario</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$status_do_contato</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contato</span><span style="color: #009900;">&#91;</span>STATUS<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$status_do_contato</span> <span style="color: #339933;">==</span> ATIVO<span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$contatosAtivos</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contato</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$contatosAtivos</span><span style="color: #339933;">;</span></pre></div></div>

<p>Acho que não preciso explicar o código, não é?</p>
<p>Outra coisa interessante, CUIDADO com as variáveis de duplo sentido.</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usuariosDoBanco</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>$total</em> recebeu o total de usuários do Banco de Dados ? o total de usuários de um determinado banco (BB, Santander, etc) ?</p>
<p>Sugestão:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usuarios_cadastrados</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ou, para o outro caso</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clientes_santander</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Eu sei que muitas vezes é difícil escrever códigos de forma bonita, mas o esforço vale a pena! Além de ser um diferencial profissional, trabalhar no meio da zona é prejudicial a você mesmo!</p>
<p>Lembrou de algo? Tens outras dicas? Comenta aê!</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/236/varias-dicas-simples-de-legibilidade-de-codigos-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Criando apresentações Power Point pelo Vim</title>
		<link>http://gustavodutra.com/post/229/criando-apresentacoes-power-point-pelo-vim/</link>
		<comments>http://gustavodutra.com/post/229/criando-apresentacoes-power-point-pelo-vim/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 21:56:13 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[aumentar produtivade]]></category>
		<category><![CDATA[como]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[gvim]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[openoffice]]></category>
		<category><![CDATA[power point]]></category>
		<category><![CDATA[produtividade]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[vimrc]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=229</guid>
		<description><![CDATA[Essa semana eu precisei de uma apresentação Power Point. Abri o Impress, o editor de apresentações do OpenOffice. Comecei meu raciocínio sobre a apresentação. Quando me dei conta, estava colocando negrito e identando um parágrafo. Ao reler o parágrafo, havia 3 erros de gramática. Foi a gota d&#8217;água: Não consigo criar apresentações, pensei.
Quando eu vou [...]]]></description>
			<content:encoded><![CDATA[<p>Essa semana eu precisei de uma apresentação Power Point. Abri o Impress, o editor de apresentações do OpenOffice. Comecei meu raciocínio sobre a apresentação. Quando me dei conta, estava colocando negrito e identando um parágrafo. Ao reler o parágrafo, havia 3 erros de gramática. Foi a gota d&#8217;água: Não consigo criar apresentações, pensei.</p>
<p>Quando eu vou escrever em algum programa de qualquer suíte de escritório &#8211; openoffice, koffice, etc -, eu geralmente me preocupo mais com o negrito da palavra, com identação do parágrafo do que com o conteúdo em si. Isso é um pecado.</p>
<p>Meu primeiro instinto foi: vou escrever tudo no Vim, depois colo no Impress. Boa! Ok, mas e quanto às páginas?<br />
Vou ter que por página por página? Ainda sim eu teria mais trabalho. Eu teria que refazer as listas para que ficassem com as &#8220;bolinhas&#8221; à esquerda. E teria que modificar todos os títulos para negrito?</p>
<p><span id="more-229"></span></p>
<p>Fui pro google e achei um plugin que já conhecia no resultado: <a rel="nofollow" href="http://www.vimoutliner.org/">VimOutliner</a>. Ele dita uma sintaxe muito intuitiva para hierarquisar (existe esse verbo?) o conteúdo. Algo assim:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Título do documento
&nbsp;
Tópico Nível 1
	Tópico Nível 2
	: Parágrafo com alinhamento justify
	; Parágrafo fica do jeito que foi escrito
	- Item de lista
	+ Item de lista numérica</pre></div></div>

<p>O plugin vem com documentação e um shell script que instala automaticamente o plugin. O site tem toda documentação, é bem simples.</p>
<p>Em <a rel="nofollow" href="http://perens.com/FreeSoftware/Outline/">http://perens.com/FreeSoftware/Outline/</a> é possível encontrar vários scripts que convertem o documento para outros formatos. Um deles é o vo2odp.rb, um script em ruby para converter arquivos para o OpenOffice Presentation.</p>
<p>Pra fazê-lo rodar, eu sofri um pouquinho. Tive que instalar o ruby (obviamente) e o rubygems. Depois de instalado:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ gem install builder
$ gem install rubyzip</pre></div></div>

<p>Também alterei o script, segue o patch das modificações:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">29,30c29,30
&lt; require_gem 'builder'
&lt; require_gem 'rubyzip'
---
&gt; require 'builder'
&gt; require 'zip/zip'</pre></div></div>

<p>Copie o trecho acima em um arquivo, por exemplo: /tmp/patch_vo2odp, depois execute</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ patch /caminho/para/vo2odp.rb &lt; /tmp/patch_vo2odp</pre></div></div>

<p>Pronto, agora só escrever sua apresentação. Lembre-se que o plugin tem uma extenção própria, a .otl. Sempre que um arquivo for aberto com esta extenção, o Vim irá carregar o syntax highlight apropriado e algumas outras opções para melhor escrever sua apresentação.</p>
<p>Concluída a apresentação, você pode usar</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ ruby /caminho/para/vo2odp.rb apresentacao.otl apresentacao.odp</pre></div></div>

<p>Abra com o OpenOffice e salve como .ppt. Pronto! Você acabou de fazer sua apresentação no PowerPoint pelo Vim.</p>
<h3>Observações importantes</h3>
<ul>
<li>O script não quebra as páginas dos slides automaticamente. É separado por capítulos de nível 1. Então, não escreva coisas muito longas dentro de um nível. Lembre-se que é uma apresentação e não um documento de texto.</li>
<li>Quando aberto no OpenOffice, use o negrito, sublinhado, coloque imagens, etc. Crie seu layout e não pense nisso durante a criação do conteúdo. Escreva antes e formate depois</li>
</ul>
<p>E isso ai! Gostou? Não? Comente! Dê dicas e sugestões!</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/229/criando-apresentacoes-power-point-pelo-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Como fazer um mini servidor HTTP em Python</title>
		<link>http://gustavodutra.com/post/141/como-fazer-um-mini-servidor-http-em-python/</link>
		<comments>http://gustavodutra.com/post/141/como-fazer-um-mini-servidor-http-em-python/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 00:06:58 +0000</pubDate>
		<dc:creator>Gustavo Dutra</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[como]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tchelinux]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://gustavodutra.com/?p=141</guid>
		<description><![CDATA[Olá! Estava lendo minhas mail lists matinais, mais especificadamente a mail list do TcheLinux (evento que, aliás, irá ocorrer em Gravataí sábado que vem, dia 28/03), quando me deparo com um post de Leonardo Menezes Vaz falando de um mini servidor http em python. Achei muito interessante e resolvi postar aqui.

Ingredientes

Lazanha
Python instalado
3 minutos de lazer


Modo [...]]]></description>
			<content:encoded><![CDATA[<p>Olá! Estava lendo minhas mail lists matinais, mais especificadamente a mail list do TcheLinux (evento que, aliás, irá ocorrer em Gravataí sábado que vem, dia 28/03), quando me deparo com um post de Leonardo Menezes Vaz falando de um mini servidor http em python. Achei muito interessante e resolvi postar aqui.</p>
<p><span id="more-141"></span></p>
<h2>Ingredientes</h2>
<ul>
<li>Lazanha</li>
<li>Python instalado</li>
<li>3 minutos de lazer</li>
</ul>
<ul>
<h2>Modo de preparo</h2>
<p>Pegue os 3 minutos de lazer e utlize para criar um diretório:</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">$ mkdir ~/htmldocs
$ cd ~/htmldocs
$ echo &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Meus posts no blog&lt;/body&gt;&lt;/html&gt;&quot; &gt; index.html
$ python -m SimpleHTTPServer
$ firefox http://localhost:8000</pre></div></div>

<p>Pronto! Agora você pode gerenciar documentações, fazer preview de posts no seu blog, fazer testes de javascript/css sem precisar instalar o apache ou criar um VirtualHost!</p>
<p>Eu achei útil! E você?</ul>
]]></content:encoded>
			<wfw:commentRss>http://gustavodutra.com/post/141/como-fazer-um-mini-servidor-http-em-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
