NYC CodeCamp 6 Recap

The 6th NYC CodeCamp was recently held at Pace University in Manhattan, focusing mostly on the Microsoft technology stack. Waking up at 4am to catch an early train into the city proved to be well worth it – the day was filled with fantastic sessions.  To give you a taste of what you missed, here’s a recap of the sessions I attended:

  • ASP.NET Web Forms vNext: Alive and Kicking by Damian Edwards – Probably my favorite session of the day.  Damian gave an in-depth overview, complete with demos of every topic, of the changes and features coming down the line with ASP.NET 4.5 WebForms.  The team has been focusing a lot of time on addressing many of the annoying pain points in the Visual Studio markup editor, and the model binding that they pulled over from MVC looks to be really clean and handy.  I tried to pull a potential RTM date out of Damian, but he wouldn’t budge.
  • Five Ways that PostSharp Can SOLIDify Your Code by Matthew Groves – Matt went through five practical scenarios where you can use the PostSharp framework and aspects (AOP) to avoid repeating yourself with boilerplate code.  I had already applied a few of the examples he provided, but his demo on using aspects for transactions was interesting.  Unfortunately a handful of attendees kept asking off-topic questions and derailing his presentation, but the overview was good.
  • Building Windows 8 Applications  with jQuery and Wijmo by Richard Dudley – Richard Dudley was hands-down the most energetic speaker of the day.  This was my first intro to Windows 8 development so I was excited to see what the Metro development story was like.  Richard gave a great overview of the new architecture and platform, and built a Metro data dashboard application in HTML5 and jQuery.  The pace was a bit too rapid and there was too much copy/pasting from working demo code to really see what was going on under the hood, but it served well as an introduction.  Overall, I was a bit disappointed in the HTML5/JS development story for Metro – it feels a bit forced.  I do think it’s a smart move to leverage the existing skillets of web developers who may not be comfortable in C# or other languages and allow them to easily create Metro apps, but after seeing it myself, I’ll be developing most of my apps using XAML.
  • Using the EntityFramework 4.1 in Real Web Applications by Adam Tuliper – Although I’m currently using EntityFramework 4.1 in most of my MVC applications, I wanted to attend this session to see how someone else was using it and verify that I wasn’t missing any best practices or other ideas.  Adam really knows his stuff and went through some very detailed demos.
  • Cross-Platform Mobile Development with .NET by Greg Shackles – Before I attended this session, I was under the impression that Greg was going to cover building natives apps for the three major platforms (iOS/Android/WP7) in their native languages (Obj-C/Java/.NET) and how to make porting C# easier to the other two languages.  When it started, I realized the session was really about MonoTouch and MonoAndroid.  At first I was disappointed, but the talk ended up being fantastic.  Greg went over how he architected his .NET and Mono code to easily develop an application for all three platforms using a common “core” project containing entities, logic, data access, etc, and then three mobile applications that consumed it.  Very informative.
  • Indie and Casual Game Development for Windows Phone 7 by Kevin Hoffman – My buddy and colleague Kevin Hoffman gave a great talk about quickly, cheaply, and easily creating games for WP7 without XNA by leveraging cloud offerings like CouchDB and AppHarbor and customizing standard XAML controls to look like game pieces.  The demos went pretty in-depth, covering everything from push notifications to multiplayer chat.
I highly recommend attending events like these – for the price ($15), they’re extremely informative and provide an incredible opportunity to network with other developers.

MIX11 Open Call Voting

MIX11: Pick Your Favorite SessionsThe MIX11 conference coming up in April has posted the top user-submitted session abstracts and posted them up to the site. Entries were up a whopping 228% this year – a total of 384 entries!  Just over 200 of these have been selected into the pool of Open Call entries and it’s now open for voting.

My session proposal, “Design as a Differentiator – 10 Design Tips for Developers” was one of the selected entries.  I’m excited about the opportunity to present at MIX – now I just need you to vote! I appreciate your support.

Vote at: http://live.visitmix.com/OpenCall/Vote/Session/40

You would think that with over 200 listed sessions, there would be a clear separation of excellent and mediocre entries.  The truth is, the vast majority of the session proposals sound fantastic.  It’s a clear indicator that this will be yet another amazing year at MIX.  Regardless of whether I get to present, I’m amazed at the quality of all of the proposals, and it makes me even more excited for 72 hours of talking with passionate developers, designers, and UXperts!

It did, however, make it that much more difficult to decide where to allocate my ten votes.  Here’s what I ended up voting on:

So many others that I wanted to vote for, but these are my top 10.  And if you have 10 seconds to spare, and can identify a cat, vote for me! http://live.visitmix.com/OpenCall/Vote/Session/40

Beginning Google Android Development for .NET Developers – Part 1

So you’re interested in building applications for the Google Android mobile platform, but you’re a .NET developer.  What a perfect opportunity to dive head-first into – gasp – Java development!  Fear not – if you’ve never taken the plunge into anything outside of the warm, cozy Microsoft development platform, it’s not nearly as painful as many make it out to be.

This is the first post in a multi-part series on Android development for .NET developers.  Throughout the series, we’ll explore how to build applications for the Android platform and approach concepts in a way that’s familiar to .NET development.  This first post is an introduction to the Android SDK and the Eclipse IDE along with a high-level overview of Android applications.

PreRequisites

  • Java Development Kit (JDK) 6 – self-explanatory; the Java runtime and development libraries.
  • Eclipse – an IDE (integrated development environment) for Java and other languages.   If you don’t have it installed, grab the Eclipse IDE for Java Developers version, which will suit the needs of this tutorial.  The Windows download doesn’t contain an installer, so extract the ZIP in an accessible location, such as C:\eclipse.
  • Android Software Development Kit (SDK) – The heart of Android development.  This provides all of the necessary tools and libraries required to build applications for the Android platform.  Extract it to an accessible location on your hard drive and run the setup executable, which will download and install a set of components.
  • Android Development Tools (ADT) Eclipse Plugin – This plugin adds Android-specific development tools and project templates to Eclipse.  Instead of a separate download, it installs within Eclipse – you can follow the instructions here to get it installed.

Configuring the Android SDK and Creating Your First Project

Okay, take a deep breath – we’re ready to get started.  Launch Eclipse by navigating to your extracted folder and double-click on Eclipse.exe.

Before we jump into a project, we’ll need to configure the Android SDK preferences.  Select “Window” from the menu bar and choose “Preferences.”  Choose “Android” from the list on the left.  In the “SDK Location” field, navigate to the folder where you unzipped and installed the SDK and hit “Apply.”  You should see the list of SDK Targets get populated.  These targets are a list of Android platform versions that you can build on.  Unlike the iPhone, which has one standard set of hardware, the Android platform is open to various hardware manufacturers which use different versions that support different sets of functionality.  For example, the HTC Droid Incredible runs version 2.1, but the T-Mobile G1 only supports version 1.6.  We’ll address these differences later.  For now, just be aware that there are various versions of the platform and click “OK” to close the window.

Next, we’ll create our Android project.  The Android SDK comes with over twenty sample applications, so we’ll create a project using one of those to get acquainted with everything.  From the menu bar, choose “File” -> “New” -> “Project.”  The pop-up window that appears is similar to the “Create Project” wizard in Visual Studio – you’ll see a list of project templates that control how your project is initially set up.  In VS, you could select things like “ASP.NET Web Application” which would automatically configure your web server and add the Default.aspx and web.config files to the project.  Here, we’ll drill-down into the “Android” group and select “Android Project” which will add all of the necessary references to the Android SDK, among other things.  Once “Android Project” is selected, click “Next.”

Now we will set up the basic details of our project.  Under the “Contents” group, choose “Create project from existing sample.”  Then, from the “Build Target” list, select the “Android 2.0″ checkbox.   The “Samples” drop-down will populate with all of the sample applications that come with the Android SDK.  Choose “Snake,” which is a port of the classic game.  When you select it, the “Project Name” and “Properties” fields will automatically populate.  Click “Finish” and your project will be created.

New Android Project Wizard

Now that our project is created, let’s explore the Eclipse IDE.

Getting Familiar with Eclipse

When you create a project in Visual Studio, by default, the files will get put in the My Documents/Visual Studio 2010/Projects folder.  Similarly, Eclipse projects will get created in your “workspace.” The location of this gets specified when Eclipse is launched.  I keep my workspace in my User directory, at C:\Users\nathan.dudek\workspace.  However, since we chose an existing sample project, you won’t find the Snake project in your workspace on the filesystem.  Instead, it uses the existing files in the Android SDK’s “samples” directory.  In this case, you’ll find everything at the “<path to android sdk>\platforms\android-5\samples\Snake”.

