Zac Bowling’s Blog

Human Code Generator

Monoport Pastbin update

without comments

The pastebin for mono, monoport.com, now has captcha. The spam was to much.

JB updated his “monoporter” ruby script for it. You can see the source and download it here.

Written by zbowling

July 20th, 2008 at 10:31 pm

Posted in Mono & .NET

Tagged with

Mono on Openmoko and iPhone

with 2 comments

I’ve been hacking this week and I did it on both phones!

First I’ve got Openmoko running Mono. Not sure if anyone else beat me too and already did it but it pretty much worked out of the box, after some environment variable tweaking. Hello World at the shell is alive! After I got it running, I stopped. This isn’t so much a challenge in that this runs Linux, up to par with the Maemo OS on the Nokia 770/N800/N810 and we already have decent ARM support for that. It was surprisingly uneventful.

On the iPhone side, I’ve got something that is working to some extent. I’m cheating in some evil ways to make it load so I feel weird calling this officially “running” Mono yet, but I thought it was blog worthy since I did get it to call me back with a string that contains the all to classic “hello world” (totally heart stopping moment). This is different then the earlier effort in that my way is fully within the rules of the official SDK from Apple (other one ran on jail broke phones). I have to give credit to the previous effort because if it wasn’t for that work to get it working on the jail broken version months ago, I wouldn’t have this working as well as I do now. Lots of issues still to overcome still but Mono is looking to be a really viable option for development needs on the iPhone.

It’s hard to post pics to get everyone excited because right its just me sitting in front a really cryptic terminal and debugger, but trust me, it works!

In the mean time I’m still working on my PocketWiki application. Finding bugs in the SDK but there are some interesting things you can do.

This little sniplet sets the content of a webview, and then a button on the window is wired up to execute a function in that HTML and get the result back and display it in an NSAlertView:

- (void)awakeFromNib {
	[webView loadHTMLString:
	 @"<html><head><title>Hello HTML</title>\n"
	 @"<meta name=\"viewport\" content=\"width = device-width, user-scalable = no\" />\n"
	 @"<script>\n"
	 @"function getText(){\n"
	 @"return document.testform.test.value + \"\\n\";\n"
	 @"}\n"
	 @"</script>"
	 @"</head><body>TEST <form name=\"testform\">"
	 @"<input name=\"test\" type=\"text\" value=\"example\" id=\"test\" />"
	 @"</form></body></html>"
					baseURL:nil];
}

- (IBAction)buttonPush:(UIButton *)sender {
	NSString* var = [webView stringByEvaluatingJavaScriptFromString:@"getText()"];
	if (var != nil)
	{
		UIAlertView *alert = [[UIAlertView alloc]
		    initWithTitle:@"The text box says "
			message:var // bug? they will release our string
			delegate:nil
			cancelButtonTitle:@"OK"
			otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	//[var autorelease];
}

Shameless plug: If your company wants to break into this hot market while it lasts and deploy a rich client app for the iPhone that ties into your business’s existing web services or applications so that you enrich them with features like quick auto-login (and other data stored locally on the the phone), offline capabilities, camera, and location apis, and the upcoming push services API Apple is soon to release, you can contact me through my site. :-)

Update:
I jumped the gun. What I was seeing was a EXC_BAD_ACCESS error releasing my thread and returning my callback I was expecting when it worked. I didn’t see the crash because of another bug. The memory on the iPhone can’t be executable and writable at the same time. This is a iPhone 2.0 change. iPhone Mono will only work if we get Mono full AOT (or someone brings back the Mono interpreter from the dead).

Written by zbowling

July 19th, 2008 at 2:36 am

Posted in Mono & .NET, iPhone

Tagged with ,

Email to Apple iTunes support

without comments

I have heard of Apple letting you re-download your music but you have to contact support, give them a good excuse and they will only do it once. Here is my email to them (trying to sound like “normal” user so they take pity on me).

I bought this brand new MacBook Pro after my Windows machine cratered about 2 weeks ago. I had all my music on an external hard drive. After connecting to my new Mac, I was able to load all the files into iTunes fairly painlessly.

The irony is that I wanted to setup Time Machine using that hard-drive as the backup device but I had to reformat. So I went to copy all the files to my local drive. What I didn’t notice was that the copy would be to big for the partition I was coping to until after it had already started, so I stopped. Not completely up on Mac usage pardime differences, I didn’t notice I was actually doing a “move” and not a “copy”, until I noticed half my files were in on the local drive and the on the external drive. Used to how Windows works, I knew that dragging the one folder to one of the same name in a different location will merge the contents of those folders, but on Mac that actually means deletes the destination folder and replace it with your source folder. (ARGGG!!!)

I though it was going to somewhat ok because I had my favorite music still on my iPhone and I knew I could pull it off there. I plugged it in but I had not associated it with my new Mac. I did so and then “backed up” in iTunes just to be safe (which turns out is not really a “full back up” like it says but just copy of the settings), and synced then I synced it up (copy purchases from iPod menu was no where to be found like remember from my iPod back in version 6). It then deleted everything on the iPhone and tried to resync from scratch.

I have lost nearly all the music, movies, tv shows, and audiobooks I’ve purchased since 2005 (everything I had before then is still on my old iPod Photo).

Can you allow me to re-download my purchases, or offer any tools that will help recover files on a FAT formated drive from the mac?

Lets see if this works :-)

