Sunday, July 31, 2016

Characters and ASCII

Fun with Char

One of the things I found to be really interesting early on in the Stanford programming methodology course was chars in Java. I found that I was taking a lot for granted about characters when it comes to computers. I know what an 'A' and a 'B' and a 'C', and so on, are and so I thought that computers understood them in the same way. I think an 'A' and an a are two versions of the same character, upper and lower case. Therefore I sometimes found myself wondering why there was this case sensitivity thing you had to deal with with computers. Doesn't the computer know an 'A' is the same character as an 'a'? So I found it rather eye opening, and oddly fascinating. to learn that an 'A' doesn't mean anything to the computer, it's actually just a number. What's more an 'a' is also just a number, and it's a different number. So of course case sensitivity is an issue for a computer because there's nothing that really ties the two characters together for the computer, they're two entirely different characters, really two different numbers.

The ASCII Table

I had seen and heard about the ASCII table before but was only using it as a reference for the sort order of the numbers and special characters in relation to the letters.  Now I was coming to have a greater appreciation for what had been established and standardized so that we could effectively communicate with one another through different computers.

I learned that an 'A' was decimal number 65 and an 'a' was number 97. I learned that a '0' was actually the number 48.



So then I learned how to write my own method to change an upper case character to it's lower case equivalent. I learned that you could do math on letters! Yes, I am fully aware that the exclamation point at the end of that sentence means that I'm a geek. What's surprising to me isn't that I found this realization fascinating, but that I hadn't discovered this sooner in life so I could geek out on it.

I learned that to change an uppercase 'A' to a lowercase 'a' you actually add 32 (65 + 32 = 97), and the same is true for every other letter. But what's better, I learned that, even though ASCII is unlikely to be changed or abandoned, you wouldn't want to put 32 in your code, instead you want to use the characters themselves and let the computer figure out the number difference between them, just in case they ever did change.

