Data Access with .NET Framework 4 (Exam 70-516)
I passed my 70-516 exam yesterday with a score of 860. Not as great as I would have liked but not nearly as bad as I had feared. Overall I'm pleased. For what it's worth, I followed the same route many others have followed in preparing for the exam. I started with the MCTS Self-Paced Training Kit (Exam 70-516): Accessing Data with Microsoft .NET Framework 4 which I obtained through the O'Reilly Safari Books Online. The nice thing is you also get access to the CD contents which includes a copy of the MeasureUp testing software so you can take practice exams. I imagine it isn't as up to date as what you would get if you went straight to MeasureUp or if perhaps the included copy of the software has a smaller question pool, but it was still helpful.
In any event, once I had finished going through the book and making sure to actually run through the examples and make an effort to answer the questions at the end of each chapter without looking back, I started going through the links from this blog post by ondrejsv. For each link, I would read through the linked article and then either follow relevant links in a new tab or open a new tab and search for a topic that seemed to be potentially of interest. Think of it as doing a depth-first-traversal of the MSDN articles. What I found was that there were interesting bits of information that were uncovered in the MSDN articles, especially in those containing sample code, which dealt with some topics in greater detail than the material covered in the book. In that way, the book was a good baseline for preparation but the MSDN links fleshed things out a bit more.
In conjunction with this, I continued to go through the sample tests. I kept a text file open and jotted down items that I was having difficulty with and would then spend time doing searches online for additional material covering that topic, both within and outside of MSDN. Additionally, I started creating mini-projects. Initially the projects would be very straightforward, switching back and forth between thick clients and web clients. Then I expanded to web services with various clients, splitting the EF entities into their own assembly, and so on.
I'm now considering which I should pursue next, 70-513 (covering WCF), 70-515 (Web apps) or 70-511 (Windows apps). If I'm going to shoot for MCPD, I will definitely need 513, but would need to choose which I would specialize in, Web apps or Windows apps. Still, not every project will involve WCF so perhaps for the short term I would be better off picking 515 or 511.
In any event, I've been told that 516 is considered to be more difficult than the other exams. Not having taken the others nor even studied them, I can't say. For those who have, I'm curious what your opinion is.
Building Buzz for your iOS App
I recently received the following email:
Hi Lynn,
I hope you are doing well and that this holiday season isn't keeping you too busy.
The reason for my e-mail is because I have a friend from College who just finished an iOS game and is looking to get some press for it. I wanted to know if there are any tips that you could share with him to help his game out there. If you could help him get in contact with any iOS websites, I'm sure he would be very grateful too.
What I responded with is more or less what I wish I had done with Centripetal and would do if I had it all to do over again. To begin with, this is premised on the notion that you are a small time developer, have virtually no reputation beyond your circle of friends and are planning to release your app with the hopes of making some money on it.
What I found is that timing is very important. When an app is first released on the app store, it will show up on lists all over the web. Ask anyone who has released a small app with little exposure what their sales looked like and they will tell you sales were highest within the first 24-48 hours of app store availability. So if you do absolutely nothing else, you will see a bump in sales and therefore in eyes on your app during that period. You want to make the most of that.
My suggestion then is to try to focus on driving your marketing and buzz building on that moment when your app first arrives on the app store. Granted, I haven't tested this since as I said this is what I would like to have done, but work with me here. ![]()
Let's assume for now that your app is not now nor has it ever been available for sale on the app store. You can make it available for review when it is done, but put the release date out into the future. This won't affect the review cycle but will keep it from being up for sale immediately after approval. Once it is approved, you can push the release date back to a current date and have control over the actual release time within a 24-48 hour window.
Next, start building buzz NOW! Don't wait for the game to be complete. Got a blog? Blog about your game. Hint at what features you're going to have. Hold a poll about which feature to include or how to implement it. Get feedback. Drum up interest. Have people anticipating the game's release. The more people get your game and at this state, the idea of the game, put in front of them the more likely they are to mention it to friends or at least share the link.
Can you create a gameplay or app usage video? If your app can be simulated on your Mac without any loss of features, then use something like Screenflick to record on your Mac. If that isn't an option, you can use a separate recording device to view a physical handheld in action. Of course that's not going to look as good, but what can you do? The point is, you want folks to see what the game is like. During development you can release videos of beta builds if you think they will be enticing. As you approach release you can snazz it up with music and such. For actual release, you definitely want to have a high quality app video available for your users to see.
You also want to have a webpage or website devoted to your app. It should make people want your game. To do this, list things people will look for in an app like yours. If it's a game, tell them how fun it will be, how many levels it has, what groundbreaking new playstyle it involves. And link to the reviews for you app.
Ah yes, reviews. I used O.A.T.S. to get a list of sites that do reviews without accepting money to create or promote your review. It's less expensive and more honest. Of course it is possible to get an honest review that you've paid for, but there is always the likelihood of a bias. If that doesn't bother you, you can of course find many sites which are willing to take your money in exchange for a review and a little extra to move yours to the top of the pile. I leave that choice to you.
To get your app into a reviewer's hands you will either have to release your app and provide promo codes, which all review sites accept but which blows the whole "control your launch date" idea out of the water, or you will need to provide them beta access through something like TestFlightApp. TestFlightApp is free and while it requires some extra fiddling on the part of the reviewer and the developer, it's pretty easy to use. I imagine a number of review sites would be willing to meet you half way and make use of this. Regardless, no reviewer is going to want to have to pay for your app in order to review it, especially if you are requesting the review. At this point, you have to wait for the review. This could take awhile. Weeks. Perhaps even a month or so. Technically there's no guarantee (unless you bought it) that you will even get a review. It's up to you how long you wait.
Once you have a satisfactory number of positive reviews you can link to, set them up on your site and in your iTunes app store description. Make the app available. Once you see it on the app store, make additional announcements about its availability anywhere you can. Ask friends to spread the word. If you're willing to spend money, you could consider advertising on sites you would expect users of your app to frequent. Advertising options vary greatly across websites. If you wish to do this, contact the webmasters of those sites directly for details.
Now, why all this fuss over timing everything to hit all at once? As I said, you get a free bump when your app is first listed on the store, especially if it is free or $0.99 because there are a number of sites and services that exist solely to scrape the iTunes App Store and list all new apps in those price ranges. It is my belief that if you can build enough buzz such that a large number of people are discussing and playing your app at the same time, it increases the odds that your app will then be mentioned to others, i.e. that it will become a hot item. And that's what this is about, increasing your odds. As I said to begin with, the premise here is that you are an indie developer with no name, no buzz and nothing to build on. If you already have established credentials, you can build on that and you'll see more success on average with the same app than if you had nothing to start with.
Of course, that's not the end of it. You should never consider your app 'finished'. Always consider things you could do to expand on it, build on it. When you release updates that provide more features or more fun or more playtime to users, it increases the perceived value and provides an opportunity for more buzz. Keep making the announcements, keep interest up.
And if your app is already on the store or if you simply disagree with this notion of opening day timing, then you can of course bust the sequence up. Release sooner, don't hold back. But the rest of it still makes sense. You still want that app use or gameplay video. You want that website. You want to build interest before you ever release anything. You want the reviews. Of course if the app is already up, you can use promo codes.
Whichever way you go, however you choose to market your app, the important thing is to give the user something they want to use and something they want to share with their friends. There's no marketing with higher quality than simple word of mouth. Hopefully, you'll be able to build your own Angry Birds. If you do follow my advice here, particularly if it's not what you were originally planning to do, I'd appreciate it if you drop me a line and let me know how it goes.
Facebook Page Tab and WordPress
Previously I discussed what I went through to use the generic SSL certificate that came with my ICDSoft hosting service with the Facebook application I set up for my Facebook Page tab. I mentioned at the end that I also had to do a little rejiggering to use a WordPress page for the Facebook app. It's actually pretty simple and I'm going to share that, too. You may want to review the setup steps for a Facebook app as a Facebook Page tab. Got it? Good, let's move on.
As you saw, when setting up a Facebook app for use as a Page tab, Facebook asks you to give them a secure (https) URL to point to, which they embed into an iframe on the page. The URL will be sent to the browser to be loaded by the client. Whatever is served up will be viewed in an iframe with a max width of 520 pixels. It is critical to understand that much. If you don't pay attention to the 520 pixel width limitation, your FB page will look rather ugly and likely have horizontal scrollbars and only partially revealed assets.
You'll want to make sure that your WordPress site will work when invoked from the https URL. I imagine this will typically be the case. I know for me, simply changing the URL to https was sufficient and I could easily traverse my WordPress driven site via SSL. If this isn't the case for you and you want to use WordPress to handle your Facebook Page tab content, you are going to have to find some means of getting your WordPress site to respond to https URLs.
Let's assume for a moment that you do manage to get SSL working for your WordPress site. Next you are going to need to create a page which you want to hit via your FB app. That much is easy, but there are two issues you will likely need to resolve. One is that your new FB app page is going to show up in any list of pages for your WP site which you have and the other is that your new FB WP page is not going to be styled optimally for inclusion as an FB app page.
Starting with the first point, why would it matter that your FB app page on your WP site is going to show up in the list of pages? Frankly, because of the second point, optimizing it for FB app usage. It's likely going to look quite different because of how it will be used, and so it would be good not to have it navigable under normal browsing situations. To eliminate this, for starters if you are using the 'Pages' widget in your sidebar, go to your WP dashboard and open 'Appearance->Widgets' and click to expand the 'Pages' widget. By default, WP allows an 'Exclude' area which you can enter the page ID of each page, separated by commas, which you do not want to have show up in the 'Pages' widget. More tricky are themes which include the pages in the header or other areas. Unless the theme provides the option to not list certain pages, you will find yourself in a bit of pickle, perhaps having to go so far as to custom edit your header in order to not list them. Because that is going to depend on which theme you have installed, it's beyond the scope of this article to discuss code customization.
The second point, however, will involve some customization in the form of a custom page template. Here is what the WordPress Codex has to say on creating your own page template. It's a bit barebones, so let me help you out a bit. First, create a new file in your theme's folder called 'customfbpage.php'. The contents of the file should look like this:
<?php
/*
Template Name: Facebook Page
*/
?>
You can upload this via FTP or your website's control panel or whatever other means you have of pushing new files up to your template folder. Now, go to your WordPress console and go to the Appearance->Editor link:


On the right you will see a list of files which can be edited for your template. You can see in my snippet I have only a scant few because I'm using a child template. YMMV. Now you need to find the 'page.php' for your template. If you are using a child template, you will need to open the parent template's copy of page.php if you haven't already overridden it in your child. Otherwise click the child copy. Regardless, just copy all of the text within by highlighting all of it, right clicking, and choosing 'Copy'. Now go back to the customfbpage.php and edit that. Click below the comment block and paste the contents in by right clicking and choosing 'Paste'. I'm using the NotesIL theme as my parent theme, so this is what I see:
<?php
/*
Template Name: Facebook Page
*/
?>
<?php get_header(); ?>
<div id="container"> <div id="content"> <?php while ( have_posts() ) : the_post(); ?> <div id="post-<?php the_ID(); ?>" class="<?php notesil_post_class(); ?>"> <h2 class="entry-title"><?php the_title(); ?></h2> <div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( 'before=<div class="page-link">' . __( 'Pages:', 'notesil' ) . '&after=</div>' ); ?> <?php edit_post_link( __( 'Edit', 'notesil' ), '<p class="edit-link">', '</p>' ); ?> </div> </div><!-- .post --> <?php comments_template(); ?> <?php endwhile; // end of the loop. ?> </div><!-- #content --> <?php get_sidebar(); ?> </div><!-- #container --> <?php get_footer(); ?>
Click on 'Update File' to save your changes to customfbpage.php then click on 'Pages' over on the left to list all of the pages including your Facebook app page. Click the 'Quick Edit' option for the FB app page and make sure it looks similar to this:
There are several key points here. First, make sure you pay attention to the 'slug' field. If you told Facebook to look for your Facebook app content at https://www.joeswebsite.com/fbpage/, then your slug should likely be 'fbpage' because that is where WordPress will display that page's content. Next, make sure the 'Template' is set to the 'Facebook Page' template which you just saved. Of course, the name will be different if you opted for a different template name. Finally, you probably don't want to allow comments. Maybe you do. I didn't, so I have that turned off. Once you are happy with your settings, click 'Update'. Now go back to the 'Appearance->Editor' panel and click on customfbpage.php again. Time to get nitty-gritty!
First, I'll just say that for my case, using a NotesIL based theme, my choices were simple. I removed the lines in the template which contained the following:
- the_title()
- wp_link_pages()
- edit_post_link()
- comments_template()
- get_sidebar()
- get_footer()
The title line wasn't necessary because the embedded content was going to be embedded within a Facebook page, so what was the point in including space to say "By the way, this content is for a Facebook page"? The wp_link_pages() line would have shown links to other pages which I didn't want to do. The edit_post_link() line would, if I were logged in and an admin, have displayed an 'Edit' link allowing me to start editing the content. It wouldn't have been visible to other users, but I would have seen it and I didn't want to, so I removed it. I can still edit the page by going through the 'Pages' section in the dashboard. The comments_template() shows any attached comments, but I have comments disabled, so that got removed. get_sidebar() and get_footer() show the sidebar and footer respectively, both things I wanted gone to save space. What you have in your page.php is going to determine what you need to remove from your customfbpage.php file.
But that wasn't it. I still needed to do some CSS customization. I also edited the style.css for my child theme and added the following:
.page-template-customfbpage-php div#header h1 {
width:520px;
}
.page-template-customfbpage-php div#blog-description {
width:520px;
}
.page-template-customfbpage-php div#container {
width:520px;
margin:0; padding:0; border:0;
}
.page-template-customfbpage-php div#content {
width:520px;
margin:0; padding:0; border:0;
}This sets pertinent content blocks to a 520 pixel width with no margins, padding or border, something we need in order to make our FB page look alright. Once I had this in place, I was able to load my Facebook page up and load the tab and my content looked right as rain.
Now, there are some other pitfalls. One example is a link I included in the content of the FB page to our contact page. This caused the contact page to load in the embedded iframe, with all of the default look and nasty horizontal scrolling. To fix this, I altered the link to have a target of _top, which caused the link to load into the page as a whole, not just the iframe. So keep in mind that what your content is loading into is an iframe and be cognizant of all that entails.
I hope you find this helpful. Let me know in the comments below or drop me a line by email.
Facebook Page Tab, SSL and Hosted Websites
Here's the setup. My company, PNG Support, has a Facebook page and we wanted to be able to set up custom content there rather than just rely on using the wall to post links back to the main site. If you are unfamiliar with how to do this, there is an excellent write up here on setting up an iFrame Application on your Facebook Page. While that page provides some nifty details, for the purposes of our discussion here I will point out that it involves the following:
- Have a website hosted somewhere
- Make sure it has SSL enabled
- Tell Facebook the URL to create the Facebook application
- Link the application to your Facebook Page
What happens is that when someone visits your Facebook Page, specifically the tab you created for the custom content, Facebook sees it is an app and embeds an iframe linked to your secure (https) URL. At that point, the behavior is entirely determined by the client's browser. And that is where things can fall down if you are using the default SSL certificate that likely came with your hosted website.
If you are unfamiliar with SSL or https or secure webpages, think of it as a means of determining trust. When you visit a secure webpage, an SSL certificate is given to your browser. Like an actual certificate, it states who you are (e.g. PNG Support or Lynn Pye or Barack Obama or...) but it also states what domain the certificate was issued for. In other words, it not only says who you are supposed to be, but where the content is supposed to be coming from. In addition, these certificates have an expiration date. So the browser checks to see if the certificate is expired or is coming from a website which it is not issued for and alerts you to this. What does that mean? Suppose I get a certificate issued for www.pyehouse.com but I install it on www.pngsupport.com. When you visit www.pngsupport.com, your browser can, and should, complain bitterly that the certificate is not valid because of the domain mismatch. In most cases you are given the option of continuing anyway.
This can also come into play on the bulk hosted services. These services have multiple servers with each server configured to host many websites, sometimes several hundred or more. If the hosting provider offers SSL as a default freebie, it means they have a certificate for their server to provide basic SSL encryption when someone uses the https handler for your website. You see, that's the other part to SSL. Once the certificate is accepted, the browser can have an encrypted conversation with the server, making it far more difficult for someone to snoop on what you are browsing for.
In the case of my company, we use ICDSoft for our hosting provider, whom I highly recommend. In our particular case, we happen to be hosted on server261. This means that if you visit https://www.pngsupport.com (note the https) you will get a certificate for server261.com, your browser will gripe, you will likely be given the option of proceeding anyway and, if you do, you will see the site as it normally looks. That's because the certificate is issued for server261.com but you visited pngsupport.com.
Now what does this have to do with Facebook Pages and custom iframe apps? Well, for security reasons Facebook requires you to use https links. Like I said, it embeds your link in an iframe on the page. So if the security doesn't match up, your audience is going to get some nasty security warning embedded in your Facebook page instead of the luscious layout you perfected last night. At this point, you'd be tempted to start investigating purchasing options for your SSL certificate. I know I did. And when I started looking at the price tag (over $100/yr for the cheaper options), I realized I didn't like that option. Then I had a thought. The certificate covers anything hosted on server261.com. Was there a way to use the server261.com domain to reach our content and therefore get a certificate match and have everything play nice.
As it turns out, there is, at least with ICDSoft. Keep in mind this may not always work if the server is not configured for this. But for ICDSoft, if you have, for example, the pngsupport.com domain hosted on their server261.com server, you can reach your content at http://pngsupport.server261.com. Even better, you can get an encrypted link with https://pngsupport.server261.com with zero complaints from your browser. So then I went into the Facebook application's settings and replaced www.pngsupport.com with pngsupport.server261.com and everything worked flawlessly. The certificate was matching, the content was coming up as desired and all was right with the world.
Of course, then I decided I wanted to link to a WordPress page instead of a hand written bit of PHP. More on that another time.
The Best Programming Tool… Ever
The best programming tool I've ever used was a whiteboard with dry erase markers. When I worked for IBM, we had a team of, oh, about 10 or so developers working on an internal project with usage spanning the globe. We turned out tight code on a tight schedule and we did it with relatively few errors and hell if we didn't come in under budget, just for kicks. We had a really great team of developers but one thing which I think had a big impact was having a huge whiteboard in every. single. office.
We were, at the time, technically part of the services division, even though we had absolutely no outside contact with customers. We provided purely internal benefit through our software. In a nutshell, we wrote the ticketing and billing software for the maintenance and support services for IBM. When you called IBM for support on your AS/400, we were the ones responsible for tracking that little guy and making sure you were billed appropriately. This involved working with several systems and a home brewed database (it was some time before we completed our migration to DB/2) but it was well done. We didn't get many complaints.
I don't know if it was due to being part of the services division or if it was something IBM was doing as a whole (I suspect the latter) but at the time, we were undergoing a management shift as well as a process management shift. Our management shift was moving to matrix management where projects had business managers and individuals had HR managers so you were reporting to two entities and.. well.. the less said the better. The process management involved weekly meetings, lots of status updates and tons of charts. But in spite of all of this, the whiteboard kept us on time and under budget.
Each office held two developers (or architect or team lead, whatever). The wall as you walked in was taken up by a massive whiteboard with two or three dry erase markers plus an eraser and maybe some whiteboard cleaner. You had to go the breakroom and grab some paper towels if you wanted to actually use the stuff.
Anyway, we used the hell out of those things. You could walk into any office and immediately know what they were working on by checking out the edges of the board, where long term task lists were kept. But the big plus were the middle areas, where technical notes and diagrams were kept. We would do object designs and data flows and leave them up for a month or so until things were complete. Need a gigantic scratch pad to work out the logic for your module? No problem, just stand up and walk over to the whiteboard and write down the contents of your mind.
Perhaps the lone problem was lack of space. Make no mistake, these whiteboards were huge, wide enough to span two cubicles. Still, if the problem was sticky enough, you wanted, nay, needed more space. And of course you were sharing with your officemate, so you had to be mindful of what space they needed. As it happened, we had a few extra rooms where we could use whiteboards unfettered by occupancy restrictions. It was a wonderful time.
Since then, I have been to many locations and seen many team sharing arrangements. The supremacy of the whiteboard has typically received at least a nod in the form of a shared whiteboard in a common area but never was worshipped as it was when I was at IBM.
Things have probably changed since then. Times certainly have. There are whiteboard software applications that allow users to draw to a shared space on their computer, but it's not the same. Using a mouse to try to draw programming diagrams and notes is like trying to build a ship in a bottle using salad tongs. And if you have a Wacom tablet or similar device you're probably not the focus of this post. No, there is no substitute for the real thing. The whiteboard is the king of programmer tools. Long live the king!
Bad News For MiniStumble (StumbleUpon Safari Extension)
As you may be aware, I've been working on a StumbleUpon Safari extension to mimic the functionality of the Firefox plugin. I've written about it here on my blog, created a page devoted to the MiniStumble project and also attempted to gather input from the StumbleUpon forums.
Yesterday, my StumbleUpon forum posts were removed, the only message in the otherwise automated email being "not legal". I then submitted a request for more information on the StumbleUpon feedback page. The following is the response I received:
Your request (#######) has been updated.
You can add a comment by replying to this email.[Name Redacted], Sep-30 05:17 pm (PDT):
Hello Lynn,Thanks for writing to us,
While we appreciate your enthusiasm for StumbleUpon, unfortunately, we do not allow third parties to create StumbleUpon extensions and we do not recommend you to invest resources on building such an extension from us. Our legal team may be contacting you with more details.
Thank you for your interest!
Best,
[Name Redacted]
StumbleUpon Support TeamRead our blog: http://www.stumbleupon.com/sublog/
Be our friend on Facebook: https://www.facebook.com/StumbleUpon
Follow us on Twitter: http://twitter.com/#!/StumbleUpon
Check out our YouTube videos: http://www.youtube.com/user/stumbleuponStumbleupon, Sep-29 03:44 pm (PDT):
I'm developing a Safari extension for StumbleUpon based upon the code in the Firefox plugin. This would provide similar functionality to the web toolbar but because it doesn't embed the stumbled content into an iframe it is resistant to frame breaking logic. Additionally it would be always on rather than having to use the toolbar. You know all the reasons it is better to use a plugin/extension in lieu of the web toolbar.I had posted some links on the forums in response to people asking for just this. Today they were all removed and the only text I got in the email was "not legal".
I would like to know if the implication is that there is an actual legal issue or if that was intended to just mean "not allowed on our forums".
Furthermore I would like to know if there is any chance that I could receive assistance on this, or perhaps offer my own assistance to you in developing a proper, StumbleUpon officially sanctioned Safari extension.
There is definitely desire for a Safari extension to use in place of the web toolbar with the obvious benefits.
I would absolutely love to hear back from you to help clarify things for me.
Regards,
Lynn
As you can see, the claim is being made that not only do they disapprove but that what I am doing is illegal. I'm not sure what exactly is illegal about it. I have my own ideas on why they are as protective as they are about outside parties working on something like this but regardless it would appear that I'm kicking against the goads as it were. As this was intended to be a free offering for myself and other Safari users, to improve upon the web toolbar experience, I have no inclination to fight StumbleUpon on this, especially if they plan to bring in lawyers.
I'm going to update the project page and remove the link to the extension itself and take it down as well. Had I known it would meet with this resistance I wouldn't have gotten anyone's hopes up on bringing this forth. My hope is that they will take the hint that this is really something that people want and that some are willing to invest time and effort into doing if it isn't done for them, and therefore build one themselves with all the bells and whistles. Based on what I see in the Firefox plugin, I think it is absolutely a manageable goal to get a similar capability going on Safari.
Private API’s (Should You Use Them?)
In working on the StumbleUpon Safari extension, I came across requests in the SU support forums about SU providing an API for developers to create SU toolbars of their own. Currently there is a Firefox plugin provided by StumbleUpon but that's it as far as actual extensions available for SU functionality. They created a toolbar that essentially puts the stumbles into an iframe but that's fragile and can be broken by sites that have code expressly to break out of iframes. And there are other limitations too, limitations that the Firefox plugin lacks. Limitations which could be overcome in other browsers if only the private API used in the Firefox plugin were made available to all. I've stared tackling the task of breaking code out of the Firefox plugin for use elsewhere but I'm still left wondering whether I should.
Ask the Right Question
Keep in mind, there are two questions to ask here. One is whether it's a good idea. The other is whether I have a right to do so. Reusing a private API has some pretty nasty downsides. Since it is private, the interface isn't likely to be documented. You're going to be spending time looking at message traffic, poring over all of the usage in their code to see what sorts of return values are checked. And if the developers of the private API get upset over your usage of their API they could change things such that you will be forced to extensively redevelop your version just to keep up. In cases where, as with the StumbleUpon extension, communication with a server is required, it gets worse because now you're dealing with their servers and interfaces there which they define. In my case, I'm actually rewriting their private API, essentially recreating code to reuse their protocol. While it's unlikely they would change the protocol extensively, since that could alienate Firefox users, it's not outside the realm of possibility.
So why do it? If you're considering using a private API, it's likely because that is the only way to do what you want to do. Left with another choice, most developers would typically prefer to use a well documented public API if one is available since the drawbacks are far fewer. There are cases, though, where there are both public and private APIs available and the public API provides less power than the private APIs. This seems to tend to happen when the APIs are provided by a single vendor who also provides applications which make use of the APIs. Their apps can make use of the private APIs, resulting in more features than any third party app can provide.
Really, it seems like this is just a judgement call. Are you crazy enough to want to ride this train? Do you really want to risk pissing off the developers who created the private API, such that you end up having to rewrite your app from scratch just because they got a bee in their bonnet about its use? Heck, that could happen even if they don't know your name. It might have been a planned revision. The fact is, you have no promises. But if you want to create your project badly enough, maybe you're just crazy enough.
A Question of Right or Wrong
The other question is of the rightness or wrongness of using the private APIs. Of course there may be legal ramifications but that's not what I'm talking about. Let me give you an example. With MiniStumble, I'm using the StumbleUpon API to retrieve stumble URLs from their servers. That makes use of their bandwidth, CPU and power. This may be miniscule, but it all adds up. Additionally, consider that they make money off of what they call paid discovery, where advertisers can pay to inject a URL into the stumble lineup for certain categories. What happens, then, if some rogue extension grabs URLs and never reports back that they were visited? SU would not be able to report the proper number of visitors sent to that site which begins to mess with their revenue stream. That is not being a good neighbor.
As it happens, the SU servers appear not to serve up additional stumbles until previous stumbles are reported as having been visited, so there is some sanity checking that goes on, and I'm aware enough of at least that part of what SU does to try to avoid being a prick about things anyway, but it could have been a problem. The Firefox plugin for SU is not the most complex software I've seen, but the code paths are many and it is easy to lose track of where different pieces of functionality will wind up taking you. In the process of trying to rewrite or just reuse a private API, you could be underdelivering to the original API writer's customers. You might be creating problems for the API writer's business. In short, maybe you shouldn't have been doing what you are doing in the first place.
"First do no harm." The physician's creed. This business about doing this in the right is, frankly, the part that gives me the most bother. I think I'm doing it responsibly and I think I'm doing it well enough, making sure folks understand that when they grab my extension, they aren't getting something officially endorsed by StumbleUpon and so on. And the code is there. Granted, just because I can doesn't imply that I should. But then just because I could screw up doesn't mean that I will either. I expect this is also something that has to be considered on a case by case basis too. Apple actively checks for private API usage for any apps entering the App Store. SU doesn't have that option, but I've also posted in their forums about this, so other than sending emails directly to their dev team, I'm not sure what else I could do. I suppose if they want me to stop, they can just send me an email. Until then, I think I'll try to make use of what they've provided, albeit inadvertently. But I'm going to try to place nice while doing it.
More MiniStumble Hacking Fun (We Have v2.0!)
Just a quickie here. We have a version 2.0 of MiniStumble, the StumbleUpon Safari extension bar! You can find more details on the MiniStumble page.
Fun With MiniStumble – Hacking a StumbleUpon Safari Extension
You may not be aware that I've created a teensy little StumbleUpon Safari extension. If not, go check it out. Apple supposedly has approved it for inclusion in their gallery, but I've checked and I don't yet see it. Regardless, as the page says it is a minimally functional StumbleUpon Safari extension, only providing a few page redirects and using the badge API to query for the view count and page ID from their database. That's all well and good but you can't use it vote on things, and it offers no protection from iframe breakers. What's a stumbler to do!?
Well, keeping in mind that this whole mess is SOLELY being developed because for whatever reason the powers that be at StumbleUpon.com have yet to develop their own Safari extension, I've been hacking around with their Firefox extension, reverse engineering it in order to do what needs doing in mine. It's been fun and I'm making some headway but I'm not exactly sure when the next release will be. I have login capability working, but I haven't yet tested doing anything useful once logged in.
One thing I'm a little concerned about is the fragility of what it is I'm doing. There is no official API for any of this. Assuming for a moment I actually manage to rip the guts out of the Firefox extension and make it work for Safari, there's no guarantee the interface won't change later on. They might alter the FF functionality such that it uses different calls. They might break some single interface that causes my whole little project to fall to pieces. Because there is no official StumbleUpon API, I have no guarantees that any of this will continue working. But, I'm enjoying doing this little bit of hackery and it seems like something useful.
I should mention too that the Firefox extension developers were thorough. I was thinking of something quick and dirty, but there are quite a few corner cases dealt with in the code and as I start bringing things over, I'm becoming torn as to whether to try to rewrite the few bits I want to pull in or try to port the entire back end over. The pain of missing those corner cases and coding for them myself or the pain of suffering through roadblock after roadblock of making Firefox extension-compatible Javascript work in a Safari extension environment. I'm leaning toward the former though the latter would, I think, be a more thorough implementation. I don't doubt that the checks in the FF extension are necessary (like making sure to check for rapid clicking on the Stumble icon and not causing multiple async stumble requests), I may start off with a more fragile implementation in some respects, just to get it out there, followed by some touch up afterward to clean things up. I'll be honest, I'm not doing this with my usual forethought, mostly because I think at some level I still see it as a "small" project.
Anyhow, I just figured I would mention what's going on with it. Bear with me and mind the mess.
Set Up Constant Speed in box2d
This brief tutorial will show you how to set up dynamic objects with a constant speed in box2d. It assumes you have a basic understanding of how to set up a box2d project with cocos2d.
As you are no doubt aware, the box2d physics engine is a wonderful tool for creating a virtual world filled with objects that interact in a way analagous to the real world. In this world gravity, friction (including rotational friction), inertia and momentum are all simulated.
But what of the concept of cruise control? You know, you set a speed and then the target continues to try to match that speed. You might control the vector direction in some other method, but the speed is intended to remain constant. How do you do that? That's what we're going to take a look out now.
Conceptually, what we want to do is measure our current speed on each update cycle and then fire an impulse of the appropriate size and direction in order to nudge us up to (or down to) speed. What we specifically do not want to do is simply call SetLinearVelocity(). Why not, you may ask. The problem is that doing so essentially tells the box2d engine "Hey, ignore whatever you *think* should be happening to that body. Here's the actual velocity." Instead, what we want to do is tell the box2d engine, "See that body over there? I want you to add this new impulse to it and factor that in along with everything else." This lets the box2d engine take the entire model and any ongoing interactions into account rather than dropping everything and running with the new values.
Because I'm taking code out of my game Centripetal, I don't have a full project with a demo set up to show you what I'm talking about. But I will pull out the pertinent bits and provide some illumination on what I'm doing.
Before we get started, remember that box2d is a physics simulator only. It does not display graphics. b2Body objects do have a UserData attribute which is a void* and which can therefore store a pointer to, for example, a CCSprite. Likewise, you can also create a CCSprite subclass which has a b2Body* member and thus the two could refer to one another. I will leave the pointer management concerns to you based on your own implementation.
In my case, I have a CCNode subclass which has member pointers to both the b2World and CCSprite objects.
@interface BodyNode : CCNode
{
...
b2Body* body;
CCSprite* sprite;
...
}
@property (readonly, nonatomic) b2Body* body;
@property (readonly, nonatomic) CCSprite* sprite;
...
@endThere's more to it, but that's enough to get us going here. Now let's focus on our CruiseControl object. We're going to subclass BodyNode for this and add a little to it:
@interface CruiseControl : BodyNode
{
...
float speed;
...
}
@property (nonatomic) float speed;
...
@endWe've got a BodyNode subclass to which we have added a speed member. Why speed? Why not a b2Vec? We don't want a steady direction, just a steady rate of movement. We want the box2d engine to bounce us around and change our direction but we want to know just how fast we should be moving and try to nudge ourselves just enough, but in the current direction, in order to achieve that. Let's so how we do it:
-(id) init
{
if ((self = [super init]))
{
...
[self scheduleUpdate];
}
return self;
}Okay, the first thing you'll see is that, among other things in init, I'm scheduling an update callback. This doesn't have to happen in init, but it's a convenient place to do so. Note that this is a subclass of BodyNode which has a pointer to the CCSprite we will ultimately be moving around in cocos2d. The update will occur on our BodyNode subclass and not directly on the CCSprite we contain.
-(void) update:(ccTime)delta
{
b2Vec2 curvel = body->GetLinearVelocity();
if (curvel.Length() < self.speed || curvel.Length() > self.speed + 0.25f)
{
float curspeed = curvel.Normalize();
float velChange = self.speed - curspeed;
float impulse = body->GetMass() * velChange;
curvel *= impulse;
body->ApplyLinearImpulse(curvel, body->GetPosition());
}
}There may be more going on inside your update method (there is in mine in fact), but what you see here is the nuts and bolts of the cruise control concept. We first retrieve the current velocity which is a vector with scale equal to current speed. We check that speed against our desired speed. If it is too low or if it is too high, we want to apply an impulse.
Note that I have a bit of a fudge factor. You are dealing with floating point numbers and the usual lack of precision that entails. You can play with your fudge factor as you like. Maybe you're okay with being a little slower but no faster. Maybe you don't mind a little wiggle room in either direction. You can alter that to your heart's content.
So if we need to apply an impulse, we first normalize our current vector of movement. That gives us the direction with a factor of 1.0f which conveniently allows us to reuse the vector by multiplying it by our speed to get what we need. We calculate our speed by simply subtracing the current speed from our desired speed. Note that if we are moving too fast, this gives us a negative value. This is important in the next step as we multiply by the body's mass to get the needed scale to apply to the vector to give us our new direction. In the case of excessive speed, this becomes a negative value which reverses the vector for purposes of applying the impulse. Finally, we apply the impulse to our body at its location, allowing the physics engine to nudge us enough to get us back to the correct level of speed.
Naturally, you can play around with this as much as you like. You can alter the scheduled update to call whichever method you prefer. You can alter the frequency of the scheduled callback too. Or if you prefer, you could conceivably eliminate the update callback on your BodyNode subclass by using the box2d processing loop to watch for your CruiseControl object and perform your check at that time. Regardless, you now have a simple method of setting up cruise control for your box2d objects.
An additional note concerning gravity: When developing Centripetal, I set the simulator up with no gravity as I was simulating a top down view of a frictionless surface. I didn't need gravity. The problem you will face when adding gravity is that if the gravity is intense enough compared to your desired speed, even with constant impulses to push the object along it won't be enough to counteract the gravitational pull between steps. So your object might end up slinking around on the bottom of your simulation view rather than moving about freely. If the gravity is low enough relative to the desired speed, then the steady stream of impulses coming each step should be enough to let you fly.