Archive for C# Coding

27 Jun 2012

Android for the Visual Studio C# developer

No Comments Android, C# Coding, Software Dev & Productivity

Last year, I started looking into learning Android development.  I’m a C# developer who spends most of his time in Visual Studio, so I had some trouble getting accustomed to it.  I’ve looked at a lot of ways to ease the transition into Android.  Here are some of my thoughts:

Mono For Android or Proper Android Java

After struggling with Eclipse, I started looking into Mono for Android.  I’m a C# developer, and I have to say that I felt a lot more at home in Visual Studio. I’ve also done very little Java development over the years.  I took a week-long course in 1999—but mostly don’t use it.

I found Mono For Android to be decent, but it’s not easy.  You still have to have learn how to use intents and activities and use the xml layouts that are expected.  I found myself trying to learn the Android architecture and how the Mono libraries work with it.

Here are my problems with Mono for Android:

1.  There is far less documentation than you would need.  If you get in a bind, not many people would be able to help you.

2.  It’s like learning VB.Net instead of C#.  At some point, you have to take the hit and relearn a few things.  Almost all of the example code you look at will be in Java.

3.  I can’t be 100% that it will perform well enough on the device.  There could be a performance hit.  And you need to include the mono runtime, so it would bloat the size of your apk.

4.  It costs $400.  This is fine if I’m asked to create an app by the end of the week by an employer.  But when learning for fun, it’s too high a price to pay.  Besides, compared to “free”, it’s too expensive.

So, I prefer to native.

PhoneGap

I did a lot of stuff with PhoneGap too.  I love coding in javascript and there is so much that can be done with HTML5.  I was able to quickly code a little app that fed off data from Toodledo.  For cross platform, I think this is ideal.  But if I want to take full advantage of the Android platform, I would need to do native.

Eclipse or IntelliJ IDEA

So, I struggled with Eclipse.  Even things like autocomplete were throwing me because I was hitting TAB instead of ENTER to accept the autocomplete suggestions.  It was messing me up.  When I went back to Visual Studio, it was messing that up too.  I hate having my flow upset like that.

The majority of tutorials for Android development are using Eclipse.  All of the Android tools are well integrated into it.

However, JetBrains has a Java IDE called IntelliJ Idea which is soooo much better for a Visual Studio user than Eclipse is.  Jetbrains also develop Resharper, so their shortcuts are very similar.  There is a community edition (free) available here.  I highly recommend it for Visual Studio developers moving to Android.

The only downside I see with IntelliJ Idea is that some tools like DDMS viewer are not integrated into the IDE.  To use them, you have to go to the tools folder of your Android sdk folder and start them manually.  But everything is there.

Windows Phone 7

I did some WP7 work last year.  It’s a nice platform and I loved writing code for it.  But the market share is too small.  I know one person who has a Windows phone.  I upgraded my phone this weekend, I looked at the Lumia—but went with the Galaxy S3.  Maybe one day Microsoft will advance in the phone arena, but I have sincere doubts. 

08 Dec 2011

I love coding for WP7

No Comments C# Coding

So, I’ve spent ages trying to learn to code on an Android.  I’ve read a few books.  I’ve got my dev environment all set up.  I’ve coded a few test apps and put them on my phone.  But the going is slow.  If I were a Java developer, I’d probably be all over it.

A friend asked me to do a quick Windows Phone 7 app and I could not believe how easy it was.  Since I’ve been working heavily with Silverlight for the past few years, I know most of the code already.  I had to do minimal reading to get a full app up and running.  It was was nice to work in Visual Studio again.  Using Resharper, I was flying through the code.

I only wish more people had Windows Phone 7. 

I would get a phone myself, but 3 things are holding me back currently:

  1. I don’t want to be one of 5 people in the UK with a Windows Phone 7.
  2. It’s not open, like Android is.  I would be at the mercy of the phone manufacturers for upgrades (like with an iPhone).
  3. It doesn’t have expandable memory (to my knowledge).
  4. My current contract isn’t up until April.

But it’s nice to be able to write apps so quickly (since I spent so much time learning the trivial details of Silverlight).  Maybe.

18 Oct 2011

The “View Source” belongs to me too.

No Comments ASP.Net, C# Coding

For me, the sign of a good web developer (or web application developer) is someone who can right-click a web page to view the source and tell you why he did things the way he did.  “I used this div to position this element over here, and used the unordered list for a sub-menu, . . . “

A bad web developer is someone who says “It looks fine in my browser” and “Well, I’m not a designer . . . “

