Posts
69
Comments
233
Trackbacks
162
May 2006 Entries
Is F# Code easy to understand?
 Robert did write about my F#/C# article where he states that F# is as easy to learn as any other imperative language.
My final comment was:
Not all concepts of functional languages should be explored by Mort and Elvis since most of them are fairly complex to understand because functional languages are very picky (just like unix) who can be their friend and who not. If Einstein does write a F# program then only a true Einstein can maintain it. When the outsourced Mort and Elvis do change his code I am sure they will screw it up
He does argument that any complicated problem will result in more or less complex code which is difficult to understand. F# is much clearer and does require in many cases less code to write. This is true. But since F# and C# are different languages what is the difference anyway? Here is the catch: The F# language itself was designed to allow scientists to write complex algorithms with few lines of code. Humans with high mental capabilities see the immediate value of short and concise code that does not distract the reader with unnecessary syntactic language elements. This high value is at the same time it's Achilles heel. The language is only useful if the code is short and concise. If Einstein plays nice with Mort and Elvis he would comment the code. Every function should be described what its purpose is, what the input variables are and what the result is. But since there are so much more functions defined F# source code  this task of thorough documentation is not very practical. The other problem I have with F# is that there are so many implicit conventions you have to know. Where does the program execution start in a F# project with 50 files? Grep for main? Einsteins have no problems with syntax. All is clear to them. But Mort and Elvis will struggle with the syntax of a language where no explicit main, no explicit function end does exist. The C# syntax is perhaps bloated but at least it makes things much more explicit which is a good thing for the people who have to understand not your algorithm but the overall program structure. Nonetheless I will continue to explore F# because it does help to look at many problems from a different perspective where it does offer some remarkably easy solutions.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Tuesday, May 30, 2006 9:50 PM | Feedback (8)
Functional Programming with F#/C#
 After all this hype around C# 3.0 where we will get LINQ, lambda expressions and many other thing I thought that it would be useful to have a deeper look at functional programming languages like F#. At Microsoft quite many people are fond of the  Functional Programming style which did influence the design of C# 3.0. Many language architects there have  Haskell background which could explain the renaissance of these "old" concepts. So what's the deal with the functional approach? It does basically force you to think in a twisted way where the problem is straight solved by calling a function which does call another function and so on. Lets assume that you want to get the list of all members of all types which are contained in the assemblies that are currently loaded into your AppDomain (to look at the problem this way is the twisted part) you could write for example (in a functional language like F# this problem is very easy to solve):
// Assign allMembers the result of our "calculation"
let allMembers = System.AppDomain.CurrentDomain.GetAssemblies()
|> Array.to_list |> List.map (fun a -> a.GetTypes()) |> Array.concat
|> Array.to_list |> List.map (fun ty -> ty.GetMembers()) |> Array.concat

// Print them out
do Array.foreach allMembers ( fun memberInfo -> printf "\n%s" memberInfo.Name)
If you want to understand what this little code fragment really does and how it can be rewritten I recommend the post from Robert. A more comprehensible version in C# code would look like this:

        public List<MemberInfo> GetAllMembers()

        {

            Assembly [] allAssemblies = AppDomain.CurrentDomain.GetAssemblies();

            List<Type> allTypes = new List<Type>();

 

            foreach(Assembly assembly in allAssemblies)

            {

                allTypes.AddRange(assembly.GetTypes());

            }

 

            List<MemberInfo> allMembers = new List<MemberInfo>();

            foreach( Type t in allTypes )

            {

                allMembers.AddRange( t.GetMembers() );

            }

 

            return allMembers;

        }

Show more ...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Sunday, May 28, 2006 6:30 PM | Feedback (0)
Create Live Videos From Your Screen
Just recently I found a very good post how to create your own live demo video with Windows Media Encoder. John Howard did put on his blog  a useful post about the preferred settings for a good encoding experience. The main thing is to get the small videos of your computer screen is that you need to set as resolution 800x600 and 16 bit color depth. This is also a very good choice if you want to share your video in a meeting room with a beamer since most of them do not support more than 800x600. After digging a bit further I did find out that I have installed on my Windows XP PC a movie editing software with since Service Pack 2. It is called Movie Maker and resides in your Program Files directory. I have installed so many programs on my PC without knowing anything about it! Scary ... Armed with these tools it is really easy to create a live demo for some presentation which will never fail. No more: "Hm it worked always before". What is even cooler that now everybody can take the demo home and watch the steps at the time he/she does need it. You do not have to do brain surgery to remember what the heck this guy did tell you three weeks ago in his demo to get this thing working. Just open the video and watch it again. This could really become a new trend since it is so easy to create a video demo this way. I found it much easier to show it live than to write (nobody reads it anyway) documentation and later people call you just to ask the question which was answered at page 95 of your famous (though unread) document. Next time I will send them the link to the demo video. 
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Monday, May 08, 2006 8:28 PM | Feedback (0)
Enterprise Library Hands On Labs available
If you are not sure if the Enterprise Library for .NET 2.0 is the right thing for your application you should check out the new Hands on Labs. All six Application Blocks (Caching, Security, Cryptography, Data Access, Logging and Exceptions Handling) are shown in action with a detailed step for step introduction to get started with each of them. Another source of  information mainly configuration of the Enterprise Library can be found in the articles of my blog.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Posted On Sunday, May 07, 2006 8:38 PM | Feedback (1)