Showing posts with label computers. Show all posts
Showing posts with label computers. Show all posts

Friday, March 12, 2010

UnitTest++ == teh awesome

Been using UnitTest++ for the last couple months on my work project. So far, enjoying it. Very simple to:
  1. set up
  2. add new tests
  3. explain to the other developers
  4. ?
  5. profit

Our unit tests are part of our project's Visual Studio solution file. Each unit test's project is setup to run the unit test as a post-build step. So far, it's caught a number of 'simple' fixes that broke some.

I've also setup a Hudson server to automatically build our project... But, I didn't want it to fail the build if the tests failed. And, I wanted to collect the XML reports when it's built from the continuous integration server.

So, rather than always just blindly calling UnitTest::RunAllTests() in the unit tests's main() function, I made a utility library that'll look at an environment variable to determine how it should run the tests.

In the unit tests's main() :



int main(int, char const *[])
{
return myUnitTest_runAllTests("my_test");
}

The utility function:




#include "cstdlib"
#include "fstream"
#include "iostream"

#include "boost/filesystem.hpp"

#include "UnitTest++/UnitTest++.h"
#include "UnitTest++/XmlTestReporter.h"


namespace bfs = boost::filesystem;

struct True
{
bool operator()(const UnitTest::Test* const) const
{
return true;
}
};



DLLExport int myUnitTest_runAllTests(const char* const testName)
{
char* xmlDir = 0;
size_t len;
errno_t err = _dupenv_s(&xmlDir,&len,"UNITTEST_XML_DIR");

if (err || len == 0)
{
// env var not set, just run the test w/ standard mechanism
return UnitTest::RunAllTests();
}
else
{
bfs::path p = bfs::path(xmlDir);

// free memory from _dupenv_s
free(xmlDir);

// if necessary, create output directory
if (! bfs::exists(p) || ! bfs::is_directory(p))
{
if (!bfs::create_directories(p))
{
std::cerr << "Problem creating directory " << p << std::endl;
return -1;
}
}

std::string fname(testName);
fname += ".xml";

// use / operator to append filename onto path
bfs::path fpath = p / fname;

std::ofstream f(fpath.file_string().c_str());
UnitTest::XmlTestReporter reporter(f);

UnitTest::TestRunner runner(reporter);

// if we're outputting to XML, don't return failure as return code
// this way tests can fail without it making the automated build think the build failed.
int ret = runner.RunTestsIf(UnitTest::Test::GetTestList(),NULL,True(),0);

return 0;

}
}


And then you just point Hudson's xUnit plugin at the generated reports. Came together suprisingly easy

Tuesday, July 21, 2009

argh

why did it take 10+ years for us to realize our round-to-nearest-100th algorithm is busted (on windows)?

Not sure why the original developer cast to 'long' rather than using some modulo division on the floating point number. Stupid windows 32bit long.

And, we can't do the easy solution of 'long long' because of incompatibility with the HP-UX C-runtime on the old-as-dirt patch levels some of our customers refuse to move from.

Saturday, July 18, 2009

why I love python

Lately, discussions at the NFJS conference and recent conversations with friends have made me introspective about why I like Python.

I first started using Python about 9 years ago. Previously, I'd used mostly C, C++, Perl, Pascal, and a very little bit of Visual Basic.

Pascal was what I'd learned in High School. VB, C, and C++ were what I'd used during college (I guess there was a teeeeny bit of Lisp thrown in there too). My first couple years as a software engineer, C++ was the hammer with which I'd pounded all programming nails.

Eventually I learned Perl. It was OK. But, like most people, I'd write Perl scripts and not be able to read them the next month.

After a recomendation I'd read online, I tried the Python tutorial. The conciseness was a revelation. The way it got out of my way and let me worry about the problem and not the compile/run/debug loop. Having dictionaries and lists as a first-class language features blew me away. I don't know why similar features in Perl never struck me in the same way.

Learning Python not only completely reinvigorated my interest in programming, but it also and completely changed the way I program. Maybe I still love Python because of the sentimental attachment to it from that first revelatory period of experimentation.

no fluff just stuff SLC 2009

It was pretty good. Only went to one session that was a dud. Decided to try to go to a number of different speakers in an attempt to not get burnt out. But, I should have just stuck with all of Venkat Subramanian's sessions the first day's afternoon. He's an awesome speaker.

I enjoyed seeing other dynamic languages -- groovy, scala, clojure. Definitely seems like mixing in Groovy to any java project would be pretty easy. Loved that it removed a lot of Java's verbosity, but kept the barrier of entry low. Groovy also seemed to be much more readable than clojure or scala.

