Archive for the 'Software' Category

PHP and MySQL on the Mac

April 24th, 2009 | Category: Entrepreneur, Software

I now am needing to learn more about PHP, MySQL, Wordpress, and so on. As you may know, this site you’re now reading runs on WordPress software, which, for the most part, I’ve been happy with. But, if I want to add my own customizations or just play around with different ideas to try out on WordPress, running a test site online is not so practical (especially with the pitiful speed of my internet here in China). So, I looked into running WordPress locally on my Mac. I had to hunt down four things to install and configure: Apache, PHP, MySQL, and WordPress. I spent four to five hours downloading, installing, and troubleshooting. In the end, it wasn’t so hard, but pulling all the info together from various websites was quite time consuming. So, I spent 20 minutes this morning culling the important information and distilled how I did it into a five-page document.

You can download the pdf file here.

It sure is nice having this set up locally. It’s incredibly fast (obviously) and as easy as editing and saving files in a basic text editor.

1 comment

Personal Code Review

March 11th, 2009 | Category: Entrepreneur, Software

In my “The First Three Weeks” post, I mentioned how one of my first projects is to re-release my shareware.  I have two closely related shareware applications.  Both are “Download Managers”, which make archiving websites, and downloading in mass easy.  My applications are written in MFC and ATL, ancient technologies by today’s standards.  This project has been occupying most of my working time; my other projects are mostly being outsourced right now.  For example, logo work and graphic design is something that must be done but I personally have no talent to do it myself.  Witness the lousy graphics that I created myself or borrowed from freeware in my last shareware release.  So, even though collecting bids and reviewing work can be time-consuming, that option sure is better than pretending I can do it myself and wasting time and effort.

But, how easy it is to digress.  So, back to the main point.  This is the first time I’ve been back in my shareware code in nearly six years.  Also, this code was written about nine years ago.  My how the time does fly.  It’s interesting to see how my coding style has transformed over the years.  So what have I noticed?  Well, why not give myself a code review for everyone interested to see?  Here it goes:

Strengths:

  • Organization – The code and projects are organized well.  It’s easy to find things and there is very little duplicated code.  The code is organized well for reuse.
  • Loosely-Coupled Code – Code is easy to move around or remove entirely without too many side effects.
  • Well-commented – The code is easy to read and commented well.  There are some fairly obscure sections that would have taken me a long time to figure out, but the comments gave me a great starting point.
  • Easy to localize – Dialog and string resources are managed well and it’s a piece of cake to localize the applications into multiple languages.

Weaknesses:

  • Error Handling – The error handling is generally good, but sometimes very lax.  There are a few egregious violations like a string buffer being passed to a function with no indication of length.  The function assumes the buffer is at least 64 bytes.  Yes, I have fixed that.  Microsoft educated me well on defensive programming.
  • Unicode support – In most places, you could tell that I was paying attention to Unicode, but I had to spend at least a full day updating the rest of the code to be cleanly build both Unicode and MBCS builds.  However, I discovered one big problem:  I realized my home-grown HTML parser simply did not work in Unicode.  And, it’s not a simple matter of using TCHARs or something like that…
  • HTML Parser – For the sake of speed, my parser assembles DWORD tags from HTML and matches them to predefined HTML DWORD tabs like “<ahr”, “<ima”, “<bas”, etc.  When I started writing this app, the web was still quite young and HTML parsers weren’t so common.  The MS DOM probably existed, but since it’s shipped with IE, I, like most normal people, probably assumed that IE could easily be uninstalled in favor of another browser.  Regardless of how engrained IE is into Windows or Anti-Trust rulings, I didn’t want to rely too much on third party libraries.

    I do have my full Unicode builds working now, but my parser doesn’t work.  It’s quite the understatement to say that’s a big problem.  The jury is still deliberating about what to do.  The easy answer is to just stick with a multi-byte character set build, which still works great.  I may do that for the first re-release and then upgrade the parser to use the DOM for the next release.

    The parser really does need an upgrade because it’s also quite complex.  There is a lot of code in this “pointer” style (and this is one of the easier sections):

    TCHAR* pBM = buffer;
    while ( _T('#') != *pBM && *pBM )
         pBM++;
    ...
    if ( _T('#') == *pBM )
    {
        *pBM = NULL;
         token = ST_HTML_FILE; 
    }

    So, with a lot of code like this, maintenance is a bit of a problem.  Time for something more reliable and easier to manage.  My IE plug-in application uses the DOM for parsing and it’s much simpler, however, that application does not need to update the links in the HTML to match the users hard drive.

  • Feature happy – Well, this one isn’t so serious because my applications already aren’t very feature heavy, but I do have a few silly features and additions that don’t provide any value.  I gained a new appreciate of this problem at Microsoft.  It was something that I fought against constantly.  Maybe I’ll write more on this later, but I was shocked at how much effort and time we put into useless features.  But, hey we did, and I sometimes felt like an outsider for opposing them.  Anyway, because of my appreciation for a feature done well vs. a mad mass of confusing features, I’ve cut my non-essential features and frills.
  • Graphics – That’s why I’m outsourcing this next release.

In summary, I’m happy with the code.  Though I’ve expanded more on the negatives here, I’d rather have this strength/weakness profile than have it flipped!  That would be a much tougher problem to deal with.  That would basically mean rewrite.  That would tempt me to abandon.

No comments