Category Archives: Programming

Beginner’s Guide To Mobile Apps: Resources and Links

It’s been pointed out to me that there’s a misspelling in this fake book cover. If I were clever I would say it’s an homage to the HTTP_REFERER attribute…

Thank you to everyone who attended my presentation about mobile applications!  As promised, here’s the list of links for information and resources that I said I would share… along with other links to items of general interest for mobile app developers and folks looking to get into this field.

“The Stacks”

In addition to the seven “stacks” I covered in varying degrees of detail last night, I also obliquely mentioned some others in passing. Here are the links to them all. One oversight I want to address: At the May 9th Meetup I said that if you want to learn more about Progressive Web Apps you should check out the KC Google Developers Group (I should have said this at the July 18th meetup as well but I forgot). Their home page — https://gdgkc.org/ — is both informational and an example of a PWA, and the code for it is available on GitHub: https://github.com/neojato/boomerang-gdgkc.

Some other language/platform options:

A Microsoft Employee making a React Native app on a Mac targeting iOS, Android, and UWP from one UI definition and then pushing new builds of the app — triggered on pushing new code to VSTS — out to handsets of testers, QA, beta users (however you want to set it up) using Microsoft Mobile Center:

Opinions,  Comparisons, Click-bait and Flame-bait, and other reading about mobile:

Xamarin 3D Questions and Answers (belated)

As promised, here are some answers to the questions raised at the “Xamarin 3D” meetup back in May. If you have more questions please feel free to contact me via Meetup or at @dotNetMike.

My apologies for not posting this much sooner… Kunjan is my witness that I emailed this reply to him the day after the presentation back in May (though I’ve updated the TFS question this morning since I have more info). I plan to completely re-do this talk with an emphasis on demonstrating everything I’m covering rather than just saying “Trust me, it’s cool and you can do it.”

Questions and Answers

Q. Can I developing Windows Mobile apps on a Macintosh?
A. No. You’ll either need a Windows VM on your machine (or an Azure VM to which you can remote?) or an actual Windows machine for this.

Q. What is the C++ interop story for Xamarin?
A. I’m linking to two articles, one which addresses building and debugging C++ libraries in Xamarin.Android with Visual Studio, and another which discusses using Visual C++ for cross-platform mobile development. Mac: I’m not sure if, in aggregate, this answers your question. If I understood it correctly, you were curious whether you can write both an Android and iOS app from the same IDE. While these articles don’t specifically say yes to this, I’m going to dig deeper on the Xamarin forums and see if I can make contact with someone engineers at Xamarin who can answer this question completely.

Link: https://blog.xamarin.com/build-and-debug-c-libraries-in-xamarin-android-apps-with-visual-studio-2015/
Link: https://msdn.microsoft.com/en-us/library/dn707591.aspx

Q. How much of the CI/CD pipeline can I do with on premises TFS?
A. Per a friend of mine who is a TFS expert: TFS on prem can do what VSTS can do. For local iOS builds you’ll need a Mac for hosting an iOS build process but TFS can connect to it and everything should Just Work.

Other Notes and Links

I mentioned Calabash as an alternative tool for creating tests for use locally or in the Xamarin Test Cloud. More information about Calabash can be found at: http://calaba.sh/

The videos that didn’t play:

The first was a section from the HockeyApp & DevOps talk at Xamarin Evolve, specifically the portion of the video which addressed the annotation and user feedback features of HockeyApp:
https://www.youtube.com/watch?v=AEWAPZ4J6eo&feature=youtu.be&t=23m7s

The second video is a later section of that same presentation which dealt with setting up automated (or manual, if you prefer) distribution pipelines such that an app could be auto-published to the app stores after passing tests and getting required authorizations from managers and testers:
https://www.youtube.com/watch?v=AEWAPZ4J6eo&feature=youtu.be&t=27m28s

I highly recommend watching the whole video as it really does a good job covering the DevOps/CI/CD story that is possible with the Xamarin & Microsoft (VSTS) tool chains:
https://youtu.be/AEWAPZ4J6eo