Written by zbowling

July 18th, 2008 at 3:02 am

Posted in iPhone

Tagged with ,

Farewell Texas Instruments…

with one comment

After 2 years, to much regret, I’ve decided to leave Texas Instruments and pursue other opportunities.

To everyone of my colleagues in TI’s educational technology division, I wish you the best and I will miss you all greatly. I’ve have had some really amazing experiences working with you all and I learned a lot. However the timing is best now now that we are coming to the end of this project for me to make my leave.

July 25th will be my last day. After that, I’m taking myself on a long needed vacation (haven’t had one since I started so I REALLY need one). Then its off to the next great adventure in life (and if I can just figure out that one out, I’ll be set :-))

I may be on the market soon, so if anyone is in need of a systems engineer or developer with more then 9 years of experience and proficient in cross platform, embedded, and network service based development (preferably in C, C++, Objective C, .NET, Mono, and Java), then leave me a comment. :-)

Written by zbowling

July 14th, 2008 at 7:21 pm

Posted in Mono & .NET, Personal

Tagged with

Phone Crazy (part 2)

without comments

I ran by the Apple Store again. It’s incredible still. 5 hour wait time estimate still and out of 16gb black versions. It’s straight up madness. I’ve never seen so much excitement over a product in my life. Not even the XBOX, PS3, and Wii lines ever compared to this type of crazy excitement (but maybe that’s because they ran out of stock where Apple keeps just enough coming to meet the demand).

I’m writing two applications for the iPhone at the same time (two track mind :-) but I have a good reason).

The first is a MetablogAPI based application so you can you quickly blog, edit, and delete your posts if you blogging software supports the MetablogAPI (other blog apis I’m to lazy to support). It’s a simple app but on the back end I’m using Mono to handle the XML-RPC calls (more as a proof of concept for mono so the application is not a high end app with tons of features like HTML input, geo tracking, and image uploading but maybe later). I’m using this as more of a test application rather the one I want to work on (unless people like it). I’ve got it working in the simulator and linking correctly there, but that is X86 and far easier. I’ve got lots of work to do on my build setup to deploy it to the device with having to build Mono. Before I release and production quality version I’ve got to get the size down as well so my go down the path of what Moonlight is doing with Cecil to trim down all the assemblies to a limited set. There is plenty of space for a full blow Mono install but not much memory.