One of the biggest crimes of ASP.net Web Forms was to strip HTML skills from new web developers.  They view the source of their code (in the browser—not Visual Studio) as gobbledy-gook.  And ASP.net ensures that it is.  It’s full of ViewState and control names like ctl_100_className_ctrlName which the developer didn’t put there.  It tried to remove the whole stateless-http challenges and make web development accessible to desktop developers.

I’m so very pleased every time I see a new site created with the Microsoft MVC Framework.  MVC is making up for the ASP.Net webform crimes.  Just like Ruby  on Rails or PHP (or classic ASP), it allows the developer to think about what gets sent from the web server to the browser.  When I do a site in MVC framework, I can view the source and recognize my own handy-work.  I can make full use of CSS3 and jQuery.  I know that everything in my user’s browser is something I put there intentionally.

CSS, Javascript, and HTML (along with images, flash movies, Silverlight, or other plugins) are the ingredients of any web application.  Server languages like ASP, PHP, and Ruby are only tools to deliver these ingredients to the browser in unique and creative ways.  A good web application developer (like a good chef) can look at his source and tell you exactly what everything does.  ASP.Net webforms are like ready-meals.  Everything is done for you, but you don’t really know everything that’s in it.

Now, don’t get me wrong, I’ve known some fantastic ASP.Net devs who build apps free of ViewState and server controls.  But I’ve worked with too many who could drag a control onto a web canvas, set a few properties, and call themselves web developers.

I recently worked on a DotNetNuke project where we customised a third-party component.  The page was not rendering as it should.  ViewSource gave me a bunch of ViewState and nested tables.   I knew of a 100 ways to get css to make the site look the way I wanted, but this wasn’t my source.  It wasn’t even the developer’s source—it was the clientIds of the server control.  Since I was struggling, a web guy (proper Mac-using, firebug-toting, standards-compliant, web guy) asked to see the source so he could suggest something.  When he saw the source, he was mortified.  I was embarrassed –“It’s not mine!  I didn’t write it.”  In the end, I hacked it with jQuery.  I didn’t have the sourcecode to modify it properly. 

The legacy of Web Forms lives on.  Sharepoint 2010 is full of it.  Young Microsoft developers (in the last 5 years or so) know nothing but how to use WebForms.  (An ASP.net dev told me a few years ago “But I don’t know html.”).  But, hopefully, one day we will get around this idea of creating tools that “do everything for you” for developers who should know to do it themselves.  Just like I wouldn’t create ready meals for people who call themselves chefs.

04 Aug 2011

DNN, Orchard, and Joomla–some thoughts

1 Comment C# Coding, Software Dev & Productivity

I’ve been looking at CMS systems a lot recently.  Here are some of my thoughts:

DotNetNuke

I’m using DotNetNuke for a contract right now.  Although it’s written in Asp.Net and I can code in that easily, it’s a pig to run.  Even version 6, which was released last week, seems sluggish when run in the browser (even on my local machine with 8gb ram). 

DNN is advanced—don’t get me wrong.  There is no lazy-ness there.  In fact, there is so much available in DNN, that it pains me that it runs so slowly.

It’s an okay platform.  But compared to MVC or PHP counterparts, the ASP.Net webforms are still far too slow and lack elegance.  DNN will always have that Asp.Net webform dependency hanging around its neck.

Orchard

Orchard is a new CMS which was started by Microsoft.  I fell in love with it last month.  It’s based on MVC3 with the razor engine.  It supports multiple sites, just like DNN.  There aren’t many extensions or themes, but it’s written in C# so I can easily create what I need.

But, then . . .

But then I looked at the page source after it has been rendered in the browser.  Although it doesn’t have a lot of ugly ViewState like DNN (and all other webform pages have), it does include a lot of stuff that I didn’t put there.  There is huge amount of javascript added which would at least triple the size of my source.  The beauty of MVC is that I have more control of the html—but Orchard adds a stunning amount of code.  Most of it is serialised model information—but I’m not sure why it is on the client.

This really bothers me because I spent a lot of time working with Orchard.  It is not easy to use as an Admin.  While DNN is simple and I could give it to any client to customise, you have to really study Orchard just to add a few things onto a page.  You can’t just add something to a sidebar, for example, you have to create a layer and add a shape, and add some code so it only shows when a page uses that layer or shape.  Really, it was ridiculously difficult.

So, Orchard adds too much to the source and is too difficult to use.  But, in terms of speed, it is very fast.

Joomla

Okay, Joomla is PHP.  I’ve done PHP projects for clients before, so I’m fine with that—but I prefer C#.  I looked at Joomla and Drupal just to see how they compare.

