Sunday, December 11, 2011

To be or not to be: A real app.

App is the new black, everyone talks about downloading, buying or selling apps, advertising about them is everywhere. The phone manufacturers have marketplaces and stores where phone users can get get those "apps".

We all know the term app is short from application. If this term was coined because was easier or because of a marketing strategy I don't know. But it is catchy, and so we will use it. But to be exact on term, int this case it means "mobile application". Otherwise any program would be an app right?

But exactly what is an "app",  really ? 

Third-party programs running on mobile is not something new at all, for  more than 10 years we had Java Midlets for almost any kind of cell phone, and I myself programmed for years for the Pocket PC and Windows Mobile, using either eVC, eVB, and later any .NET language like C# or VB.NET by using the .NET Compact Framework (.NET CF). And all those were actually apps. So, if is not new, why the boom now?

We can spot 2 main differences in today's app model, if we look back in time.

1) The deployment/installation mode.

Before the Apple App Store, Microsoft Zune Marketplace, Android's Market and similar came to exist, we used to manually put the programs in our phones, either by following a link that will do the "automatic" installation, running a setup program on the phone,  or from the desktop by using Active Sync, Windows Mobile Center or a similar tool. To be honest, it was not a good time for developers like me, because around 80% of the support questions I got were about "how to setup" the program on the device.

But we the new model to download and install apps, is even easier. And one of the best things of this model is that your app is right away available to million of users, also, as an end-user, you have access to a lot of apps on a single place, and by "a lot" I really mean that many. Just by googling around I see there are about:

  • 425,000 for iOS
  • 319,000 for Android
  • 43,000 for Windows Phone

The new model to distribute mobile applications comes with a drawback; for platforms like the iPhone/iPad and Windows Phone, you can't just run your program there, you need to put it on the store, and wait to "be accepted". So sometimes you could use a different approach like the Vatican personal did.

You might also have to pay a developer or publisher license, and give the store a cut (30% on Apple Store) and might be subject to more restrictions. But hey, now everyone can find our apps and we don't need to explain people HOW to install them.

2) Where the "real thing" happens?

The other important part was the fact, that "old apps" used to be executed entirely on the device, no matter if the program used a Internet connection to communicate with a server or a service somewhere. The programs always, did run on the device. Otherwise it was just a website fitted for the device.

That line is not "solid" anymore, the term app, no longer means you have a program on your device. Sometimes all your app does is to have a shortcut to the phone's browser that will open a website designed to match your device screen and browser capabilities. The good part is that regular users don't know that (and what is more important, they don't care about it) to use the app. The bad part of this is that you likely won't be able to use the app if you are offline. Of course some apps are a mix of both things.

There is also features like accessing devices camera(s), GPS, storage, sensors, memory storage, function keys and video acceleration that you most probably wont be able to use it from a web browser.

So, which one is a real app?

Just to be fair with technical terms, all of them are apps, from the end-user's point of view. For me, as a developer, a real app runs on the device, although it might use online services to store data on the cloud, or retrieve information (like maps or images). Otherwise, is just a shortcut to a web site that is well fit for the device, so here "web app" would be a proper term.

We also now got the new term "web app", although that would be material for another day.

Sunday, November 13, 2011

Git, git extensions and the case-sensitive thing...

As a general rule, I always use some kind of source control on all my projects. For the matter of fact I use GIT even when some people might find that weird, being myself a .NET developer .... But hey... GIT is in my opinion the best things out there when it comes to really good team development tools.

Then the second part is to use it with people online, for that is pretty good, and the final part is a good add-in for Visual Studio or a shell extension. I use Git-Extensions for all that and so far, except for the little problem I am going to explain here, I have no complains at all.

The problem:
Git branches are case-sensitive, so you can have "test" and "TEST" as different branches, and it will work fine if you use linux as a client. But when using git-extensions from Windows, and ran into a huge problem, where one of my friends was pushing code and I was not able to see it. She was uploading code to same branch but just with different casing. Is just a typing mistake, and then you get what it seems a huge problem in your hands. The Git-Extensions tool will even show you the to branches completely on UPPERCASE, so you wont have a chance at all, and picking any of them wont do any difference.

But it is not so difficult to fix it...

The solution:
Well, not pretty clean, but you can just delete the branch from, and mix branches in local git. How to delete the branch from git-hub?, easy after some googling:

git push MY_REMOTE :mybranch

and it worked fine! note that right after MY_REMOTE there is a space. that means something like,  take "nothing" from here and put it on the "mybranch" branch at "MY_REMOTE". Which is actually just deleting the branch. I would really love if they just add a command to just do that, or just add that option from the website itself.

The note: Careful with casing when using git on windows!

Saturday, September 10, 2011

Referencing Silverlight assemblies from non-SL projects

One of the best things about Silverlight is that represents a set of portable functionality that you can expect to run almost anywhere. Its similarity – although reduced – with WPF results in an amazing way to develop rich UIs and logic in Browser-side apps. And then results normal to want to reuse Silverlight code from our own .NET applications.

Reusing code from Silverlight assemblies is possible; the referencing process works well because Silverlight is a subset of .NET Framework, so that “by logic” should just work. Of course this is not all happiness, there are lot of limitations, but it will work as long as you keep yourself into the borders of certain assemblies like Mscorlib , System ,System.Core ,System.ComponentModel.Composition and Microsoft.VisualBasic , playing with others might give you mixed results.

Now the trick.

You SHOULD NOT add the reference to the Silverlight PROJECT.

You MUST add the reference to the Silverlight ASSEMBLY.

So let’s assume you have a scenario with 2 projects, SilverlightCommonTools.dll and WPFMain.exe, targeting Silverlight and WPF respectively.

1) Compile your Silverlight library project.
2) Add a reference to your WPF project, locate the compiled Silverlight dll on disk.
3) Code, compile and run!

