And So It Begins

Update: Excluding this post, all subsequent articles I write about this project will be on its own space.

This semester, I'm taking RCOS when involves creating or improving an open source project for the benefit of society. But part of the requirement of RCOS is to post, at least, a weekly blog post so that the professor can keep up-to-date with the latest happenings of the project.

The Project

The project I'm working on is a generic, web-based course scheduler. Yes, I'm familiar with web development, but it would be good introduction to creating mobile user interfaces, which I have not extensively done since the iPhone was released upon the world - thus, changing the mobile web space forever.

Existing Solutions

Back on topic, my school is in a transitionary period. The widely popular java desktop application, RPI Scheduler, is currently not working at the time of this writing because of RPI's switch from a text-only course output to an XML variant.

This change was implemented to support the new ROCS scheduler. ROCS is a fork of the former, RPI Scheduler, and converted to be a web application. This is more tightly integrated with RPI's other systems, most notable is SIS, or Banner. Right now, the only difference, besides being web-based, between ROCS and the project it forks is the ability to display the number of seats left for a particular section (as part of the new XML course data).

ROCS is designed to support a set of goals motivated by RPI's DotCIO.

  • To integrate with a Java-based portal system (conforming to JSR-168 specification).
  • To have tighter integration with SIS system, including registering courses through the course scheduler interface (sounds sweet to me).
  • To place the code under an open source foundation to accept contributions by other universities.

While nice goals, there is little concern to the users of the software.

Initial-rcos

Besides the less than great design (which is known a problem), it has many goals motivated by DotCIO. Yes, call be a selfish ignorant lazy bum, but Java web dev isn't my cup of tea. And it isn't for many.

Although the possibility of helping a bunch of schools with scheduler is very inticing.

The Alternative

My project would be a python / django based web app for course scheduling. Because of my familiarity of Django, this removes the hurdles of learning a web framework and UI framework while attempting to learn about designing good user interfaces and creating mobile versions.

Because of the poor design of ROCS, many students have avoided using it in preference of the older RPI Scheduler. Of the students that know about ROCS, many avoid it because of the interface alone.

Both RPI Scheduler and ROCS also are void of any sharing of schedulers created in them. Students commonly take screenshots of RPI Scheduler; crop the image; then finally upload it to facebook. A web scheduler should provide this feature for easily sharing schedules to friends. Also providing calendar feeds will make it a snap to add the courses to one's calendar.

The Future

But since this project wouldn't have quite the backing or reach as ROCS does, it would be best to work on ROCS. Hopefully, I could merge the user interface design and feedback back into ROCS. Ideally, this project is a rapid prototype, in user interfaces before possibly integrating it back to ROCS.

 

Objective-C Dip

Part of increasing my apple fanboy-ism, I have started to Objective-c for a relatively fast language to use. Rather than explain why I like its features directly, let's compare it with a couple languages to help build my case.

C++

C++ is the good old language that managed to survive the ages. Although its flaws are numerous: ranging from const correctness to class managem. The typical use-cases take little concern for developer satisfaction. For example, why do you need to declare private methods in the header file? Sure, maybe friend classes might need it, but why can't these method prototypes be optional for a header file. Add to that templates tend to make a huge mess of code (both in the compilation process and just visual verbosity).

 

One benefit is C++ keeps you thinking about the performance. STL is a timesaver over regular C, but boost is even better. I wish iterators were a bit more generic and concise. The fact that iterators are child classes to their specific (templated) data types makes it hard to have a generic iterator.

In terms of language features, objective-c has reflection, "method passing" (ie - using a delegate and selector), and Categories (alias to monkey patching) which are definitely a plus for software design. The message passing architecture of obj-c will generally make it slower in comparison to C++'s vtables but, in comparison to higher level languages, it is fast enough. Unlike C++, Apple's Frameworks that creates a huge library for you to use without third party libraries. Boost is similar in idea to Apple's collection of frameworks, but far less comprehensive.

Also, the lack of interfaces makes C++ feel really old. No offense, C++.

In typical Apple fashion, there's some minor details of the language improved from C:

  • #import statement to avoid the need of include guards
  • @synthesize to avoid manually creating getters/setters.
  • Use of dot-syntax for properties (to reduce verbosity).
  • Good documentation with reasons behind the design architecture of the libraries (like object ownership).
  • Foreach statement support.
  • A pretty good IDE - with the XCode 4 beta being better than Java IDEs (in terms of intellisense, at least).

Java

Java is another power house in the industry. Objective-c originates from C and smalltalk while Java was trying to make a better C++. Both are mostly on par with differing core design. Like Apple's design philosophy for its products, java was all about reducing the number of choices a developer had to make, supplimented with a large built-in API.

The most notable difference is in the implementation. Objective-C is a superset of C, with features implemented in C, where java exists in a virtual machine - complete with managed memory. While not having to worry about memory management reduces leaks and code-size, it comes with the overhead because of the JVM's garbage collector. This overhead can be problematic. For example, Watson tries to avoid the JVM's garbage collector from running - which freezes it for about 2 minutes.

