Saturday, June 13, 2009

fundamentals of better programming


Just a quick note. This site, SourceMaking, is probably the best single collection of information on three key areas of software development: Design Patterns, Refactoring and UML.

If you aren't actively practicing the methods described here then you should at least be reading about them and hoping to put them into practice soon. I'm sure you are already a pretty good programmer, why not become a better one?

P.S.
The clickable geek picture will bring you to the 56 Geeks Project where you can find even more geeks you may recognize.

Sunday, June 07, 2009

PDF bookmarks


This isn't a programming post but if you are a programmer, you've probably had to read a PDF based ebook or two. Everyone has had to open a PDF file at one time or another right? You click on a link on a web page which turns out to be a PDF and if you're lucky, Adobe's Acrobat Reader pops up and in a few short moments, you are reading the material you were after. Far too often however you are stuck waiting for a multi-megabyte file to download and then when it finally finishes, Acrobat throws up a baffling dialog with an obscure list of things that it thinks are vital for you to download immediately. It really throws off your rhythm.

It's even worse if you don't have Acrobat installed. It's an ever changing gauntlet to finally get to a page that actually has a link to download the software you need to read what you just clicked. And acrobat just keeps growing! It's up to about 41 MB now and seems to want to dig its grimy little fingers into every part of your system. If it ever finishes installing you will probably be told to restart your browser. Eventually you'll have your browser running again and you'll be staring at the Google home page saying to yourself "Where the hell was I and what was I trying to read?!" and "What the hell are all these new icons on my desktop?"

It's experiences like this that really make me hate PDF files. But if you want to read many of the ebooks that are out there, you don't have much choice. I've found myself reading more and more PDF based books so I can't avoid them anymore but I've made a couple of startling discoveries recently that I felt like sharing.

First, Adobe Acrobat Reader isn't the only free reader available for Windows. What? Yes! It's true. There are probably more than these and I haven't rigorously tested them but here they are in order from big, feature loaded to light and fast:
Now the first two are commercial and allow you to get extra features in exchange for cash but the free versions are more than adequate. You may encounter some of the same kind of nagging you get from Acrobat but it should be much less. Sumatra is free and open source.

After spending an hour or more scouring the internet for these Acrobat alternatives I realized that I should have started at this Wikepedia page of everything PDF related. Oh well.

Where was I? Oh yes, the second realization. None of these 'book' readers can do the one basic, fundamental thing that you can do with any crappy, worn out, dead-tree book on the planet.. stick some reasonably flat object between a couple of pages and walk away, knowing that when you get back, you can resume reading right where you left off. PDF readers have no bookmark feature!

When I realized I didn't want to read my 243 page book in one sitting, I went searching through the menus in Acrobat looking for the bookmark command. When I finally did find something with the word 'bookmark' on it, it turned out to be hardwired into the PDF file and only if the authors decided to provide some. Hmm, a bunch of bookmarks laid out in sections that mark all the key sections of the book... like, oh I don't know.. a table of contents! Ok, so Adobe thinks a table of contents should be called bookmarks. Well, in a world of internet browsers that's not confusing at all. Geez.

The other menu items in Acrobat seem to hint at the ability to edit or mark up a PDF file but that must be some of the functionality they want you to pay for. This is essentially what started me looking for an alternative to Acrobat. Sumatra looked nice and light but it is only a reader pure and simple, no help there. Foxit however looked much more promising.

I wasn't really keen on editing the PDF itself but that seemed like the only option. It turns out there are alot of ways to edit a PDF that all sound slightly similar. I'm sure this is great for publishers but it's way too much for somebody just looking for a way to mark their position in a book.

One thing that looked promising was the ability to add what looked like little post-it notes. You could place them anywhere on a page and they could hold all kinds of text. Unfortunately, the only way to navigate to a note was to page through the PDF file one page at a time until you found the note. There was no way to navigate directly to a note! Unbelievable... back to Google.

