This blog was created as a platform for my Android apps, namely NTW Text Editor and Pendulum Chaos so far. But I admit I neglect it and often digress, a lot :'(

Nevertheless, if you are interested in this sort of things, you can glean some conceptual insights into how NTW was conceived in my earliest posts

Friday, 12 August 2011

Wednesday, 10 August 2011

The birth of NTW Text Editor

When I first registered this blog, I hadn't yet decided what to put in it. My daily scribbles are mostly too personal  for public viewing, so I abandoned this blog for months, all alone and devoid of content. Then one day, I realized I could really do with a website to put all my programming related stuff. And thus, its first* meaningful blogpost!!!!!!

I wrote the Android software Need To Write after I got my first Android phone. Problem with Android was nobody designed a text editor for it that could edit any text file larger than a few kb. Also very very irritating was that among all the existing text editors at the time (2010 Q4), there were limited poweruser options like undo/redo, save or discard changes, find/replace, save under another filename, save/view with different encoding, save as a plain text file rather than some weird android note format or worse, docx format.

These limitations just drove a text editing junkie like me crazy, I ended up creating file1.txt, file2.txt, etc etc, and regularly cursed and sweared when I accidentally deleted text or saved unwanted changes. I couldn't take it anymore after a month or so. So, despite not knowing any java, I resolved by hook or by crook to write my own "perfect" text editor! Thanks to the tons of guides and demo codes out there, I picked up the basics of Java surprisingly fast. Thus NTW was born!

These were the basic requirements when I started out.
  1.  Be able to open txt files of any size for editing
  2.  Let the user decide to save or discard changes
  3.  Allow undo
  4.  Support a variety of different encodings
  5.  Customized color schemes and font sizes
It took me about a month to come up with the first working prototype that met all 5 requirements. I had to pick it all up from scratch, because I had no experience with OOP, Java, or SDKs before. But I did have a lot of experience with C, Matlab, Labview, so it was basically a case of installing Android SDK, learning the new IDE and programming syntax, knowing where to look for advice, and trying to apply OOP concepts. In the course of all this, I realized that modern OOP programming is often a case of find out, apply, then forget. If I need to use it again in one form or another, I just copy, paste, and then tweak the hell out of it. Is true! There are so many classes, and they all behave differently that nobody can really remember all the specifics to take note of unless they use all these classes every day.

I am ashamed to admit I neglected my real job somewhat during this time, I spent my lunch and teabreaks and slack time in the office writing it, kept on writing it again at night. Most of the time I couldn't go to bed until after I completed a new feature or debugged a dreaded. I ended up staying up until 1-2+am frequently, then woke up at 7am the next day to travel to my workplace, it was hectic, but so satisfying :D.

Yay! No more hostage to crappy mobile offices and docx!

Then from these basics, NTW grew in power and fanciness, until it became the superlatively amazing software that it is today, muahahahahaahahahahhahahahahaah! :D (But why oh why isn't its sales hitting the roof :'( :'( :'(, I dun get any serious complaints... Maybe I should have keep the 10 day trial period for the trial version.... grrrrrrr! )

Ok, gloating aside. What I would really like to say before I forget the details of NTW's beginnings is how I conceptualized from scratch the implementation of (1) and (2).
  1. Opening any sized files without hitting any RAM restrictions meant that NTW had to open small chunks of the file at a time. The user would therefore be viewing and editing small chunks of the file. When the user flips to another chunk, the previously edited chunk will have to be stored, but not in RAM, since that would just accumulate until out-of-memory error occurs. Therefore, these small chunks would have to be saved permanently in the sdcard which is usually a few GBs for most modern android phones
  2. But if lots of small chunks are constantly being edited around and saved, how the heck do I allow the user to save or discard these changes? Saving these changes permanently in the original file would prevent the discarding of changes. I needed some kind of buffer system that uses the sdcard instead of RAM, but saving the edited chunks as separate files would mean a logistics hell during programming. A backup file might work, but should the user be editing the backup or the original?
Eventually, I decided the best system was to create a backup file that the user edits any way he likes. He can then decide whether to save his changes by overwriting the original with the backup, or to leave the original file completely intact. Furthermore, NTW can compare the original file with NTW's own editing log to detect any deletion/updates of the original by the user using other software. This way, all the complicated stuff occurs behind the scenes, and the original file stays untouched until the decision to save it.

I dun think any users realize it, but IMHO anyway, this implementation was the most valuable part of NTW to me and I'm so very glad I got it right the first time. :') :') :')

* Well, this is not the actual first post. I deleted the first post the day after I registered this blog address because I got too shy to post it. BTW, Julian Barbour's hypothesis on the illusion of time is remarkably similar to some theories I was brainstorming up for a fantasy story back in 1997-2000. We even referred to it the same way - "The Illusion of Time", although mine consists of other aspects of a larger theory as well.