Another problem about java is the language itself. It is a verbose language. Some may argue that Objective-C is like that too, but it's still more readable, for example:

person.cashInBet(5, 2.0, true);

This invocation gives little information about what the function does.

[cashInBet:5 withMultiplier:2.0 isPartOfTournament:YES];

Which is a lot clearer about what is going on?

Cons

But no language is perfect, the most notable is the few objective-c based third party libraries and its nearly non-existant cross-platform options. Sure you can write for all Darwin-based systems, but not really anything else. Also, redefining NSInteger / NSUInteger gives the wrong perception of the native c times, which is slightly annoying.

How do you help someone with programming?

This is always in my mind when helping a fellow student with an assignment. (Although, this could be be expanded to many other subjects.) I feel like comprehension of the concepts is a critical part of an assignment (and why they are given it in the first place). So when a student asks for help, you should help with the concept the problem is testing. It's like that old saying:

Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime

So if a student needs a help with a specific problem, you don't give an answer. Instead, you give the method to how you got your answer and why. You don't give a fish, but teach how to fish.

But there's a series of problems, besides being hated for not giving the answer.

Most students are only looking for end result (based on how he/she asks the question) and not the process of getting there. What do you do? How can you tell if you're dealing with a student only concerned with the fish? How can you convert such a student?

And how do you explain the solution if he/she is just started programming? Do you give code directly? Do you try to get them to produce code one line at a time? What if they don't understand a programming feature (eg - while loops), what method do you employ to teach that?

How do you help someone gain the problem-solving insight programmers think through?

The Text Editor Problem

Lately, I’ve become sensitive to poor user interfaces - most likely due to redesigning my blog. Most notably, the text editors I use most of the time I’m on the computer. I planned on writing about all the editors I used, but that proved to be too long. So I’ll simply talk about my primary editor of choice for now...

Emacs

Emacs

Sadly, this is currently my editor of choice. Emacs is my default editor for most languages. Emacs has a set of keyboard shortcuts used for efficiently editing text with your hands on the home row. Although it feels productive to work in, it is less productive than IDEs. That’s simply because writing (and reading) code is still a large amount work, over just editing code, which Emacs does not provide out-of-the-box. If you are new or lost your configuration files, countless hours await of configuration awaits after you freshly install Emacs. Here’s a some of the poor Emacs defaults:

  • Writing (multiple) backup files in the same directory as the original file
  • Writing autosaves in the same directory as the original file (and sometimes failing to clean it up)
  • A system beep on error.
  • Few programming languages supported (plugins required).
  • Scrollbar on the left instead of right.
  • Warning when following symlinks. Why wouldn’t I want to follow a symlink?
  • Weak options page (programming required).

Sure Emacs is an old editor, but it can adapt the defaults to today.

After you’ve spent the countless hours learning and configuring it, there are still plenty of problems. The interface is not discoverable. It’s hard to discover new features since most of them are tucked behind hotkeys. I can never remember hotkey for find and replace for the few times I use it. Besides the fact that it’s nearly impossible to use someone else’s Emacs configuration (because of rebinded hotkeys), the GUI is a custom, inferior implementation.

First, Emacs uses akill ring for clipboard functionality. Therefore, deleting text copies it into the kill ring for pasting. I delete text so I can paste text I copied from somewhere else, not to paste the text I just deleted again. This kill ring is separate from the operating system’s clipboard. You can never tell when you’re pasting from the clipboard or from the kill ring. The same applies to copying text out of Emacs into another problem. Emacs makes cut, copy, and paste more difficult than it needs to be.

Second, Emacs lacks tabs. Sure you can use a custom plugin, but it doesn’t have the look or behavior of system tabs. Using the default buffer system fast file switching that tabs provide - easy visual landmarks. It’s why you can easily remember where that window is located in comparison to the title of the window.

I’ll probably get heat from Emacs aficionados for this, but using a mouse to click at the text you’re looking at is far more efficient that figuring out the sequence of keystrokes if it’s greater than a few keys. Take an example:






__all__ = [
    'render_to', 'login_required', 'AppViews',
    'recieves_queryset_and_returns_object_list',
    'recieves_queryset_and_returns_object',
]



Now let’s assume the caret is at the beginning (before ‘__all__’), what’s the sequence of keys you need to use to get between queryset_ and and_returns_object (the 4th line)? With a mouse, there is no thought required: just click there. In Emacs hotkeys, I naturally think: C-n, C-n, C-n, and then M-f a few times. But M-f moves too much (after object) and i’m forced to walk back by character. Alternatively, you can search for recieves_queryset and press search again to skip the first match, but by typing that you lose against the mouse (unless you have amazingly fast and error-free typing).

That being said, Emacs does support a large number of languages and features (like debugger integration) if you can integrate all the plugins. But I haven’t bothered configuring all of it because of complexity. I don’t want to write scripts to customize my editor, I want reasonable defaults.