Scala seemed very interesting -- liked the type inference, and concurrency support. But, I hate hate hate the underscore. And that g-damn colon that changed the operator/operand. Maybe if I used it every day, it'd seem more readable.

I guess if people can hate Python's significant whitespace (which I love), I can have an irrational hatred of Scala's underscores/colons.

Monday, July 13, 2009

further adventures in horrible code -- effin assert

Lots of assert() checks spread throughout our code, testing perfectly valid error conditions. Used sparingly, testing things that absolutely could not happen... ok. But checking for NULL values passed as parameters to various type comparison functions? Eeesh.

It's caused problems up a couple times before... but last Friday's was extra awesome. I'd been working for 3 days with a customer, trying to resolve the cause of a crash of our application at their site. Finally get them to install WinDbg and run our debug build so we can get some crash dumps.

Bang. Assertion failure. Nowhere near the crash we see when running a release build.

Dig into the crash dump. Dirty data in their database that the release-compiled version of our application just ignores because the assert() check is turned into a no-op by the preprocessor for release builds.

I can't tell them it's their data that needs to be fixed. This application and its periodic releases has been running just fine on their system for 5+ years.

But, I also can't run the debug version of the latest release to diagnose their current problem. It's stopping during initialization due to the asserts.

Argh.

Saturday, January 10, 2009

best weird debugging experience ever

I am captivated by each nugget of horrible code.

typedef struct RMAP
{
bill* pbill;
line* pline;
rule* prule;
} rmap;

I'm not sure what I find the most interesting... The fact that somebody thought it was fine to copy that struct definition throughout 15+ .c files.

Or, the fact that somebody slightly modified a couple of those instances.

typedef struct RMAP
{
bill* pbill;
line* pline;
rule* prule;
Bool overrideFlg;
} rmap;

typedef struct RMAP
{
bill* pbill;
line* pline;
rule* prule;
double accum;
} rmap;

Or... the best subtle weirdness, in one instance someone reordered the pointers.

typedef struct RMAP
{
rule* prule;
bill* pbill;
line* pline;
} rmap;

So... when you debug the following code in any of the _other_ .c files...

void myCrazyFunction(rmap* a_rmap)
{
rule* r = a_rmap->prule;
double reduction = r->reduction;
... blahblahblahblahblah ...
}

At runtime, everything works -- the definition of rmap used by the compiler is the definition within the .c file, and the third set of pointer-size bits within the a_rmap struct are assigned to 'r'.

But, when I try to debug the code in Visual Studio and hover over the a_rmap->prule I see a bunch of garbage. I hover of 'r', and I see it's got the values I expect.

I'm guessing the debugger finds the first instance of the rmap type in the .pdb file, and the one oddly ordered struct just so happens to be in the first .c file alphabetically (and also first in build order).

But, that realization doesn't come until about 2 hours of other wild goose chases through the rest of the call stack to eliminate the other 'more likely' possibilities.

Good times.

Monday, May 05, 2008

project A makes baby jesus cry

And so... for some reason I'd gotten it into my head to volunteer for Project A at work. Project A is a rules engine for processing ... things... Myself and another fellow newbie on the project (Hi Jeff!) are slowly coming up to speed on the crazy.