In Visual Studio, we’re used to Project and Solution files, such as “Company.Application.proj.”  Eclipse also uses project files, but in every case, the filename is “.project.”  The context of the particular project is taken from the directory that it resides in instead of a descriptive filename.  Take a peek at the contents of this .project file in a text editor and you’ll notice it’s very similar to a .NET project file – XML describing various properties of the project.

We’re also used to the concept of “References” in Visual Studio – pointers to various assemblies and libraries that are utilized in the application.  Eclipse (actually, Java) handles this with a “Class Path”.  All references to outside libraries, such as JAR files (similar to DLLs), need to be included in this class path.  Eclipses stores these in the “.classpath” file alongside the .project file.

Let’s take a look at the Eclipse UI.  Eclipse is built on around an extremely powerful, pluggable architecture, so it can seem complex and confusing at first.  But, after navigating around a bit, you’ll find many tools that appear similar to the ones you’re used to in Visual Studio.  After all, the tools you need to build and debug an application, regardless of platform or language, are generally the same.

  • Package Explorer – Similar to the Solution Explorer in Visual Studio.  Let’s you navigate through the various files in your project.
  • Editor Window – tabbed, colored-syntax editor window.
  • Problems – Shows you build errors and warnings, similar to the Error List in Visual Studio.
  • Console – Shows you build messages and runtime output, similar to the Output window in Visual Studio.
  • Toolbar – You’ll see the buttons to debug, run, save, open, etc.

Eclipse IDE with Android Sample Project Snake

One other quick note about Eclipse before we jump into the Android application itself – by default, it will build the application automatically as you edit it.  It’s a handy feature to find problems as you create them!  I liken it to personalized continuous integration – immediate feedback that you broke the build.

Take a few moments to get familiar with the IDE. Ready to dive into Android code? Let’s go!

Note: Several readers have sent me a note saying that an error appears in the “Problems” window when the project is opened, stating that “Project ‘Snake’ is missing a required source folder: ‘gen’.” To fix this error, expand the “Snake” project in the “Package Explorer” window, then expand the “gen” folder along with the “com.example.andorid.snake” item below it.  Delete the file R.java by right-clicking on it and choosing “Delete.”  The file will immediately be regenerated and the error will disappear.  I haven’t discovered the cause of this yet; I don’t know if it’s a problem with Eclipse or the Android samples, but if I find out more I will update this post.

Exploring the Components of an Android Application

There are five key components that make up Android applications:

  • Activity – Activities represent your application’s user interface layer.  Each Activity represents a single action that a user can interface with.  It could be related to a Form.
  • Service – Services represent background tasks.
  • Broadcast Receiver – Broadcast Receivers react to announcements, similar to events.  An example of system-level announcement could be that the battery is low.  Applications (including your own) can also generate their own announcements.
  • Content Provider – Content Providers expose datasets from your application to other applications.  If our Snake sample application wanted to allow other applications to access the high scores, it could expose them in a Content Provider.
  • Intent – Intents are messages.  You can use intents to send messages to a specific Activity or Service, or send it to the entire system.

Each of these components are represented by Java classes – Activity, Service, BroadcastReceiver, ContentProvider, and Intent, respectively.  The classes that make up your application end up being subclasses of these base classes.  Java uses the “extends” keyword to perform inheritance.  So,

public class Snake extends Activity { ... }

in Java is basically the equivalent of

public class Snake : Activity { ... } 

in C#.

You can read about these components in detail in the Android Developer Documentation at http://developer.android.com/guide/topics/fundamentals.html

Every Android application also has a “manifest” file which This is stored in the file AndroidManifest.xml, included with the Snake sample source.  The main purpose is to inform Android what components make up the application.

Our simple Snake sample application will only deal with a single Activity and none of the other components mentioned above.  Our Activity represents the Snake game that the user can play.  Let’s take a look at the source code by opening up the Snake.java file.  You can find it in the “Package Explorer” window by drilling down to Snake -> src -> com.example.android.snake -> Snake.java.

