Saturday, April 12, 2014

SMS to Machine

So today I wrote an Android app that lets you text from your computer (so long as it has a JRE).

Basically the server (SMS to Machine) runs on your phone in the background and you can connect to it from the desktop client (SMS Client) using the address provided by the server. All of the messages are encrypted with a password in the form of a SecureSMS object (essentially a pretty container with an array list of encrypted strings).

I wrote a miniature messaging protocol for the communication. All SecureSMS messages are wrapped with [BEGIN] and [END] tags to let the server/client know where content begins and were it ends. The connection first has to be accepted when the [CONNECT] command is sent. A disconnect can be achieved when the [DISCONNECT] command is sent. All other transmissions right now only contain encrypted content to be decrypted by either end of the connection.

Currently I'm still in a testing stage. It sends and receives fine, but I still have work to do. I've decided I'm going to send metadata in the form of JSON using the framework provided at json.org. And I plan on handling MMS by zipping images and sending a "SecureMMS" object through the output stream.

This sort of application already exists in the Playstore, but I honestly don't care. I'm doing this for fun (as with everything I write).

As of right now, it's a very small but powerful application with a primary focus on minimalism. I'm all about minimalism. And as few bugs as possible. ;P

Okay. Back to coding!

Thursday, April 10, 2014

The Battle for Optimization

So a little update on ZerothScript. The project has come along smoothly. But for the first time in years, I've come across an optimization issue. I set up my unit test in the form of scripts. One script for USL and one script for ZS. The test creates a variable for storing numerical values and loops one hundred thousand times decrementing the value by one each iteration. At first ZS was clocking in a little over half a minute while USL was finishing at nine seconds. This seriously boggled my mind. I didn't think something I wrote three years ago could possibly be any more efficient than what I can write now. I couldn't be more incorrect. I attacked this slowness issue in two ways: rewriting the interpreter, and removing the logger calls. Starting with the interpreter, I was passing the tokens down the chain of command and it was grossly inefficient. The interpreter is much more organized thanks to the analyzer function I wrote. The interpreter no longer needs to pass off the tokens down the chain of command. It goes directly to where it's supposed to go. This increased the speed by a lot but it wasn't good enough. The real speed increase came from removing the calls to the logger. Previously each call printed to stdout the stack trace. That was a terrible idea. I have no idea why I thought that would be a good idea. So this functionality has been destroyed. The error logging will still exist because it's necessary. I forgot the nature of a language of this sort required the code to be as bare bones as possible.

I was able to cut the time down to fourteen seconds. Those are incredible results to me. It's only five seconds slower than USL now. I'm about to merge the shell into the interpreter for efficiency purposes. Right now the only function of the shell is to contain variables and methods. It doesn't do anything else. So merging seems completely appropriate. I'll only merge the appropriate functions and variables. I can abide by the Law of Demeter in this case since calls to the shell just to get their variables (and their values) are heavily used throughout the interpreter. It was a good idea at first, and maybe it still is, but as of right now, optimization is what I need. I need this language to be faster and more powerful than USL. I truly believe that I can achieve the same speed if not better. It will take time, but I will get there. And if I optimize sooner than later, I won't have to work through a finished project to optimize everything.

I'm learning more and more as a software developer each day. Professionally, and on my own time. I'm seriously blessed to have this skill. I wish I knew more people who were as passionate about code as I am. One day, when (and if) I leave Oklahoma, maybe that will happen.

Okay, so what's new in ZS since I left off?

I've implemented variables (of type integer, double, and string) and for loops. I actually got nested for loops down to one nest! I had to deprecate nested control structures in USL. It doesn't seem like a lot of functionality right now (at least to me), but later on down the line (next month or so), I will have a completed language to expand upon. Right now I'm going to continue working on optimizations and start implementing if-statements. Then I will implement methods.

So this post is about an issue I had encountered, and how I handled it. I had to drop unnecessary features and rewrite some things, but in the end it was worth it.

Until next time! I'll probably check in the changes right now just for the heck of it.

Here it is: ZerothScript