Joomla puts the .net CMS alternatives to shame.  It is easy to set up, the code is very current, and it delivers pages super-fast.  The admin interface is not as easy to use as DNN (in my opinion), but much easier than Orchard.  There are loads of themes and extensions available.  When I did a viewSource, all the html was what I expected it to be.

Why can’t the .net projects be this good?

 

One thing I hear a lot in my contracts are developers comparing .Net, PHP, and Java (and sometimes Rails).  DotNet developers always say .Net is better.  PHP and Java developers talk about how sluggish .Net is and how it is inferior because it requires being hosted on Windows (except for Mono—but who really uses that?).  The truth is, all these languages pretty much do the same thing—they deliver HTML to the browser.  You can write a site in any language and it wouldn’t matter.  I’ve seen .Net sites outperform PHP sites (but unfortunately, it is the other way around). 

I’ve looked at other .net CMS systems lately too (Umbraco, Sitefinity, etc) and didn’t like the look of those enough to even install.

I might start using Joomla.  Page speed is far more important than how easy it is to code.  Hopefully, someone will write a decent .Net CMS system one of these days.

02 Dec 2010

Looking forward to Silverlight 5

No Comments C# Coding, Software Dev & Productivity

So, I watched the Silverlight Firestarter keynote where some of the Silverlight 5 features were revealed and have to say that it all looks really good. 

There were some pretty impressive interfaces demo’d. 

I’m so tired of hearing how Microsoft is dumping Silverlight.  The keynote alleviated some of those fears, I hope.

The biggest benefit, I think, will be the ability to put breakpoints in xaml databinding.  Most of the Silverlight problems I have are trying to figure out if the INotifyPropertyChanged event was fired for an element in my gui. 

So, life will be easier . . . by the end of next year.

02 Nov 2010

I take back all the things I’ve said about Silverlight

No Comments C# Coding, Software Dev & Productivity

After my initial resistance to using Silverlight, I have to say that I have been using it heavily for the past month and am very impressed with it.  When I look at Silverlight as a web technology, I am amazed by the stuff you can do with it and how extensible it is.

My apprehension was due to web standards.  And I still have concerns here.  Microsoft had a big win when they got SL to work on Macs as well as Windows.  But the lack of a Linux version still bothers me (the Mono guys are working on this).  The biggest blight on the technology is lack of iPad support.

I like HTML and I feel comfortable with it.  When ASP.Net webforms were released 10 years ago, I felt Microsoft were trying to bring a Visual Basic-type development experience to the web.  I can’t tell you how many developers I’ve met who profess not to know html.  They only know the very basics of html and a bunch of tags like <asp:Button>.  With php, classic asp, and the new MVC framework, you have more control of how your page renders in different browsers because you wrote the code to do it.  I guess I’m a purist in this area.

But Silverlight is not html development.  It’s also not flash.  It’s more like writing a client application which runs on the desktop—but has to play safely in a web sandbox.  The rules are all different.  All calls back to the server are asynchronous and you can’t stop and wait for them.  Binding is very heavily used, and the code-behind works better than in ASP.Net because there are no postbacks required.

In the past month, I’ve really geeked out.  I spend most of my time thinking about the project I’m working on and how I can improve it.  I’m reading my fourth book on Silverlight in the evenings and spending the days coding away.  You might think that’s sad (it has been said to me), but I’m really enjoying it.  It won’t last forever, so you need to take full advantage of enthusiasm when you get it.

Anyway, I take back some of the things I said before about Silverlight. 

09 Feb 2010

The scary thing about Silverlight . . .

No Comments C# Coding, Software Dev & Productivity, Usability

The scary thing about Silverlight is that you are one security threat away from losing your clients.  One thing that I’ve thought a lot with the problems on IE lately is that people who wrote “Only-for-Internet-Explorer” websites did not give their users the option to switch browsers if they felt unsafe due to all the security flaw hype.

A little common sense and a knowledge of web standards and it’s easy to write HTML that will look good and be functional in all browsers.  Still, in my experience, too many developers are choosing a platform and sticking with it—most of the time that is IE.  It’s easier to test one browser, it’s easier to tell a user to use the browser that’s probably already installed on their pc.

Flash and Silverlight are different than HTML—they are runtimes which are allowed to run inside the browser—kind of like how Java applets used to be able to.  They are executables which run compiled functionality on your computer.  They are cross-browser—but not like html is cross-browser.  When I look at a Silverlight or Flash app on my pc, it’s always the same runtime working.  Silverlight is a few years old and really starting to look like Flash—allowing Microsoft developers like me to get more fancy and provide far better functionality for our users.  Silverlight runs on Windows and Mac, but has ignored the Linux landscape (there is an open-source Silverlight runtime called Moonlight being developed for that—but I consider it a snub).

