<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://geeks.ms/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Amigo mío Siempre estas Programando en .NET : Visual Studio, C#</title><link>http://geeks.ms/blogs/lruiz/archive/tags/Visual+Studio/C_2300_/default.aspx</link><description>Etiquetas: Visual Studio, C#</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>El mal uso de var</title><link>http://geeks.ms/blogs/lruiz/archive/2009/11/23/el-mal-uso-de-var.aspx</link><pubDate>Mon, 23 Nov 2009 12:01:22 GMT</pubDate><guid isPermaLink="false">2a2e7ade-7474-448b-9de5-1515d8bb7d1b:161069</guid><dc:creator>Luis Ruiz Pavón</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://geeks.ms/blogs/lruiz/rsscomments.aspx?PostID=161069</wfw:commentRss><comments>http://geeks.ms/blogs/lruiz/archive/2009/11/23/el-mal-uso-de-var.aspx#comments</comments><description>&lt;p&gt;Ultimamente vengo viendo mucho código en el que se hace intensivo el uso de &lt;strong&gt;var&lt;/strong&gt; para declarar todo tipo de variables y me gustaría dar mi opinión sobre este mal uso:&lt;/p&gt;  &lt;p&gt;El uso extensivo de &lt;strong&gt;var&lt;/strong&gt; dificulta la legibilidad y comprensión del código fuente, porque un buen código (por lo menos para mí) es el que con leerlo lo podemos entender, por ejemplo:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;var i = obj &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;En este caso concreto se puede observar claramente que el tipo es &lt;strong&gt;string&lt;/strong&gt; (porque lo vemos), pero y en esta caso:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;var i = obj;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Pues en esa caso lo mejor podemos hacer es situarnos encima de &lt;strong&gt;obj&lt;/strong&gt; y dejar que el &lt;strong&gt;VS&lt;/strong&gt; nos ilumine con su sabiduría, o por ejemplo en este caso no sabemos que devuelve ese método:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;var i = DAL.GetValor();&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;y no vale la excusa de que es cómodo y que hay clases que son muy largas de escribir, para eso está eso tenemos a Resharper y en su defecto al intellisense de VS :)&lt;/p&gt;

&lt;p&gt;Mis 2 céntimos :)&lt;/p&gt;

&lt;p&gt;Salu2&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://geeks.ms/aggbug.aspx?PostID=161069" width="1" height="1"&gt;</description><category domain="http://geeks.ms/blogs/lruiz/archive/tags/NET/default.aspx">NET</category><category domain="http://geeks.ms/blogs/lruiz/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://geeks.ms/blogs/lruiz/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item><item><title>[Tips] Crear nuestras propias directivas de compilación</title><link>http://geeks.ms/blogs/lruiz/archive/2009/11/06/tips-crear-nuestras-porpias-directivas-de-compilaci-243-n.aspx</link><pubDate>Fri, 06 Nov 2009 10:29:00 GMT</pubDate><guid isPermaLink="false">2a2e7ade-7474-448b-9de5-1515d8bb7d1b:160012</guid><dc:creator>Luis Ruiz Pavón</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://geeks.ms/blogs/lruiz/rsscomments.aspx?PostID=160012</wfw:commentRss><comments>http://geeks.ms/blogs/lruiz/archive/2009/11/06/tips-crear-nuestras-porpias-directivas-de-compilaci-243-n.aspx#comments</comments><description>&lt;p&gt;Una entradita r&amp;aacute;pida para ser viernes. El otro d&amp;iacute;a un compa&amp;ntilde;ero me dijo que s&amp;iacute; sab&amp;iacute;a como se pod&amp;iacute;an crear directivas de compilaci&amp;oacute;n para un tipo de configuraci&amp;oacute;n especifica como por ejemplo se hace con la directiva DEBUG:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;
&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span style="color:#cc6633;"&gt;#if&lt;/span&gt; DEBUG&lt;/pre&gt;

&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Debug&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span style="color:#cc6633;"&gt;#endif&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Los pasos son los siguientes:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/dcp_5F00_20D16E6A.png"&gt;&lt;img height="122" width="271" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/dcp_5F00_thumb_5F00_6609C593.png" alt="dcp" border="0" title="dcp" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/dcp2_5F00_08EA8744.png"&gt;&lt;img height="446" width="713" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/dcp2_5F00_thumb_5F00_60F76217.png" alt="dcp2" border="0" title="dcp2" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_08DA6177.png"&gt;&lt;img height="235" width="440" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_thumb_5F00_06512FB9.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Nos vamos a las propiedades del proyecto:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_71EB6A2D.png"&gt;&lt;img height="389" width="290" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_thumb_5F00_1708B49A.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_2015401B.png"&gt;&lt;img height="190" width="668" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_thumb_5F00_5BA5290E.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Una vez creada y configurada y guardada, nos vamos al editor de VS y con la configuraci&amp;oacute;n de Debug habilitada vemos que el texto est&amp;aacute; en gris, eso quiere decir que no estamos en la configuraci&amp;oacute;n adecuada para que se cumpla esa directiva de compilaci&amp;oacute;n:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_1547C2F9.png"&gt;&lt;img height="424" width="454" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_thumb_5F00_5E1E34FF.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Cambiamos la configuraci&amp;oacute;n a MyConfiguration:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_10A19272.png"&gt;&lt;img height="472" width="467" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_thumb_5F00_0E1860B4.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Y probamos:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_6FEAA2FF.png"&gt;&lt;img height="346" width="681" src="http://geeks.ms/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/lruiz/image_5F00_thumb_5F00_60871B23.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Salu2 y buen finde&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://geeks.ms/aggbug.aspx?PostID=160012" width="1" height="1"&gt;</description><category domain="http://geeks.ms/blogs/lruiz/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://geeks.ms/blogs/lruiz/archive/tags/NET/default.aspx">NET</category><category domain="http://geeks.ms/blogs/lruiz/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://geeks.ms/blogs/lruiz/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item></channel></rss>