The second thing I’m working on a Tomboy like notes app. Wiki-text like input on the iPhone interface is weird so I’m creating new concepts to help out with that, that I’m experimenting with now (all new ball game of user interface rules and expected norms in this world). I’m working the use interface at the moment. I’m designing my own custom text view to render the data, handle links, and handle in input events. My text view has to support handles my input and supports highlighting (which is really difficult it turns out). The text view in CocoaTouch is ok and may work (but with a lot of fighting) so rather then overloading and extending it, I’m designing my own from scratch and doing it in C. My hope is to create something more portable to other devices later. I’m abstracting all the paint calls and input event handling out to an abstraction so that when I get my OpenMoko setup going, I can reuse the same input system and rendering between the two by implementing another backend for the rendering code against whatever graphics system I use there and fit it in to whatever control/widget system I use there (hopefully it pays off because i would love to do a release for both).

Right now, I’m handling basic input and font geometry (to wrap and format the text). Since I’m only doing this for the text view area leaving everything else native and properly abstracted from my core it should be maintainable and easy to port and maintain my ability to be act like a properly native citizen on any platform I port it too.

When I get Mono working on the first application and evaluate it, I’ll decide if I want to do the backend in Mono on this second one (I would love to share code from Tomboy if I can so that maybe I can do some syncing between the two but with the differences in how I can display, it may turn into a converter rather then a syncing system).

Written by zbowling

July 12th, 2008 at 5:58 pm

Posted in Mono & .NET, Personal, iPhone

Tagged with ,

Phone Crazy

without comments

Well, the same day my OpenMono FreeRunner ships (which I ordered because Apple was too restrictive on the developer program and giving me the cold shoulder) I got accepted into the iPhone Developer Program. So payed the $99 and downloaded the new SDK.

Now I’m conflicted. It’s a good kind of conflict though. All the more reason to get Mono working on both a develop something cross platform. :-)

I waited in line at the Apple store for the iPhone 3G. It was nearly 900 people thick at when I arrived at 6:00am. By 10am, it was still 300 people still in front of me (but now moved into the store) but I had to get to work so left and didn’t my any new phone hotness today. In all there were maybe 2000 in line, and a lot more trying to get a peak.

It was a weird experience though. The Apple guys where getting us into the mall early (it opened really at 9am so they had too), handing out free coffee and answering questions, while we waited which was awesome. When the doors opened, there were about 50 people in Apple shirts clapping and screaming and wanting to shake our hands and take pictures with us like we were rock stars or something. Was a little awkward. I bought my first gen iPhone at an AT&T were the reception was far from as crazy. Oh well. Try again tomorrow I guess.

Written by zbowling

July 12th, 2008 at 1:51 am

Posted in Personal, iPhone

Tagged with

Ordered Openmoko

without comments

Don’t ask me why but I just purchased an Openmoko Freerunner (and debug board). My order number is just over the three thousand marker (would of figured it would have been higher because of the international press but that could be because of anything). I’m also going to be out there to Friday morning most likely in line buying the iPhone 3G. My excuse is that I’m a software engineer and need to know the market and my options (a good enough excuse for me. got ideas and need to know the platforms :-)).

Written by zbowling

July 8th, 2008 at 9:19 pm

Posted in Personal

You should too

without comments

Written by zbowling

July 3rd, 2008 at 9:25 pm

Posted in Personal, whatever

iPhone 3G/2.0 or OpenMoko or Andriod

without comments

Two revolutionary phones coming out at the same time and a third that people will think is revolutionary (just kidding).

My thoughts coming from my thoughts a developer and what I know from my experience as a OSS developer and enlightened consumer myself. I’ve done lots of mobile development in the past. Limited by J2ME or Brew, horrible systems that limit my break in to the market put in my cell providers, having to get approval to run the software on my own phones or customers phones from the manufacture and the cell company using signatures and keys (killing open source efforts for the phones). It’s a nasty game.

OpenMoko

Very interesting. I defiantly will be ordering the OpenMoko Freerunner as soon as it comes out to evaluate after it comes out. I’ve been following the project and tinkering with the developer kit in the past. It’s Linux, I can do what I want, its not sold by the cell company, and so it’s mine to do what I want and it’s free for me to change it. This appeals to me as a developer and is great for customers because it brings variety and customization, cheaper software and better quality.