In the world of web development, I think Flash and Silverlight are “cheating” at cross-platform compatibility.  Everyone has accepted Flash (except the iPhone/iPad), but the jury is still out on Silverlight.

Silverlight and Flash are great in that they move a lot of the processing to your computer and free up resources on the server from which they originate.  But they also increase the responsibilities of they client over the server.

Security flaws are found all the time.  We all scramble around and try to fix them when they come up.  As a software developer, I like the idea that I can apply a patch to a server and be done with it.  With client driven app, I need to make sure all of my users apply the patch (and do it in a way that lets them know that the app is safe—and not to panic).  Flash could bounce back from it (“You need it for Youtube, too. You should apply the patch”), but Silverlight is too new.

I’m often seduced by the cool things that Silverlight can do.  I’ve played around with it a lot and have written several small apps (including an animated Overpass ad on my blog), but I’m not ready to jump in head-first yet. 

31 Jul 2009

Some thoughts on the ASP.Net MVC Framework

No Comments Agile, C# Coding, Software Dev & Productivity

A few months ago, I got tired of ASP.Net.  I was tired of developers who depended on server-side controls, the Microsoft ajax implementations (as opposed to under-the-hood javascript ajax), excessive use of session and view state.  My preferred method of coding which relies more on the html than on the “runat=server” attribute, was considered old fashioned.

pics 006
Creative Commons License photo credit: paulb

So, I wanted to look at something else.  In my mind, Asp.net was getting too bloated and heavy.  I started learning Ruby on Rails.  RoR is a fantastic framework which integrates testability and maintainability.  Rails is the framework—Ruby is the language.  It’s easy to set up an Model View Controller site very quickly.  I love Rails, but I hate Ruby.  I had to lean how to do everything over again in Ruby.  It was like learning to speak a new language—even the simple things were hard.

Then, I looked at the ASP.net MVC framework that was released earlier this year.  The MVC framework is like Rails for ASP.  It keeps aspects of ASP.Net that I really like (like master pages and C#) and moves away from the bulky server-side, viewstate heavy, controls (like the DataGrid) that slow down ASP.Net performance.

My faith in ASP.Net is restored.  My brief foray into the hip and trendy world of Ruby development has given way to working on Microsoft code again.

I’ve been using the MVC framework in a few projects now.  I’ve started writing a Chinese Dictionary application (using the CEDict database) and am enjoying every minute of it.  I don’t know if I’ll every put this site live, but coding it is helping me learn the finer points of the framework.

There are some great MVC tutorials here:

http://www.asp.net/mvc/learn/

The best video tutorial (to start off with) is “Creating a Movie Database Application with ASP.NET MVC”.

05 Jul 2009

Nike+ API Revisited

1 Comment C# Coding, Running, Software Dev & Productivity

One of the highest traffic posts I get on this blog is the brief post on accessing the Nike+ API with C#. I’m pretty proud of that post, but I don’t keep up with how the API works.Running Shoes

The Nike+ API is not published, so it’s not public.  It can change at any time.

If you are interested in the Nike+ iPod API, there is a much more up-to-date blog you may want to have a look at.  It’s called Running Tracker.  I’ve been subscribed to the RSS feed of this site.  They’ve created a cross-platform desktop application to examine the data stored with Nike.  I know about their API changes through Running Tracker.

If you have come to this site about the API, by all means, use the code if you can– but also check out the Running Tracker site as it is more up-to-date on the subject than I have been.  Their application doesn’t use C#, but it might be able to help you out with more information.

Creative Commons License photo credit: marksteelenz

09 Feb 2009

Nike+ in Subversion . . . again

5 Comments C# Coding, Running, Software Dev & Productivity

I’ve uploaded my Nike+ API to a new SVN repository. Previously, I used Google Code, but it required people to register with Google and I couldn’t find the way to open it up to anonymous users.

So, here it is again. I have it on my own server in a repository:

https://svn.overpass-software.com/svn/nikeplus/trunk

I didn’t run (or go to work) at all last week because of the heavy snow and a bout of the flu. I should be ready to head out this morning, but I think I broke a toe yesterday. I walked right into a door jam barefoot in the house and now they are starting to swell up. I sound like someone who is always looking for excuses, but he Reading Half Marathon is 7 weeks away, and I’m already registered.

Update 12 Oct 2009: Since this post was written, I have moved the code to the Google Code repository at https://nikepluscsharp.googlecode.com/svn/trunk. Use your Google username and password to access it. It is not a complete working app and will require some C# knowledge to see what it does.