Making the Climb Part 2–Object-Oriented Programming in Scala

In Part 2 of this series we’re going to move into some of the object-oriented aspects of Scala. For a primer on what Scala is, and a quick primer on syntax, check out part 1. Let’s start with the built-in object structure Like C# and Java, Scala has a built-in object hierarchy, and a standard library full of goodies. Unlike Java and C#, Scala tackled the issue of reference types and value types head-on, so while the root type in the Scala type system is the Any type, there are two descendants of Any that come into play before any other type. The two are: AnyRef, and AnyVal. As you might guess AnyRef is the base type for all reference types (including types made available from Java), and AnyVal is the base type for all value types. This is a little bit like the class and struct type constraints in C#, only you can use these as variables. They can also be used to limit type parameters, but Scala Generics are going to have to get their own post. ...

14 August 2011 · 7 min

Making The Climb: Head-To-Head with Project Euler (questions #1 & #2)

I’m going to take a brief intermission in my Scala series, and show a head-to-head comparison of some code in Scala and C#. To do this, I’m going to go with the first and second problems from Project Euler. If your not familiar with the site, it’s a playground full of problems that are absolutely perfect for functional languages (cause they tend to be mathematical functions). So let’s get started with Question #1: ...

4 August 2011 · 5 min

Making the Climb: Chronicling the journey from C# to Scala

Hows that for a title, eh? Yeah, I know, not great, but there is only so much creativity I can manage in a day, and as you will soon find out my mind is busy with all kinds of new and interesting thing, so any spare neural pathways which may have one been useful for something like clever titles are now just too busy to be bothered. So what is this all about? Several months ago I had an interesting experience. One that I could almost compare to a religious experience, only not quite so….religious. It started with the most excellent book [Seven Languages in Seven Weeks](http://pragprog.com/book/btlang/seven-languages-in-seven-weeks) by Bruce Tate, from our good friends at the [Pragmatic Programmers](http://pragprog.com/). Now, I will admit that I’ve not actually read all of it…yet. The reason is that while I found the first several languages (Ruby, Io, and Prolog) interesting, and challenging, it was [Scala](http://www.scala-lang.org) that had a certain something that kept me wanting to know more. Mr. Tate actually didn’t care much for the syntax of Scala, and was rather pleased to move on to Erlang. Meanwhile I was off and running downloading Eclipse and the Scala IDE, looking at testing frameworks, online documentations, and what’s this? Android development with Scala!?!? I was hooked. What is Scala all about? 2003 - A drunken Martin Odersky sees a Reese’s Peanut Butter Cup ad featuring somebody’s peanut butter getting on somebody else’s chocolate and has an idea. He creates Scala, a language that unifies constructs from both object oriented and functional languages. This pisses off both groups and each promptly declares jihad. James Iry - A Brief, Incomplete, and Mostly Wrong History of Programming Languages ...

31 July 2011 · 9 min

Announcing the Duhking Library for .Net 3.5

If it walks like a giraffe and talks like a duck then what is it? Maybe a duhk? Who knows, but it certainly is not a duck. So if that is the case, then you can probably guess what the Duhking library is all about…or maybe you can’t. In terms of programming, Duck Typing refers to the ability of some languages to allow you to treat an object of one type as an object of a different type, provided the methods/properties needed exist on both objects. Statically typed languages are usually not very good at this sort of loosey-goosey type inference, which is why this behavior is typically restricted to languages with less stringent rules on typing. ...

17 June 2010 · 6 min

More CodeRush Awesomeness

On November 27th, a beta release of the 9.3 version of the Developer Express components, including CodeRush and Refactor Pro! was made available to subscribers. This release is pretty significant to me because it contains a major feature that I have been waiting for for a long time: A Unit Test Runner. There were some teasers released by Mark Miller a while back, which only made me want to get my hands on the tool that much more. My initial impressions are that it is very nice. It is similar to TestDriven.Net in that it provides context menu options to run tests at various levels of granularity (single test, file, project, and solution level) and includes a debug option. At this point it does not contain some of the additional coolness that TestDriven gives you like NCover/Team Coverage and TypeMock integration, but it does have the advantage of being extensible. I know it was extensible because Mr. Miller told me it was extensible (the title “The Extensible Unit Test Runner You’ve Been Waiting For” was a clue). I did not realize how extensible, however, until after I submitted a bug report to DevExpress. The bug I was reporting (the NUnit TestCase attributes were not recognized), it turns out, was already brought to the attention of the DX team by way of a forum post, and they had already planned on correcting it with the next 9.3 release, but I could have saved myself (and Vito on DevExpress team) some time by taking a peek at the source samples bundled with the 9.3 release. Yep, you guessed it, there with a shared source license were all of the test framework implementation projects. So this meant I could whip together my own temporary fix while I was waiting for the next release. It seemed like something that other folks might want to know about, so I thought I would share it here. ...

15 December 2009 · 5 min

Announcing CR_MoveFile: DxCore plug-in for moving files around in a solution

As of right about now, you should be able to mosey on over to the DxCore Community Plug-ins page, and grab a copy of CR_MoveFile. This is a plug-in I created primarily as a tool to aid in working in a TDD environment, but which certainly has uses for non-TDD applications. It does basically what the name suggests, it allows you to move a file from one directory in your solution/project structure to another, even one in a different project. I implemented this as a code provider (since it could change the functionality if you move the file from one project to another), so it will appear in the Code menu when you have the cursor somewhere within the beginning blocks of a file (“using” sections, namespace declaration, or class/interface/struct declarations). Once selected you are presented with a popup window which has a tree that represents your current solution structure, with your current directory highlighted. You can use the arrow keys to navigate the directories and choose a new home for your file. ...

7 December 2009 · 3 min

Getting a CodeRush: Inside a CodeRush CodeIssue

Anyone who has been around me for more than a few hours while coding, or who pays any attention to me on Twitter will know that I am a huge fan of CodeRush and Refactor Pro! from DevExpress. I consider these sorts of tools essential to getting the most out of your development environment, and I think CodeRush is one of the best tools available for a number of reasons, not the least of which is it’s extensibility. CodeRush is built on top of DxCore, which is a freely available library for building Visual Studio plug-ins (incidentally, DevExpress also have a free version of CodeRush called CodeRush XPress, which is built on the same platform). DxCore provides any developer who wants it access to the same tools that the folks at DevExpress have for building plug-ins and extensions on top of VisualStudio, and several developers (including yours truly) have done just that. ...

7 October 2009 · 13 min

Some code for sorting lists which may contain dependencies

I ran into this odd problem recently working with some Linq2SQL based persistence code. There is some code someone put together to commit a list of changed entities to the database as part of a single transaction, which simply iterates through the list and performs the appropriate action. The problem I was having was that I had an object referenced by another object that needed to be persisted first, otherwise there was a foreign key violation. To add to the strangeness there seemed to be some magic going on (most likely utilizing the INotifyPropertyChanged goodness), so that even if I tried to persist just my dependent object first, both were still showing up in the list, and always in exactly the wrong order. Now, I’m okay with magic. Magic makes a lot of things a lot easier. The problem arises whenever the magic is incomplete, and doesn’t follow through to take care of all of the operation. Its like someone comming up to you and saying “Pick A Card”, at which point you do, and put the card back, and they say “I know what your card was” and walking away. Not real convincing. This is what was going on here. There was the smarts to know that changes were being made to more than one entity, and there were even attributes to define what properties contained dependent objects, but no smarts to actually deal with a case when you would want to save more than one object in an object graph at a time. ...

18 September 2009 · 4 min

Review: Art of Unit Testing by Roy Osherove

I was pleased to find recently that Roy Osherove’s Art of Unit Testing was available on Safari. I have been following Roy’s blog for a while now, and was quite excited at the prospect of him writing a book on Unit Testing. It was only my personal cheapness that kept me from shelling out the $25 to get the E-Book version from Manning ahead of time. I have to say, now that I have read it, that it would have been well worth the money. Before I get too deep I want to provide some context for what I am about to say. ...

2 September 2009 · 7 min

Some (good?) string extension methods

So, to take a slightly different turn from my usual meta discussions of process, theory, and architecture, there have been several people who have offered up some examples of extension methods that they have found useful, now that .Net 3.5 is roaring along nicely. There are some collections of such utilities, like the Umbrella project, and some folks like Bill Wagner who have written books on the subject (okay, there are other things in there too), so I thought I might as well throw my hat into the ring as well. Specifically, there was this tweet from @elijahmanor a few days ago. It points to a positing which includes some extensions on string to convert from strings to value types (int, long, short, etc). I pointed out that in our current project we have distilled this down to a single extension method: To(). ...

22 February 2009 · 3 min