<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>Jon Skeet: Coding Blog : Java</title><link>http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx</link><description>Tags: Java</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Noda Time is born</title><link>http://msmvps.com/blogs/jon_skeet/archive/2009/11/06/noda-time-is-born.aspx</link><pubDate>Fri, 06 Nov 2009 18:02:31 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1738052</guid><dc:creator>skeet</dc:creator><slash:comments>50</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1738052</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1738052</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2009/11/06/noda-time-is-born.aspx#comments</comments><description>&lt;p&gt;There was an amazing response to &lt;a href="http://msmvps.com/blogs/jon_skeet/archive/2009/11/05/what-s-in-a-name-again.aspx"&gt;yesterday&amp;#39;s post&lt;/a&gt; – not only did readers come up with plenty of names, but lots of people volunteered to help. As a result, I&amp;#39;m feeling under a certain amount of pressure for this project to actually take shape.&lt;/p&gt;  &lt;p&gt;The final name chosen is Noda Time. We now have a &lt;a href="http://code.google.com/p/noda-time/"&gt;Google Code Project&lt;/a&gt; and a &lt;a href="http://groups.google.com/group/noda-time"&gt;Google Group&lt;/a&gt; (/mailing list). Now we just need some code…&lt;/p&gt;  &lt;p&gt;I figured it would be worth explaining a bit more about my vision for the project. Obviously I&amp;#39;m only one contributor, and I&amp;#39;m expecting everyone to add there own views, but this can act as a starting point.&lt;/p&gt;  &lt;p&gt;I want this project to be more than just a way of getting better date and time handling on .NET. I want it to be a shining example of how to build, maintain and deploy an open source .NET library. As some of you know, I have a few other open source projects on the go, and they have different levels of polish. Some have downloadable binaries, some don&amp;#39;t. They all have just-about-enough-to-get-started documentation, but not nearly enough, really. They have widely varying levels of test coverage. Some are easier to build than others, depending on what platform you&amp;#39;re using.&lt;/p&gt;  &lt;p&gt;In some ways, I&amp;#39;m expecting the code to be the easy part of Noda Time. After all, the implementation is there already – we&amp;#39;ll have plenty of interesting design decisions to make in order to marry the concepts of Joda Time with the conventions of .NET, but that shouldn&amp;#39;t be too hard. Here are the trickier things, which need discussion, investigation and so forth:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;What platforms do we support? Here&amp;#39;s my personal suggested list:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;.NET 4.0&lt;/li&gt;      &lt;li&gt;.NET 3.5&lt;/li&gt;      &lt;li&gt;.NET 2.0SP1 (require the service pack for DateTimeOffset)&lt;/li&gt;      &lt;li&gt;Mono (versions TBD)&lt;/li&gt;      &lt;li&gt;Silverlight 2, 3 and 4&lt;/li&gt;      &lt;li&gt;Compact Framework 2.0 and 3.5 &lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;What do we ship, and how do we handle different platforms? For example, can we somehow use &lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;Code Contracts&lt;/a&gt; to give developers a better experience on .NET 4.0 without making it really hard to build for other versions of .NET? Can we take advantage of the availability of TimeZoneInfo in .NET 3.5 and still build fairly easily for earlier versions? Do developers want debug or release binaries? Can we build against the client profile of .NET 3.5/4.0?&lt;/li&gt;    &lt;li&gt;What should we use to build? I&amp;#39;ve previously used &lt;a href="http://nant.sourceforge.net/"&gt;NAnt&lt;/a&gt; for the overall build process and MSBuild for the code building part. While this has worked quite well, I&amp;#39;m nervous of the dependency on &lt;a href="http://nantcontrib.sourceforge.net/"&gt;NAnt-Contrib&lt;/a&gt; library for the &amp;lt;msbuild&amp;gt; task, and generally being dependent on a build project whose last release was a beta nearly two years ago. Are there better alternatives?&lt;/li&gt;    &lt;li&gt;How should documentation be created and distributed?&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Is &lt;a href="http://www.sandcastledocs.com/"&gt;Sandcastle&lt;/a&gt; the best way of building docs? How easy is it to get it running so that any developer can build the docs at any time? (I&amp;#39;ve previously tried a couple of times, and failed miserable.)&lt;/li&gt;      &lt;li&gt;Would &lt;a href="http://www.mono-project.com/Monodoc"&gt;Monodoc&lt;/a&gt; be a better approach? &lt;/li&gt;      &lt;li&gt;How should non-API documentation be handled? Is the wiki which comes with the Google Code project good enough? Do we need to somehow suck the wiki into an offline format for distribution with the binaries?&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;What do we need to do in order to work in low-trust environments, and how easily can we test that?&lt;/li&gt;    &lt;li&gt;What do we do about signing? Ship with a &amp;quot;public&amp;quot; snk file which anyone can build with, but have a private version which the team uses to validate a &amp;quot;known good&amp;quot; release? Or just have the private key and use deferred signing?&lt;/li&gt;    &lt;li&gt;While the library itself will support i18n for things like date/time formatting, do we need to apply it to &amp;quot;developer only&amp;quot; messages such as exceptions?&lt;/li&gt;    &lt;li&gt;I&amp;#39;m used to testing with NUnit and Rhino.Mocks, but they&amp;#39;re not the last word in testing on .NET – what should we use, and why? What about coverage?&lt;/li&gt;    &lt;li&gt;Do we need any dependencies (e.g. logging)? If so, how do we handle versioning of those dependencies? How are we affected by various licences?&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;These are all interesting topics, but they&amp;#39;re not really specific to Noda Time. Information about them is available all over the place, but that&amp;#39;s just the problem – it&amp;#39;s all over the place. I would like there to be some sort of documentation saying, &amp;quot;These are the decisions you need to think about, here are the options we chose for Noda Time, and this is why we did so.&amp;quot; I don&amp;#39;t know what form that documentation will take yet, but I&amp;#39;m considering an ebook.&lt;/p&gt;  &lt;p&gt;As you can tell, I&amp;#39;m aiming pretty high with this project – especially as I won&amp;#39;t even be using Google&amp;#39;s 20% time on it. However, there&amp;#39;s little urgency in it for me personally. I want to work out how to do things &lt;em&gt;right&lt;/em&gt; rather than how to do them &lt;em&gt;quickly&lt;/em&gt;. If it takes me a bit of time to document various decisions, and the code itself ships later, so be it… it&amp;#39;ll make the next project that much speedier.&lt;/p&gt;  &lt;p&gt;I&amp;#39;m expecting a &lt;em&gt;lot&lt;/em&gt; of discussion in the group, and no doubt some significant disagreements. I&amp;#39;m expecting to have to ask a bunch of questions on Stack Overflow, revealing just how ignorant I am on a lot of the topics above (and more). I think it&amp;#39;ll be worth it though. I think it&amp;#39;s worth setting a goal:&lt;/p&gt;  &lt;p&gt;In one year, I want this to be a first-class project which is the natural choice for any developers wanting to do anything more than the simplest of date/time handling on .NET. In one year, I want to have a guide to developing open source class libraries on .NET which tells you everything you need to know other than how to write the code itself.&lt;/p&gt;  &lt;p&gt;A year may seem like a long time, but I&amp;#39;m sure everyone who has expressed an interest in the project has significant other commitments – I know I do. Getting there in a year is going to be a stretch – but I&amp;#39;m expecting it to be a very enlightening journey.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1738052" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Noda+Time/default.aspx">Noda Time</category></item><item><title>What's in a name (again)?</title><link>http://msmvps.com/blogs/jon_skeet/archive/2009/11/05/what-s-in-a-name-again.aspx</link><pubDate>Thu, 05 Nov 2009 20:01:05 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1737867</guid><dc:creator>skeet</dc:creator><slash:comments>54</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1737867</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1737867</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2009/11/05/what-s-in-a-name-again.aspx#comments</comments><description>&lt;p&gt;I have possibly foolishly decided to stop resisting the urge to port &lt;a href="http://joda-time.sf.net"&gt;Joda Time&lt;/a&gt; to .NET. For those of you who are unaware, &amp;quot;use Joda Time&amp;quot; is almost always the best answer to any question involving &amp;quot;how do I achieve X with java.util.Date/Calendar?&amp;quot; It&amp;#39;s a Java library for handling dates and times, and it rocks. There is a plan to include a somewhat redesigned version in some future edition of Java (&lt;a href="https://jsr-310.dev.java.net/"&gt;JSR-310&lt;/a&gt;) but it&amp;#39;s uncertain whether this will ever happen.&lt;/p&gt;  &lt;p&gt;Now, .NET only gained the ability to work with time zones other than UTC and the local time zone (using only managed code) – it has a bit of catching up to do. It&amp;#39;s generally easier to work with the .NET BCL than the Java built-in libraries, but it&amp;#39;s still not a brilliant position to be in. I think .NET deserves good date/time support, and as no-one else appears to be porting Joda Time, I&amp;#39;m going to do it. (A few people have already volunteered to help. I don&amp;#39;t know how easily we&amp;#39;ll be able to divvy up the work, but we&amp;#39;ll see. I suspect the core may need to be done first, and then people can jump in to implement different chronologies etc. As a side-effect, I may try to use this project as a sort of case in terms of porting, managing an open source project, and properly implementing a .NET library with useful versioning etc.)&lt;/p&gt;  &lt;p&gt;The first two problems, however, are to do with naming. First, the project name. Contenders include:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Joda Time.NET (sounds like it would be an absolutely direct port; while I intend to port all the tricky bits directly, it&amp;#39;s going to be an idiomatic port with appropriate .NET bits. It&amp;#39;s also a bit of a mouthful.) &lt;/li&gt;    &lt;li&gt;Noda Time (as suggested in the comments and in email)&lt;/li&gt;    &lt;li&gt;TonyTime (after &lt;a href="http://msmvps.com/blogs/jon_skeet/archive/2009/11/02/omg-ponies-aka-humanity-epic-fail.aspx"&gt;Tony the Pony&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;CoffeeTime &lt;/li&gt;    &lt;li&gt;TeaTime &lt;/li&gt;    &lt;li&gt;A progression of BreakfastTime, CoffeeTime, LunchTime, TeaTime, DinnerTime and SupperTime for different versions (not a serious contender) &lt;/li&gt;    &lt;li&gt;ParsleySageRosemaryAndThyme (not a serious contender) &lt;/li&gt;    &lt;li&gt;A few other silly ones too &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I suspect I&amp;#39;m going to go for CoffeeTime, but we&amp;#39;ll see.&lt;/p&gt;  &lt;p&gt;The second problem is going to prove more awkward. I want to mostly copy the names given in Joda Time – aside from anything else, it&amp;#39;ll make it familiar to anyone who uses Joda Time in Java (such as me). Now one of the most commonly used classes in Joda is &amp;quot;&lt;a href="http://joda-time.sourceforge.net/api-release/org/joda/time/DateTime.html"&gt;DateTime&lt;/a&gt;&amp;quot;. Using that name in my port would be a Bad Idea. Shadowing a name in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.aspx"&gt;System&lt;/a&gt; namespace is likely to lead to very disgruntled users who may prove hard to regruntle before they abandon the library.&lt;/p&gt;  &lt;p&gt;So what do I do? Go for the subtly different DateAndTime? Tie it to the library with CoffeeDateTime? Change it to Instant? (It&amp;#39;ll derive from AbstractInstant anyway – assuming I keep the same hierarchy instead of moving to a composition model and value types.)&lt;/p&gt;  &lt;p&gt;Obviously this is a decision which the &amp;quot;team&amp;quot; can make, when we&amp;#39;ve got one… but it feels like a decision which is lurking round the corner in a hostile way.&lt;/p&gt;  &lt;p&gt;What I find interesting is that these are two very different naming problems: one is trying to name something in a relatively arbitrary way – I know I want something reasonably short and memorable for the overall name, but beyond that it doesn&amp;#39;t matter too much. The other is trying to nail a very specific name which really &lt;em&gt;has&lt;/em&gt; to convey its meaning clearly… but where the obvious name is already taken. Also interestingly, neither is a particularly good example of my most common issue with naming: attempting to come up with a two or three word noun for something that actually needs a whole sentence to describe it adequately.&lt;/p&gt;  &lt;p&gt;Oh well – we&amp;#39;ll see what happens. In another blog post I&amp;#39;ll suggest some of the goals I have in terms of what I&amp;#39;m hoping to learn from the project, and how I&amp;#39;d like it to progress. In other words, expect a work of complete fiction…&lt;/p&gt;  &lt;p&gt;If you&amp;#39;re interested in helping out with the project, please &lt;a href="mailto:skeet@pobox.com"&gt;mail me directly&lt;/a&gt; (rather than adding comments here) and as soon as I&amp;#39;ve set the project up, I&amp;#39;ll invite you to the mailing list.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;UPDATE: &lt;/strong&gt;I&amp;#39;ve already got a few interested names, which is great. Rather than be dictatorial about this, I&amp;#39;ll put it to a vote of the people who are willing to help out on it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1737867" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category></item><item><title>A different approach to inappropriate defaults</title><link>http://msmvps.com/blogs/jon_skeet/archive/2009/05/14/a-different-approach-to-inappropriate-defaults.aspx</link><pubDate>Thu, 14 May 2009 17:03:52 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692419</guid><dc:creator>skeet</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1692419</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1692419</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2009/05/14/a-different-approach-to-inappropriate-defaults.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;ve had a couple of bug reports about &lt;a href="http://code.google.com/p/protobuf-csharp-port/"&gt;my Protocol Buffers port&lt;/a&gt; - both nicely detailed, and one including a patch to fix it. (It&amp;#39;s only due to my lack of timeliness in actually submitting the change that the second bug report occurred. Oops.)&lt;/p&gt;  &lt;p&gt;The bug was in text formatting (although it also affected parsing). I was using the default &lt;code&gt;ToString&lt;/code&gt; behaviour for numbers, which meant that floats and doubles were being formatted as &amp;quot;50,15&amp;quot; in Germany instead of &amp;quot;50.15&amp;quot;. The unit tests caught this, but only if you ran them on a machine with an appropriate default culture.&lt;/p&gt;  &lt;p&gt;Aaargh. I&amp;#39;ve been struggling with a similar problem in a library I &lt;em&gt;can&amp;#39;t&lt;/em&gt; change, which uses the system default time zone for various calculations in Java. When you&amp;#39;re running server code, the default time zone is almost never the one you want to use, and it certainly isn&amp;#39;t in my case.&lt;/p&gt;  &lt;p&gt;A similar problem is Java&amp;#39;s decision to use the system default encoding in all kinds of bizarre places - &lt;code&gt;FileReader&lt;/code&gt; doesn&amp;#39;t even let you specify the encoding, which makes it almost entirely useless in my view.&lt;/p&gt;  &lt;p&gt;So I&amp;#39;ve been wondering how we could fix this and problems like it. One option is to completely remove the defaults. If you always &lt;em&gt;had&lt;/em&gt; to pass in a &lt;code&gt;CultureInfo&lt;/code&gt;/&lt;code&gt;Locale&lt;/code&gt;, &lt;code&gt;TimeZoneInfo&lt;/code&gt;/&lt;code&gt;TimeZone&lt;/code&gt;, &lt;code&gt;Encoding&lt;/code&gt;/&lt;code&gt;Charset&lt;/code&gt; when you call any method which might be culturally sensitive.&lt;/p&gt;  &lt;h3&gt;Making life easier (in .NET)&lt;/h3&gt;  &lt;p&gt;It strikes me that .NET has a useful abstraction here: the assembly as the unit of deployment. (Java&amp;#39;s closest equivalent is probably a jar file, which probably gets messier.)&lt;/p&gt;  &lt;p&gt;Within one assembly, I suspect in many cases you always want to make the same decision. For example, in protocol buffers I would like to use the invariant culture all the time. It would be nice if I could say that, and then get the right behaviour by default. Here are the options I&amp;#39;d like to be able to apply (for each of culture, time zone and character encoding - there may be others):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use a culture-neutral default (the invariant culture, UTF-8, UTC)&lt;/li&gt;    &lt;li&gt;Use a specific set of values (e.g. en-GB, Windows-1252, &amp;quot;Europe/London&amp;quot;)&lt;/li&gt;    &lt;li&gt;Use the system default values&lt;/li&gt;    &lt;li&gt;Use whatever the calling assembly is using&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Of course you should still have the option of specifying overrides on a per call basis, but I think this &lt;em&gt;might&lt;/em&gt; be a way forward.&lt;/p&gt;  &lt;p&gt;Thoughts? I realise it&amp;#39;s almost certainly too late for this to actually be implemented now, but would it have been a good idea? Or is it just an alternative source of confusion?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1692419" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Wacky+Ideas/default.aspx">Wacky Ideas</category></item><item><title>Language proliferation</title><link>http://msmvps.com/blogs/jon_skeet/archive/2009/05/12/language-proliferation.aspx</link><pubDate>Tue, 12 May 2009 16:54:47 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692248</guid><dc:creator>skeet</dc:creator><slash:comments>18</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1692248</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1692248</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2009/05/12/language-proliferation.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;ve always been aware that .NET supports multiple languages (obviously) and that Microsoft has been experimenting with this to some extent. It&amp;#39;s only recently struck me just to what extent this is the case though.&lt;/p&gt;  &lt;p&gt;Here&amp;#39;s a list - almost certainly incomplete - of .NET languages &lt;em&gt;from Microsoft alone&lt;/em&gt;.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vcsharp/default.aspx"&gt;C#&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/default.aspx"&gt;VB&lt;/a&gt; (or VB.NET if you wish) &lt;/li&gt;    &lt;li&gt;C++/CLI &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/fsharp"&gt;F#&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://codeplex.com/ironpython"&gt;IronPython&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/ironruby"&gt;IronRuby&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://research.microsoft.com/en-us/projects/specsharp/"&gt;Spec#&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-gb/library/dd129519.aspx"&gt;M&lt;/a&gt; (with &lt;a href="http://msdn.microsoft.com/en-us/oslo/default.aspx"&gt;Oslo&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd795202.aspx"&gt;Axum&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/jscript/archive/2007/05/04/managed-jscript-announced.aspx"&gt;Managed JScript&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx"&gt;PowerShell&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://research.microsoft.com/en-us/um/cambridge/projects/comega/"&gt;Cω&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;J# (not shipping any more, I believe)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Some of these are research languages which are more important for the ideas they&amp;#39;ve contributed to more mainstream ones at a later date than for anything else – but there&amp;#39;s still a lot of effort represented in the list.&lt;/p&gt;  &lt;p&gt;In addition, there are third party languages targeting .NET, such as &lt;a href="http://boo.codehaus.org"&gt;Boo&lt;/a&gt;, &lt;a href="http://www.codeplex.com/IronScheme"&gt;IronScheme&lt;/a&gt; and &lt;a href="http://www.scala-lang.org/node/168"&gt;Scala&lt;/a&gt;. (Wikipedia &lt;a href="http://en.wikipedia.org/wiki/List_of_.NET_languages"&gt;lists loads of them&lt;/a&gt;.)&lt;/p&gt;  &lt;p&gt;Now, think back to the time before .NET. Was Microsoft actively experimenting with languages back then? Plenty of people were trying things against the JVM, but Sun was pretty much absent from that party. .NET seems to be a &amp;quot;missing ingredient&amp;quot; that has allowed smart folk at Microsoft to let their imaginations loose in ways which they couldn&amp;#39;t previously. (Of course, not everyone in the language business at MS started there: Jim Hugunin was hired by Microsoft precisely &lt;em&gt;because&lt;/em&gt; of his work on IronPython.)&lt;/p&gt;  &lt;p&gt;I wonder how long this will continue.&lt;/p&gt;  &lt;h3&gt;Tower of Babel, or land of polyglots?&lt;/h3&gt;  &lt;p&gt;What does this mean for the average developer? Currently, if you&amp;#39;re writing a non-web application in .NET, you really only need to know a single language – and any of them will do. (Plus potentially SQL of course…) Compare this with web developers who have to be intimately familiar with HTML, CSS and JavaScript – and the differences between various implementations.&lt;/p&gt;  &lt;p&gt;How long will it be before backend developers are expected to know a dynamic language, a static OO language and a functional language? Does the benefit of mixing several languages in a project worth the impedance mismatch and the increased skillset requirements? I&amp;#39;m not going to make any predictions on that front – I can certainly see the benefits of each of these approaches in certain situations. They&amp;#39;ve been designed to play well together, but there are bound to be limitations and oddities: times when you need to change how you write your F# so that it&amp;#39;s easily callable from C#, for example.&lt;/p&gt;  &lt;p&gt;Whether or not you learn multiple languages to a professional level is one thing, but becoming &lt;em&gt;familiar&lt;/em&gt; with them is a different matter. In the course of co-authoring &lt;a href="http://manning.com/petricek/"&gt;Functional Programming for the Real World&lt;/a&gt; (where &amp;quot;co-author&amp;quot; is a bit of a stretch title - I&amp;#39;ve played more of an editorial role really, with the added bonus of picking on Tomas whenever I felt he was perhaps a little harsh towards C#) I&amp;#39;ve learned to appreciate many of F#&amp;#39;s qualities, but I don&amp;#39;t really &lt;em&gt;know&lt;/em&gt; the language. If someone asked me to write a complete application in it (rather than just a toy experiment) I&amp;#39;d be reaching for books every other minute. I hope I&amp;#39;ll learn more over the course of time, but I doubt that I&amp;#39;ll ever be sufficiently experienced in it to put it on my CV. The same goes for IronPython, although I&amp;#39;m considerably more likely to need Python at work than I am F#. (Python is one of the three &amp;quot;approved&amp;quot; languages at Google, along with Java and C++.) None of this means that time spent in these languages is wasted: I&amp;#39;ll be able to apply a lot of what I&amp;#39;ve learned about F# to my C# coding, even if it will make me pine for things like pattern matching and asynchronous workflows periodically.&lt;/p&gt;  &lt;p&gt;I think it&amp;#39;s pretty much a given that these days we all need to bring a wide range of technologies to bear in most jobs. While it used to be just about feasible in the .NET 1.1 days to have a pretty good grasp of all the major aspects (ASP.NET for sites and web services, ADO.NET, WinForms, Windows services, class libraries, interop) it&amp;#39;s just impossible these days. We learn something new when we need to - but usually against the background of a familiar language. How well would we cope if we had to learn whole new languages (to the level of being able to use them for production code) as often as we have to learn new libraries?&lt;/p&gt;  &lt;p&gt;This worries me a little. I&amp;#39;m pleased to see that C# 4 is a much smaller change than the previous versions were. Admittedly I&amp;#39;d rather have had immutability support than dynamic, but that&amp;#39;s just me... and that&amp;#39;s the problem, too. While I worry about our ability to actually learn everything that&amp;#39;s becoming available, it&amp;#39;s all good stuff. Can there be &amp;quot;too much of a good thing&amp;quot;?&lt;/p&gt;  &lt;p&gt;What I really &lt;em&gt;don&amp;#39;t &lt;/em&gt;want to see is developers having to know multiple languages, and everyone knowing them poorly. I&amp;#39;m a big believer in having a thorough understanding of your language, so that even if everything else is new, you can rely on your understanding of that aspect of your code. It would be a shame if the pressure of knowing many languages turned many of us into &lt;a href="http://blogs.msdn.com/ericlippert/archive/2004/03/01/82168.aspx"&gt;cargo cult programmers&lt;/a&gt;. The utopia would be for us all to turn into &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=332"&gt;language renaissance&lt;/a&gt; developers. I suspect the reality will be somewhere between the two.&lt;/p&gt;  &lt;p&gt;Still, as long as I get to keep helping authors write about languages I know almost nothing about, I&amp;#39;m sure I&amp;#39;ll be happy...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1692248" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>What's in a name?</title><link>http://msmvps.com/blogs/jon_skeet/archive/2009/02/27/what-s-in-a-name.aspx</link><pubDate>Fri, 27 Feb 2009 11:29:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1674533</guid><dc:creator>skeet</dc:creator><slash:comments>23</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1674533</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1674533</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2009/02/27/what-s-in-a-name.aspx#comments</comments><description>&lt;p&gt;T.S. Eliot had the right idea when he wrote &lt;a href="http://www.americanpoems.com/poets/tseliot/5536"&gt;&amp;quot;The naming of cats&amp;quot;&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Naming of Cats is a difficult matter,&lt;br /&gt;It isn&amp;#39;t just one of your holiday games&lt;br /&gt;...&lt;br /&gt;When you notice a cat in profound meditation,&lt;br /&gt;The reason, I tell you, is always the same:&lt;br /&gt;His mind is engaged in a rapt contemplation&lt;br /&gt;Of the thought, of the thought, of the thought of his name:&lt;br /&gt;His ineffable effable&lt;br /&gt;Effanineffable&lt;br /&gt;Deep and inscrutable singular Name.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Okay, so developers may not contemplate their &lt;em&gt;own&lt;/em&gt; names much, but I know I&amp;#39;ve certainly spent a significant amount of time recently trying to work out the &lt;em&gt;right&lt;/em&gt; name for various types and methods.&amp;nbsp; It always feels like it&amp;#39;s just out of reach; tauntingly, tantalisingly close.&lt;/p&gt;
&lt;p&gt;Recently I&amp;#39;ve been thinking a bit about what the goals might be in coming up with a good name. In particular, I seem to have been plagued with the naming problem more than usual in the last few weeks.&lt;/p&gt;
&lt;h3&gt;Operations on immutable types&lt;/h3&gt;
&lt;p&gt;A while ago I asked &lt;a href="http://stackoverflow.com/questions/521893/"&gt;a question on Stack Overflow&lt;/a&gt; about naming a method which &amp;quot;adds&amp;quot; an item to an immutable collection. Of course, when I say &amp;quot;adds&amp;quot; I mean &amp;quot;returns a new collection whose contents is the old collection and the new item.&amp;quot; There&amp;#39;s a really wide range of answers (currently 38 of them) which mostly seem to fall into four categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use Add because it&amp;#39;s idiomatic for .NET collections. Developers should know that the type is immutable and act accordingly.  &lt;/li&gt;
&lt;li&gt;Use Cons because that&amp;#39;s the term functional programming has used for this exact operation for decades.  &lt;/li&gt;
&lt;li&gt;Use a new method name (Plus being my favourite at the moment) which will be obvious to non-functional developers, but without being so familiar that it suggests mutability.  &lt;/li&gt;
&lt;li&gt;Use a constructor taking the old collection and the new item.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Part of the reasoning for Add being okay is that I originally posted the question purely about &amp;quot;an immutable collection&amp;quot; - e.g. a type which would have a name like ImmutableList&amp;lt;T&amp;gt;. I then revealed my &lt;em&gt;true&lt;/em&gt; intention (which I should have done from the start) - to use this in &lt;a href="http://code.google.com/p/minibench/"&gt;MiniBench&lt;/a&gt;, where the &amp;quot;collection&amp;quot; would actually be a TestSuite. Everything in MiniBench is immutable (it&amp;#39;s partly an exploration in functional programming, as it seems to fit very nicely) but I don&amp;#39;t want to have to name every single type as Immutable[Whatever]. There&amp;#39;s the argument that a developer should know at least a &lt;em&gt;little&lt;/em&gt; bit about any API they&amp;#39;re using, and the immutability aspect is one of the first things they should know. However, MiniBench is arguably an extreme case, because it&amp;#39;s &lt;em&gt;designed&lt;/em&gt; for sharing test code with people who&amp;#39;ve never seen it before.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m pretty sure I&amp;#39;m going to go with Plus in the end:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It&amp;#39;s close enough to Add to be familiar  &lt;/li&gt;
&lt;li&gt;It&amp;#39;s different enough to Add to suggest that it&amp;#39;s not &lt;em&gt;quite&lt;/em&gt; the same thing as adding to a normal collection  &lt;/li&gt;
&lt;li&gt;It sounds like it returns something - a statement which &lt;em&gt;just&lt;/em&gt; calls Plus without using the result sounds like it&amp;#39;s wrong (and indeed it would be)  &lt;/li&gt;
&lt;li&gt;It&amp;#39;s meaningful to everyone  &lt;/li&gt;
&lt;li&gt;I have a precedent in the &lt;a href="http://joda-time.sourceforge.net/"&gt;Joda Time&lt;/a&gt; API&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another option is to overload the + operator, but I&amp;#39;m not really sure I&amp;#39;m ready to do that &lt;em&gt;just&lt;/em&gt; yet. It would certainly leave brief code, but is that really the most important thing?&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s look at a situation with some of the same issues...&lt;/p&gt;
&lt;h3&gt;LINQ operators&lt;/h3&gt;
&lt;p&gt;Work on &lt;a href="http://code.google.com/p/morelinq/"&gt;MoreLINQ&lt;/a&gt; has progressed faster than expected, mostly because the project now has four members, and they&amp;#39;ve been expending quite a bit of energy on it. (I must do a proper consistency review at some point - in particular it would be nice to have the docs refer to the same concepts in the same way each time. I digress...)&lt;/p&gt;
&lt;p&gt;Most of the discussion in the project hasn&amp;#39;t been about functionality - it&amp;#39;s been about naming. In fact, LINQ is particularly odd in this respect. If I had to guess at how the time has been spent (at least for the operators I&amp;#39;ve implemented) I&amp;#39;d go for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;15% designing the behaviour  &lt;/li&gt;
&lt;li&gt;20% writing the tests  &lt;/li&gt;
&lt;li&gt;10% implementation  &lt;/li&gt;
&lt;li&gt;5% writing the documentation (just XML docs)  &lt;/li&gt;
&lt;li&gt;50% figuring out the best name&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It really is that brutal - and for a lot of the operators we still haven&amp;#39;t got the &amp;quot;right&amp;quot; name yet, in my view. There&amp;#39;s generally too much we want to convey in a word or two. As an example, we&amp;#39;ve got an operator similar to the oft-implemented ForEach one, but which yields the input sequence back out again. Basically it takes an action, and for each element it calls the action and then yields the element. The use case is something like logging. We&amp;#39;ve gone through several names, such as Pipe, Tee, Via... and just this morning I asked a colleague who suggested Apply, just off the top of his head. It&amp;#39;s better than anything we&amp;#39;d previously thought of, but does it convey both the &amp;quot;apply an action&amp;quot; and &amp;quot;still yield the original sequence&amp;quot; aspects?&lt;/p&gt;
&lt;p&gt;The old advice of &amp;quot;each method should only do one thing&amp;quot; is all very well, and it clearly helps to make naming simpler, but with situations like this one there are just &lt;em&gt;naturally&lt;/em&gt; more concepts which you want to get across in the name.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s stay on the LINQ topic, but stray a bit further from the well-trodden path...&lt;/p&gt;
&lt;h3&gt;The heart of Push LINQ: IDataProducer&lt;/h3&gt;
&lt;p&gt;I&amp;#39;ve probably bored most of you with &lt;a href="http://msmvps.com/blogs/jon_skeet/archive/2008/01/04/quot-push-quot-linq-revisited-next-attempt-at-an-explanation.aspx"&gt;Push LINQ&lt;/a&gt; by now, and I&amp;#39;m not actively developing it at the moment, but there&amp;#39;s still one aspect which I&amp;#39;m deeply uncomfortable with: the core interface. IDataProducer represents a stream of data which can be observed. Basically clients subscribe to events, and their event handlers will be called when data is &amp;quot;produced&amp;quot; and when the stream ends.&lt;/p&gt;
&lt;p&gt;I &lt;em&gt;know&lt;/em&gt; IDataProducer is an awful name - but so far I haven&amp;#39;t found anything better. IObservable? Ick. Overused and isn&amp;#39;t descriptive. IPushEnumerable? Sounds like the client can iterate over the data, which they can&amp;#39;t. The actual event names (DataProduced/EndOfData) are okay but there &lt;em&gt;must&lt;/em&gt; be something better than IDataProducer. (Various options have been suggested in the past - none of them have been so obviously &amp;quot;right&amp;quot; as to stick in my head...)&lt;/p&gt;
&lt;p&gt;This situation is slightly different to the previous ones, however, simply because it&amp;#39;s such a pivotal type. You would think that the more important the type, the more important the name would be - but in some ways the reverse is true. You see, Push LINQ isn&amp;#39;t a terribly &amp;quot;obvious&amp;quot; framework. I say that without shame - it&amp;#39;s great at what it does, but it takes a few mental leaps before you really grok it. You&amp;#39;re really going to &lt;em&gt;have&lt;/em&gt; to read some documentation or examples before you write your own queries.&lt;/p&gt;
&lt;p&gt;Given that constraint, it doesn&amp;#39;t matter too much what the interface is called - it&amp;#39;s going to be explained to you before you need it. It doesn&amp;#39;t need to be discoverable - whereas when you&amp;#39;re picking method names to pop up in Intellisense, you really want the developer to be able to &lt;em&gt;guess&lt;/em&gt; its purpose even before they hover over it and check the documentation.&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t given up on IDataProducer (and I hope to be moving Push LINQ into MoreLINQ, by the way - working out a better name is one of the blockers) but it doesn&amp;#39;t feel like &lt;em&gt;quite&lt;/em&gt; as much of a problem.&lt;/p&gt;
&lt;h3&gt;Read-only or not read-only?&lt;/h3&gt;
&lt;p&gt;This final example came up at work, just yesterday - after I&amp;#39;d started writing this post. I wanted to refactor some code to emphasize which methods only use the read-only side of an interface. This was purely for the sake of readability - I wanted to make it easier to reason about which areas of the code modified an object and which didn&amp;#39;t. It&amp;#39;s a custom collection - the details don&amp;#39;t matter, but for the sake of discussion let&amp;#39;s call it House and pretend we&amp;#39;re modelling the various things which might be in a house. (This is Java, hence House rather than IHouse.)&lt;/p&gt;
&lt;p&gt;I&amp;#39;m explicitly &lt;em&gt;not&lt;/em&gt; doing this for safety - I don&amp;#39;t mind the fact that the reference could be cast to a mutable interface. The point is just to make it self-documenting that if a method only has a parameter in the non-mutating form, it&amp;#39;s not going to change the contents of the house.&lt;/p&gt;
&lt;p&gt;So, we have two interfaces, like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="Type"&gt;interface&lt;/span&gt; NameMePlease&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Color getDoorColor();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Type"&gt;int&lt;/span&gt; getWindowCount();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="InlineComment"&gt;// This already returned a read-only collection&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set&amp;lt;Furniture&amp;gt; getFurniture();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="Type"&gt;interface&lt;/span&gt; House extends NameMePlease&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Type"&gt;void&lt;/span&gt; setDoorColor(Color doorColor);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Type"&gt;void&lt;/span&gt; setWindowCount(&lt;span class="Type"&gt;int&lt;/span&gt; windows);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Type"&gt;void&lt;/span&gt; addFurniture(Furniture item);&lt;br /&gt;} &lt;/div&gt;
&lt;p&gt;Obviously the challenge is to find a name for NameMePlease. One option is to use something like ImmutableHouse or ReadOnlyHouse - but the inheritance hierarchy makes liars of both of those names. How can it be a ReadOnlyHouse if there are methods in an implementation which change it? The interface should say what you &lt;em&gt;can&lt;/em&gt; do with the type, rather than specifying what you &lt;em&gt;can&amp;#39;t&lt;/em&gt; do - unless part of the contract of the interface is that the implementation will genunely prohibit changes.&lt;/p&gt;
&lt;p&gt;Thinking of this &amp;quot;positive&amp;quot; aspect led me to ReadableHouse, which is what I&amp;#39;ve gone with for the moment. It states what you can do with it - read information. Again, this is a concept which Joda Time uses.&lt;/p&gt;
&lt;p&gt;Another option is to make it just House, and change the mutable interface to MutableHouse or something similar. In this particular situation the refactoring involved would have been enormous. Simple to automate, but causing a huge check-in for relatively little benefit. Almost all uses are &lt;em&gt;actually&lt;/em&gt; mutating ones. The consensus within the Google Java mailing list seems to be that this would have been the preferred option, all things being equal. One interesting data point was that although Joda Time uses ReadableInstant etc, the current proposals for the new date/time API which will be included in Java 7, designed by the author of Joda Time, &lt;em&gt;don&amp;#39;t&lt;/em&gt; use this convention. Presumably the author found it didn&amp;#39;t work quite as well as he&amp;#39;d hoped, although I don&amp;#39;t have know of any specific problems.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;You&amp;#39;ll probably be unsurprised to hear that I don&amp;#39;t have a recipe for coming up with good names. However, in thinking about naming I&amp;#39;ve at least worked out a few points to think about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Context is important: how discoverable does this need to be? Is accuracy more important than brevity? Do you have any example uses (e.g. through tests) which can help to see whether the code feels right or not?  &lt;/li&gt;
&lt;li&gt;Think of your audience. How familiar will they be with the rest of the code you&amp;#39;re writing? Are they likely to have a background in other areas of computer science where you could steal terminology? Can you make your name consistent with other common frameworks they&amp;#39;re likely to use? The reverse is true too: are you reusing a familiar name for a &lt;em&gt;different&lt;/em&gt; concept, which could confuse readers?  &lt;/li&gt;
&lt;li&gt;Work out the information the name is trying to convey. For types, this includes working out how it participates in inheritance. Is it trying to advertise capabilities or restrictions?  &lt;/li&gt;
&lt;li&gt;Is it possible to make correct code look correct, and buggy code look wrong? This is rarely feasible, but it&amp;#39;s one of the main attractions of &amp;quot;Plus&amp;quot; in the benchmark case. (I believe this is one of the main selling points of true Hungarian Notation for variable naming, by the way. I&amp;#39;m not generally a fan, but I like this aspect.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I may expand this list over time...&lt;/p&gt;
&lt;p&gt;I think it&amp;#39;s fitting to close with a &lt;a href="http://people.famouswhy.com/phil_karlton/"&gt;quote from Phil Karlton&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There are only two hard things in Computer Science: cache invalidation and naming things.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Almost all of us have to handle naming things. Let&amp;#39;s hope most of us don&amp;#39;t have to mess with cache invalidation as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1674533" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/LINQ/default.aspx">LINQ</category></item><item><title>Redesigning System.Object/java.lang.Object</title><link>http://msmvps.com/blogs/jon_skeet/archive/2008/12/05/redesigning-system-object-java-lang-object.aspx</link><pubDate>Fri, 05 Dec 2008 17:52:44 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1655908</guid><dc:creator>skeet</dc:creator><slash:comments>31</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1655908</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1655908</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2008/12/05/redesigning-system-object-java-lang-object.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;ve had quite a few discussions with a colleague about some failures of Java and .NET. The issue we keep coming back to is the root of the inheritance tree. There&amp;#39;s no doubt in my mind that &lt;em&gt;having&lt;/em&gt; a tree with a single top-level class is a good thing, but it&amp;#39;s grown a bit too big for its boots.&lt;/p&gt; &lt;p&gt;Pretty much everything in this post applies to both .NET and Java, sometimes with a few small changes. Where it might be unclear, I&amp;#39;ll point out the changes explicitly - otherwise I&amp;#39;ll just use the .NET terminology.&lt;/p&gt; &lt;h3&gt;What&amp;#39;s in &lt;a href="http://msdn.microsoft.com/en-us/library/system.object.aspx"&gt;System.Object&lt;/a&gt;?&lt;/h3&gt; &lt;p&gt;Before we work out what we might be able to change, let&amp;#39;s look at what we&amp;#39;ve got. I&amp;#39;m only talking about instance methods. At the moment:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;A &lt;a href="http://msdn.microsoft.com/en-us/library/system.object.object.aspx"&gt;parameterless constructor&lt;/a&gt;  &lt;li&gt;A &lt;a href="http://msdn.microsoft.com/en-us/library/system.object.finalize.aspx"&gt;finalizer&lt;/a&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.object.gettype.aspx"&gt;GetType()&lt;/a&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx"&gt;GetHashCode()&lt;/a&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.object.equals.aspx"&gt;Equals(Object)&lt;/a&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx"&gt;ToString()&lt;/a&gt;  &lt;li&gt;(&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.monitor.wait.aspx"&gt;Monitor.Wait&lt;/a&gt;)  &lt;li&gt;(&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.monitor.pulse.aspx"&gt;Monitor.Pulse&lt;/a&gt;)  &lt;li&gt;(&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.monitor.pulseall.aspx"&gt;Monitor.PulseAll&lt;/a&gt;)  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.object.memberwiseclone.aspx"&gt;MemberwiseClone&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Life-cycle and type identity&lt;/h3&gt; &lt;p&gt;There are three members which I believe really need to be left alone.&lt;/p&gt; &lt;p&gt;We need a parameterless constructor because (at least with the current system of chaining constructors to each other) we have to have &lt;em&gt;some&lt;/em&gt; constructor, and I can&amp;#39;t imagine what parameter we might want to give it. I certainly find it hard to believe there&amp;#39;s a particular piece of state which really deserves to be a part of &lt;em&gt;every&lt;/em&gt; object but which we&amp;#39;re currently missing.&lt;/p&gt; &lt;p&gt;I really don&amp;#39;t care that much about finalizers. Should the finalizer be part of Object itself, or should it just get handled automatically by the CLR if and only if it&amp;#39;s defined somewhere in the inheritance chain? Frankly, who cares. No doubt it makes a big difference to the implementation somewhere, but that&amp;#39;s not my problem. All I care about when it comes to finalizers is that when I have to write them it&amp;#39;s as easy as possible to do it properly, and that I don&amp;#39;t have to write them very often in the first place. (With &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.safehandle.aspx"&gt;SafeHandle&lt;/a&gt;, it should be a pretty rare occurrence in .NET, even when you&amp;#39;re dealing directly with unmanaged resources.)&lt;/p&gt; &lt;p&gt;GetType() or (getClass() in Java) is pretty important. I can&amp;#39;t see any particular alternative to having this within Object, unless you make it a static method somewhere else with an Object parameter. In fact, that would have the advantage of freeing up the name for use within your own classes. The functionality is sufficiently important (and really does apply to every object) that I think it&amp;#39;s worth keeping.&lt;/p&gt; &lt;h3&gt;Comparison methods&lt;/h3&gt; &lt;p&gt;Okay, time to get controversial. I don&amp;#39;t think every object should have to be able to compare itself with another object. Of course, most types don&amp;#39;t really support this anyway - we just end up with reference equality by default.&lt;/p&gt; &lt;p&gt;The trouble with comparisons is that everyone&amp;#39;s got a different idea of what makes something equal. There are some types where it really is obvious - there&amp;#39;s only one natural comparison. Integers spring to mind. There are other types which have multiple natural equality comparisons - floating point numbers (exact, within an absolute epsilon, and within a relative epsilon) and strings (ordinal, culture sensitive and/or case sensitive) are examples of this. Then there are composite types where you may or may not care about certain aspects - when comparing URLs, do I care about case? Do I care about fragments? For http, if the port number is explicitly specified as 80, is that different to a URL which is still http but leaves the port number implicit?&lt;/p&gt; &lt;p&gt;.NET represents these reasonably well already, with the &lt;a href="http://msdn.microsoft.com/en-us/library/ms131187.aspx"&gt;IEquatable&amp;lt;T&amp;gt;&lt;/a&gt; interface saying &amp;quot;I know how to compare myself with an instance of type T, and how to produce a hashcode for myself&amp;quot; and &lt;a href="http://msdn.microsoft.com/en-us/library/ms132151.aspx"&gt;IEqualityComparer&amp;lt;T&amp;gt;&lt;/a&gt; interface saying &amp;quot;I know how to compare two instances of T, and how to produce a hashcode for one instance of T.&amp;quot; Now suppose we didn&amp;#39;t have the (nongeneric!) Equals() method and GetHashCode() in System.Object. Any type which had a natural equality comparison would still let you compare it for equality by implementing IEquatable&amp;lt;T&amp;gt;.Equals - but anything else would either force you to use reference equality or an implementation of IEqualityComparer&amp;lt;T&amp;gt;.&lt;/p&gt; &lt;p&gt;Some of the principle consumers of equality comparisons are collections - particularly dictionaries (which is why it&amp;#39;s so important that the interfaces should include hashcode generation). With the current way that .NET generics work, it would be tricky to have a constraint on a &lt;em&gt;constructor&lt;/em&gt; such that if you only specified the types, it would only work if the key type implemented IEquatable&amp;lt;T&amp;gt;, but it&amp;#39;s easy enough to do with static methods (on a non-generic type). Alternatively you could specify any type and an appropriate IEqualityComparer&amp;lt;T&amp;gt; to use for the keys. We&amp;#39;d need an IdentityComparer&amp;lt;T&amp;gt; to work just with references (and provide the equivalent functionaliy to Object.GetHashCode) but that&amp;#39;s not hard - and it would be &lt;em&gt;absolutely&lt;/em&gt; obvious what the comparison was when you built the dictionary.&lt;/p&gt; &lt;h3&gt;Monitors and threading&lt;/h3&gt; &lt;p&gt;This is possibly my biggest gripe. The fact that every object has a monitor associated with it was a mistake in Java, and was unfortunately copied in .NET. This promotes the bad practice of locking on &amp;quot;this&amp;quot; and on types - both of which are typically publicly accessible references. I believe that unless a reference is exposed explicitly for the purpose of locking (like &lt;a href="http://msdn.microsoft.com/en-us/library/system.collections.icollection.syncroot.aspx"&gt;ICollection.SyncRoot&lt;/a&gt;) then you should avoid locking on any reference which other code knows about. I typically have a private read-only variable for locking purposes. If you&amp;#39;re following these guidelines, it makes no sense to be able to lock on absolutely any reference - it would be better to make the Monitor class instantiable, and make Wait/Pulse/PulseAll instance members. (In Java this would mean creating a new class and moving Object.wait/notify/notifyAll members to that class.)&lt;/p&gt; &lt;p&gt;This would lead to cleaner, more readable code in my view. I&amp;#39;d also do away with the &amp;quot;lock&amp;quot; statement in C#, making Monitor.Enter return a token implementing IDisposable - so &amp;quot;using&amp;quot; statements would replace locks, freeing up a keyword &lt;em&gt;and&lt;/em&gt; giving the flexibility of having multiple overloads of Monitor.Enter. Arguably if one were redesigning all of this anyway, it would be worth looking at whether or not monitors should really be reentrant. Any time you &lt;em&gt;use&lt;/em&gt; lock reentrancy, you&amp;#39;re probably not thinking hard enough about the design. Now there&amp;#39;s a nice overgeneralisation with which to end this section...&lt;/p&gt; &lt;h3&gt;String representations&lt;/h3&gt; &lt;p&gt;This is an interesting one. I&amp;#39;m genuinely on the fence here. I find ToString() (and the fact that it&amp;#39;s called implicitly in many circumstances) hugely useful, but it feels like it&amp;#39;s attempting to satisfy three different goals:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Giving a developer-readable representation when logging and debugging&lt;/li&gt; &lt;li&gt;Giving a user-readable representation as part of a formatted message in a UI&lt;/li&gt; &lt;li&gt;Giving a machine-readable format (although this is relatively rare for anything other than numeric types)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;It&amp;#39;s interesting to note that Java and .NET differ as to which of these to use for numbers - Java plumps for &amp;quot;machine-readable&amp;quot; and .NET goes for &amp;quot;human-readable in the current thread&amp;#39;s culture&amp;quot;. Of course it&amp;#39;s clearer to explicitly specify the culture on both platforms.&lt;/p&gt; &lt;p&gt;The trouble is that &lt;em&gt;very&lt;/em&gt; often, it&amp;#39;s not immediately clear which of these has been implemented. This leads to guidelines such as &amp;quot;don&amp;#39;t use ToString() other than for logging&amp;quot; on the grounds that at least if it&amp;#39;s implemented inappropriately, it&amp;#39;ll only be a log file which ends up with difficult-to-understand data.&lt;/p&gt; &lt;p&gt;Should this usage be explicitly stated - perhaps even codified in the name: &amp;quot;ToDebugString&amp;quot; or something similar? I will leave this for smarter minds to think about, but I think there&amp;#39;s enough value in the method to make it worth keeping.&lt;/p&gt; &lt;h3&gt;MemberwiseClone&lt;/h3&gt; &lt;p&gt;Again, I&amp;#39;m not sure on this one. It would perhaps be better as a static (generic!) method somewhere in a class whose name indicated &amp;quot;this is for sneaky runtime stuff&amp;quot;. After all, it constructs a new object without calling a constructor, and other funkiness. I&amp;#39;m less bothered by this than the other items though.&lt;/p&gt; &lt;h3&gt;Conclusion&lt;/h3&gt; &lt;p&gt;To summarise, in an ideal world:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Equals and GetHashCode would disappear from Object. Types would have to explicitly say that they could be compared&lt;/li&gt; &lt;li&gt;Wait/Pulse/PulseAll would become instance methods in Monitor, which would be instantiated every time you want a lock.&lt;/li&gt; &lt;li&gt;ToString &lt;em&gt;might&lt;/em&gt; be renamed to give clearer usage guidance.&lt;/li&gt; &lt;li&gt;MemberwiseClone &lt;em&gt;might&lt;/em&gt; be moved to a different class.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Obviously it&amp;#39;s far too late for either Java or .NET to make these changes, but it&amp;#39;s always interesting to dream. Any more changes you&amp;#39;d like to see? Or violent disagreements with any of the above?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1655908" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Wacky+Ideas/default.aspx">Wacky Ideas</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/CSharpDevCenter/default.aspx">CSharpDevCenter</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/CSharpDev/default.aspx">CSharpDev</category></item><item><title>Data Structures and Algorithms: new free eBook available (first draft)</title><link>http://msmvps.com/blogs/jon_skeet/archive/2008/08/29/data-structures-and-algorithms-new-free-ebook-available-first-draft.aspx</link><pubDate>Fri, 29 Aug 2008 19:25:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1646210</guid><dc:creator>skeet</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1646210</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1646210</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2008/08/29/data-structures-and-algorithms-new-free-ebook-available-first-draft.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;ve been looking at this for a while: &lt;a title="http://dotnetslackers.com/projects/Data-Structures-And-Algorithms/" href="http://dotnetslackers.com/projects/Data-Structures-And-Algorithms/"&gt;Data Structures and Algorithms: Annotated reference with examples&lt;/a&gt;. It&amp;#39;s only in &amp;quot;first draft&amp;quot; stage at the moment, but the authors would love your feedback (as would I). Somehow I&amp;#39;ve managed to end up as the editor and proof-reader, although due to my holiday the version currently available doesn&amp;#39;t have many of my edits in. It&amp;#39;s a non-academic data structures and algorithms book, intended (as I see it, anyway) as a good starting point for those who know that they ought to be more aware of the data structures they use every day (lists, heaps etc) but don&amp;#39;t have an academic background in computer science.&lt;/p&gt; &lt;p&gt;An implementation will be available in both Java and C#, I believe.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1646210" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Books/default.aspx">Books</category></item><item><title>Automatic lambda expressions</title><link>http://msmvps.com/blogs/jon_skeet/archive/2008/06/20/automatic-lambda-expressions.aspx</link><pubDate>Fri, 20 Jun 2008 16:33:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1636119</guid><dc:creator>skeet</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;This morning I happened to show a colleague (Malcolm Rowe) the neat trick of using nullable types and the null-coalescing operator (??) to implement compound comparisons in C#. He asked whether it wouldn&amp;#39;t have been nicer to make this a library feature rather than a language feature. I&amp;#39;m all for putting features into libraries where possible, but there&amp;#39;s a problem in this case: the ?? operator doesn&amp;#39;t evaluate its right operand unless the left operand evaluates to &lt;code&gt;null&lt;/code&gt;. This can&amp;#39;t be replicated in a library. Or can it?&lt;/p&gt;
&lt;p&gt;The obvious way to lazily evaluate an expression is to turn it into a closure. So, we can write out coalescing method as:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="code"&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="Modifier"&gt;static&lt;/span&gt; T CoalesceNulls&amp;lt;T&amp;gt;(T lhs, Func&amp;lt;T&amp;gt; rhs)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Statement"&gt;return&lt;/span&gt; lhs != &lt;span class="Keyword"&gt;null&lt;/span&gt; ? lhs : rhs();&lt;br /&gt;} &lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That&amp;#39;s quite an efficient way of doing it, but the assymetry isn&amp;#39;t ideal. We can fix that by making the first argument a function too: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="code"&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="Modifier"&gt;static&lt;/span&gt; T CoalesceNulls&amp;lt;T&amp;gt;(Func&amp;lt;T&amp;gt; lhs, Func&amp;lt;T&amp;gt; rhs)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; T first = lhs();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Statement"&gt;return&lt;/span&gt; first != &lt;span class="Keyword"&gt;null&lt;/span&gt; ? first : rhs();&lt;br /&gt;} &lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One of the nice things you can do with the null-coalescing operator is use it for multiple expressions, e.g. &lt;code&gt;a ?? b ?? c ?? d&lt;/code&gt; which will evaluate &lt;code&gt;a&lt;/code&gt;, then (if it&amp;#39;s null) evaluate &lt;code&gt;b&lt;/code&gt;, then (if that&amp;#39;s null) evaluate &lt;code&gt;c&lt;/code&gt; etc. With the symmetry present we can now make this into a parameter array: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="code"&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="Modifier"&gt;static&lt;/span&gt; T CoalesceNulls&amp;lt;T&amp;gt;(&lt;span class="MethodParameter"&gt;params&lt;/span&gt; Func&amp;lt;T&amp;gt;[] functions)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; T current = &lt;span class="Modifier"&gt;default&lt;/span&gt;(T);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Statement"&gt;foreach&lt;/span&gt; (Func&amp;lt;T&amp;gt; func &lt;span class="Statement"&gt;in&lt;/span&gt; functions)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; current = func();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Statement"&gt;if&lt;/span&gt; (current != &lt;span class="Keyword"&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Statement"&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="Statement"&gt;return&lt;/span&gt; current;&lt;br /&gt;} &lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;(In some ways it&amp;#39;s still more elegant to specify a bare &lt;code&gt;T&lt;/code&gt; as the first parameter, as that ensures that at least you&amp;#39;ve got one function to call. The change required is pretty obvious.)&lt;/p&gt;
&lt;p&gt;Now there are only two problems: invoking the method, and the performance characteristics. I&amp;#39;m going to ignore the latter - yes, you could end up with a significant performance hit creating all these closures all the time if you use this in performance critical code. There&amp;#39;s not a lot of options available there, really. But what about the syntax for invoking the method? &lt;/p&gt;
&lt;p&gt;In its current form, we can write the current &lt;code&gt;a ?? b ?? c ?? d&lt;/code&gt; as &lt;code&gt;CoalesceNulls(() =&amp;gt; a, () =&amp;gt; b, () =&amp;gt; c, () =&amp;gt; d)l&lt;/code&gt;. That&amp;#39;s a wee bit ugly. Malcolm &lt;a href="http://www.farside.org.uk/200806/auto_lambda"&gt;blogged about an alternative&lt;/a&gt; where the parameters could be declared on the declaration side) as calling for deferred execution, and automatically converted into closures by the compiler. &lt;/p&gt;
&lt;p&gt;Just like Malcolm, I&amp;#39;m not terribly keen on this - for instance, I really like the fact that in C# it&amp;#39;s always very clear when a parameter is being passed by reference, because there&amp;#39;s the &lt;code&gt;ref&lt;/code&gt; keyword on the caller side as well as the declaration side. Going against this would just feel wrong. &lt;/p&gt;
&lt;p&gt;If we have to change the language and introduce new keywords or symbols, we&amp;#39;re then back where we started - the whole idea was to avoid having to introduce ?? into the language. The plus side is that it could be &amp;quot;usage agnostic&amp;quot; - just because it &lt;i&gt;could&lt;/i&gt; be used for a null-coalescing operator replacement doesn&amp;#39;t mean it would have to be. However, this feels like using a sledgehammer to crack a nut - the number of times this would be useful is pretty minimal. The same argument could be applied to the null-coalescing operator itself, of course, but I think its utility - and the way it fits into the language pretty seamlessly - justifies the decisions made here.&lt;/p&gt;
&lt;p&gt;Still, it was an interesting thought experiment... &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Since originally writing this (a few days ago, before the blog outage, Malcolm has been informed that &lt;a href="http://www.scala-lang.org/"&gt;Scala&lt;/a&gt; has precisely this capability. Just another reason for getting round to learning Scala at some point...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1636119" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category></item><item><title>The Beauty of Closures</title><link>http://msmvps.com/blogs/jon_skeet/archive/2008/05/06/the-beauty-of-closures.aspx</link><pubDate>Tue, 06 May 2008 22:08:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1615602</guid><dc:creator>skeet</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1615602</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1615602</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2008/05/06/the-beauty-of-closures.aspx#comments</comments><description>&lt;p&gt;Fairly soon I&amp;#39;m going to write a blog post comparing the different proposals under consideration for Java 7 when it comes to closures. I thought it would be worth writing some background material on it first though, so I&amp;#39;ve put an &lt;a href="http://csharpindepth.com/Articles/Chapter5/Closures.aspx"&gt;article on the C# in Depth site&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I&amp;#39;m not entirely comfortable that I&amp;#39;ve captured why they&amp;#39;re important, but the article can mature over time like a good wine. The idea is to counter the &lt;a href="http://c2.com/cgi/wiki?BlubParadox"&gt;Blub Paradox&lt;/a&gt; (which I hadn&amp;#39;t come across before, but I agree with completely - it&amp;#39;s part of the effect I believe Steve McConnell was fighting against when talking about &lt;a href="http://msmvps.com/blogs/jon.skeet/archive/2008/04/23/programming-quot-in-quot-a-language-vs-programming-quot-into-quot-a-language.aspx"&gt;programming in a language&lt;/a&gt;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1615602" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category></item><item><title>Programming "in" a language vs programming "into" a language</title><link>http://msmvps.com/blogs/jon_skeet/archive/2008/04/23/programming-quot-in-quot-a-language-vs-programming-quot-into-quot-a-language.aspx</link><pubDate>Wed, 23 Apr 2008 18:47:15 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1601545</guid><dc:creator>skeet</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1601545</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1601545</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2008/04/23/programming-quot-in-quot-a-language-vs-programming-quot-into-quot-a-language.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m currently reading Steve McConnell&amp;#39;s &lt;i&gt;Code Complete&lt;/i&gt; (for the first time - yes, I know that&amp;#39;s somewhat worrying) and there was one section was disturbed me a little. For those of you with a copy to hand, it&amp;#39;s in section 4.3, discussing the difference between programming &lt;i&gt;in&lt;/i&gt; a language and programming &lt;i&gt;into&lt;/i&gt; a language: &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Programmers who program &amp;quot;in&amp;quot; a language limit their thoughts to constructs that the language directly supports. If the language tools are primitive, the programmer&amp;#39;s thoughts will also be primitive. &lt;/p&gt; &lt;p&gt;Programmers who program &amp;quot;into&amp;quot; a language first decide what thoughts they want to express, and then they determine how to express those thoughts using the tools provided by their specific language. &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now don&amp;#39;t get me wrong - I can see where he&amp;#39;s coming from, and the example he then provides (Visual Basic - keeping the forms simple and separating them from business logic) is fine, but he only seems to give one side of the coin. Here&amp;#39;s a different - and equally one-sided - way of expressing the same terms: &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Programmers who program &amp;quot;in&amp;quot; a language understand that language&amp;#39;s conventions and idioms. They write code which integrates well with other libraries, and which can be easily understood and maintained by other developers who are familiar with the language. They benefit from tools which have been specifically designed to aid coding in the supported idioms. &lt;/p&gt; &lt;p&gt;Programmers who program &amp;quot;into&amp;quot; a language will use the same ideas regardless of their target language. If their style does not mesh well with the language, they will find themselves fighting against it every step of the way. It will be harder to find libraries supporting their way of working, and tools may well prove annoying. Other developers who come onto the project later and who have experience in the language but not the codebase will find it hard to navigate and may well accidentally break the code when changing it.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;There is a happy medium to be achieved, clearly. You certainly shouldn&amp;#39;t restrict your thinking to techniques which are entirely idiomatic, but if you find yourself wanting to code in a radically different style to that encouraged by the language, consider changing language if possible!&lt;/p&gt; &lt;p&gt;If I were attacking the same problem in C# 1 and C# 3, I could easily end up with radically different solutions. Some data extraction using LINQ in a fairly functional way in C# 3 would probably be better solved in C# 1 by losing some of the functional goodness than by trying to back-port LINQ and then use it without the benefit of lambda expressions or even anonymous methods.&lt;/p&gt; &lt;h3&gt;Accents and Conventions&lt;/h3&gt; &lt;p&gt;That&amp;#39;s just between different versions of the same language. Between different actual languages, it can get much worse. If you&amp;#39;ve ever seen Java code written in a C++ style or vice versa, you&amp;#39;ll know what I mean. I&amp;#39;ve previously referred to this in terms of speaking a language with an accent - you can speak C# with a Java accent just as you can speak French with an English accent. Neither is pleasant. &lt;/p&gt; &lt;p&gt;At the lowest level, this is likely to be about conventions - and I&amp;#39;m pretty sure that when Steve writes &amp;quot;Invent your own coding conventions, standards, class libraries, and other augmentations&amp;quot; he doesn&amp;#39;t actually mean us to do it in a gratuitous fashion. It &lt;i&gt;can&lt;/i&gt; be worth deviating from the &amp;quot;platform favoured&amp;quot; conventions sometimes, particularly if those differences are invisible to clients, but it should always be done with careful consideration. In a Java project I worked on a few years ago, we took the .NET naming conventions for interfaces (an I prefix) and constants (CamelCasing instead of SHOUTY_CAPS). Both of these made the codebase feel slightly odd, particularly where Java constants were used near our constants - but I personally found the benefits to be worth the costs. Importantly, the whole team discussed it before making any decisions.&lt;/p&gt; &lt;h3&gt;Design Patterns&lt;/h3&gt; &lt;p&gt;At a slightly higher level, many design patterns are just supported much, much better by some languages than others. The iterator pattern is a classic example. Compare the support for it from Java 6 and C# 2. On the &amp;quot;client&amp;quot; side, both languages have specific syntax: the enhanced &lt;code&gt;for&lt;/code&gt; loop in Java and the &lt;code&gt;foreach&lt;/code&gt; loop in C#. However, there is one important difference: if the iterator returned by &lt;code&gt;GetEnumerator&lt;/code&gt; implements &lt;code&gt;IDisposable&lt;/code&gt; (which the generic form demands, in fact) C# will call &lt;code&gt;Dispose&lt;/code&gt; at the end of the loop, no matter how that occurs (reaching the end of the sequence, breaking early, an exception being thrown, etc). Java has no equivalent of this. Imagine that you want to write a class to iterate over the lines in a file. In Java, there&amp;#39;s just no safe way of representing it: you can make your iterator implement &lt;code&gt;Closeable&lt;/code&gt; but then callers can&amp;#39;t (safely) use the enhanced for&lt;/code&gt; loop. You can make your code close the file handle when it reaches the end, but there&amp;#39;s no guarantee that will happen. &lt;/p&gt; &lt;p&gt;Then consider the &amp;quot;server&amp;quot; side of the iterator - the code actually providing the data. Java is like C# 1 - there&amp;#39;s no specific support for implementing an iterator. In C# 2 and above, iterator blocks (i.e. methods with &lt;code&gt;yield&lt;/code&gt; statements) make life much, much easier. Writing iterators by hand can be a real pain. Reading a file line by line isn&amp;#39;t too bad, leaving aside the resource lifetime issue - but the complexity can balloon very quickly. Off by one errors are really easy to introduce. &lt;/p&gt; &lt;p&gt;So, if I were tackling a project which required reading text files line by line in various places, what would I do? In Java, I would take the reasonably small hit of a &lt;code&gt;while&lt;/code&gt; loop in each place I needed it. In C# I&amp;#39;d write a &lt;code&gt;LineReader&lt;/code&gt; class (if I didn&amp;#39;t already have one!) and use a more readable &lt;code&gt;foreach&lt;/code&gt; loop. The contortions involved in introducing that idea into Java just wouldn&amp;#39;t be worth the effort. &lt;/p&gt; &lt;p&gt;At a much higher level, we get into whole programming styles and paradigms. If your natural inclination is to write imperative code, you&amp;#39;re likely to create a mess (or get very frustrated) in a functional language. If the problem really does call for a functional language, find someone else to help you think in a more functional way. If the problem suits imperative programming just as well as it does functional programming, see if you can change the environment to something more familiar.&lt;/p&gt; &lt;h3&gt;Conclusion&lt;/h3&gt; &lt;p&gt;I&amp;#39;m not suggesting that Steve&amp;#39;s point isn&amp;#39;t valid - but he&amp;#39;s done his readers a disservice by only presenting one side of the matter. Fortunately, the rest of the book (so far) is excellent and humbling - to such a degree that this minor quibble stuck out like a sore thumb. In a book which had more problems, I would probably barely have even noticed this one. &lt;/p&gt; &lt;p&gt;There&amp;#39;s another possibility, of course - I could be competely wrong; maybe I&amp;#39;ve been approaching problems from a restrictive viewpoint all this time. How about you? &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1601545" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Books/default.aspx">Books</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Book+reviews/default.aspx">Book reviews</category></item><item><title>Macros, and languages within languages</title><link>http://msmvps.com/blogs/jon_skeet/archive/2008/02/08/macros-and-languages-within-languages.aspx</link><pubDate>Fri, 08 Feb 2008 23:31:32 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1503965</guid><dc:creator>skeet</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1503965</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1503965</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2008/02/08/macros-and-languages-within-languages.aspx#comments</comments><description>&lt;p&gt;Ian Griffiths mailed me about macros, and explained how LISP macros were very different to C/C++ macros, working at a language level instead of at a text level. I won&amp;#39;t pretend to understand all about what would be possible and what wouldn&amp;#39;t, but Ian gave a good example: query expressions in C# 3. Instead of being part of the language itself, they could apparently have been written as macros, if C# supported them. Then if you wanted to have similar support for different forms of expression, you could just write your own macro library.&lt;/p&gt; &lt;p&gt;Assuming that&amp;#39;s what people are actually requesting, I can certainly see the attraction - but I&amp;#39;d still prefer it if C# didn&amp;#39;t go down that route. I&amp;#39;ll go back to C++ for the guts of the reason why, but it&amp;#39;s not really about macros at this point. It&amp;#39;s about building your own language. Once, someone told me that C++ wasn&amp;#39;t a language - it was a meta-language; no-one used &amp;quot;bare&amp;quot; C++, they worked out their own language made from the building blocks of normal C++, and then used that.&lt;/p&gt; &lt;p&gt;That may or may not be true - or more likely, it&amp;#39;s true in some places but not others - but it scares me as an idea. I&amp;#39;m not going to claim I know every nuance of C#, but it&amp;#39;s pretty rare that you&amp;#39;d throw a line at me without it being reasonably clear what&amp;#39;s going to happen and why, at the language level. Extension methods might mean a bit more information is required as to where a particular method comes from, but it doesn&amp;#39;t take a lot of digging to see what&amp;#39;s going on.&lt;/p&gt; &lt;p&gt;Now imagine that C# 3 didn&amp;#39;t include query expressions, but that someone had come up with them as a macro library. It&amp;#39;s not an insignificant amount of effort to learn what&amp;#39;s going on there, and how it all maps to normal method calls, potentially with expression trees as arguments instead of delegates. Until you understand what&amp;#39;s going on at a reasonably deep level, you can&amp;#39;t really make any firm decisions as to what code including a query expression will do. (Heck, that&amp;#39;s one of the premises of the book: you should really know this stuff, or at least be aware of it.)&lt;/p&gt; &lt;p&gt;That&amp;#39;s fine when there&amp;#39;s a single macro library used globally, but now imagine every company has their own - or worse still, has a bunch of them grabbed from Code Project, possibly including a load of bugs. Most of us aren&amp;#39;t accomplished language designers, and I suspect there&amp;#39;d be an awful lot of macro libraries out there which weren&amp;#39;t quite thought through enough - but were still useful enough to be attractive. They&amp;#39;d become magnets for code warts.&lt;/p&gt; &lt;p&gt;It&amp;#39;s hard enough when you change company to work out what 3rd party libraries are in use, &lt;em&gt;how&lt;/em&gt; they&amp;#39;re being used, what the coding conventions are etc. It would be much worse if I had to learn another flavour of C# itself each time. I&amp;#39;m already worried that developers are picking up C# 3 without having a firm enough grasp of C# 2 - and that&amp;#39;s when there&amp;#39;s just a progression within a single language.&lt;/p&gt; &lt;p&gt;I know this all sounds patronising and/or elitest and/or &amp;quot;nanny state&amp;quot; applied to programming languages - but it&amp;#39;s how I feel nonetheless. I just don&amp;#39;t think we (as a development community) are mature enough to handle that sort of power without it turning into a blood bath. This sort of thing sounds fabulous for hobby and research development, and would probably be great in the hands of the best few companies in the world - but I don&amp;#39;t think it&amp;#39;s a good idea for the mainstream.&lt;/p&gt; &lt;p&gt;Okay - time to hear why I&amp;#39;m wrong :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1503965" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_+4/default.aspx">C# 4</category></item><item><title>Java isn't an acronym</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/09/18/java-isn-t-an-acronym.aspx</link><pubDate>Mon, 17 Sep 2007 23:21:34 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1203078</guid><dc:creator>skeet</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=1203078</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=1203078</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/09/18/java-isn-t-an-acronym.aspx#comments</comments><description>&lt;p&gt;Just a quickie while I remember. A pet peeve of mine has surfaced again recently, while reading some CVs.&lt;/p&gt; &lt;p&gt;Java, the programming language, is just written &amp;quot;Java&amp;quot;. It&amp;#39;s not an acronym. There&amp;#39;s no need to write it as &amp;quot;JAVA&amp;quot;. That just looks shouty and somewhat silly. Why do so many people get it wrong? While we&amp;#39;re at it, why does it irritate me so much to see it written the wrong way?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1203078" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category></item><item><title>Why hasn't Microsoft bought JetBrains yet?</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/06/01/why-hasn-t-microsoft-bought-jetbrains-yet.aspx</link><pubDate>Fri, 01 Jun 2007 22:07:07 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:937914</guid><dc:creator>skeet</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=937914</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=937914</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/06/01/why-hasn-t-microsoft-bought-jetbrains-yet.aspx#comments</comments><description>&lt;p&gt;For those of you who aren&amp;#39;t aware, &lt;a href="http://www.jetbrains.com/"&gt;JetBrains&lt;/a&gt;&amp;nbsp;is the company behind IntelliJ IDEA, the Java IDE which I&amp;#39;ve heard amazing things about (I&amp;#39;ve tried it a couple of times but never got into it - I think I need an expert sitting beside me to point out the cool stuff as I go) and ReSharper, the incredibly useful (although somewhat resource hungry) add-in to Visual Studio that turns it into a respectable IDE.&lt;/p&gt; &lt;p&gt;What would happen if Microsoft bought JetBrains?&lt;/p&gt; &lt;p&gt;I&amp;#39;m sure that killing off the reportedly best Java IDE would do .NET no harm (even if it would be a fairly cruel thing to do, and still leave other perfectly good IDEs in the Java space), and &lt;em&gt;surely&lt;/em&gt; they could use the ideas and experience of the company to improve Visual Studio significantly. I strongly suspect that tighter integration could make all the ReSharper goodness available with less performance overhead, and while it&amp;#39;s no doubt too late now, wouldn&amp;#39;t it have been wonderful for all of those features to be available in Orcas?&lt;/p&gt; &lt;p&gt;Anyway, just a thought.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=937914" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category></item><item><title>Sheer Evil: Rethrowing exceptions in Java</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/04/03/sheer-evil-rethrowing-exceptions-in-java.aspx</link><pubDate>Tue, 03 Apr 2007 20:07:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:749170</guid><dc:creator>skeet</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=749170</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=749170</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/04/03/sheer-evil-rethrowing-exceptions-in-java.aspx#comments</comments><description>&lt;p&gt;This morning, I was looking through some code and I was annoyed (yet again) at Java's exception hierarchy, particularly when it comes to checked exceptions. Just as a reminder, everything that can be thrown in Java derives from &lt;code&gt;Throwable&lt;/code&gt;. The predefined direct subclasses are &lt;code&gt;Error&lt;/code&gt; and &lt;code&gt;Exception&lt;/code&gt;. (You can derive from &lt;code&gt;Throwable&lt;/code&gt; directly yourself, but I've never seen anyone do it, thank goodness.) &lt;code&gt;Exception&lt;/code&gt;, and any class deriving from it, count as a &lt;em&gt;checked exception&lt;/em&gt; - one that you have to declare if your method might throw it. Oh, except for &lt;code&gt;RuntimeException&lt;/code&gt;, and &lt;em&gt;its&lt;/em&gt; descendants such as &lt;code&gt;NullPointerException&lt;/code&gt;. Blech.&lt;/p&gt;
&lt;p&gt;This is really painful in some situations. In particular, the code I was looking at wanted to catch everything, act on it, and then rethrow it. My method was declared to throw &lt;code&gt;IOException&lt;/code&gt;, and without the &lt;code&gt;catch&lt;/code&gt; block everything compiled fine, so I knew that nothing I was calling should throw any checked exceptions other than IOException. However, rethrowing the exception is tricky - because the compiler doesn't know what you're up to. I ended up with this foul code:&lt;/p&gt;
&lt;table class="code"&gt;

&lt;tr&gt;
&lt;td&gt;&lt;pre&gt;&lt;span class="Statement"&gt;try&lt;/span&gt;
{
    &lt;span class="InlineComment"&gt;// Stuff here&lt;/span&gt;
}
&lt;span class="Statement"&gt;catch&lt;/span&gt; (Throwable t)
{
    &lt;span class="InlineComment"&gt;// Log the error (or whatever)&lt;/span&gt;
            
    &lt;span class="InlineComment"&gt;// Now rethrow&lt;/span&gt;
    &lt;span class="Statement"&gt;if&lt;/span&gt; (t &lt;span class="Keyword"&gt;instanceof&lt;/span&gt; IOException)
    {
        &lt;span class="Statement"&gt;throw&lt;/span&gt; (IOException) t;
    }
    &lt;span class="Statement"&gt;if&lt;/span&gt; (t &lt;span class="Keyword"&gt;instanceof&lt;/span&gt; RuntimeException)
    {
        &lt;span class="Statement"&gt;throw&lt;/span&gt; (RuntimeException) t;
    }
    &lt;span class="Statement"&gt;if&lt;/span&gt; (t &lt;span class="Keyword"&gt;instanceof&lt;/span&gt; Error)
    {
        &lt;span class="Statement"&gt;throw&lt;/span&gt; (Error) t;
    }
    &lt;span class="InlineComment"&gt;// Very unlikely to happen&lt;/span&gt;
    &lt;span class="Statement"&gt;throw&lt;/span&gt; &lt;span class="Keyword"&gt;new&lt;/span&gt; RuntimeException(t);
}
&lt;span class="Statement"&gt;finally&lt;/span&gt;
{
    &lt;span class="InlineComment"&gt;// More stuff here&lt;/span&gt;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;Nasty, isn't it? It would be lovely to somehow tell the compiler that you know there won't be any other kinds of checked exceptions thrown, just rethrow the original, it's all right guv, you can trust me, honest.&lt;/p&gt;
&lt;p&gt;Well, apparently you can't really trust me. Not since the hack I worked out this morning. You see, exception checking only occurs at compile time. So, let's define a really harmless little class called &lt;code&gt;ExceptionHelper&lt;/code&gt;:&lt;/p&gt;
&lt;table class="code"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;class&lt;/span&gt; ExceptionHelper
{
    &lt;span class="BlockComment"&gt;/** Private constructor to prevent instantiation */&lt;/span&gt;
    &lt;span class="Modifier"&gt;private&lt;/span&gt; ExceptionHelper()
    {
    }
    
    &lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="Modifier"&gt;static&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; rethrow (Throwable t)
    {
    }
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;Nothing nasty going on, is there? So the compiler won't mind at all if I change the original code to:&lt;/p&gt;
&lt;table class="code"&gt;

&lt;tr&gt;
&lt;td&gt;&lt;pre&gt;&lt;span class="Statement"&gt;try&lt;/span&gt;
{
    &lt;span class="InlineComment"&gt;// Stuff here&lt;/span&gt;
}
&lt;span class="Statement"&gt;catch&lt;/span&gt; (Throwable t)
{
    &lt;span class="InlineComment"&gt;// Log the error (or whatever)&lt;/span&gt;
            
    &lt;span class="InlineComment"&gt;// Now rethrow&lt;/span&gt;
    ExceptionHelper.rethrow(t);
}
&lt;span class="Statement"&gt;finally&lt;/span&gt;
{
    &lt;span class="InlineComment"&gt;// More stuff here&lt;/span&gt;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;The only trouble is, it doesn't rethrow the exception any more, regardless of the name of the method. But as I suspect you've guessed by now, once we've satisfied the compiler, we can change &lt;code&gt;ExceptionHelper.rethrow&lt;/code&gt; slightly:&lt;/p&gt;
&lt;table class="code"&gt;

&lt;tr&gt;
&lt;td&gt;&lt;pre&gt;&lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="Modifier"&gt;static&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; rethrow (Throwable t) throws Throwable
{
    &lt;span class="Statement"&gt;throw&lt;/span&gt; t;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;Recompile &lt;code&gt;ExceptionHelper&lt;/code&gt; &lt;em&gt;but not the calling code&lt;/em&gt; and we achieve exactly what we want - it will rethrow whatever exception we ask it to, and we've fooled the compiler into not worrying about the potential consequences. Of course, this means we could change the code in the &lt;code&gt;try&lt;/code&gt; block to something which throws a completely different checked exception, and we'd never know until it happened - the compiler couldn't help us. The workaround for this is to temporarily remove the &lt;code&gt;catch&lt;/code&gt; block and see whether or not the compiler complains.&lt;/p&gt;
&lt;p&gt;I'm not actually suggesting anyone should do this, despite a certain appeal in terms of simpler, more readable code in the catch block. A hack like this is horrible, evil, awful. Which is why I had to share it, of course.&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=749170" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category></item><item><title>Wacky Ideas 3: Object life-cycle support</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/02/28/wacky-ideas-3-object-life-cycle-support.aspx</link><pubDate>Wed, 28 Feb 2007 15:51:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:625991</guid><dc:creator>skeet</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=625991</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=625991</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/02/28/wacky-ideas-3-object-life-cycle-support.aspx#comments</comments><description>&lt;p&gt;No, don't leave yet! This &lt;em&gt;isn't&lt;/em&gt; another article about non-deterministic finalization, RAII etc. That's what we almost always think of when someone mentions the object life-cycle, but I'm actually interested in the other end of the cycle - the "near birth" end.&lt;/p&gt; &lt;p&gt;We often take it as read that when an object's constructor has completed successfully, the object should be ready to use. However, frameworks and technologies like Spring and XAML often make it easier to create an object and then populate it with dependencies, configuration etc. Yes, in some cases it's more appropriate to have a separate configuration class which is used for nothing but a bunch of properties, and then the configuration can be passed into the "real" constructor in one go, with none of the readability problems of constructors taking loads of parameters. It's all a bit unsatisfactory though.&lt;/p&gt; &lt;p&gt;What we most naturally want is to say, "Create me an empty X. Now configure it. Now use it." (Okay, and as an obligatory mention, potentially "Now make it clean up after itself.")&lt;/p&gt; &lt;p&gt;While configuring the object, we don't want to call any of the "real" methods which are likely to want to do things. We may want to be able to fetch some of the configuration back again, e.g. so that some values can be relative to others easily, but we don't want the main business to take place. Likewise, when we've finished configuring the object, we generally want to validate the configuration, and after that we don't want anyone to be able to change the configuration. Sometimes there's even a third phase, where we've cleaned up and want to still be able to get some calculated results (the byte array backing a &lt;code&gt;MemoryStream&lt;/code&gt;, for instance) but not call any of the "main" methods any more.&lt;/p&gt; &lt;p&gt;I'd really like some platform support for this. None of it's actually that hard to do - just a case of keeping track of which phase you're in, and then adding a check to the start of each method. Wouldn't it be nicer to have it available as attributes though? Specify the "default phase" for any undecorated members, and specify which phases are valid for other members - so configuration setters would only be valid in the configuration phase, for instance. Another attribute could dictate the phase transition - so the &lt;code&gt;ValidateAndInitialize&lt;/code&gt; method (or whatever you'd call it) would have an attribute stating that on successful completion (no exceptions thrown) the phase would move from "configure" to "use".&lt;/p&gt; &lt;p&gt;Here's a short code sample. The names and uses of the attributes could no doubt be improved, and if there were only a few phases which were actually useful, they could be named in an enum instead, which would be neat.&lt;/p&gt; &lt;table class="code"&gt;  &lt;tr&gt; &lt;td&gt;&lt;pre&gt;[Phased(defaultRequirement=2, initial=1)]
&lt;span class="ReferenceType"&gt;class&lt;/span&gt; Sample
{
    IAuthenticator authenticator;
    
    &lt;span class="Modifier"&gt;public&lt;/span&gt; IAuthenticator Authenticator
    {
        [Phase(1)]
        [Phase(2)]
        get
        {
            &lt;span class="Statement"&gt;return&lt;/span&gt; authenticator;
        }
        [Phase(1)]
        set
        {
            authenticator = value;
        }
    }
    
    [Phase(1)]
    [PhaseTransition(2)]
    &lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; ValidateAndInitialize()
    {
        &lt;span class="Statement"&gt;if&lt;/span&gt; (authenticator==&lt;span class="Keyword"&gt;null&lt;/span&gt;)
        {
            &lt;span class="Statement"&gt;throw&lt;/span&gt; &lt;span class="Keyword"&gt;new&lt;/span&gt; InvalidConfigurationException(&lt;span class="String"&gt;"I need an authenticator"&lt;/span&gt;);
        }
    }
    
    &lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; DoSomething()
    {
        &lt;span class="InlineComment"&gt;// Use authenticator, assuming it's valid&lt;/span&gt;
    }
    
    &lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; DoSomethingElse()
    {
        &lt;span class="InlineComment"&gt;// Use authenticator, assuming it's valid&lt;/span&gt;
    }
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;Hopefully it's obvious what you could and couldn't do at what point.&lt;/p&gt;
&lt;p&gt;This looks to me like a clear example of where AOP should get involved. I believe that Anders isn't particularly keen on it, and when abused it's clearly nightmarish - but for certain comment things, it just &lt;em&gt;makes life easier&lt;/em&gt;. The declarative nature of the above is simpler to read (IMO - particularly if names were used instead of numbers) than manually checking the state at the start of each method. I don't know if any AOP support is on the slate for Java 7 - I believe things have been made easier for AOP frameworks by Java 6, although I doubt that any target just Java 6 yet. We shall have to see.&lt;/p&gt;
&lt;p&gt;One interesting question is whether you'd unit test that all the attributes were there appropriately. I guess it depends on the nature of the project, and just how thoroughly you want to unit test. It wouldn't add any coverage, and would be hard to exhaustively test in real life, but the tests &lt;em&gt;would&lt;/em&gt; be proving something...&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=625991" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Wacky+Ideas/default.aspx">Wacky Ideas</category></item><item><title>Wacky Ideas 2: Class interfaces</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/02/28/wacky-ideas-2-class-interfaces.aspx</link><pubDate>Wed, 28 Feb 2007 10:38:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:625340</guid><dc:creator>skeet</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=625340</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=625340</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/02/28/wacky-ideas-2-class-interfaces.aspx#comments</comments><description>&lt;p&gt;(Disclaimer: I'm 99% sure I've heard someone smarter than me talking about this before, so it's definitely not original. I thought it worth pursuing though.)&lt;/p&gt; &lt;p&gt;One of the things I love about Java and C# over C/C++ is the lack of .h files. Getting everything in the right place, only doing the right things in the right files, and coping with bits being included twice etc is a complete pain, particularly if you only do it every so often rather than it being part of your everyday life.&lt;/p&gt; &lt;p&gt;Unfortunately, as I've become more interface-based, I've often found myself doing effectively the same thing. Java and C# make life a lot easier than C in this respect, of course, but it still means duplicating the method signatures etc. Often there's only one implementation of the interface - or at least one initial implementation - but separating it out as an interface gives a warm fuzzy feeling and makes stubbing/mocking easier for testing.&lt;/p&gt; &lt;p&gt;So, the basic idea here is to extract an interface &lt;em&gt;from&lt;/em&gt; a class definition. In the most basic form:&lt;/p&gt; &lt;table class="code"&gt;  &lt;tr&gt; &lt;td&gt;&lt;pre&gt;&lt;span class="ReferenceType"&gt;class&lt;/span&gt; &lt;span class="ReferenceType"&gt;interface&lt;/span&gt; Sample
{
    &lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; ThisIsPartOfTheInterface()
    {
    }
    
    &lt;span class="Modifier"&gt;public&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; SoIsThis()
    {
    }
    
    &lt;span class="Modifier"&gt;protected&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; NotIncluded()
    {
    }
    
    &lt;span class="Modifier"&gt;private&lt;/span&gt; &lt;span class="ValueType"&gt;void&lt;/span&gt; AlsoNotIncluded()
    {
    }
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;So the &lt;em&gt;interface&lt;/em&gt; &lt;code&gt;Sample&lt;/code&gt; just has &lt;code&gt;ThisIsPartOfTheInterface&lt;/code&gt; and &lt;code&gt;SoIsThis&lt;/code&gt; even though the &lt;em&gt;class&lt;/em&gt; &lt;code&gt;Sample&lt;/code&gt; has the extra methods.&lt;/p&gt;
&lt;p&gt;Now, I can see a lot of cases where you would only want &lt;em&gt;part&lt;/em&gt; of the public API of the class to&amp;nbsp;contribute to the interface - particularly if you've got properties etc which are meant to be used from an Inversion of Control framework. This could either be done with cunning keyword use, or (to make fewer syntax changes) a new attribute could be introduced which could decorate each member you wanted to exclude (or possibly include, if you could make the default "exclude" with a class-level attribute).&lt;/p&gt;
&lt;p&gt;So far, so good - but now we've got two types with the same name. What happens when the compiler runs across one of the types? Well, here's the list of uses I can think of, and what they should do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Variable declaration: Use the interface 
&lt;li&gt;Construction: Sse the class 
&lt;li&gt;Array declaration/construction: Use the interface (I think) 
&lt;li&gt;&lt;code&gt;typeof&lt;/code&gt;: Tricky. Not sure. (Note that in Java, we could use &lt;code&gt;Sample.class&lt;/code&gt; and &lt;code&gt;Sample.interface&lt;/code&gt; to differentiate.) 
&lt;li&gt;Type derivation: Not sure. Possibly make it explicit: "&lt;code&gt;DerivedSample : class Sample&lt;/code&gt;" or "&lt;code&gt;DerivedSample : interface Sample&lt;/code&gt;" 
&lt;li&gt;Generics: I think this would depend on the earlier "not sure" answers, and would almost certainly be complicated&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;As an example, the line of code "&lt;code&gt;Sample x = new Sample();&lt;/code&gt;" would declare a variable &lt;code&gt;x&lt;/code&gt; of the interface type, but create an instance of the concrete class to be its initial value.&lt;/p&gt;
&lt;p&gt;So, it's not exactly straightforward. It would also violate .NET naming conventions. Would it be worth it, over just using an "Extract Interface" refactoring? My gut feeling is that there's something genuinely useful in here, but the complications do &lt;em&gt;seem&lt;/em&gt; to overwhelm the advantages.&lt;/p&gt;
&lt;p&gt;Perhaps the answer is not to try to have two types with the same name (which is where the complications arise) but to be able to explicitly say "I'm declaring interface &lt;code&gt;ISample&lt;/code&gt; and implementing it in &lt;code&gt;Sample&lt;/code&gt;" both within the same file. At that point it may be unintuitive to get to the declaration of &lt;code&gt;ISample&lt;/code&gt;, and seeing &lt;em&gt;just&lt;/em&gt; the members of it isn't straightforward either.&lt;/p&gt;
&lt;p&gt;Is this a case where repeating yourself is fundamentally necessary, or is there yet another way of getting round things that I'm missing?&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=625340" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Wacky+Ideas/default.aspx">Wacky Ideas</category></item><item><title>Wacky Ideas 1: Inheritance is dead, long live mix-ins!</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/02/27/wacky-ideas-1-inheritance-is-dead-long-live-mix-ins.aspx</link><pubDate>Tue, 27 Feb 2007 20:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:623385</guid><dc:creator>skeet</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=623385</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=623385</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/02/27/wacky-ideas-1-inheritance-is-dead-long-live-mix-ins.aspx#comments</comments><description>
&lt;p&gt;(Warning: I've just looked up &lt;a href="http://en.wikipedia.org/wiki/Mixin"&gt;"mix-in" on Wikipedia&lt;/a&gt; and their definition isn't quite what I'm used to. Apologies if I'm using the wrong terminology. What I think of as a mix-in is a proxy object which is used to do a lot of the work the class doing the mixing says it does, but preferably with language/platform support.)&lt;/p&gt;
 
&lt;p&gt;I've &lt;a href="http://msmvps.com/blogs/jon.skeet/archive/2006/03/04/inheritancetax.aspx"&gt;blogged before&lt;/a&gt; about my mixed feelings about inheritance. It's very useful at times, but the penalty is usually very high, and if you're going to write a class to be derived from, you need to think (and document) about an awful lot of things. So, how about this: we kill of inheritance, but make mix-ins really easy to write. Oh, and I'll assume good support for closures as well, as a lot can be done with the Strategy Pattern via closures which would otherwise often be done with inheritance.&lt;/p&gt;
 
&lt;p&gt;So, let's make up some syntax, and start off with an example from the newsgroups. The poster wanted to derive from &lt;code&gt;Dictionary&amp;lt;K,V&amp;gt;&lt;/code&gt; and override the &lt;code&gt;Add&lt;/code&gt; method to do something else as well as the normal behaviour. Unfortunately, the &lt;code&gt;Add&lt;/code&gt; method isn't virtual. One poster suggested hiding the &lt;code&gt;Add&lt;/code&gt; method with a new one - a solution I don't like, because it's so easy for someone to break encapsulation by using an instance as a plain &lt;code&gt;Dictionary&amp;lt;K,V&amp;gt;&lt;/code&gt;. I suggested re-implementing &lt;code&gt;IDictionary&amp;lt;K,V&amp;gt;&lt;/code&gt;, having a private instance of &lt;code&gt;Dictionary&amp;lt;K,V&amp;gt;&lt;/code&gt; and making each method just call the corresponding one on that, doing extra work where necessary.&lt;/p&gt;
 
&lt;p&gt;Unfortunately, that's a bit ugly, and for interfaces with lots of methods it can get terribly tedious. Instead, suppose we could do this:&lt;/p&gt;
 
&lt;table class="code"&gt;  
&lt;tr&gt; 
&lt;td&gt;
&lt;pre&gt;&lt;span class="Namespace"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br&gt;&lt;br&gt;&lt;span class="ReferenceType"&gt;class&lt;/span&gt; FunkyDictionary&amp;lt;K,V&amp;gt; : IDictionary&amp;lt;K,V&amp;gt;&lt;br&gt;{&lt;br&gt;    IDictionary&amp;lt;K,V&amp;gt; proxyDictionary &lt;span class="Modifier"&gt;proxies&lt;/span&gt; IDictionary&amp;lt;K,V&amp;gt;;&lt;br&gt;    &lt;br&gt;    &lt;span class="ValueType"&gt;void&lt;/span&gt; IDictionary&amp;lt;K,V&amp;gt;.Add(K key, V value)    &lt;br&gt;    {&lt;br&gt;        &lt;span class="InlineComment"&gt;// Do some other work here&lt;/span&gt;&lt;br&gt;        &lt;br&gt;        proxyDictionary.Add(key, value);&lt;br&gt;        &lt;br&gt;        &lt;span class="InlineComment"&gt;// And possibly some other work here too&lt;/span&gt;&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Now, that's a bit simpler. To be honest, that kind of thing would cover &lt;i&gt;most&lt;/i&gt; of what I use inheritance for. (Memo to self: write a tool which actually finds out how often I &lt;i&gt;do&lt;/i&gt; use inheritance, and where, rather than relying on memory and gut feelings.) The equivalent of having an abstract base class and overriding a single method would be fine, with a bit of care. The abstract class could still exist and claim to implement the interface - you just implement the "missing" method in the class which proxies all the rest of the calls.&lt;/p&gt;

&lt;p&gt;The reason it's important to have closures (or at least delegates with strong language support) is that sometimes you want a base class to be able to very deliberately call into the derived class, just for a few things. For those situations, delegates can be provided. It achieves the same kind of specialization as inheritance, but it makes it much clearer (in both the base class and the "derived" one) where the interactions are.&lt;/p&gt;

&lt;p&gt;One point of interest is that without any inheritance, we lose the benefits of a single inheritance tree - unless &lt;code&gt;object&lt;/code&gt; becomes a general "any reference", which is mostly what it's used for. Of course, there are a few methods on &lt;code&gt;System.Object&lt;/code&gt; itself which we'd lose. Let's look at them. (Java equivalents aren't specified, but Java-only ones are): 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ToString&lt;/code&gt;: Not often terribly useful unless it's been overridden anyway 
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GetHashCode/Equals&lt;/code&gt;: Over time I've been considering that it may have been a mistake to make these generally available anyway; when they're not overridden they tend to behave very differently to when they are. Wrapping the existing behaviour wouldn't be too hard when wanted, but otherwise make people use &lt;code&gt;IEquatable&amp;lt;T&amp;gt;&lt;/code&gt; or the like 
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GetType&lt;/code&gt;: This is trickier. It's clearly a pretty fundamental kind of call which the CLR will have to deal with itself - would making it a static (natively implemented) method which took an &lt;code&gt;object&lt;/code&gt; argument be much worse? 
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;MemberwiseClone&lt;/code&gt;: This feels "systemy" in the same way as &lt;code&gt;GetType&lt;/code&gt;. Could something be done such that you could only pass in "&lt;code&gt;this&lt;/code&gt;"? Not a terribly easy one, unless I'm missing something. 
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;finalize&lt;/code&gt; (Java): This could easily be handled in a different manner, similar to how .NET does. 
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;wait/notify/notifyAll&lt;/code&gt; (Java): These should never have been methods on &lt;code&gt;java.lang.Object&lt;/code&gt; in the first place. .NET is a bit better with the static methods on the &lt;code&gt;Monitor&lt;/code&gt; class, but we should have specific classes to use for synchronization. Anyway, that's a matter I've &lt;a href="http://pobox.com/%7Eskeet/csharp/miscutil/usage/locking.html"&gt;ranted about elsewhere&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;What are the performance penalties of all of this? No idea. Because we'd be using interfaces instead of concrete classes a lot of the time, there'd still be member lookup even if there aren't any virtual methods within the classes themselves. Somehow I don't think that performance will be the reason this idea is viewed as a non-starter!&lt;/p&gt;

&lt;p&gt;Of course, all of this mix-in business relies on having an interface for everything you want to use polymorphically. That can be a bit of a pain, and it's the subject of the next article in this series.&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=623385" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Wacky+Ideas/default.aspx">Wacky Ideas</category></item><item><title>What would make a good Java book?</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/02/14/what-would-make-a-good-java-book.aspx</link><pubDate>Wed, 14 Feb 2007 20:25:03 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:579773</guid><dc:creator>skeet</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=579773</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=579773</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/02/14/what-would-make-a-good-java-book.aspx#comments</comments><description>&lt;p&gt;So, Groovy in Action has been out for a little while, and I'm missing it - or rather, book writing. I'd like my next project to be a solo effort, almost certainly on Java. However, I'm interested in hearing what you good folks think would make a good Java book. I've got some ideas myself, but I'd rather hear unprejudiced opinions first. (I may be soliciting more feedback at a later date, of course.) So, shoot - what would you like me to write about?&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=579773" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/General/default.aspx">General</category></item><item><title>Groovy 1.0 released</title><link>http://msmvps.com/blogs/jon_skeet/archive/2007/01/03/groovy-1-0-released.aspx</link><pubDate>Wed, 03 Jan 2007 19:19:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:467223</guid><dc:creator>skeet</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=467223</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=467223</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2007/01/03/groovy-1-0-released.aspx#comments</comments><description>Groovy 1.0 has finally been released, and is available for download from the&amp;nbsp;&lt;a href="http://groovy.codehaus.org"&gt;Groovy home page&lt;/a&gt;.  
&lt;p&gt;For those of you who didn't read my &lt;a href="http://msmvps.com/blogs/jon.skeet/archive/2006/04/20/groovy.aspx"&gt;last blog post&lt;/a&gt; on it, Groovy is a dynamic language which runs on the Java platform and integrates very nicely with Java itself.&lt;/p&gt;
 
&lt;p&gt;What I haven't advertised on this blog until now is that a month or so after starting with Groovy, I became involved in the &lt;a href="http://www.amazon.com/Groovy-Action-Dierk-Koenig/dp/1932394842/sr=8-1/qid=1167851817/ref=pd_bbs_sr_1/105-8671831-3555646"&gt;Groovy in Action&lt;/a&gt;&amp;nbsp;book. I won't claim that I wrote a lot of it - more polishing and adding some introductory material, really. I'm still extremely proud of it, however, and obviously I hope it'll sell bucket-loads.&lt;/p&gt;
 
&lt;p&gt;So, if you haven't played with Groovy yet, now's a very good time to start: download it, have a bit of a play, and then buy the book!&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=467223" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category></item><item><title>Everything old is new again</title><link>http://msmvps.com/blogs/jon_skeet/archive/2006/12/13/everything-old-is-new-again.aspx</link><pubDate>Wed, 13 Dec 2006 23:46:10 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:419369</guid><dc:creator>skeet</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/rsscomments.aspx?PostID=419369</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/jon_skeet/commentapi.aspx?PostID=419369</wfw:comment><comments>http://msmvps.com/blogs/jon_skeet/archive/2006/12/13/everything-old-is-new-again.aspx#comments</comments><description>&lt;p&gt;I feel I'm too young to be making this kind of statement, but the sense of deja vu I get when reading about the layouts in WPF makes me nearly laugh out loud. Of all the things I can remember about Java 1.0 (this was before any number of things we take for granted now) I know that LayoutManagers exist - including the insanely hard to use GridBagLayout. Fortunately I learned over time that it wasn't always the most appropriate manager (far from it) but it &lt;em&gt;was&lt;/em&gt; powerful.&lt;/p&gt; &lt;p&gt;Ever since I started using .NET I've been annoyed at WinForms' lack of layout management facilities. I'm pretty sure that when I complained about this to Chris Anderson once he said that it's all there really, but just not exposed very well. Hmm. I've tried and lost patience a few times - I suspect there are ways of sorting it all out, but it's not exactly straightforward.&lt;/p&gt; &lt;p&gt;Fortunately it all changes with WPF, which not only has various layout managers (not sure whether there's anything like Java 1.4's SpringLayout, which seemed useful last time I looked at it) but also makes them relatively easy to use with XAML. No more GridBagConstraints messes! Hurrah!&lt;/p&gt; &lt;p&gt;Anyway, it's good to see that .NET 3.0 has caught up with Java 1.0 :) (And no, I'm not under the impression that Java invented the concept of layout managers. It just happens to be the first environment I used them in.)&lt;/p&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=419369" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/jon_skeet/archive/tags/Java/default.aspx">Java</category></item></channel></rss>