After some time, I stumbled on a link to a book called PDF Hacks. There are alot of tips and tricks there, most of which you need to buy the book to see but down the list at #15 was Bookmark PDF Pages in Reader. It seems that Acrobat can can run Javascript and this guy wrote some Javascript that will add the ability to bookmark a page. Best of all, it doesn't modify the PDF file to do it. It is stored with your application settings for Acrobat instead. The next time you open that PDF file, you can go to any of the bookmarks you created for it. Excellent!

This is what I've been looking for. Unfortunately I have to go back to Adobe Acrobat Reader to use it but I can live with that. If you can live with it too, here's how you do it.
  1. Go to this page and download the zip file that is linked there.
  2. Unzip that file. You should end up with a file named "bookmark_page.js".
  3. Copy that file to the "Javascripts" directory for your copy of Acrobat. You will typically find that directory at "C:\Program Files\Adobe\Reader 9.0\Reader\Javascripts", or something like that.
  4. If Acrobat is running, close it and then run it again and open your favorite PDF file. You should now have some bookmark commands under the "view" menu as shown in the following image..

That should do it. Enjoy!

Update:
It would seem that the javascript hack above was written before Adobe made some changes to security settings that affect javascript. This may manifest as an error dialog stating there was an internal error. I don't know the Acrobat API or javascript enough to troubleshoot the problem but a work around is to go to the 'Edit' menu in Acrobat and open 'Preferences'. Find the 'Javascript' settings and uncheck 'Enable global object security policy'. I also don't know exactly what implications that change brings either so use with caution.

Sunday, May 17, 2009

java time


I've dedicated myself for the last 2 years to the task of completely mastering C++. I had used C++ on and off for a long time but never really made an attempt to really know it so I read, and researched and practiced and read again.

It didn't take long to realize that if you want to use C++ effectively, you better establish or learn, some best practices.. alot of them! Every time I peeled back a layer of functionality, I found 5 more underneath. After 2 years, I was starting to wonder.. how long will I have to do this? How many gotchas can one language have? Why do people use this fricken language anyway?

One of the more valuable resources I found while searching for good sources of C++ information was this one.. the C++ FAQ LITE. If you are a C++ programmer, you should be doing the things that are described here.

This FAQ has gems of information like this:

[18.5] What's the difference between "const Fred* p", "Fred* const p" and "const Fred* const p"?

You have to read pointer declarations right-to-left.

  • const Fred* p means "p points to a Fred that is const" — that is, the Fred object can't be changed via p.
  • Fred* const p means "p is a const pointer to a Fred" — that is, you can change the Fred object via p, but you can't change the pointer p itself.
  • const Fred* const p means "p is a const pointer to a const Fred" — that is, you can't change the pointer p itself, nor can you change the Fred object via p.

This was all well and good until one day I found the C++ FQA LITE (frequently questioned answers). The floodgates were opened. All the things that have been bugging me for years about C++ were laid out in a very well considered manner. If you are a C++ programmer that has had enough, you should read this. Heck, you should read it even if you aren't a C++ programmer, it's very entertaining. You'll find gems such as:

The idea to overload "bitwise exclusive or" to mean "power" is just stupid. I wonder where they get these ideas. It's as if someone decided to overload "bitwise left shift" to mean "print to file". Wait a minute - they did that, too... Oh well.

I had been fooling myself for years that C++ was the way it was for a good reason and that if I just kept at it, it would all make sense and I would be master of all that I survey... NOT. It was a great relief however to know that I didn't have to keep slugging it out. I could give up and not feel ashamed. But now what?

I still have to use C++ at work which is fine but what about my own development projects?

I decided to stick to what I had already considered to be the more important requirements for a language. It had to be well thought out, clean, powerful, backed up by a large selection of libraries and be cross platform. Oh, and I shouldn't have to be a masochist to want to use it everyday.

After some consideration Java and Python were the front runners and after a little more consideration Java seemed the clear winner. Python still looks interesting and I may yet give it some time in the future but for right now, Java is it.

Java has come a long way from when it first burst onto the scene back in 1996 (when the JDK 1.0 was release). I have to admit that I held alot of biased opinions of it over the years based purely on what was known about it in that first year or two of its existence. When I finally got around to giving it serious consideration, I found a robust developement framework that I should have adopted years ago.

So.. It's Java time!