<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx</link><description>I've recently gotten used to the idea that extreme ideas are an important part of learning . It seems that when trying to understand an idea, it helps to consider the idea in its most extreme form. For example, consider the idea of coding in C# with Short</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#154944</link><pubDate>Mon, 14 Jun 2004 05:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154944</guid><dc:creator>Michael Giagnocavo</dc:creator><description>&amp;quot;One line&amp;quot; is a bad metric. Here's what happens if you do that:&lt;br&gt;&lt;br&gt;Your code looks worse and worse, as you inevitably try to cram more info into the line:&lt;br&gt;&lt;br&gt;public string Hash(string s)&lt;br&gt;{&lt;br&gt;return Convert.ToBase64String(new MD5CryptoServiceProvider().ComputeHash((System.Text.Encoding.UTF8.GetBytes(s))));&lt;br&gt;}&lt;br&gt;&lt;br&gt;And the output is a lot worse too. IIRC, The compiler outputs stack based code instead of using locals. I actually benchmarked this code a while ago, and it was slower this way than doing it using a few locals (and the resulting IL was a bit larger).&lt;br&gt;&lt;br&gt;So you get:&lt;br&gt;1: Harder to read code.&lt;br&gt;2: Harder to debug code (see greggm's WebLog)&lt;br&gt;3: (Maybe) larger code.&lt;br&gt;&lt;br&gt;As well, this doesn't work very well if you need error handling.&lt;br&gt;&lt;br&gt;I just don't see how trying to conserve lines any more than usual is going to help at all. All I see it doing is stopping coders from making things extra clear.&lt;br&gt;&lt;br&gt;Of course, you could just remove the newlines -- would that count?  ;)</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155042</link><pubDate>Mon, 14 Jun 2004 11:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155042</guid><dc:creator>Andy</dc:creator><description>The point isn't to write methods that only contain one line. The point is to think about doing so - what would happen *if* all your methods were one line long? This is the farthest that you can take the concept of &amp;quot;how small should my methods be&amp;quot;, since it obviously doesn't make any sense to have methods with zero lines.&lt;br&gt;&lt;br&gt;If you don't consider this case, then why did you &amp;quot;stop&amp;quot; by making all of your methods 5 lines? Or 10? Or some other arbitrary number?</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155104</link><pubDate>Mon, 14 Jun 2004 13:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155104</guid><dc:creator>Jim Argeropoulos</dc:creator><description>I worked with a self trained C guy once. His idea of good code was the smallest footprint you could have. Well this resulted in code that was very compact, but few besides him could read it. &lt;br&gt;&lt;br&gt;I know that you are not saying this, but it is the danger. &lt;br&gt;&lt;br&gt;On the whole I agree with you. I like short functions. One purpose. Self describing/commenting code. I frequently run metrics analysis on my code, just validate myself. I like to keep my cyclomatic complexity under 6 (switch statements are the gotcha's) and my line count low. But I find that if I stick to one purpose, the line count is usually automatically handled.</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155106</link><pubDate>Mon, 14 Jun 2004 13:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155106</guid><dc:creator>Jim Argeropoulos</dc:creator><description>Do you find that when you learn something new, you use it everywhere? &lt;br&gt;&lt;br&gt;I have. I need to check myself sometimes. There are times when the latest technique I learned, just should be put back on the bookshelf. But on the whole I am a better programmer because I apply those sometimes in appropriate tools. I guess it is my way of learning their limits and uses.</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155206</link><pubDate>Mon, 14 Jun 2004 16:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155206</guid><dc:creator>David Cottrill</dc:creator><description>Be careful -- I can tell you from personal experience with Perl one-liners that you are on the path to perdition... ;)</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155263</link><pubDate>Mon, 14 Jun 2004 17:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155263</guid><dc:creator>Jesse Ezell</dc:creator><description>Just about the only worthwhile one line methods are function overloads, because of C#'s wonderful lack of default parameters :-). &lt;br&gt;&lt;br&gt;It is far more important to understand that methods are about small, logical units of work than it is to break them up into 1 liners. You are focusing on the wrong problems if you are counting the lines of code in your methods.</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155273</link><pubDate>Mon, 14 Jun 2004 17:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155273</guid><dc:creator>Darrell</dc:creator><description>David - no kidding! I used to write recursive perl programs that would scrub my entire web site (university web site), and the only interesting stuff happened on 1 line!  Yikes!&lt;br&gt;&lt;br&gt;But Jaybaz(?) has a good point. It's like the old game show &amp;quot;Name that tune&amp;quot;, where people bid down the number of notes they need to figure out a song. The really good people could win it in 1 note! It teaches you to concentrate to figure out what exactly is the minimum needed to accomplish your goal. Challenging conventional thinking, thinking outside the box, and all that blah blah blah. :)</description></item><item><title>The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155361</link><pubDate>Mon, 14 Jun 2004 22:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155361</guid><dc:creator>Darrell Norton's Blog</dc:creator><description>The most extreme thing that could possibly work</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155401</link><pubDate>Mon, 14 Jun 2004 20:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155401</guid><dc:creator>e</dc:creator><description>rex onliner</description></item><item><title>It Looks Like ML to me....</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155439</link><pubDate>Tue, 15 Jun 2004 00:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155439</guid><dc:creator>Wizzy's World</dc:creator><description /></item><item><title>Properties as objects</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155454</link><pubDate>Tue, 15 Jun 2004 00:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155454</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155707</link><pubDate>Tue, 15 Jun 2004 02:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155707</guid><dc:creator>Darren Oakey</dc:creator><description>I go with the idea of no duplication.... at all..  Which does lead to lots of one line functions - but often, you then realise these functions you use a hell of a lot - you put them in your common libraries, and suddenly the world all gets better again.&lt;br&gt;&lt;br&gt;My rule is simple: you do it once, fine.  Twice, optional.  Three times NO&lt;br&gt;&lt;br&gt;For example - &lt;br&gt;F1:  if ( myString.Instr(subString)!=-1) ...&lt;br&gt;F2:  if ( theString.Instr(stringToFind)!=-1) ...&lt;br&gt;&lt;br&gt;that's not good - time for &lt;br&gt;&lt;br&gt;bool StringContains( string stringToCheck, string stringToFind) &lt;br&gt;{return stringToCheck.InStr( stringToFind)!=-1;}&lt;br&gt;&lt;br&gt;And immediately&lt;br&gt;a) your code looks better&lt;br&gt;if ( StringContains( myString, subString))&lt;br&gt;&lt;br&gt;b) you have something you can use in lots of places, and will work with different implementations of string in the future&lt;br&gt;&lt;br&gt;c) you have something that when you find odd situations (what do we do with null strings?) - (what do we do with empty strings?) - you can solve the problem across the board.&lt;br&gt;&lt;br&gt;Yes - this means that my code is littered with one line functions, but a few points:&lt;br&gt;&lt;br&gt;1) each time I do this, the actual raw _size_ of my code gets smaller&lt;br&gt;2) you would be surprised at how many of these one line functions don't stay one line!&lt;br&gt;3) every time I fix a problem or enhance one of the functions, the code improves _across the board_&lt;br&gt;&lt;br&gt;So - basically, don't set out to design functions this way (I go with the rule one screenful is utter max for a function, including comments) - but also don't permit any code duplication - anywhere - and you automatically evolve quite an elegant structure - I guarantee it :)&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#155751</link><pubDate>Tue, 15 Jun 2004 04:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155751</guid><dc:creator>Sean</dc:creator><description>Here's the most compact, semi-useful code I know of:&lt;br&gt;&lt;br&gt;DVD Decrypt&lt;br&gt;The program takes a five-byte title key on the command line (five decimal numbers in least to most-significant order, separated by colons) and an MPEG 2 Program Stream VOB file on stdin, and outputs a decrypted version of the VOB file. For example: to play a movie whose title key is 0xcd302010fe, do: cat file.vob | perl -I 254:16:32:48:205 qrpff | extract_mpeg2 | mpeg2dec - &lt;br&gt;&lt;br&gt;#!/usr/bin/perl # 472-byte qrpff, Keith Winstein and Marc Horowitz &amp;lt;sipb-iap-dvd@mit.edu&amp;gt;&lt;br&gt;# MPEG 2 PS VOB file -&amp;gt; descrambled output on stdout.&lt;br&gt;# usage: perl -I &amp;lt;k1&amp;gt;:&amp;lt;k2&amp;gt;:&amp;lt;k3&amp;gt;:&amp;lt;k4&amp;gt;:&amp;lt;k5&amp;gt; qrpff&lt;br&gt;# where k1..k5 are the title key bytes in least to most-significant order&lt;br&gt;&lt;br&gt;&lt;br&gt;s''$/=\2048;while(&amp;lt;&amp;gt;){G=29;R=142;if((@a=unqT=&amp;quot;C*&amp;quot;,_)[20]&amp;amp;48){D=89;_=unqb24,qT,@&lt;br&gt;b=map{ord qB8,unqb8,qT,_^$a[--D]}@INC;s/...$/1$&amp;amp;/;Q=unqV,qb25,_;H=73;O=$b[4]&amp;lt;&amp;lt;9&lt;br&gt;|256|$b[3];Q=Q&amp;gt;&amp;gt;8^(P=(E=255)&amp;amp;(Q&amp;gt;&amp;gt;12^Q&amp;gt;&amp;gt;4^Q/8^Q))&amp;lt;&amp;lt;17,O=O&amp;gt;&amp;gt;8^(E&amp;amp;(F=(S=O&amp;gt;&amp;gt;14&amp;amp;7^O)&lt;br&gt;^S*8^S&amp;lt;&amp;lt;6))&amp;lt;&amp;lt;9,_=(map{U=_%16orE^=R^=110&amp;amp;(S=(unqT,&amp;quot;\xb\ntd\xbz\x14d&amp;quot;)[_/16%8]);E&lt;br&gt;^=(72,@z=(64,72,G^=12*(U-2?0:S&amp;amp;17)),H^=_%64?12:0,@z)[_%8]}(16..271))[_]^((D&amp;gt;&amp;gt;=8&lt;br&gt;)+=P+(~F&amp;amp;E))for@a[128..$#a]}print+qT,@a}';s/[D-HO-U_]/\$$&amp;amp;/g;s/q/pack+/g;eval&lt;br&gt;</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#156104</link><pubDate>Tue, 15 Jun 2004 15:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156104</guid><dc:creator>jaybaz [MS]</dc:creator><description>My favorite was the 3 lines of perl that implemented encryption strong enough to be classified as a munition, and therefore illegal to export.  &lt;br&gt;&lt;br&gt;I have trouble grokking the notion of &amp;quot;export of software&amp;quot;.  Somehow it seems meaningless.</description></item><item><title>re: Interface implementation </title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#160058</link><pubDate>Sat, 19 Jun 2004 18:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:160058</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>No castes!</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#161554</link><pubDate>Mon, 21 Jun 2004 20:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:161554</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>Jay Bazuzi</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#163948</link><pubDate>Wed, 23 Jun 2004 21:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:163948</guid><dc:creator>public MattBerther : ISerializable</dc:creator><description>One of my favorite bloggers as of late is Jay Bazuzi (rss), who works on the Visual C# IDE team at Microsoft. Give him a read; he's got some posts that are sure to melt your brain, such as &amp;quot;no...</description></item><item><title>Looking for small programming problems</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#168186</link><pubDate>Tue, 29 Jun 2004 02:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:168186</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#168201</link><pubDate>Mon, 28 Jun 2004 23:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:168201</guid><dc:creator>Chad Myers</dc:creator><description>Uh oh, jaybaz, Sean just made this weblog illegal! The MPAA will be coming to confiscate your computer soon. Run!</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#168233</link><pubDate>Tue, 29 Jun 2004 01:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:168233</guid><dc:creator>Sean</dc:creator><description>*hangs my head* sorry man! ;)</description></item><item><title>re: The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#168305</link><pubDate>Tue, 29 Jun 2004 03:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:168305</guid><dc:creator>Aleksei Guzev</dc:creator><description>Hi,&lt;br&gt;You will get effect of huge function on another level.  We use functions and classes to bring stucture to our code. When every function is one-line long they become similar to each other because they are of the same length. This will make Your code homogenous like assembler but with much longer statements.&lt;br&gt;&lt;br&gt;Aleksei Guzev</description></item><item><title>Test Methods are neither Methods nor Tests</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/13/154918.aspx#171402</link><pubDate>Fri, 02 Jul 2004 03:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:171402</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item></channel></rss>