You’ll notice the file is only 83 lines long.  That’s because this file simply represents the Android Activitythe actual Snake game logic is contained in the SnakeView.java file.  Here are the key things to note about Snake.java:

  1. It’s a subclass of Activity.
    public class Snake extends Activity
  2. Three methods from the Activity base class are overridden, as noted from the @Override keyword (same as the override keyword in C#):
    public void onCreate(Bundle savedInstanceState)
    protected void onPause()
    protected void onSaveInstanceState(Bundle outState)

    These three overrides handle the events that the method names state – when the activity is created, when the game is paused, and when the application state is saved.

  3. This Snake class relies heavily on the SnakeView class, which you can also find in the src folder.  SnakeView is a subclass of another very important Android class – View.  Views are used by Activities to draw things to the screen and handle user interaction.  Since we’re just trying to demonstrate the Android specific components of this application, just understand that SnakeView handles all of the details of user keystrokes, drawing and animating the snake to the screen, etc.

Let’s run the application and see how it launches.

Launching the Application in the Simulator

From the menu bar, click Run ->Run.  You’ll get a message stating “No compatible targets were found.  Do you wish to add a new Android Virtual Device?”  Click yes to set up the Android simulator.

Since we chose Android 2.0 as our platform during the project setup, we’ll create an Android 2.0 virtual device.  Enter a device name such as “Android2.0″ and choose “Android 2.0 – API Level 5″ from the Target drop-down list.  Then click the “Create AVD” button to complete the setup.

Android Virtual Device Setup

Click Run -> Run again to launch your application in the simulator.  The first run may take several minutes to load the virtual device, so don’t be alarmed if your application doesn’t launch immediately.  Once it finishes loading, your Snake game will appear on the screen.

Snake in Android Virtual Device

You can use the on-screen buttons to interact with the simulator, or you can use the buttons on your physical keyboard.  You can also interact with the rest of the Android platform by using the Home, Menu, Back, and Search buttons.

Next Steps

It’s worth exploring the samples provided with the Android SDK.  They cover many aspects of the available functionality, such as voice recognition, gaming, BlueTooth, gestures, and graphics.  In the next post, we’ll create an Android project from the ground up and create our first basic application.  In the meantime, dive deeper into the Snake source code and its SnakeView.java file if you want to see how the game logic and drawing engine works.  Also, take the time to get familiar with the Eclipse IDE.  After a little playing around, you’ll find it’s a pretty comfortable (and powerful) IDE.

The 2010 Caffeinedi.com Ultimate Budget Developer Rig

A few years ago, Jeff Atwood did a great series of blog posts on building the ultimate developer rig for Scott Hanselman.  For $2000, he put together a fantastic machine with stellar performance.

My five-year-old developer rig has had a great run, but lately, it just hasn’t been able to keep up with my needs – not to mention a lot of random artifacts and lines on the monitors, indicating the impending death of my video card.  So, I set out to build my own ultimate developer rig, but on a  lower budget of $1100.

This $1100 budget took into consideration the reuse of my existing chassis, data hard drive, DVD-RW drive, and dual monitors.  So, if you’re setting out to build one from the ground up with similar components, a budget of $1400 is probably more realistic.

Somewhat similar to Hanselman’s priorities, the requirements for my rig were as follows:

  1. Fast.  When I launch an app, I want it to display immediately.  When I compile, I want fast build times.  When I power it on, I want Windows to boot fast.  When I click on something, I want the action to register immediately.
  2. Multitasking.  Since I often run a ton of applications at once, some of which can be memory hogs, I need it to remain fast and performant even with tons of windows open.  If I can have multiple instances of VS2010, Photoshop, Eclipse, VirtualBox, Tweetdeck, iTunes, Firefox, and Word open simultaneously without losing much performance, it’s a win.
  3. Quiet.  I like to work in a quiet environment and can’t stand fan and hard drive noise.
  4. Reliable.  I can’t afford any extended downtime, data loss, or reoccurring blue screens, so I need the rig to be reliable.
  5. Budget.  I want to stick as close as possible to the budget while achieving the first three requirements.

After lots of research, I ultimately came up with the following component list:

Since I/O has almost always been the slowest aspect of my machines, I really wanted to go with an SSD as my boot drive.  I have heard nothing but fantastic things about the Intel X-25M, so I decided to go with it.  I also really wanted an i7, and the price for the i7-860 is a great value.  Additionally, to satisfy the low-noise requirement, I went with the upgraded Zalman cooler and the Cooler Master Silent Pro power supply.

Initial Results

I’ve been using this new development rig for about two weeks now, and it has absolutely blown away my expectations.  For my $1100 budget, I expected a great machine with room for improvement.  But, the machine’s performance is absolutely fantastic.

Windows Experience Index

The SSD makes all the difference in the world.  Windows boots in seconds, and applications load instantly.  The splash screens for applications like Visual Studio 2010, Photoshop CS5, and Microsoft Office only appear for a split-second before the actual application loads.  I cannot recommend the Intel X-25M enough – it is incredible as an OS and program drive.

To top it all off, the machine is quiet.  Like, real quiet.  Sometimes I have to look under the desk to see if the power light is illuminated because the fans are almost completely silent.

I could not be more pleased with the result of this build.  The performance of this budget rig has made me so much more productive, since I don’t have to wait for any of my clicks or keystrokes to register.  And, the reliability and low noise levels keep me focused on the tasks at hand.

CodeGuru’s Ten Great CodePlex Projects for ASP.NET Developers

CodeGuru.com has an article called Ten Great CodePlex Projects for ASP.NET Developers in which the author, Jason Gilmore, mentions Hollywood Hackers – the demo project that I built with Kevin Hoffman to go along with our MSDN article, “Fueling Your Application’s Engine with Windows Azure.”

The list contains some other really great sample CodePlex projects that you should check out, such as the classic NerdDinner and TailSpin Travel.  All of the projects mentioned provide excellent code samples to help you new technologies and development techniques.  Check the out and learn something new!

http://www.codeguru.com/vb/vb_internet/aspnet/article.php/c17085

Dynamic Controller and Action Authentication in ASP.NET MVC 2 by Ryan Wright

My friend and colleague Ryan Wright has posted a fantastic article about dynamic controller and action authentication in ASP.NET MVC 2. His techniques describe an architecture without hard-coding roles into the Authorize attribute – which makes it possible to add roles to application functionality strictly through configuration – no application rebuild required.

He also provides his code samples, which additionally use Windows Identity Foundation (WIF) and a custom STS. It’s a great starter project for anyone who’s looking into seeing how these tools work.

http://www.ryanmwright.com/2010/04/25/dynamic-controlleraction-authorization-in-asp-net-mvc/

Memory Limit Errors in WordPress or Other PHP Applications

When working in WordPress or other PHP applications, it’s relatively common to run into memory limit errors like the following:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /public_html/wp-admin/includes/template.php on line 699

The default memory limit setting is in the php.ini file, and many web hosts have it set to 12MB.  You can change it by modifying the php.ini file:

memory_limit = 64M

…but, many hosts don’t give you direct access to this file.

Instead, you can control the memory limit directly in your application.  In the wp-config.php file, just add a single line:

define('WP_MEMORY_LIMIT', '64M');

This issue came up on a recent project involving the BuddyPress WordPress plugin, which can be a fairly memory intensive module.  If you run into it, just bump up your memory limit and you should be fine.  If you’re using a platform other than WordPress, there are usually similar methods to define memory limits – just check the documentation for your particular application.

MIX10 Sessions Start Today!

The MIX10 Microsoft UX conference sessions start today.  This is a reminder that I’ll be tweeting all day live from the event (@natedudek) and posting summaries of my sessions at the end of every day.  The keynote starts in a little over an hour where we should here about the Windows Phone 7 Series.  It’s also being streamed live if you want to watch!

I Will Be Blogging and Tweeting Live from MIX10

mix10logo I will be attending Microsoft’s MIX10 conference next month in Las Vegas.  I’m really looking forward to networking with other developers and designers and being immersed in a User Experience-focused community for three days.

I will be blogging and tweeting LIVE from the event on www.caffeinedi.com and www.twitter.com/natedudek.

Although the schedule hasn’t been posted yet, I’ll be focusing mostly on the sessions related to Windows Azure, Silverlight 4, UX, MVC, jQuery, AJAX, and Visual Studio.  The sessions that are currently on my short list are:

Obviously, there’s LOTS of amazing content planned.  I won’t be able to attend every session I listed, but at the very least I’m hoping to catch up with some of the presenters of the sessions I’m not able to make it to.  I’m also hoping to sit down with guys like Elijah Manor and Clemens Vasters for a few minutes.

If you have things you’d like me to check out for you, or questions you’d like me to ask presenters or other attendees, drop me an e-mail, leave a comment, or send me a direct message on Twitter.

My Windows Azure Article Is In the January 2010 Issue of MSDN Magazine

An article I wrote with Kevin Hoffman on Windows Azure is in the January 2010 issue of MSDN Magazine. “Fueling Your Application’s Engine with Windows Azure Storage” discusses the utilization of Azure Queue and Table storage, Azure Worker Roles, and jQuery to send asynchronous messages to an ASP.NET MVC application and process shopping cart orders. Check it out!

Fueling Your Application’s Engine with Windows Azure Storage