Not that I don't trust them, but businesses need to make business decisions, and Microsoft's licensing decisions haven't always aligned with the small time/hobby developer. This isn't to say that they haven't changed immensely over the past few years (they have), or that they won't continue to make more open decisions in the future (they will).
I'm not here to persuade you into changing platforms, simply offering an alternative to those who are looking for one like I was. Personally, I just like the idea of being free from both costs and restrictions with technologies that I can use today. And if there's something out there that can make me just as productive, but it's free and open source, why not? I decided I'd never know unless I try.
Some of the nagging thoughts/issues I've had in the past include:
- What if my SQL Database outgrows 10 GB?
- Can I set up a test environment without worrying about licensing?
- If I need to spin up another instance, do I need more licenses?
- Wow, does a Windows install really require over 20 GB?
- How in the world can I automate [X]?
- IDE - Visual Studio is by far the best development experience on the market (IMO, of course). Even better now that it's free.
- Language - I like languages with a lot of compile time guarantees. The quicker I can find errors, the better. I also like the functional features (lambdas specifically) that come with C#.
- Toolbelt - I've been a .NET developer for so long that all the major hurdles (deployment, artifact repository, tools, quirks, etc) are a known quantity.
- Familiarity - I know the style, commonly used patterns, and the most popular libraries to get things done.
- An OO/functional language with static type guarantees
- Visual Studio
- ASP.NET MVC
- Entity Framework
- SQL Server
- SQL Database Project (.dbproj)
Note that I'll be writing these examples with a C# style to start out with, and then show you the common Scala style at the end.
Basic C# to Scala Examples
Scala is a statically typed language that runs on the JVM. On first glance, it kind of looks like a cross between Ruby and C#:
InheritanceIt supports class inheritance, just like C#. Note that the call to base is actually set directly on the base class declaration, since this is the default constructor:
InterfacesYou can declare an interface by using traits:
Static ClassesOne interesting feature of Scala is that there are no static classes. Instead, you would use an object, which is instantiated automatically at runtime as a singleton:
Objects can be accessed from anywhere by calling them by name (similar to a static class, you do not need to instantiate it):
PropertiesYou can also create properties with getters and setters:
Note that we don't actually need parenthesis on method declarations. This is up to you to determine each time you create a new member. You can think of omitting the parenthesis as if you are creating a getter property, and adding parenthesis as if it were a normal method. Very similar to C#.
No Return KeywordAnother important thing to note is that everything evaluates to a value in Scala. This basically means that everything has to return something - there is no void (returning a Unit is the equivalent of void). Since each method you write has to return something, it's redundant to write the "return" keyword at the bottom of each method.
String InterpolationSimilar to Ruby and C# 6.0, Scala has a really nice string interpolation feature:
Updating our StyleTying this all together, we can update the Person example to match the conventional Scala style:
Of course there's tons more to learn, but we'll get to that as we move onto Part 2: More Scala Concepts. Thanks for reading!
I'm currently accepting new clients and projects! If you need an experienced Software Developer, please contact me.