How crazy? Let me count the ways...
  • Release every month!
  • Without a project manager, development manager, or release manager. Who needs 'em? Crybabies.
  • We can't control the # or scope of change requests coming in each month. State regulations drive all the changes to the system. Some nebulous decision process allows us to occasionally drop some changes from the queue... but we don't know which until the deadline has been blown.
  • Crumbling 12+ year old code base. Not given love or documentation over the years. Occasionally tossed a bucket of fish heads. You can tell which dark corners survived from the halcyon days -- they use the hacked-in exception handling in what appears to be the correct way. While I appreciate the cleverness of adding exception handling to C (preprocessing macros around some setjump/longjump magic), I'd appreciate it more if anyone had bothered to write a brief document describing said 'right' way. An example in the .h file? Pshaw! That's for suckers! In the 3 weeks I've spent diving through the code to correct memory leaks, there's at least 4-5 different exception handling idioms. Many possibly broken sections of code, swallowing exceptions with no comment to explain whether the author did accidentally or on purpose. If there aren't comments, it's usually right... for certain values of right. If there are comments, the author clearly thinks exceptions either work like Java's or has no clue.
  • Functions are named as ambiguously as possible with regard to whether it returns a reference to a list that shouldn't be modified, or a copy of the list that's safe to modify and needs to be cleaned up by the caller.
  • It doesn't matter that developers create the builds pushed to customers, right?
  • Oh, and developers have been doing the source control labeling too.
  • Oh, and they're doing both of those tasks half-assed
  • The developers have been too lazy or too scared of the HP-UX makefile to allow it to work without manually copying all source files from their CVS checkout directory to the application directory.
  • You know what'd be a great idea? Basing the fancy new .Net-based Product B's rules engine on Project A. Wait... let's add a Java JNI wrapper around its re-packaged Project A. Awww, yeah... now that's good and f*^@#$ed up.
  • Cherry on top: some genius decides to branch to support Project B. "Branches are neat! Wait... branches are hard... oh well, we'll just branch this one directory that has the DAO stuff, that code definitely has to be different between Project A and B. That's what branching is for, right?" The branched directory also contains nearly identical files that will be slowly, and not-so-slowly , diverging to meet each project's mostly identical monthly release requirements. What? Labels on the branch/trunk to indicate merged code? Nah, that'd be too helpful. I should consider myself lucky that the branch has only existed for a year.
  • Oh yeah, we're releasing Project B mid-Summer. Sweet!
Somehow, I'm the calming influence on Jeff. Probably up to the point where he reads this rant. C'mon, we're in it together! You know, like Musketeers! But less flouncy.

I'm pretty sure I'm living in a sitcom written by The Daily WTF. The alternative is unthinkable.

This is Mark's cue to waltz through with a comment where he doesn't say a thing. Which I appreciate.

Saturday, April 19, 2008

more ponytails than should be allowed by law

Decided to go to the April UJUG meeting a couple nights ago. The presenters varied a little in quality, but were average to great. The topic was interesting, I would have enjoyed more "What went horribly wrong" war stories.

I thought it was telling that even though Maven was held up as a savior for many of the projects, everyone who spoke up mentioned their love/hate relationship with it. It sounded like the LDS church's team had embraced it the most, and a big part of their success with it appears to be because they've dedicated 2-3 engineers to supporting it full time within their organization.

Turnout was huge, 100+. I think I prefer the smaller, and less formal, UPyUG meetings. And it's not just because I think software developers with long hair look silly. So many ponytails at the UJUG meeting. And at least one beret.

Thursday, November 08, 2007

MarkMail, sweet!

Last May, at the Mark Logic User Conference, Jason Hunter showed off MarkMail. It's finally available to the public at http://markmail.org/

Various links about it:
One part that wowed me is the ability to view attachments within the interface. Maybe I'm easily impressed. For an example, go here for email with a PDF attached. Click on the link for the attachment. Search for other attachments with a search string like 'extension:ppt' or 'extension:doc'

Tuesday, October 30, 2007

who knew?

Finally added labels to the blog posts. Who'd have guessed? Tied for the most frequent label:
  • computers
  • i am lame

Thursday, September 27, 2007

nuggets from the dumb monkey sack

We've got a new developer in the group. As he's installing all the supporting tools he'll need for the projects he'll be working on, he came to me when Ant stopped working. Odd messages about Ant core/tools version incompatibilities.

We fiddle and fiddle with JAVA_HOME, with ANT_HOME, with PATH... No luck. Same messages, despite the Ant we want being right there at the start of PATH and in ANT_HOME.

Like a revelation from heaven, I realize... wait... what's in CLASSPATH? Well, there's a Documentum Jar in there... but that wouldn't have stuff to do with Ant, right?

The documentum Jar in question turned out to not have any classes in it, but it did have a giant list of other Jars in the manifest's classpath. Including Ant. More specifically, a local install of Ant 1.2 beneath the Documentum installation.

As much as I'd like to blame Sun for not providing a non-insane standard for application startup, I think its more appropriate to vent at EMC/Documentum for creating an installer that modifies the system's classpath environment variable to add their kitchen-sink Jar. For as much money as they charge, you'd think they could write an installer that doesn't screw up your system.

I'm not sure why I was surprised. Nearly every other interaction I've had with Documentum has been an exercise in agony. They must have a burlap sack full of exceptionally dumb monkeys deciding how their software gets installed and configured. Other nuggets from the monkey sack:
  • No desktop application needs to talk to more than content server, right? Well, if they do, they can manually edit this INI file in c:\windows.
  • No desktop application needs to talk to more than one version of a content server right? Well... if they do, they can uninstall/re-install to do so.