The Freerunners hardware could be better, but they are trying to use components with only hardware with publicly documented interfaces or using open standards or provide free drivers, so it’s hard. Only USB 1.1 USB, no camera, a limited to 256mb of internal flash hurt (with SD card support we may be able to get up to 8gb). The hardware is open as well as OpenMoko publishes the CAD designs for everything, and its packed full of interfaces to stick add on new things.

iPhone 2.0 and 3G

I was one of the first to stand in line to get the iPhone. I was one of the first to run the activation hacks and jailbreak it. I seen the potential of the platform for myself. When apple anonocced the developer program I was extreemly happen until I read all the restrictions. Feels like everything I faced before. I’ve signed up and have been rejected by the developer program, so no chance of my application running on through app store (thankfully the jailbreaking community wasn’t deterred by this program so I will continue my development plans.

I will still likely upgrade my iPhone to the 3G version though. One thing is that the iPhone chick magnet of hotness ( just kidding :-) ).

Andriod

Its neat, but I don’t think it will get as accepted highly by the development community. It’s going to be hard to convince people to rewrite their applications since Andriod’s system pretty requires it to run since everything must run on their VM. Sure its linux and its going to open, but its like BSD open and the people selling the phones are likely to lock it down for there versions preventing modification, so no native code will not be able to be introduced. Just not doing it for me.

howtoqk0.png

Written by zbowling

July 3rd, 2008 at 5:33 pm

Posted in Personal, iPhone

Tagged with

I installed Vista finally

without comments

Alright, that isn’t entirely true. I installed Vista on my new MacBook Pro with Ubuntu and SuSE at the same time. I only did so because Fry’s no longer stocks XP. This is the first time I have honestly used it (with SP1). It feels like XP except for a little more annoying (I had trouble finding display settings in the control panel, the new start menu being embedded with a scroll pane was annoying at first until I figured it out, etc.) I still see a lot of the same in many places though. One thing is the all to famous common color picker dialog (same since Windows 3.1). Other then that, nothing to special with it from my view (except getting to play with .NET 3.5 but its still slow even on this brand new 2.6ghz macbook, Nvidia Geforce 8600 with 4g of ram running in bootcamp).

The biggest reason for installing it is to test an application that runs in Vista that I’m maintaining in my free time that has a bug running on Vista. One of my friends told he had a bug and after investigating I blame the DRM in Windows sound. (His older Creative card has horrible support on Vista.) I gave him a copy of Ubuntu and he is running like a champ (he complained about not having I haven’t iTunes to play his DRM encoded music but I showed him Wine and he was good to go. Thanks to Mono, my app runs on Linux (in fact I developed it on Linux and thats the only place I’ve ever tested it and it worked for everyone on Windows that used it until I heard this bug on Vista happening). (I’ve mentioned DRM twice so far so that can’t be good).

I’m putting together a public release of that program later and a making some cool YouTube videos on the topic on what is to come (hoping to generate some excitement). I have to admit that its mainly written in C but it embeds Mono on the Linux and Mac versions. It’s little but its big at the same time. :-) That’s all the details you get. No planned release date yet. (don’t you wish you knew what it was yet?).

Written by zbowling

June 27th, 2008 at 9:44 pm

Posted in Personal

Fun weekend.

without comments

I’m ordered a new MacBook Pro last week. Still waiting on it to arrive. I can’t wait!

As many may remember my troubles with Dell and Alienware on waiting over 3 months with both companies trying to get a super-maxed out laptop shipped to me back in 2005-06 and both constantly stringing me out and delaying me for so long that the machines dropped in price by the time they wanted to ship. The second pass I got the Alienware finally but it turned into the worst nightmare ever (this is before Dell bought Alienware too). I spent over $4500 on that machine. The sad part is that saga still hasn’t ended. I filed a lemon law claim review request with the Florida district attorney (where Alienware is located) after the hardware failed within a week after getting it back from service, on three separate occasions, each time taking around 30 to 45 days to repair. By the time I got to make any use of the machine, it was already antiquated and outdated and only worth $1500 if bought brand new. Machine is collecting dust because it failed a 4th time.

