|
October 2006
October 31, 2006
XML to C, The Easy Way
These days, we all have to deal with XML data. But mapping the often complex heirarchical data in an XML file to C data structures can be at best time consuming, and at worst confusing and error prone. So it's best to let the right tools do the work for you whenever possible. Jim Kent presents four tools—autoXml, AutoDtd, sqlToXml, and xmlToSql—that can make your life a lot easier.
Posted by Kevin Carlson at 02:30 PM Permalink
|
October 24, 2006
A Global No-No
I must hang my head in shame. I'm guilty of the very sin that Jack Ganssle denounces in his piece "A Pox on Globals." A certain piece of code I have written (which shall remain nameless) is peppered with the sort of oft-accessed and dangerously exposed variables that Jack decries. Dozens of them. All over the place. Not surprisingly, I am the only one willing or perhaps even able to to modify the code. Often, I'm the only one willing to even use the code.
And were I to ever leave, someone would inevitably get stuck doing the task that this code is meant to automate. Poor SOB. I can almost guarantee that, rather than try to maintain this monster, they would do the job by hand until they could devise their own automation.
Depending on global variables is like leaving a loose threads hanging off a sweater: You try to pull on any one of them, and the sweater quickly turns back into a pile of yarn. These are basic principles of encapsulation—we're talking computer science 101, folks. So why is it so easy to keep making these mistakes? For me, it's about the nearly always mistaken perception that my code is a temporary stop gap, and that spending twice as long designing it as writing it is a waste of time. Let me tell you, it is NEVER a waste of time. Take all your assumptions about how long you think your code will be in use, and multipy them by at least a factor of 10. Then imagine all the modifications and maintenance that you'll do in that time frame. The design time isn't looking like such a burden now, is it?
Posted by Kevin Carlson at 01:04 PM Permalink
|
October 17, 2006
Arbitrary-length Integers
Translating code with floats or doubles to fixed-point arithmetic can be fraught with tricky corner cases, as bit-width limits can generate even more-complex limits for operands. Andres Takach describes the Algorithmic C datatypes, a freely available C++ library that provides arbitrary-length integer and fixed-point types.
Posted by Kevin Carlson at 02:41 PM Permalink
|
October 09, 2006
Code Cleanup
When Diomidis Spinellis built CScout, a refactoring C code browser capable of mapping the complexity introduced by the C preprocessor back into a project's original source code files, he discovered a bug that, ironically, required a serious refactoring of CScout. Learn from his experiences in his article.
Posted by Kevin Carlson at 04:26 PM Permalink
|
October 03, 2006
The APR Alternative
Picking the right API for native-code portability is a crucial decision. The Apache Portable Runtime (APR) provides a free and commercial-friendly choice for this sort of thing. What's more, it's got some miles under its belt, having been a part of Apache web server development for many years. Ethan McCallum demonstrates its use in his article "APR Networking & the Reactor Pattern."
Posted by Kevin Carlson at 01:18 PM Permalink
|
|