misc gadget, review, surface_pro_3

To be brutally honest I didn’t need this device when I bought it. I had started considering of buying one and, as usually I do, just ended up buying it just because it’s a shiny little toy that got my attention!

Since I forked over £1350 quids I had to justify it to myself to be able to sleep at nights. And my justification is that now that I have a fully mobile device I can work outside home quite often. In coffee shops, pubs and even in parks come spring. I think changing venues every now and then is a good idea to increase productivity and motivation. The main benefit of this device is that it’s running the exact OS my desktop is running meaning that I can use the exact same development environment on the go. I already had a 17” laptop which, in theory, allowed me to do that but it was a 5kg unwieldy beast with only 3-hour battery life so in practice it’s doomed to stay at home or office.

Laptop vs. tablet

First impressions

Another driving factor behind my decision was since it’s also a tablet I could use it as a comic book reader and it’s indeed a great reader. Compared to my good ol’ iPad 2 it provides a much better experience.

Performance-wise it’s working great so far. The model I got has an Intel Core i7 CPU with 8GB RAM and 256GB SSD which is close to my desktop. The desktop has 32GB RAM but it runs a lot of virtual machines so 8GB with no-VMs sucking a ton of memory is good enough for a decent development machine.

Tips, Pros and cons

  • Tip: Toggle function keys: Fn button + Caps Lock. Fn keys are used much more frequently than searching or changing screen brightness.
  • Pro: Lovely and crisp 12” screen with 2160 x 1440 resolution. Great for reading comic books.
  • Pro: Good performance for development
  • Pro: Type-cover feels sturdy with strong magnets
  • Con: Appears connected to network while it’s not after waking up from sleep (I guess it’s a Windows flaw rather than Surface)
  • Con: Only 1 USB port is generally not good enough especially when it’s generally occupied by the mouse
  • Con: The type-cover keyboard feels a bit flimsy at times. But still it’s good enough to write code and blogposts.
  • Con: Gets hot sometimes

Conclusion

All in all, I’m glad I bought this device. Once I manage to forget the price tag I’m sure I’ll enjoy it even more! The 12” screen is great for comic books and it becomes a full-blown development machine with the type-cover attached. People criticize the battery life but I think it’s adequate for a work laptop (at least compared to my Asus my laptop it lasts forever.

I’m writing this post in a coffee shop and I guess I’ll be around town more often and still be able to write code while travelling around :-)

Resources

dev visual_studio, web_api

In Visual Studio 2013 they decided to create one web project called ASP.NET Web Application to make it simpler as opposed to VS 2012 which had 7 different templates. I like this project wizard but I think there is a gap in the templates it provides when you want to start a Web API project. If you select Web API it comes with a full blown ASP.NET MVC website. If you select Empty you don’t get anything. I feel like there should be something in between: A functional Web API project with no overhead of the website.

Minimal Web API

The steps to achieve this are simple. I found this blog post that helped me to get what I wanted quickly.

For the sake of completeness the steps to create the minimal Web API project is as follows (I changed some of the steps to suit my needs):

  1. Create an Emptry ASP.NET Web Project
  2. Install Web API package via Nuget

     Install-Package Microsoft.AspNet.WebApi
    
  3. Add a Global Configuration Class and add the following line defining a default route to Application_Start method

     protected void Application_Start(object sender, EventArgs e)
     {
         GlobalConfiguration.Configuration.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
     }
    
  4. Add a controller from Web API Controller Class (v2.1) template and rename it to DefaultController. By default it comes with method implementations for GET/POST/PUT/DELETE HTTP verbs:

     public class DefaultController : ApiController
     {
         // GET: api/Entry
         public IEnumerable<string> Get()
         {
             return new string[] { "value1", "value2" };
         }
    
         // GET: api/Entry/5
         public string Get(int id)
         {
             return "value";
         }
    
         // POST: api/Entry
         public void Post([FromBody]string value)
         {
         }
    
         // PUT: api/Entry/5
         public void Put(int id, [FromBody]string value)
         {
         }
    
         // DELETE: api/Entry/5
         public void Delete(int id)
         {
         }
     }	
    
  5. In order to run properly the following references need to be deployed:
    • System.Net.Http.Formatting
    • System.Web.Http
    • System.Web.Http.WebHost

So change Copy Local to true in the properties window.

That’s all it takes to create a working Web API.

Templates in action

Now I have what I want but when I need a new Web API project I don’t want to start from scratch every time. Instead I’d rather use the nice and easy templating feature of Visual Studio. To create the template:

  1. Select File -> Export Template

    Visual Studio Project Template Wizard

  2. Leave “Project template” selected and click next. Give the template a name and description. It will automatically import the template to Visual Studio so leave the defaults.

    Visual Studio Project Template Wizard Otions

When you need to create a simple Web API you can use this template from now on by simply searching webapi in the templates:

Visual Studio Project Template Search

And when you create a new project based on this template (not surprisingly) you get something like this:

Visual Studio Project Template-Based Project Output

Creating the project from scratch was easy enough but using templates is even easier so why not use it!

Resources

dev fsharp

Moving on in the TryFSharp.org site today I finished the last two sections in the Advanced part.

Notes

  • Computational Expressions can be used to “alter the standard evaluation rule of the language and define sub-languages that model certain programming patterns”

    The reason we can alter the semantics of the language is the F# compiler rewrites (de-sugars) computation expressions before compiling.

    For example the code snippet below

      type Age =
      | PossiblyAlive of int
      | NotAlive
    	
      type AgeBuilder() =
          member this.Bind(x, f) =
              match x with
              | PossiblyAlive(x) when x >= 0 && x <= 120 -> f(x)
              | _ -> NotAlive
          member this.Delay(f) = f()
          member this.Return(x) = PossiblyAlive x
    	
      let age = new AgeBuilder()
    	
      let willBeThere a y =
        age { 
          let! current = PossiblyAlive a
          let! future = PossiblyAlive (y + a)
    	
          return future
        }
      willBeThere 38 150
    

    is de-sugared to this:

      let willBeThere2 a y =
        age.Delay(fun () -> 
          age.Bind(PossiblyAlive a, fun current ->
            age.Bind(PossiblyAlive (y+a), fun future ->
              age.Return(future))))
    	
      willBeThere2 38 80
    

    At this point this concept seems too complicated to sink my teeth into. TryFSharp.suggests further study of the following concepts to have a better understanding of computation expressions:

    • The sophisticated architecture of function calls that are generated by de-sugaring
    • Monads - the theory behind computational expressions
  • Quotations is a language feature “that enables you to generate and work with F# code expressions programmatically. This feature lets you generate an abstract syntax tree that represents F# code. The abstract syntax tree can then be traversed and processed according to the needs of your application. For example, you can use the tree to generate F# code or generate code in some other language.”

Conclusion

After dabbling 4 days in TryFSharp.org I think it’s time to move on. There are 4 more sections in the site but since I can only learn by building something on my own I’ll try to come up with a small project to use the basics. Otherwise it’s likely that all this information will be forgotten. It’s already very overwhelming and I need a small achievement to motivate myself.

So I leave TryFSharp.org at this point, for a while at least. Even though I don’t find the advanced topics well-explained it’s still a very nice resource to get started.

TryFSharp.org

Resources