Predicting future with F# and Azure Machine Learning

Earlier this year I blogged about StockEstimator – my side project for predicting future stock prices. Recently in addition to F# module, which estimates future prices, I added Web Service that takes advantage of Azure Machine Learning to do the same much faster.

Last month I talked about my project at .NET Developers Association Meetup in Redmond and in Seattle. I streamed both session with YouTube live, and recordings are already available:

Both videos cover the same topics. Not sure, which one is better. However, there was one gentleman who went to both my talks and he said that the second one was better 🙂

In both presentations I do a quick intro to F#, an overview of Machine Learning, and how I took advantage of both to predict future stock prices.

If you are interested in F# I recommend you to check my Getting started with F#.

Presentation slides are available here (you can find there a lot of references to materials about F#, Machine Learning and Azure Machine Learning).

StockEstimator project is open source and available on github.

I’m not going to stop here. As you can see on my slides, and at the end of my presentations I have future plans to evolve this overnight project 🙂

Getting started with Xamarin in 2016


Xamarin is a cross-platform mobile development framework that allows you to build native mobile applications with C# and share code between them. There are two approaches:

  • native Xamarin – write native UI code in C# (views cannot be shared, business logic can be shared)
  • Xamarin.Forms – write shared UI in XAML (native controls are being generated, and business logic can be shared as well)

Xamarin vs Xamarin.Forms

The beauty of the first approach is ability to take advantage of Swift (iOS) or Java (Android) code samples, documentation, and community support. Swift/Java code can be easily translated into C#. In Xamarin.iOS app you have storyboards, ViewControllers and everything else you know from native iOS development. Similarly in Xamarin.Android – there are activities, fragments, action bars etc.

Xamarin.Forms on the other hand allows you to build apps faster. It’s very good fit for business applications.

Which approach should you choose? Ask StackOverflow.

Resources to get started

The great way to get started with Xamarin is Xamarin University. You can also find variety of Xamarin courses at Pluralsight. I especially recommend Building Your First Xamarin.iOS App from Start to StoreBuilding Your First Xamarin.Android App from Start to Store, and Introduction to Xamarin.Forms.

Friend of mine, James Montemagno (Developer Evangelist at Xamarin), runs video series Motz Codes Live where he explores different areas of Xamarin: from internals of MVVM, through Xamarin Inspector, to using Azure as backend for Xamarin mobile apps. You can also find a bunch of his videos from variety of conferences on youtube.

Additionally, there is a bunch of guides, recipes, and samples at Xamarin website. The official documentation is also a good source of knowledge.

Many of you were asking about Xamarin.Forms on reddit. A lot has been changed in this area as well. Check out the latest, greatest Xamarin.Forms update from James on .NET Rocks:

Code sharing strategies

One of the main advantages of Xamarin is code sharing. There are two ways to share code across platforms:

  • Portable Class Library (PCL) – produces separated .dll
  • Shared Project – compiled into one assembly with platform specific projects (you can think about files in shared projects as they all are present in all platform specific projects)

Most important differences:

  • PCL can have referenced libraries, while shared project cannot.
  • When we want to test shared code then in PCL case it is enough to reference PCL project only in the test project, while shared project requires additionally to add reference for all references that are being used by Shared Project.
  • You cannot have platform specific code in PCL, while shared project allows that using compiler directives.

You can learn more about code sharing here.

Two apps – two approaches

A few months ago I created two mobile apps with Xamarin, for 3 platforms (iOS, Android, UWP) and published them to 3 stores (App Store, Google Play, Windows Store):

  • Shopping Pad – smart shopping list that allows you not only to create a shopping list, but also remembers items that you have purchased in the past, how often they have been purchased, and based on that suggests items for your next grocery store trip.
  • Bread Crumbs – enables you to save your current location, and you can navigate to it later on (useful if you are in the new city, and you want to comeback to some place that you are “currently at”)

In Shopping Pad I used Portable Class Library to share code between platforms. In Bread Crumbs – Shared Project. I used SQLite for persistence in both apps, and the only difference I experienced was in creating SQLite connections. In PCL you need to create connection on “platform project” (you cannot do it from PCL). Shared Project allows you to use conditional compilation, and instantiate connection(s) in one file (using compiler directives).

I created unit tests (with xUnit) for Shopping Pad, and I was able to test entire app logic (for 3 platforms!) with only one test project. No platform specific code. Awesome!

Many times when I was looking for a solution to particular problem, I was able to reuse native iOS (Objective-C/Swift) or Android (Java) code samples, and translate them into C#.

Even for these two, small apps, shared code reuse was significant during development process. Especially in keeping consistency across platforms.

Both apps are available on App Store, Google Play, and Windows Store (Shopping Pad, Bread Crumbs).

Tips & Tricks

The struggle you may (and you probably will) experience at the beginning is platform setup. I recommend you to use Visual Studio simulators for Android (with Hyper-V) – they are faster. You need to have XCode installed on your Mac in order to run iOS apps built with Xamarin.

I develop Xamarin apps with Visual Studio on my ThinkPad X1, and use Mac only as host for running iOS apps. Some people run Windows on Mac with Parallels. Others use Xamarin Studio for iOS and Android, and switch to Windows only for UWP development. This will minimize the number of configuration issues, but will also give you worse development experience. I find Visual Studio much nicer for C#, and also for Xamarin development.

Xamarin – Windows Setup guide and Xamarin – Mac OS X Setup guide can help you get through configuration process. There is also fresh post from James about Setting Up Xamarin on Surface Book.

During mobile apps development with Xamarin you will encounter some problems that will not occur when developing pure native apps with Swift and Java. To save you some time, here are the list of a few of typical problems, together with solutions:

  • Problem: connecting with iOS host sometimes will not work. Solution: update your Mac (and XCode), update Xamarin plugin for Visual Studio, make sure your XCode path in Visual Studio settings is correct, and restart both machines. If it does not help check other solutions here.
  • Problem: iOS simulators not visible in Visual Studio. Solution: link.
  • Problem: Error: “Failed to add reference to ‘System.Collections’. Please make sure that it is in the Global Assembly Cache.”. Solution: add, manually, Droid/iOS dlls to references.
  • Problem: free provisioning Xamarin.iOS app. Solution: this guide.
  • Generic solution for many problems: restart Visual Studio (seriously, I’ve seen many StackOverflow questions where somebody was wondering why something does not work, and then “oh…after restarting Visual Studio it started working”).

One, not Xamarin specific tip: if want to have relations in SQLite database? Use SQLite-Net Extensions.

Publishing apps to stores

Android – bananas! Seconds for auto-validation, and ~3 hours to the store. I didn’t encounter any problems except copyrights for Bread Crumbs app icon, which I had to change. It was automatically detected! Impressive! This guide is more than enough to guide you through the process.

iOS – ~20 minutes for auto-validation, and ~4(!) days to the store. You can check current wait times here. Creating app bundle might be a little bit challenging. I was able to figure it out with Xamarin guide and this gist (I recommend option 2).

Windows Store – ~3h for auto-validation, and ~1 day to the store. I had my apps rejected, despite the fact that they were working on Windows machine, and on Windows Phone Device (Lumia 920). There were 2 issues:

  1. Referencing incorrect SQLite assembly: “SQLite for Universal App Platform” instead of “SQLite for Universal Windows Platform”.
  2. I didn’t test apps with with .NET Native (Project properties > Build > Compile with .NET Native Tool Chain), and one app was crashing during verification process. After debugging with .NET Native I was able to repro, diagnose and fix the problem.


Xamarin is not only sunshine and rainbows. You will have problems you wouldn’t when developing native apps, but also – you do not have some problems you would have when developing native apps. Check discussion about pros and cons of using Xamarin at Hacker News: Some thoughts after (almost) a year of real Xamarin use.

Be aware that there are also other cross-platform mobile frameworks, e.g., Apache CordovaReact Native, or NativeScript .

Since this year, Xamarin is free for Students, OSS projects and small teams (up to 5 people). You can use Visual Studio (including free Visual Studio Community Edition) or free Xamarin Studio Community Edition. That means – now you can use Xamarin for FREE!

Happy development!

Let me know in comments if you have any questions about developing apps with Xamarin!

dotNetConfPL – the second edition

dotNetConfPL - 2nd edition

The first edition of dotNetConfPL was pretty successful, and together with Michal and Pawel we decided to do a second edition. This conference is in Polish language, which makes it unique, because there are no other online conference like that in Poland.

This year talks looks promising as well. Maciej Aniserowicz prepared second part of his talk about unit tests from the last year, Filip Wojcieszyn will talk about the hottest thing in this year: Roslyn. Jakub Gutkowski prepared a talk about cooperation of MVC in client and server side. Maciej Grabek proposed a talk about BDD, which is getting more and more popular in .NET World. Michał Łusiak (from tretton37) will talk about F#. This year, we have a women speaker! Barbara Fusińska will talk about Aspect-Oriented Programming. Another new thing is a non-technical talk: Patryk Góralowski prepared a talk with mysterious title: Talent for 2 dolars!

I really can’t wait! All talks sounds very interesting. Remember to buy pizza and beer, and join us on On Air, this Saturday, October 18, 3PM (UTC+01:00, Warsaw Time Zone).

Find out more about talks and speakers.

This year we have 6 ReSharper licenses, and 3 NCrunch licenses to give away. Additionally, Filip Wojcieszyn volunteered to give away one copy of his book: ASP.NET Web API 2 Recipes: A Problem-Solution Approach. To join the raffle, register your attendance!

See you at the conference!

C# in Nutshell

C# 5.0 in a Nutshell: The Definitive Reference

C# 5.0 in a Nutshell is a great reference book about C#. Furthermore, it is worth to read it from the beginning to the end, to understand how C# works and to get familiar with the language features (can be used in the future as a reference). This book describes many features, which I have never used (after over 4 years programming in C#) like some XML serializers, COM interoperability or advanced threading/tasking techniques. Now, I know about them and where to look if needed.

This book is rather for experienced C# programmers. I do not recommend it as “first C# book”. It has a lot of examples, but the structure is rather encyclopedia style, than discovering the language from the basics. For beginner I would recommend Sams Teach Yourself Visual C# 2010 in 24 Hours.

C# in Nutshell has 1064 pages! Although it takes a while to read, it is worth your time if you think seriously about becoming good C# programmer. There are very detailed overviews and analysis of the language, supported by examples. If you do not want to spend time reading entire book, I recommend to use it as a reference and start learning about concrete feature, which you need at the time, from specific chapter in this book.

Why we read

How top 10 programming languages work

TIOBE index: July 2014

I am programming for more than 10 years. I realized that, when I found my first, personal home page (written in PHP) on my hard drive. Some files have last modification date: May 2003. Since that time I was working (or playing) with 9 of top 10 programming language from TIOBE Index list. As I mentioned, I started with PHP, then I learnt a little bit JavaScript (to create fancy menus or ‘secret pages’ on my website). In high school I started learning C++. At the University I learnt C, more C++ and Java. Then I learnt C# on my own, and it is still my favorite language. Along with C# I learnt ASP.NET and T-SQL (to be able to create websites with databases). I also learnt Python and Objective-C. Former became useful when I started my Research Assistant Job.

More experience I gain, more interested I am in how things work underneath the code level. In this post I want to provide short description of the Top 10 programming languages (by TIOBE Index), how they work and their super short history.


Interpreted language created by Rasmus Lerdorf. Originally, collection of Perl scripts, rewritten to C for performance reasons, ability to work with web-forms and communicate with databases. Most popular interpreter: Zend Engine. Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine. Facebook developed two PHP interpreters: HipHop (transforms the PHP scripts into C++ code and then compiles) and HipHop Virtual Machine (converts PHP into a high-level bytecode, which is then translated into x86-64 machine code dynamically). Recommended book: PHP and MySQL Web Development.


Dynamic, interpreted and prototype-based language. JavaScript is superset of ECMAScript standard. Usually used as part of web browser, but also in server-side (Node.js) or even for desktop and mobile application development. Current browsers perform just-in-time compilation. There are many JavaScript engines (interpreters): Rhino (written in Java), SpiderMonkey (written in C, first JS engine), V8 (written C++, by Google, used in Google Chrome), Chakra (performs JIT compilation on a separate CPU core, parallel to the web browser; created by Microsoft, used in Internet Explorer) etc. Recommended book: JavaScript: The Good Parts.


C is compiled, static type language created by Denis Ritchie. It influenced many other languages, e.g.: C++, C#, Java, JavaScript, Objective-C, Perl, PHP, Python, and even Unix’s C Shell. C++ is nearly a superset of C, with object oriented features inspired by Simula language, created by Bjarne Stroustrup. C and C++ are compiled to machine specific code, thus platform specific compiler is needed. Most popular compilers: GCC and Visual C++. C++ evolve, Modern C++ (currently C++ 11 and vNext: C++ 14) introduces: smart pointers, for each (range for), lambda functions and much more. Recommended book: Ivor Horton’s Beginning Visual C++ 2012The C Programming Language (by Brian Kernighan and Denis Ritchie)  used to be one of the most popular programming books ever.


C-based language created by James Gosling, which introduces automatic memory management by Garbage Collector. Java is compiled to bytecode (.class files), which runs on JVM (Java Virtual Machine). Its main design goal is “Write Once, Run Anywhere” (WORA). The same code can be compiled to the same bytecode on different machines. Then JVM (platform-specific) translates bytecode to particular machine code during run-time (Just-in-Time (JIT) compilation). Java applets can run in web browser. My personal recommendation for Java book is Hortsmann’s Core Java Volume I – Fundamentals and Volume II – Advanced Features. Well known Java book is Bruce Eckel’s Thinking in Java.


C# is Microsoft’s version of Java language created by Anders Hejlsberg. However, C# is closer to C++ in case of design and syntax. It is compiled to Intermediate Language (equivalent of bytecode in Java) and runs on Common Language Runtime (equivalent of JVM). C# also uses Garbage Collector. It has many features not existing in Java like rich native interoperability, query language (LINQ) or dynamic type. For more, check Comparison of C# and Java. Book for quick start: Sams Teach Yourself Visual C# 2010 in 24 Hours recommended by Eric Lippert (former developer of C# compiler). To dive in, check: C# 5.0 in a Nutshell: The Definitive Reference by Joseph Albahari and Ben Albahari, C# in Depth by Jon Skeet and CLR via C# by Jeffrey Richter.


Dynamic, interpreted language, created by Guido van Rossum. Most popular implementation: CPython (implemented in C). It compiles Python programs to intermediate code (.pyc files) and runs them on Virtual Machine. There are many other implementations, e.g. Jython, which compiles Python to Java Bytecode (.class files). Python is much more expressive language than C or Java. Some constructs, which needs 10 lines of C code or 3 lines of Java code, requires only 1 line in Python (check reverse words example in my post about Python). Python uses whitespace indentation, rather than curly braces or keywords, to delimit blocks. To get started I recommend Google’s Python Class (videos section) created by Nick Parlante. Other resources: Python tutorial and Dive into Python. You can also check my post Python jump start for more details.


Strict superset of C language with object-oriented capabilities inspired by Smalltalk. Every C program can be compiled by Objective-C compiler, C code can be included within Objective-C code. Most popular compilers: Clang and LLVM. Instead of calling methods (like in C++: obj->method(param)), messages to objects are being sent ([obj method:param]) and resolved at runtime (not at compile time like in C++). There is no Garbage Collector (which works at run-time) in Objective-C, but instead Automatic Reference Counting (compile-time feature) is used. Objective-C is the main programming language used by Apple for the OS X and iOS. However, in this year Apple announced plans to replace Objective-C with new Swift language. Resources to learn Objective-C can be found in my other post.


Declarative language for managing data held in a relational database management system (RDBMS). Created by Microsoft (for MS SQL Sever), T-SQL is an extension to SQL, which makes it Turing complete. It adds to SQL: procedural programming, local variables, functions for string and date processing, mathematics etc. and allows FROM clause in DELETE and UPDATE statements (which allows joins to be included). T-SQL (and SQL) query differs from program in such a way that they just tell what to do, not how to do that. Figuring out how to execute query is a role of query analyzer. Check Understanding how SQL Server executes a query.  To learn T-SQL, you should learn SQL first. Recommended tutorial: T-SQL Step by Step Course (video tutorial). Recommended books: Itzik Ben-Gan’s Microsoft SQL Server 2012 T-SQL Fundamentals and other his books.

(Visual) Basic (.NET)

Compiled language created by Microsoft. Compiles to native language or P-Code and uses the Microsoft C++ compiler to generate the executable. It derives from BASIC. Similar to Python: tabs and new lines are used to delimit blocks. VB (under Visual Studio) allows to create GUI using drag-and-drop technique. Last version (VB6) was released in 1998 and is abandoned in favor of VB.NET, which introduces many features (present also in C#), but still supported, even on Windows 8. Check Comparison of VB and VB.NET. Both (VB.NET and C#) run on the same run time (CLR). More details can be found here. Recommended tutorials to get started: Visual Basic Fundamentals: Development for Absolute Beginners by Bob Tabor and Visual Basic .NET Tutorials. Good reference is Visual Basic at Wikibooks. To get VB syntax highlighting in SublimeText, this package works.


I read about all 10 languages in Wikipedia before writing this post. I was surprised how much I could learn in 5-10 minutes reading. I don’t know why, but I feel much better now, when I refreshed and organized my knowledge. If you want to start learning about new programming language, I recommend you to read about it on Wikipedia first. Even more, read about all languages you are using now on Wikipedia as well. It gives you great, high-level overview. Now, Wikipedia will be my start point of research about “some new thing”.