What you know is that 'A' through 'Z' will always be sequential numbers in whatever code is used and 'a' through 'z' will always be sequential. In ASCII there are six extra characters ( [  \   ]   ^   _   ` ) between 'Z' and 'a' (26 letters + 6 characters = 32). But should some other table ever be used, the difference may no longer be 32. So what you write to convert an upper case character to it's the lower case version is something like this...

public static char toLowerCase(char ch){
   if (ch >= 'A' && ch <= 'Z') { /* to see if input character is upper case */
      return ch + 'a' - 'A'; 
        /* dynamically determines and adds the difference between the two */
   } else {
      return ch; /* if not upper case, return as is */
   }
} 

Since they are really just numbers, you can also use char in control statements to loop through the equivalent letters, such as...

for (char ch = 'A'; ch <= 'Z'; ch++)

This is actually a simple concept but it was an eye opening and fun realization.

i++

Thursday, June 30, 2016

Eclipse and Karel the Robot


The Eclipse IDE

One of the first things I did for the Stanford programming methodology course was to install the Java JDK and then the Eclipse IDE. This was my first experience with an IDE, a step up from Notepad++. While a later book I read encouraged avoiding IDEs and typing out code with no assistance, I found the automatic code completion and instant feedback for syntax errors helpful for beginning to learn Java. For the course, Stanford developed a customized version of Eclipse. This version made it possible for beginners to get started with some basic object-oriented programming ideas without having to start with something like the main() class.

I have since had experience with the Android Studio IDE, which seems quite similar to Eclipse, and have learned of a few others. In time I would like to try out Emacs, NetBeans and others.

Karel the Robot

The first few course assignments were to be written in Karel, a simple object-oriented language similar to Java. Karel is the name of a little robot that will follow programming commands as he moves through a grid. Karel has only four main functions:

  • move()
  • putBeeper()
  • pickBeeper()
  • turnLeft()

You are told what to have Karel do and then you must accomplish it using only those four functions. 

move() tells him to move forward one step. putBeeper() has him put down a marker in the grid and pickBeeper() has him pick a marker up. turnLeft() does what the name suggests. You may need to have him turn right but there is no turnRight() function. So you can have him turnLeft() three times, then you learn to write your own turnRight() function to use.

Karel the Robot was a fun introduction to programming. It teaches you to problem solve, using logic, and to begin to think in a object-oriented way. You can find the Karel the Robot Learns Java book here.



i++

Sunday, June 5, 2016

Stanford Programming Methodology (CS106A)

The Programming Methodology course is a part of Stanford University's Stanford Engineering Everywhere. Through this program, students and educators can access many of Stanford's courses online, free of charge. I was essentially able to audit this introductory, semester-long, computer science course for free. I watched the lectures, did the reading assignments and the programming assignments. I found it very interesting and learned a lot. You can find the course at https://see.stanford.edu/Course/CS106A. Here's some basic information about it.

Professor

The course was taught by Mehran Sahami. You can read his profile here. You can tell that Mehran enjoys teaching the course. I found his enthusiasm for the subject to be very engaging. He uses a lot of helpful illustrations for what could be complicated topics and even throws in some fun pop culture references that I could appreciate. Through his video lectures, I got a sense of what it would have been like had I pursued computer science in college.

Textbook

The course textbook is The Art and Science of Java by Eric Roberts. It is available for purchase and a free PDF version of an early draft is also available online. Just search for it and you should find it. I found the book to be informative and easy enough to follow. I even put up a quote from the book in my cube at work, his definition of software engineering - “the discipline of writing programs so that they can be understood and maintained by others”.

What's Covered

As one would expect from the course name, it provides an introduction to good programming methodology and uses Java as the language of choice to do this. It covers, among other things, Variables and Types; Expressions, Statements and Control Structures, Methods, Randomness and Events, Objects, Strings, Classes, Arrays and ArrayLists, HashMaps, Interactors, Collections, Debugging Strategies and Searching and Sorting.

Assignments included three games, Breakout, Hangman and Yahtzee; a data graphing program and a simple social networking program. I enjoyed working on these programs.Naturally it would be better to actually take the course and get feedback on your code but because so many people have taken the course, it's easy to find other people writing about the assignments online. I also created a Stack Overflow account and was able to get some help and feedback that way.

I do recommend the course to anyone looking for an introduction to programming in general and to Java in particular. I will get into some of the specific things I learned through this course in future posts.

i++

Sunday, April 24, 2016

What Other Languages to Learn?

I consider myself to be very blessed to have been able to start in a full-time programming job in my forties. This is especially true as I did not start with any formal computer science education. Because of what I was able to do for about 15 years, mainly with Microsoft Access and Excel, I was given a chance in my company to write OmniScript. This has shown me just how much I enjoy programming. Therefore I came to want to learn a lot more about it, especially learning some other programming languages.


Where to Start?

What other,  more common,  programming language would I start with?  A simple Google search yields a lot of blog posts and articles on this subject. There are many different opinions but one of the languages that was on the short list of most, if not all, was Java.  C and C++ were also near the top of most lists but I found that Java appealed to me the most.


Why Java? 


I decided to start with Java for a few reasons.

  • Though Java has been around for over 20 years now, it is still one of the most popular programming languages. 
  • Java is cross platform.  "Write once, run anywhere." 
  • Java is used in making Android apps, something I had an interest in doing.
  • Though I'm still interested in learning C and/or C++, Java seemed like an easier starting point. 
  • I liked what I was seeing for online resources to learn Java.

Regarding the last point, I found a Udemy course in Java that I was planning to start but then I came across the Stanford Programming Methodology course (CS106A) and decided that would be a great place to start. Not only would I be learning Java, I'd also be learning good programming principles. I'll write more about my experience with the Stanford course in my next post.

While to some extent this could be said of my introduction to OmniScript, in the words of Obi-Wan Kenobi, I felt like I was about to take my first step into a larger world, and I was quite excited.

i++

Sunday, April 17, 2016

Notepad++ and OmniScript

Writing OmniScript in the default application, OmniStation, soon had me longing for something more. In that application there are no helps for the programmer. There is no language color coding and no hotkeys. Then I got on a big project developing a new website and we were introduced to a browser based scripting tool that does have some color coding. This was a welcome addition but this scripting tool also had some limitations and still no hotkeys. So I still wanted something more. Enter Notepad++.



Language Support


I had come across Notepad++ earlier but at that time I wasn't doing any programming so I didn't fully appreciate what it could do. Naturally there was no pre-programmed Notepad++ language support for OmniScript. So I set about setting up a user defined language for OmniScript. With colors for if/ ends, loop/endloops, routines, functions, comments and more, this made looking at and following scripts so much easier. I have continued to tweak this user defined language over the last couple of years and a growing number of scripters on our team are using it and Notepad++. It's worth having to paste script back into OmniStation over and over to be able to use the benefits of this great text editor.  



Other Great Features


Other great features of Notepad++ have made it one of my favorite programs of all time. The hotkeys are a great time saver. I constantly use them to delete or duplicate and move whole lines. Indenting or un-indenting whole sections at once has been another great benefit. And then there are the search features. Simply double clicking on a word and having all other such occurrences of the same word in that file automatically highlighted has been a huge help in avoiding and finding errors. Searching for all occurrences in one file or all open files has been wonderful for making changes or just tracing the flow of a program. I regularly have 30+ component scripts open at the same time and I can't say enough about being able to so easily search for all occurrences of a variable or term across all scripts at the same time, with all of the results so nicely cataloged for me. On top of all of that there are the great plugins.


I am constantly singing the praises of Notepad++ to my co-workers. I have often said that I want a Notepad++ shirt to wear. It has become goal of mine to at one point contribute to this great program.


i++

Sunday, April 10, 2016

OmniScript Containers

One of the best features in OmniScript is what is known as Containers. The closet thing I can compare them to is a table in a database, such as Microsoft Access. The same thing could be accomplished with a multi-dimensional array but the container structure ties everything together very nicely and makes it very simple to set up and work with.

Creating Containers

When you create a container in OmniScript you declare the length of the key for each record as well as how many of each type of field you will be using in the container. As with OmniScript variables, there is only one type of numeric field but there are three different types of text fields based on the length of the string.  There are 10 byte, 40 byte and 200 byte text fields. So you determine how many of each field you will need and declare them in the container create statement.

Adding and Updating Container Records

Once the container is created you can add records or update existing records based on the unique record key. Numeric fields can be set or added to or subtracted from. Text fields can only be set but through a two step process you can read what is in them, append to that string, and then reset them. Any record fields that are not set when the record is added to the container default to 0 for numeric fields or null for text fields.

Because each key is unique and the records in a container are sorted by the key, containers are useful for both sorting and consolidating duplicates.

Accessing Container Records

Individual records in a container can be accessed with a get statement by specifying the record key.

Just like with the built in sets of records in the recordkeeping database you can loop through the records in a container. You can either loop through all records or you can use a key prefix to only loop through the records that have a key starting with the string provided. This allows you to create one container with a primary set of records and then create a second container that has a varying number of records that relate to the records in the first container, in a one to many relationship. The key of each item in the second container begins with the key of the corresponding item in the first container.

And so then you can loop through the first container and for each item in that container you loop through the second container with the key of the first container being used as a keyprefix for the loop on the second container.

Cleaning up Containers

Naturally, container items can be deleted and containers can be emptied and reused as needed. When you are done with them it is also important to destroy containers to clear them out of memory and free that memory up.


Containers are definitely one of the strengths of OmniScript and a very useful tool in managing data.

i++

Sunday, March 13, 2016

OmniScript and Other Languages

As I shared in my last post, OmniScript is a proprietary, server-side, interpreted scripting language for the OmniPlus System, a COBOL based financial application. Like any language, as I've been learning, OmniScript has it's strengths and weaknesses. There are some things it naturally does very well in dealing with the data structure of the OmniPlus system, and, as I've been learning about other languages, I'm seeing some of OmniScript's limitations (at least with my limited knowledge anyway).

Language Learning


In college I took two years of Greek. I found learning this ancient language, with it's different letters,fascinating. One interesting thing I found was that learning Greek had the added benefit of helping me with my English. The fresh experience of seeing grammatical concepts in Greek gave me a better understanding of similar concepts in English that I had taken for granted for the most part.

When it comes to OmniScript, my early understanding of BASIC helped to prepare me, and as I've spent time since learning Java and a little Python, that has given me a clearer understanding of the concepts I'm using in OmniScript. Studying Java through Stanford's Programming Methodology course online has made me a better OmniScripter. It's interesting to learn and compare the similarities and differences in languages and it makes me a better writer of whatever language I'm working with.


i++

Sunday, March 6, 2016

My Introduction to OmniScript

In my retirement services recordkeeping job I worked mostly in Microsoft Access for the first 15 years or so. Due to that nature of the group of retirement plans that my department did the reocrdkeeping for, we had to perform the annual compliance testing on the plans outside of the main recordkeeping system, OmniPlus by SunGard (now FIS). Therefore my main job was maintaining and developing a growing Access database. But then when some changes came in 2011, I started in a new role shortly after I went back to working there fulltime. In these first 15 years I had limited experience with gathering and exporting data from the OmniPlus system. Then in 2012 I officially joined the technical team and began writing OmniScript fulltime.

OmniScript

What is OmniScript? OmniScript is a proprietary, server-side, interpreted or compiled scripting language for the OmniPlus System, a COBOL based financial application. It is a VBA type scripting language which provides access and update capability to the OmniPlus database, and access to internal operations.

When I started, I knew next to nothing about the scripts I started looking at. There were no good training materials available to me so my training was much like getting dropped into the pool to learn how to swim. Thankfully my past experiences with programming, limited as they may have been, provided a good foundation for learning this new language.

My first tasks were making modifications and enhancements to existing processes and reports. With each one I studied what was being done in the scripts, tracing the structure and flow. I quickly got a sense of things and soon came to enjoy scripting. 

Less Visual (sort of)

Because my work with Access was much more visual than looking at code and seeing data showing up in files and transactions, I was unsure at first if I would like it as much. Now though, I can say that I enjoy writing code more than anything else I have done. I like designing and structuring the logical flow needed to gather data and accomplish tasks. While I spend a lot of time just looking at text, in my mind I'm visualizing the structure of my program, seeing how the many details work together, step after step, to accomplish what's needed.

As I modified scripts and wrote new things I learned about OmniScript quickly. Neither my boss nor I expected it, but within six months I was assigned with writing a whole new product we wanted to offer our clients. I'll write more about that and OmniScript in future posts.

i++

Saturday, January 16, 2016

AutoHotkey

I love macros. I love being able to have the computer quickly do repetitive tasks for me. Early on I learned to use macros in Excel and when I started using Access I began using more and more macros in that program.  Soon, however, I realized that I needed something more, something independent of just one program. I needed something that could even switch between programs.  That's when I discovered AutoHotkey.


If you aren't familiar with AutoHotkey you owe it to yourself to check it out. It's an open-source macro and automation program for Windows. As it says on the website, "It is driven by a scripting language that was initially aimed at providing keyboard shortcuts, otherwise known as hotkeys, that over time evolved into a full-fledged scripting language."

Features


The scripting language gives you a lot of options. In addition to sending keystrokes, the feature I first wanted, you can check to see if certain windows are open and switch to them, conditionalize steps based on the window being open or wait until that window opens. You can minimize and maximize windows. You can change the transparency of windows.You can also control the mouse with the position being relative to a window or the screen. You can move the mouse and click either button. You can change the system volume and even play sound files. The last option is particularly helpful when you want to be sure that certain steps are taking place, that you hit the right hotkey.

I have been amazed at what I've been able to write and accomplish with AutoHotkey. Just about every time I've thought, "I wonder if I could do that with AutoHotkey?" I've been able to make it happen. I can't imagine how much time I've saved at repetitive tasks by being able to use it.

Little did I know when I started with it that I was beginning to learn a scripting language. In addition to the helpfulness of the program itself, I've also learned from writing script in it.

i++