I’ve been investing in Apple lately. Bought in at $122 and the stock rose to $185 a few days ago. Nice 50% return in unrealized profit. I knew it was going to happen. Even as much as I’ve dogged Apple’s developer program in previous blog posts, the device and the OS are still kick ass from the development perspective. OpenMoko is posed to give it a run for its money. Not a big fan of Andriod (which is a joke if you ask me… an almost side stepped evolution of J2ME junk). The iPhone is basically a desktop OS with all the pieces, so everything ports nicely which is the right direction for mobile software (desktop/laptop and mobile will be indistinguishable soon, so Android is dead from the start). OpenMoko and Nokia’s Maemo (or even ACCESS’s linux platform and the Qtopia from Trolltech) are far better off.

Playing with PS3 this weekend while I wait on my laptop. Got Metal Gear Solid 4. As a developer, thinking of how much there is too it, its amazing. If you know anything about game development, 3D rendering, or just a ultra geek about gaming, then this is the game of the year. The online part is a little lacking but makes use of bit torrent for updating.

Written by zbowling

June 22nd, 2008 at 8:11 pm

Posted in Personal

My keys are good

with 2 comments

I know I run Debian and with the latest Debian OpenSSL fiasco, everyone is a bit jumpy. My keys however were not generated using OpenSSL’s ssh-keygen app but instead a propitiatory application I use that bases my keys off my finger print. :-)

Written by zbowling

May 24th, 2008 at 3:29 pm

Posted in Personal

Tagged with

Vista SP1 sales video “rocks”?

with one comment

I just don’t know what to make of this video… I guess Microsoft is trying to break the stigma around Vista as best they can (I don’t think this video is helping their case much).

Texas Instruments, my company, will not support upgrading to Vista across the entire corporation as was leaked to the inquirer back in late 06 to early 07. No Vista machines in sight here still (except in the testing labs). Everyone is running XP if they are using Windows, but you do see a lot of Mac’s running Leopard, or and few laptops running the latest Fedora, Ubuntu, SuSE, and OpenSolaris desktops for those of using in various development and engineering roles.

I’m sure TI would probably use Vista if Windows 7 isn’t out by the time that XP goes into legacy support status, but XP works and we don’t have any problems with it. We already bought our huge corporate level volume licenses for XP so I can see the logic into why really IT doesn’t want to upgrade more then 10,000 users machines here when there isn’t a significant gain (and more of a loss really) by doing so even still. Nothing in Vista (even in SP1) is really worth upgrading for.

Written by zbowling

April 16th, 2008 at 9:30 pm

Posted in Personal, whatever

iPhone developer program is a joke

with 50 comments

The developer program is turning out to be bunch of hype for something stupid. The restrictions on what your application is allowed to do is total, laugh-out-loud, crap.

I was initially excited about the SDK and developer program for the iPhone. I was willing to live with Apple being only distributor of Apps and getting a cut of the profits. I was willing to live with an entrance criteria to get into the App Store.

But then I heard about the other restrictions, and if you haven’t heard yet about the restrictions placed on your applications, here are gritty details:

  • “Applications may only use Published APIs in the manner prescribed by Apple and must not use or call any unpublished or private APIs.” (section 3.3.1 in the SDK license agreement) That means currently no access to IOKit
  • “An Application may write data on a device only to the Application’s designated container area, except as otherwise specified by Apple.” (section 3.3.4 in the SDK license agreement). No full file system access basically.
  • Your application is completely closed when the user leaves it like when they get a call or any of a number of actions happen. (specified in the Human Interface Guidelines). Only one application can run at a time basically so no background applications. (Something you can do in the current Open SDK)
  • “An Application may not itself install or launch other executable code by any means, including without limitation through the use of a plug-in architecture, calling other frameworks, other APIs or otherwise. No interpreted code may be downloaded and used in an Application except for code that is interpreted and run by Apple’s Published APIs and builtin interpreter(s).” (section 3.3.2 in the SDK Agreement)
  • “If Your Application includes any FOSS, You agree to comply with all applicable FOSS licensing terms. You also agree not to use any FOSS in the development of Your Application in such a way that would cause the non-FOSS portions of the SDK to be subject
    to any FOSS licensing terms or obligations.” (section 3.3.14 in the SDK license agreement)
  • No way to write plugins for the apps that exist on the phone right now, even for apps that openly support it plugins like Safari.
  • Applications can be rejected for not meeting the Human Interface Guidelines
  • No VoIP apps that work over cell network (that is acceptable, VoIP is a bandwidth hog and with unlimited data, it hurts the carrier)