Another plus is that Emacs’ smart indent feature is second to none. I’m using this implementation of smart tabbing which smart indents when not at the end of the word and auto completes otherwise (M-/). Although Emacs’ auto complete is primitive (only completing based on words you’ve typed), it’s still a time saver.

I was about to talk about the poor documentation Emacs has about its language and editor, but recent changes improved that dramatically. But, these manuals are huge, with very little on getting started. Also, I’m not interested in pouring more hours learning how to program my editor. Why can’t it do reasonable things by default?

Extensibility is Emacs’ touting feature, but it’s also it’s Achilles’ heel. Plugins are almost never on par with core implementations: plugin developer drops support or the plugin was a quick hack up. Whatever the reason, a poor implementation of some time saving features creates a weaker experience. Despite the embracing of extensibility, Emacs lacks a plugin management system. ELPA is a good start, but doesn’t have a large repository base yet.

For added icing, here’s some other problems I still have, which I account to ignorance and user-stupidity (aka, me). Nonetheless, this is bad design if I just have to feel stupid for this:

  • There’s some alt+mouse click feature that creates a permanent highlighted text that I never figured out how to remove (other than cutting & pasting the highlighted code).
  • In Ubuntu, I have extra large fonts, in comparison to Windows. Setting the fonts with (set-face-attribute ‘default ...) seems to only set it for the first frame created.
  • Being unable to integrate plugins (or just giving up in frustration).

Good AI Design?

Besides web programming, I'm attempting to implement infinite detective from 300 Mechanics (It doesn't have 300 ideas yet, but it is an interesting site for game ideas). The basic idea is to dynamically generate murder mysteries. One of the most laborious task is to implement various goals for the people (eg - kill a person, cook a meal, etc.). Essentially, goals are a series of actions to complete over a time span. If you've made a game before, you know the normal time flow of a game is written something as:



def main():
    init_game()
    running = False
    while running:
        process_input()
        process_actions()
        draw_frame()


Designing a series of actions to walk through several steps is not a fun task. Take the task to murder a target:

  1. Get a weapon from the current room
  2. Find target without any witnesses
  3. Kill person
  4. Dispose of weapon (perhaps in a different room)
  5. Pretend nothing happened

Now how would you design as system that would allow this goal, and others like it, to be easy to implement? Creating a class per goal may work, but the problem is the logic above shouldn't get partitioned. An iterator interface looks reasonable, but having something like:

 



class MurderPerson(object):
    # init code (self.person = murderer, self.target = target to kill, self.state = 0)
    def next():
        if self.state == 0:
            return self.find_weapon() # self.state += 1 on success
        elif self.state == 1:
            return self.kill_target() # self.state += 1 on success
        elif self.state == 2:
            return self.dispose_weapon() # self.state += 1 on success


 

Luckily, python provides the nice yield statement which behaves similar to continuations. This allows a nicer way to implement this without case/if statements:






import random
def murder(person, target):
    weapon = find_weapon_close_to(person)
    while weapon.room is not person.room:
        person.move_closer_to(weapon.room)
        yield
    while target.room is not person.room:
        person.move_closer_to(target.room)
        yield
    person.kill(target)
    yield
    while random.random() < 0.25:
         person.move_to_random_room()
         yield
    person.drop(weapon)
    yield



Now it's more verbose since the requirement have having yield call in the same function, but it's easier to see what's going on here. The main problem is that there can be reusable code. But yield can return values, so we can return functions (our subgoals) to complete.

<pre style="color: #000000; background: #ffffff;">def murder(person, target):
    weapon = find_weapon_close_to(person)
    yield [
        {'exec': move_to_room, 'args': (weapon.room)},
        {'exec': move_to_target, 'args': (target.room)},
    ]
    person.kill(target)
    yield
    yield [{'exec': move_to_random_room}]
    person.drop(weapon)
    yield
</pre>


We could make classes and functions instead of yielding lists and dictionaries, but it's simple enough to see what goes on. The person object will handle the work of completing subgoals before proceeding on the current goal.

Surprise, I've switched.... again.

I promise this is the last time I switch (unless posterous dies).

I'm moving from my own custom solution to posterous. It satisfies all my needs, including the need to be able to embed code snippets easily and a simple, large WYSIWYG editor. Besides my recent rage over my editor, I've been having problems with Django - it's a problem worth its own post at a later time [or perhaps a screencast ;)]. It's been feeling a bit more stagnate, although the multiple-db support was nice, in comparison to rails.

That being said, I'm planning a "web dev" tutorial series to getting into web development.

But, I'll be off to Apple for next week.

"... I typically walk around with the conviction that people aren’t THAT naive, but…"

(via Zoya)

Dear visitors from Google. This site is not Facebook. This is a website called ReadWriteWeb that reports on news about Facebook and other Internet services. To access Facebook right now, click here. For future reference, type “facebook.com” into your browser address bar or enter “facebook” into Google and click on the first result. We recommend that you then save Facebook as a bookmark in your browser.

nature will always make a better fool.

(from Will)