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

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.


  1. I've just downloaded your creation now. You call yourself a text editing junkie. Instead I'm a text editing slave, 'cause I'm a translator of scripts.

    From Italian into English.

    Man do tablets suck for serious editing! I just bought myself an HTC Flyer!

    It's an okay program - I guess. though I still haven't figured out how to change the font size (I hope to God it's possible!). I'm already missing my DOS XT clamshell HP 200LX.

    Erik, I have a proposal for you. hear me out: want to turn your okay editor into the must-have killer editor for Android?

    I can tell you how... That's right, me, a non-programmer, an old fool, a lowly end-user who translates movie scripts in Rome Italy. They give me 120K character monstrosities (spaces included), to be delivered in a week and so I am condemned to editing.

    I will tel you what you need to encode into your program to make it wildly superior to anything on the market. And it's REAL SIMPLE, (for an Android programmer such as yourself). This not the time to sit on your laurels. I guarantee you it's a winner. In my desperation to turn this wonderful toy into an acceptibly decent editor via my one-key-editor idea, I even wrote to the Softmaker, the German company of WM fame who will son be selling on the Android market. The CEO himself answered saying that he likes it.

    Send me an e-mail if you're interested and the next time I go to Piedmont, I'll mail you wine to toast to your success.

  2. Haha, it's great to have feedback! :D
    You can change font size by pressing your menu key. pressing Themes, select your current theme button, then the scroll down a bit to find the font size slider. Adjust as desired!

    You've piqued my interest, I just sent you an email.

  3. Erik sei GRANDE! I just emailed you back describing the idea in detail.

  4. Hehe, I saw... Dunno why you think I would send you to hell though. I will google up the 90kb text editor you mentioned, maybe "borrow" some ideas ;)

    But the limitation of mobile platforms is always the screen size and the touch interface :( I am constrained quite severely by the need to implement advanced features conveniently, intuitively, and while maintaining the at least 30% of the screen estate for text display.
    Tablet users have lots of screen space to spare, but the rest of us poor android phone users have to suffer from barely any screen space left for text display after even just 2 toolbars are expanded. So its tricky...

  5. Ciao Erik,

    You might wish to send me to hell because you busted your hump to do your fine coding and here I am complaining instead of thanking.

    But I do thank you while at the same time hope and pray that someone clever like you with programming savvy will come up with an editor that... well... allows for easy EDITING and not just easy writing.

    As I hate to be chained to my desktop and am prone to get terribly antsy, I have years of experience translating huge texts on small handheld devices while walking.

    I've got a wonderful bar/cafè 350 meters from my house where I reckon I do 30% of my work, thumbing on my superannuated equipment and legacy software as I walk there at a leisurely pace, as I sit al fresco and as I return. Not to mention all the work I do when caught in Rome's horrendous traffic jams.

    The other day I went to a smartphone/tablet/IPad store and challenged the trendy and youthful sales clerks who came smiling towards me to find something better than my I-Bone (what I've dubbed my ancient DOS clamshell) as far as ease and speed are concerned. I showed them what I do saying: "Never mind the eye-destroying text mode and the sheer ugliness of the screen, or the fact that I can't play Angry Birds or check all 3 of my email accounts while downloading Lady Gaga, just find me something modern that will let me work on-the-go even at half my present speed and I'll pay you double for it."

    They failed as I knew they would.

    I guess years ago computers were considered sorta like typewriters with college degrees... and then internet came along and gaming and picture taking and music listening and whatnot. And so despite huge technological advances it has gotten very difficult to work fast and well on small devices.

    The all round best was the Psion 5MX, except the flat cable was vulnerable and so the machines had a short life span.

    My hope now resides in the for-pay company Softmaker, up in Germany. As I said, I wrote to them and the CEO loved the idea of the one-key-editor and passed it on to his development team. They're in Beta testing for Android.

    I danced a Hitler Jig when he answered.

    Now I'll write to Jiro of Jota, and Paul Mach of Text Edit and then to Nasa, the Israeli Android association... to everybody. Even to the hardware houses, HTC, Samsung, Toshiba, Sony, Motorola.

    I want to work well on a modern gizmo. I'm a great believer in the word "AND"... as in work AND play, old-fashioned text-editing AND ultra-modern cloud computing. The script that needs to be translated AND Angry Birds.

    Yes those smartphone screens are small... and that's a problem, but an even greater problem is that fingers are pudgy, clumsy and imprecise. If I were a programmer I'd make my one-key-editor assignable to a regular keyboard key, but one that is rarely used.

    I'm gonna win this war! (okay, now I'll take my meds and go to bed)

  6. Constructive complaints are good. Much better than obscure complaints in a language I don't understand about how some encoding is not supported or something anyway, grrrrr....

    :D You remind me of another guy who contacted me a few months back. He was also emailing many developers including me for power options like controlling the end of line characters, wordwrap, etc. Sure enough, a few weeks later I took a look at some of the other text editors out there, and I could instantly recognize his influence on them :D

    Good night!