Porting Firefox would be impossible because it supports downloading and running “interpreted code” with its Javascript engine. Things like Mono could only be used if you included a version Mono with your application, so basically no system wide install. No way to write a usable IM or IRC client on it, since apps can’t run in the background. Since we won’t be able to write plugins for existing apps like Safari, it means no Silverlight/Moonlight and no third party Flash support. IOKit isn’t in the list of document APIs even though its on the iPhone today, so no way to access the dock port to get to the PC or access the Bluetooth hardware. No way to tie into the data sync integration as well, so you can have it sync data with other things on your PC when docked.

What we get is so much more limited then what you can get natively in the unofficial Open SDK that is out there for the jail broke iPhones today. What annoys me is that Apple only played it off like their was only restrictions around application acceptance criteria for the application if was porn or a bandwidth hog. Not all this crap.

I think its idiotic of Apple to think this is what we were looking for. It’s pretty much a giant joke. I hope the public out cry about this is enough to knock Steve out of his black sweat-shirt and blue jeans, and have another wake up call.

Written by zbowling

March 14th, 2008 at 10:01 pm

Posted in Personal

Tagged with , ,

T³ conference

with 2 comments

Yesterday, I attended the first day of my company’s huge T³ conference. It was something else and a little different then the software conferences that I’m used to attending. Nearly 3000 people there. So many teachers from around the world. It made me appreciated the reach our software and hardware has a bit more getting to see how large our customer base is. As a software developer, I think we sometimes get separated from our customers through so many layers, and for me it was great to get to meet so many of them. One part thing I love about our company is that we try to get everyone in just about every role out there to interact and listen to our customers. Everyone from software developers, QA testers, project managers, distribution, sales, marketing, customer service, product managers, HR, configuration management, hardware/electrical engineers, and just about everyone else in our division came out to help with the conference.

I also met up with the Vernier guys there, one of the members of the GNOME Mobile community, and I got to play with their new GNOME based LabQuest. The Vernier guys are awesome. I’ve enjoyed working with them in the past to make sure that our TI-Nspire product works with their Vernier EasyTemp®/Go!® Temp/Go!® Motion probes and sensors, so they can power the data collection features of our product. The Vernier guys are big Linux supporters which is nice to see.

Written by zbowling

March 1st, 2008 at 3:18 pm

Posted in Personal

Tagged with

Unit Testing

with 4 comments

I’ve come across some really bad unit tests in a number of projects recently. I’m assuming that were written in the past only because someone said to the developers something like “Writing more unit tests improves code quality, so everyone write more unit tests!”. That was all the direction they got it seems (I’m assuming that from reading the code), and unfortunately, the developer and the leader wanting the developer to write unit tests wasn’t exactly sure why unit tests are important or how to write effective unit tests.

There are a few common goals that writing units help solve.

  1. Unit tests provide an excellent facility for regression testing, in that help they allow programmers to easily refactor a piece code at a later date, and make sure that each module still works correctly.
  2. Unit tests can be written to help simplify integration if you are working from the bottom-up in many cases. This goes well with really good planning around integration points. In a large project you may need to separate everything out into smaller units or modules. All the pieces are probably going to developed concurrently by different developers and teams. If you write unit tests around your integration interfaces, you can flush out any issues before hand and move on to develop other pieces of the project, and that lessens the strain on your integration phases later.
  3. Unit tests can also offer a form living document for others to understand how the code works and how they can use it or call it by providing a bunch of working examples. Since the unit tests are constantly being updated as code gets refactored they are usually more reliable then any static documentation which can drift and get out of date.