Last is this two and a quarter minute high-level overview of the features of HockeyApp… short enough to be digest-able by most managers:
https://www.youtube.com/watch?v=gVEpupXd3W8

Clean Code versus Really Clever Code

Last year I found this humorously unreadable chunk of C# code on a blog.  Without explanation, here’s the code:

// “Animal” is a class from which there are many
// inherited classes, one of which is “Dog”
for (Dog _dog = _animal as Dog; _dog != null; _dog = null) {
//more code here
}

As we’re preparing to interview candidates to back-fill a C# web developer position here at work, I’ve decided to print out this code on a sheet of paper and have it on hand for possible use in an interview.  The questions based on this code are:

1. Describe what will happen when this for loop executes.
2. What would you do if you encountered code like this in the application?

If your first reaction to the code is confusion, don’t be alarmed. Most senior devs will blink and stare at this code and not get it, and have to “mentally compile and run it” even after it’s explained.  If another reaction is a desire to gag, puke, or want to do violence to whomever wrote that, you’re also in good company.

But the question remains: what is happening here?  I think this is a valid code scenario with which to quiz a C# interviewee because most of us only think of the for loop construct as being useful for iterating over a collection.  Yes, you can iterate over a collection with a for loop but C# has a better tool for that: the foreach loop.  What makes the for loop interesting is that it’s an assign, evaluate, reassign construct.

(If you really want to know what’s happening here, the explanation is at the end of this piece.)

Admittedly, this looks like a blatant gotcha of an interview question, but that’s not the point. The expectation isn’t for someone to explain it (which they probably won’t be able to do unless they’ve already read this: http://stackoverflow.com/a/7113387) but to be knocked a bit off balance by it before having the logic flow described, allowing them to see how and why it works. Once the process of the for loop is explained and the interviewee gets it, the table is set to ask the question that this scenario is really about:  What would you do if you encountered code like this in a production application? Any reasonable variation on the following is what I’m looking for: I would re-write it as follows to make it more easily readable to every programmer after me who has to work in this part of the code base:

Dog _dog = _animal as Dog;
if (_dog != null) {
//more code here
}

It’s not unusual for interviewees to write code in an interview: depending on the scenario it gives insight into the person’s thought process and problem solving skills. But I think it’s also useful to get a feel for whether a candidate would be inclined to impose readability on a block or section of obtuse code while passing through.

The real question here is: do you write clean code? Are you merely going to add code to the applications here, or are you going to make it a better code base as you go along? Any programmer can write code that a machine can understand but I want to know if you’re committed to code that humans can read. And if you are a clean-code programmer then I want you on my team.

(If you have not taken Cory House’s course on clean code — Clean Code, Writing Code for Humans — you really should… I can’t recommend it highly enough.)

* * * * * * * * * * * * * * *

As promised, here’s the explanation to the weird looking for loop. To understand this it’s important to remember that a for loop isn’t a mere iteration construct: it’s a construct with an initial assignment following by an evaluate, process, re-assign loop which continues until the evaluation returns false. Let’s go through it step by step:

The initial assignment: this which happens only once in the life-cycle of a for loop — we define a variable of the type Dog and, using the “as” keyword, we cast _animal to Dog and assign that to the variable _dog.  If the “as” keyword in C# is new to you the key thing to know is that if _animal cannot be cast to Dog then null is returned.

The evaluation statement: _dog != null.  In the previous step, if _animal can be cast to Dog, then this evaluates to true (_dog won’t be null) so code in the body of the for loop.

The reassignment statement: this might be the part that tripped you out the most. Typically this statement is something along the lines of “i++” (or “i + 2” if you’re skipping every other item in an array) but any valid assignment work here… such as “_dog = null.” This statement runs after the first execution of the code in the body of the loop and immediately before re-running of the evaluation test (_dog != null).

So in plain English: if _animal is able to be cast to the type Dog then run the block of code exactly once. It’s useful to realize a for loop can be used this way, but writing code like this is extremely hard to read… so hard that even after it’s explained you probably went back to step through it in your brain.  Code as obtuse as this should always be re-written to something simpler to understand.