NOTE: I have selected WPF as an example, but you can reuse your Silverlight code from any .NET code.

The Weird Errors
If you add a reference to the project in Visual Studio, instead of doing what I just said above, you might experience some very weird error messages. Specially some “Could not load assembly ‘some.asembly.dll’”. The “missing” assembly changes depending on your scenario. I got this one from a console app:

Could not load file or assembly 'System.Xml.Linq, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified

And got this one from an ASP.NET:

Could not load file or assembly 'System.Windows, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified

It is also important to notice that at least for me, project always compiled fine, the problem was at runtime. But don’t worry, as long as you remember to reference the DLL file directly instead of the project, you will be ok.

Wednesday, August 24, 2011

WCF, Data Contracts and Enums

With Windows Communication Foundation it is easy to create any kind of services, of course my opinion could be biased because I am a .net (mainly c#) developer, but I really find hard to believe that someone could disagree with such statement.

Of course there is a lot of know-how and trouble for beginners, specially trying to understand that WCF integrates all communication models we know (web, tcp, pipes, message queues) under one uniform paradigm.

But there are some moments where you hit a rock in the path; years ago I stumbled upon the following scenario:

I had a library “common.dll” that I used from both the client and the service. You might think this is not something you would do too often, and many people would say “that a client must not know anything about the service internals”. Well… that’s true, but this is not that case. It is just a situation where a client shares some business logic with the service.

And the problem?

Well, there is no problem with that configuration unless you have an enum in common.dll AND you tag it with the “DataContract” attribute. WCF allows you to do so, but I don’t recommend it. Usually when you have a common set of libraries referenced from both the service and the client, you mark the “reuse types in referenced assemblies” on Visual Studio, right? Look below:

Now, when you do that, and you have tagged an enum as a data contract you will get an error like this:

The solution? Well, do not attribute enums as Data Contracts if you reuse the assemblies. Here you can download a sample project with full source code so you can test this behavior. In order to check both situations, just add/remove the “DataContract” attribute from the MyEnum enum.

Thursday, August 11, 2011

Disable ENTER key on web pages with multiple forms

As an developer, you might find pretty common to have more than one form on a web page, sometimes you decided so, sometimes you just inherited a design and have to make it work. Let's just put the case where we have a form on the master page area, like a “search” or a “subscribe” button, and our inner page is a simple form with some fields to collect user information and submit it back to our site, like the image below.

Both forms will cause well-formed postbacks to the server if you click either on the search or the submit button, however if you are typing on a textbox and you hit ENTER, anything could happen. You might have inadvertently submitted form 1 instead of form 2 or vice versa.

Changing the default button of the page is simple and will help you if you know which button will be the one to respond to the ENTER key all the time. If you are using ASP.NET Just one line of code and you are done.

However, this might not work smoothly across different browsers and in some cases it turns out you might decide to completely disable the ENTER KEY on the page, how to do so? Well you can use some javascript and add it to your regular page or master page. See the fragment below:

And this should be enough, well, users will have to click on buttons, but at least they won’t submit the wrong data by mistake.

Monday, August 08, 2011

Before blogging about code....

The first thing that we need before blogging in a tech blog, is a way to display well-formatted code, and that means with all the syntax highlighting that our more beloved editors do. You can’t deny, after all, that reading code without colors, is not the same. So I checked a bit online and I managed to show code like this:

var total = (from u in ctx.Blogs
                     where u.Name.Contains("Blogger")
                     select u).Count();
        if (total > 1) return "I though blogger was the only one";

The best thing about this tool is that supports “brushes” to render a lot of languages, so we can have pieces of code in html, c#, c++, python or whatever we want, the setup is quite easy. I found many entries on internet but finally when to they integration page to really see it working.

So it seems we are ready to start blogging with source code!