Another overlooked piece is when should you write unit tests. I know that in a lot of projects that I’ve worked on, the time developers would take to write their unit tests is usually delegated to the end or when they have any extra time. The unit tests usually end up the victim of procrastination and a lack of coverage usually causes more headaches later.

I believe unit tests should almost drive your development, especially when you are developing in an agile environment, defining features as you go and you are constantly refactoring your code.

Unit tests are great way of showing you where you have spaghetti code and complex environmental dependencies right away.

If you enforce unit tests on all business logic, you pretty much can enforce a clean separation of interface and implementation, and drive you code towards using better coding standards and patterns out of necessity to just be able to test your own code (like moving your code to a basic model/view/controllers pattern). It’s a great practice to get into for writing maintainable code.

You have to be smart about your unit tests though. More is not always better. You have to be practical and not walk about until you feel you have sufficiently covered everything. Anything that preforms any custom logic based on a specific input is a big candidate for a unit test. Sanity check unit tests are not usually necessary (such as writing a unit test around a property/setter-getter method that simply reads or writes to a field in a class).

One of my pet peeves is a test that knows the internals of a particular unit, not the function of that unit provides. You should pretend you don’t know how your code works internally, and write tests how other code is going to interact with it. The exception to that rule is if you know of ways that unit could easily break with specific inputs but stay within the confines of what that unit provides you. Do not write units tests that simply reconfirm that your code works exactly the way that you wrote it and would probably break if someone refactored the internals of that code.

For example, lets say I have a function called “SaveCustomer(String id, Customer customer)” that I know saves to a database underneath and another function called “LoadCustomer(String id)” that loads from that database underneath (the underlying database is not intended to be accessed directly except by the customer abstraction in this case). It would not be an effective test to write a test that calls the SaveCustomer function and then connects to the database to see if its written, or similarly, write a test that calls the LoadCustomer function and checks to see if the data returned is the same as in the database. Rather a more effective test would be write a test creates a customer and attempts to store it using the SaveCustomer function and then tries to load it back out using the LoadCustomer function and verify the data in the customer objects survived round trip.

Another example that I ran into was a function called “getOffset” which was meant to return the internal position of where to read off an array returned by that same class. The previous programmer that wrote the function knew that the value would always return 16 at that time but made the function so that he didn’t have any magic numbers running his code and that he could change the value it returned to something different someday (or possibly even dynamically figuring its position at some point). However the programmer wrote a unit test to make sure it always returned 16 and sure enough when I went in and changed what the offset would was, the unit tests broke although no code did that called that function. Effectively, the test was broke and not the code.

It comes down to being smart and practical about your unit tests. There is no perfect setup. I try to shoot for a test around each public function and protected function (if intended to be inherited by other classes), and if applicable how the class is used as a whole (thinking of it as almost writing examples and documentation for the code).

Some good candidates for unit tests are around that code that does logic in loops, contains switch statements (especially in languages that all statements to can fall through), any goto/jump statements, any regular expressions usage, any “auto-magical” features that can possibly fail at runtime, non generic collection usage, null pointers, static position access on non-rigged arrays, primitives based by reference, and code that calls reflection features of your language.

In scripting/interpreted/dynamically typed languages, lots of sanity check tests are also more useful to attempt to test each code path possible. I wish you luck if you are writing a large application in one of these languages if you don’t have a strict coding standard and a whole bunch of tests.

Whatever you do, you can’t trust unit tests to be your only type of testing. Unit tests are not well suited for GUI testing and they can almost never do functional testing. Unit tests can only tell you if an error occurs in one particular case but not that couldn’t foresee to happen in many cases. Automated testing solutions depending on your project are really important as well in many cases.

Written by zbowling

January 27th, 2008 at 10:31 pm

Posted in Personal

Tagged with , ,

Coke machines that take credit cards

with 6 comments



What the hell is the world coming too. I found this in my local grocery store tonight. $1.50 + credit card interest is totally worth the convenience of not having to handle a dollar bill.

Update -
Found the company’s product docs. “Bright, flashing blue LEDs to attract customers.”

Written by zbowling

November 25th, 2007 at 2:21 am

Posted in Personal, whatever