I can excuse their crappy, obfuscated APIs. Still hate them, but I can understand inflicting them on software developers. But to screw things up for all the end-users, QA, and support that need to use their crappy desktop apps, seems mind-numbingly stupid.

Tuesday, September 25, 2007

hardware problems are teh suck

Why does my home PC pick the worst time to decide to stop booting? I really didn't want to spend 4 hours tonight fiddling in the XP recovery console, the BIOS settings, and running disk tests.

At first, I thought it was the height of inconvenience that I'd packed up my Windows XP install disk, had to search the basement, unpack the box, re-pack the box. Then, unpack the box again after realizing I forgot to grab the floppy disk with the SATA drivers.

However, that turned out to be minor compared to having to reboot twice every time I changed something in the XP recovery console. Once to get out of the console, and again so that the XP install disk would release itself from the CD-ROM drive. Gah!

System Rescue CD and the XP recovery console both seemed happy to read the disks, no problem getting into the partitions and looking at files. Tried fixboot, tried fixmbr, ran DFT's tests on both hard disks. No love from the boot gods.

Finally, decided to start fiddling with the BIOS. Swapped the order in which the hard disks are booted (SATA then IDE), and it came up. Not sure why I didn't notice it before. Also not sure why the BIOS implies it'll check disk #1 then disk #2 when booting, but only actually try #1 and give up.

Also not sure what would have screwed it up. I re-installed Ad-Aware, and Spybot S&D over the weekend. We also had a couple power-bumps a couple days ago.

In less annoying news, System Rescue CD is 4-6x as awesome as it was the last time I tried it a few months ago.

Sunday, June 24, 2007

Salt Lake Software Symposium, day #2

Last day. Still pretty good, but didn't rock as much as the first.

Attended a couple more of Jared Richardson's sessions: "Agile Testing Strategies", and "Software Development Techniques". Lots of good real-world examples, and lots of inspiration for changing our processes. Definitely thinking of picking up Ship It!

Neal Ford's "Pragmatic Extreme Programming" was good. But, I think it'll be easier to work in lessons from Jared's sessions (on days 1 and 2) into our existing process.

I wasn't going to attend Brian Sam-Bodden's "Complex Builds with Ant" session. From the slides, it appeared like I'd already knew the major tips on my own. But, I was wiped out by the last session. Decided it was worth going to a topic I was familiar with in order to pick an expert's brain. Only three attendees, so the session went fast and I was able to ask a lot of questions.

More sour-grapes today over all the Ruby rah-rah-rah. Again, Neal Ford declared Ruby the winner in the dynamic language race on the JVM. Neal is a very smart guy, a great presenter, and also great to talk to one-on-one. I don't have any issue with him advocating Ruby. Any language that makes developers more productive is a good thing. But, it seems disingenuous to declare a victor in a wide open race to a room full of people who have little to no experience with dynamic languages.

Personally, I prefer Python over Ruby. Others can and should disagree. Here's a fair, but slightly biased (since the author is familiar with Python), comparison of Python vs. Ruby.

I'm not sure who to blame for lack of Python excitement in the Java world (or at least at this conference). Maybe with the recent revitalization of the Jython project, it will get more Java developer's attention.

Microsoft's CLR (and the new DLR and Silverlight) seems very exciting. See here and here and here. The second link is a screencast showing interoperation between Ruby, JavaScript, Python, and VB.

All in all, the conference was very good. I'll definitely plan on going next year.

Friday, June 22, 2007

Salt Lake Software Symposium, day #1

Since this blog is all about (pick one):
  • lame book reviews
  • lame software conference anecdotes
  • odd things I've put in my mouth
Here's more software conference anecdotes.

Spent today at the Salt Lake Software Symposium (aka No Fluff Just Stuff). So far, the conference is very good. Attended presentations by Neal Ford, Jared Richardson, and Brian Sletten. All great presenters, showing off great technology.

A friend has tried 2-3 times to explain Aspect Oriented Programming to me. It sounded... like more trouble than it was worth. Brian Sletten's AOP presentation was very useful in cluing me in. Seeing the AspectJ/Eclipse tools in action got me all excited to try it out. The immediate use-case I have would to remove a bunch of cut-n-paste concurrent locking boilerplate in my pipeline application. If I understood it correctly (always a questionable assumption), I can replace all that code scattered throughout my class with an aspect that'll do the

writeLock();
try {
// .... do stuff....
} finally {
releaseWriteLock();
}