Top 10 pages on Conservapedia

without comments

This is the best thing that I have seen all day! http://www.conservapedia.com/Special:Statistics. Not gay at all.

Written by zbowling

November 22nd, 2007 at 6:47 am

Posted in Personal

Phalanger on Mono (part 2)

with 5 comments

I blogged earlier about getting Phalanger running on Mono and the missing feature missing being the native extension support because the bridge was written in Managed C++.

Well I came up with an all C# solution. It’s not close to being done, more just a proof concept. I’m not sure the willingness of the upstream with supporting this method because it probably means a lot more work to maintain this method then the managed C++ version. With the managed C++ version, its less complicated because at least you can reuse the headers from PHP to help out with all the function declarations, typedefs, macros, and structs (that sometimes break ABI compatibility on rare occasion in PHP from version to version which everyone who has ever used the Zend optimizer knows about when they upgrade their PHP version the old version of Zend’s optimizer breaks). With the all C# solution, it means reversing all those headers and duplicating their function in C#.

There are also a few typedefs in the headers that compile to two different sizes between 32bit and 64bit platforms so I have to declare two versions of the same p/invoke calls on some occasions and use one or the other if the code is running on 32bit or 64bit.

The way the code works on the managed C++ side is that the code will iterate through all the php extension dynamic libraries. All the extensions in PHP are required to expose a standardized set of function exports. The managed C++ code will dlopen them (I’m using Unix terminology here, LoadLibrary on windows), use dlsym to get the function pointers for that extension, store them in to a struct, and stick the struct on to an array where it holds references to all the extensions. (I’m way over simplifying what it does, as phalanger also does some neat isolation tricks by loading the extensions into a different memory spaces/processes to keep buggy extensions from crashing the process phalanger is running in and remotes into them).

This same kind of operation using dlopen and dlsym like this can be done from Mono/.NET natively in a cross platform safe manner using just plain old P/Invoke and some really cute System.Reflection.Emit code. (Cecil maybe able to help me here for what I’m doing later). Basically, it means I emit an class for each extension on the native side, with all the emited classes inheriting from a interface that matches the same method signatures of the exports I’m P/invoking in on with each lib. It’s not possible to declare an extern in an interface, so I emit both a private pinvoke call and a public function with the same signature and name that just calls it which is in the interface. The class I emit each time is almost identical except for the given library name each of the p/invoke calls call out to. Poor mans dynamic p/invoke. This entire process can be at runtime, or done before hand, where I can generate assemblies or even exes that remote into a parent process for poor mans process isolation (which is really easy since I’m using a well known interface for each of the extensions so remoting to it is simple).

After the extension is loaded up, the managed C++ code will then do some System.Reflection.Emit operations to generate a wrapper assembly around the functions provided by the php extension library. This is done using the reflection like information provided by the extension to emit a similar call in the .NET side that proxies down to the extension. PHP has setter and getter methods, overloading, purely dynamic functions, well known functions, etc. Thankfully this managed C++ code converts to C# without to much trouble. There is still a lot of structs to rebuild though.

In all, its about a 6 to 8 week project if I had the time. (which I don’t) :-)

Written by zbowling

November 21st, 2007 at 3:12 pm

Posted in Personal

Tagged with

Phalanger on Mono

without comments

In my free time, I’ve been trying to get Phalanger working better on top of Mono. Phalanger is a PHP implementation for the CLI and ASP.NET. It runs like a champ with the basic features on top of Mono.

One of the greatest features, and also biggest missing feature with running Phalanger on Mono, is native support for PHP extensions. The extensions in PHP are basic dynamic libraries, exposing a common set of standard C exports. In Phalanager, they have written a wonderful bridge between them, but unfortunately for me though, this bridge is written in Managed C++ (icky) and does a lot of Win32 specific things. They are also doing a lot with named pipes and running things in separate memory spaces, and worst of all, a good portion of the managed C++ code is doing Reflection.Emit. No easy way to get around this it looks like. *sigh*

Written by zbowling

November 19th, 2007 at 12:29 pm

Posted in Personal

Tagged with