logic all from a single place for all the setters methods in my class. And a similar readLock() aspect for my getters.

Brian also presented NetKernel. Also awesome. Still trying to get a handle on how exactly we can leverage it for our needs. His Mashup/SemanticWeb/RDF presentation was also good.

Jared Richardson's presentation Shippers Unite was very good. The best part, calling sales people 'Sales Critters'. He had lots of great advice, and great best-practice type information.

Neal Ford's SOA presentation, and his keynote after dinner were also very good. His keynote, "Polyglot Programming" was very interesting. Contrasted the increasing cruft, and complexity (and irrelevancy) of the Java language against the awesomeness of the Java platform. Described the increasing place Dynamic Languages will have within the software industry. In particular their place inside managed runtime environments (either JVM or CLR).

The only major disappointment I experienced was the (apparent) disdain the conference presenters seemed to show for Python/Jython. Lots of Groovy/Ruby/JRuby/Grails rah-rah-rah. I know Rails is the new poster child, and Ruby folks should be proud. But, to give Python/Jython/IronPython hardly a mention. And, the one time the word Python appeared on a slide, to explicitly declare Ruby the winner over Python... seems premature.

Yeah, yeah. Sour grapes. Maybe I should try Ruby before deciding I don't like it... but the Perl-like $ and @ syntax rubs me the wrong way. And, maybe I should just be happy about the rising tide of dynamically typed languages that'll lift all boats.

Thursday, May 31, 2007

mmm... pie.

It's turns of phrase like this that keep me going back to Worse Than Failure :

Of course, upon his return to work, fate crapped on his hope and served him up a big, steaming slice of shattered dream pie. The familiar stench of hot computers and death descended on him while he tried to shut out the familiar fear of dying in the room and having the network absorb nutrients from his decaying body.

Thursday, May 17, 2007

san francisco -- day #4 -- "You like extreme?"

Final conference sessions today. OK, but nothing fantastic.

Great lunch at House of Nanking. The waiter arrived, said "Your first time here?" When we said yes, he took our menus. No idea what the dishes were, but they were all super-excellent.

Then got a taxi to the airport. After a few minutes of silence, the driver asks, "You like extreme?"

I'm not sure I hear him right. He asks again, "You like extreme?"

Yep. I had heard him right.

Pause....... I'm not sure if I'm going to get invited to a cock fight, or what. I guess that maybe he's asking if it's OK to play his favorite thrash metal CD. "Uhhh.... extreme music?" I ask.

He explains, "No! Extreme! Like X! .... Games! Extreme. Sports."

I respond, "umm. A little?"

The rest of the ride was enclosed in blissful silence.

Wednesday, May 16, 2007

san francisco -- day #3

Noisey street. Some sleepy sessions. A couple awesome ones -- displaying debugging and profiling support for XQuery.

Then the final session of the day. At first, I'm thinking... blah, a mailing list archive viewer? Oh, how wrong I was. Sweet zombie Jesus, it was cool. Or maybe Jason Hunter is an great speaker. Or maybe both?

It was also very applicable to the work we're doing -- transforming and enhancing XML and non-XML assets into an normalized XML form and storing the results in MarkLogic.

Tuesday, May 15, 2007

san francisco -- day #2

Noisey street + hotel room close to street = no sleep.

As the opening session begins, I realize I can't focus. Then I notice the strobing migraine precursor.... Today is going to be awesome!

Interesting sessions. One of the sessions on the technical track of the conference seemed like a waste of time, but most of the others were interesting. And an added plus, presentations by the vendor and one of our competitors seem to validate our current architectural approach.

Monday, May 14, 2007

san francisco -- day #1

Flew to San Francisco for a technical conference. Flight uneventful, and in a teeny CRJ200. Only 12 and a half rows of seats.

Googled up restaurants near the hotel. I've been craving Vietnamese all the time lately, so I decided on a hole-in-the-wall place with good reviews -- Golden Flower Vietnamese. Just a couple minutes walk from the hotel.

Pretty good, but not the best I've had. The imperial rolls were greasy, and more mystery-meaty than I'd have preferred. The bun with grilled pork and shrimp was tasty.

In order of worst to first:
Pho Cali
-> Golden Flower Vietnamese -> Pho Hoa -> Shanghai Cafe -> The deeee-licious versions Dien made for us over at Mark's house. Mmmmm.

Also, it's less fun to travel without coworkers. Wandering aimlessly is less fun to do on your own... it feels more like getting lost than having an adventure.