Debugging Run BASIC Web Apps

In Run BASIC's first release there is effectively no built-in debugger. Of course you can use print to log to the browser page or to a file, and this is no more or less than many other web scripting systems. We aim to do something about this in the very near future.

One of our users suggested that it would be good to create an inspector panel in Run BASIC itself and that we should add some reflection via an EVAL$() function that would allow arbitrary execution of BASIC code at runtime. We would probably also need to at least metaprogramming features like the ability to get information from the runtime like:
  • The name of the current context (ie. function or subroutine)
  • The names of all the variables and arrays in scope
  • The source code for the current context
  • A collection of objects that models the stack
  • Probably more stuff

While this sort of thing is possible I think that we probably will initially provide a high level runtime inspection panel that the programmer can show and hide as needed. This is BASIC after all, and it should be as easy as possible to use. The metaprogramming stuff is cool though. ;-)

Solving algorithmic problem

There are some general techniques that I've found quite useful to come up with a solution for an algorithmic problem.

Understand the problem
  1. Make sure the problem is well defined and understood. Try to rephrase the problem in different ways to double verify the understanding is correct.
  2. Understand the constraints and optimization goals of the expected solution. There will be many conflicting dimensions of a solution (e.g. performance, security, scalability ... etc), knowing what can be traded off is important.
Design the solution
  1. While you are thinking about the solution, try to make it visual. e.g. Sketch the solution on a whiteboard to help you think.
  2. See if you can solve the problem by using a simple-minded, brute force search. Try all the possible combinations of solution to determine which one works. But get a sense of the BigO complexity analysis to judge whether the brute-force approach is feasible.
  3. See if you translate the problem into a search problem. Then you can utilize existing search algorithm (e.g. hill climbing, A*, BFS, DFS ... etc) to help.
  4. By exploit the nature of the problem, see if you can define your solution recursively. Assume that you already have a solution with the problem of the smaller size, can you use that to construct the current solution. e.g. Can you define F(n) based on F(n-1), F(n-2) .... etc. And also try to see if you can translate the recursive solution into an iterative one.
  5. At this point, you may have found multiple solutions. Do a BigO analysis in both time and space and pick the one that aligns with your optimization goal.
Verify the solution
  1. Walk through some simple examples to test out your solution, include some boundary cases in the examples to see how your solution handle those corner cases.
  2. Prototype your solution. Define some measurement and instrument your prototype. Run it and compare the result with what you expect.

Web Programming for Fun

There has always been a culture of complexity-worship in the programming community. Some people seem to think that the Internet is a good excuse to take this even farther. This takes the fun out of programming, and it scares a lot of people away from even trying it. We think that this needs to be pushed back against. One of our goals in creating Run BASIC has been to make web development so easy that anyone can do it. As a language designed to make programming simple, BASIC is an ideal platform for realizing this idea.

We need a culture of simplicity. The computer should do that hard stuff for you. For example web application servers manage user sessions and processes, and these are things that require special administration by an expert in most web systems. With Run BASIC, except for a couple of fields in the Preferences tab that let you configure how long the timeouts are for sessions and processes, you don't really need to know anything about these. It's all done for you automatically.

Or for example let's say you want to draw graphics? There are no add-ons that you have to locate, download, and install with Run BASIC. It's all built right in, and just a few lines of code can draw some meaningful graphics into your web apps.

It's easy, and it's fun.

Run BASIC - Zero Configuration Web Application Server

I found a blog post today that compared PHP with Ruby on Rails in terms of how much easier PHP is to install and configure than Ruby on Rails. Both of these systems are composed of at a minimum:
  • A web server (usually Apache)
  • A language interpreter for PHP or Ruby
  • And usually a database server

And this is a simplification. The user needs to install and configure these things which requires knowing about a lot of esoteric stuff. If you've never done this before, you can lose some of your hair. Unless you like pain, why put yourself through this?

If you want to create your own web applications, Run BASIC will install everything ready to run in one shot. http://www.runbasic.com/

Why do people put up with complex programming systems? Because for more than a decade they had much harder tools, so now they think PHP and RoR are easy.

Run BASIC Tour Video Posted

One big challenge we face in explaining Run BASIC to people is that people have a preconceived notion of what an easy programming system is. Ruby on Rails is supposed to be easy, right? Easy compared to what? Java server pages? Apache and Perl? For a certain class of problems we need the kind of easy that BASIC (and I don't mean Visual Basic) has always provided.

So, today I created a 20 minute video that walks through installation, startup, and gives a tour of the features of the Run BASIC programming software and several examples. This includes creation and hosting of a simple app. Visit the Run BASIC site and check out the video and I'm sure you'll agree that you've never seen anything easier.

Web Debugging

The topic of web debugging in Run BASIC came up today in the forums, and the topic started with some ambitious ideas from Bill W. who always has something interesting to say (here for example).

Run BASIC does need a debugging facility. I realize that most web programmers probably write to logs, and you can do that in RB without adding anything but we can make it a lot easier. Just for starters I was thinking of adding a logging object of some kind. A debug button would be added to the toolbar, and then you could specify either logging of all variable changes, or specify watches so that only certain variables would get logged, and a LOG statement could also be added that would only log if the program is executed in debug mode (instead of merely run).

Also, it would be no hard matter to include an inspector object which could be rendered into the page whereever it is convenient for the programmer. You could examine and change the value of variables, and perhaps even execute code dynamically on a running program in the web browser.

I'm eager for feedback on this!

Recursion vs Iteration

Recursion is a very commonly used technique to express mathematical relationship as well as implement computer algorithm. Define a function recursively usually result in very concise form and ease the understanding. However, recursive function is not performance friendly in terms of stack growth and processing time.

Here is a general form of a recursive function ...

def f(n)
if (n <= j)
return known_value[n]
else
return g(f(n-1), f(n-2), ... f(n-j))

When this function is invoked, the stack size will grow linearly O(n) and the processing time will grow exponentially O(j**n)

However, the above function can be rewritten into an iteration form. The idea is to revert the order of execution, moving from the known points to the unknown values.

def f(n)
if (n <= j)
return known_value[n]
for i in 0..j
cache[i] = known_value[i]
for i in (j+1) .. n
cache[i] = g(cache[i-1], cache[i-2], ... cache[i-j])
return cache[n]

In this iteration form, the stack size will not grow and the processing time will grow linearly O(n). Therefore, performance gains significantly when the recursive form is rewrittened in the iteration form.

A* Search

Given a start state S and a Goal state G, find an optimal path S -> A -> B -> ... -> G

We can assign a cost to each arc so the optimal path is represented with the lowest sum of cost. This problem can be modeled as a weighted Graph where nodes represent a state and cost associated arcs represent the transition from one state to another.

A* search is one of the most popular search algorithm and it has the following characteristics
  1. If there is a path existing between S to G, it can always find one
  2. It will always find the one that is optimal (least cost)
Here is the description of the algorithm
  • Define a function: f(X) = g(X) + h(X) where ...
  • g(X) = minimal cost path from A to X
  • h(X) = a heuristic estimation cost from X to S. It is important that the estimated cost h(X) is less than the actual cost
  1. The algorithm keep track of a list of partially explored path, with an associated f(X) within a priority queue as well as a list of explored nodes. Initially the priority queue contain just one path [S] with cost C and the visited node list contains just S.
  2. Repeat the following ...
  3. Pick the lowest cost path ... based on f(X) from the priority queue to explore
  4. Set current_node to be the last node of the lowest cost path
  5. If current_node is explored already, skip this node and go back to step 3
  6. If current_node is the goal, then done. This is the optimal path
  7. Otherwise, find out all the neighbours of the current_node. For each of them, insert a path that leads to them into the priority queue.



def A_Search(S, G)
visited_nodes = [S]
priorityQ.add([] << S)
while priorityQ.non_empty
lowest_cost_path = priorityQ.first # according to f(X)
node_to_explore = lowest_cost_path.last_node
continue if visited_nodes contains node_to_explore
if node_to_explore == G
return lowest_cost_path
else
add node_to_explore to visited_nodes
for each v in node_to_explore.neighbors
new_path = lowest_cost_path << v
insert new_path to priorityQ
end
end
end
return nil # No solution
end



Proof: A* Search can always find a path if it exist

This should be obvious because the while loop will only terminate if the Goal is reached or all connected node has been explored

Proof: A* Search will find the path with least cost

Lets say the algorithm find a path S -> A -> K -> ... -> G which is not the optimal path
S -> A -> B -> ... -> G

That means, in the last extraction from the priorityQ, f(G) is smaller than f(B)

This is not possible because ...
f(G) == cost(S->A->K...G) > cost (S->A->B...G) > g(B) + h(B) == f(B)

BASIC Back By Popular Request

Sales of Run BASIC have been pretty strong since we launched it on Jan 5. It's been really encouraging to see our users post about their experiences. People are building a lot of really neat things with it.

One thing that people seem interested in doing with Run BASIC is to use it as a frontend interface to various systems like home automation, machine control, monitoring and such. So requests for RS-232 serial port access, hardware port I/O and even USB devices are a hot topic. See this thread.

Hobbyists and people who take it upon themselves to automate their own work without the help of IT experts have traditionally used BASIC, and we intend to make Run BASIC work for them.

Run BASIC Podcast Interview - Part 2

As promised, part two of the Run BASIC interview with James Robertson is now online. Amongst other things, we chatted about how web development is harder than it needs to be, and about the challenges of marketing something different because people's perceptions can be hard to break through.

http://www.cincomsmalltalk.com/blog/blogView?entry=3378296271

Enjoy!

-Carl

Java and BASIC - Simplicity and backwards compatibility?

Bruce Eckel and Joshua Bloch kick the can around about Java and complexity. Read about it here:

http://www.infoq.com/news/2008/01/java-evolution

I especially like this quote about Java and web development:
Web application development - this is difficult, and developing web applications with complex and underpowered technologies like JSP and JSF "is like eating soup with a fork"

I've been a Java programmer for 7 years. I've never liked the language. It always seemed to me to be much too verbose and controlling. It's amazing to me that it has been so popular, but that is more of a marketing accomplishment than anything else.

Run BASIC is a web programming system in development, and a really important part of what Scott McLaughlin and I are trying to do is to manage how the language grows. One important question to ask is how much emphasis to place on backwards compatibility as we more forward. Our goal is to create the best BASIC for the web, and it should still be simple and fun to use even as it becomes more powerful.

I invite your comments. :-)

Amazon's EC2 and Run BASIC?

I've been trying to figure out how to provide hosting for Run BASIC users. Someone had asked, so I suggested Amazon's EC2 system. I had read about it somewhere, and then it was recommended to me while I was being interviewed here.

The idea that I've been toying with is to charge a reasonable monthly fee like $15 for a Run BASIC user account on a VPS on EC2. A single instance of a VPS costs about $75 a month, and additional instances are created and removed as load changes.

So far things aren't looking really encouraging. Jerry Muelver has been looking into this matter, and so far it looks like a difficult matter to set up. Documentation is not easy to follow, and it just seems like a real hair puller. Check it out Jerry's story here.

Operation on Bits and Bitwise Operators

OK guys, this is my first post in the New Year 2008, I thought of posting it
earlier but at last I didn’t. It’s already been so long since I
posted so let’s keep everything aside and talk just about what we have
for today. ;-)


I was sitting the other day thinking about what to write for a post here. Suddenly
I realized that we have discussed operations
on matrices
, arrays,
and what not but we haven’t had the chance to talk anything about the
most fundamental thing a computer understands. Yeah, Operation on Bits.


Bits can have only two values either ON (1) or OFF (0). In this article, we’ll
be discussing about the different operations which can be performed on bits.
One thing to note here is, we don’t perform these operation on single
bits but rather on a group of bits (byte(s)). So even though Bitwise operators
operate on bits its almost always a part of a group (byte, which makes up each
data type), it means we can do bitwise operations on any data type.


BTW, the operators that perform operation on bits are called Bitwise Operator
and such operations are known as Bitwise Operations


The six bitwise operators are listed below:




























&


AND


|


OR


^


XOR


>>


Right shift


<<


Left shift


~


One’s complement


For this post we’ll only be discussing &(AND) and | (OR) operators
leaving the rest for future posts ;-)


Bitwise AND (&) Operator: First thing, it’s nothing to do with the
Logical (&&) operator, both are different.


Now, if you know something about Logic Gates then you might already know about
this. For the rest of us, it does an AND mask on bits.


So, suppose if we have two separate bytes having binary values as 00100000
and 00100001 then doing AND operation would give us the following result.











First Byte:

Second Byte:

00100000

00100001

Result:

00100000

The truth table for this would be:













First Bit
Second Bit
& (AND)

1


1


0


0


1


0


1


0



1


0


0


0



As the Logic AND Gate does, it takes two bits (from the two separate bytes)
and if both of them are ON (1) then only it gives ON (1) in all other cases
it gives OFF (0). So starting from the right there is 0&1->0, 0&0->0,…,
1&1->1 and so on.


Bitwise OR (|) Operator: Here again, both OR (||) and Bitwise OR (|) are different.


The following example is sufficient for you all to understand its operation.











First Byte:

Second Byte:

00100000

00100001

Result:

00100001

Truth table













First Bit
Second Bit
& (OR)

1


1


0


0

1


0


1


0

1


1


1


0


There won’t be any example program here because to fully understand these
operators we need to express data as bits (binary form) and see how the operations
change them. Since decimal to binary conversion programs require some bitwise
operations that we’ve yet to discuss so I think it’ll be pointless
to have such programs now!


P.S. An integer in 32-Bit (Windows) environment is 4 bytes long. Short int
is half of that

8 bits make up one byte.


Related Articles:


Ajax and BASIC

Ajax (Asynchronous Javascript and XML) style techniques for building interactive web applications are the rage today. They are somewhat overhyped, but there is some value there.

Run BASIC already provides an exceptionally easy web programming system, but it does so with minimal special effects. There is a tiny bit of Javascript being used but almost everything is done with XHTML on the browser, and a very smart web application server.

In release v1.0 of Run BASIC the widgets (and indeed the page itself) are all objects. They are created by very simple statements. Any sort of Ajax inspired widgets for a future release of Run BASIC must not be any more complicated to use than the simple to use widgets that are already there.

Additionally, one of the most important aspects of Ajax is partial page reloading. This is important and we are eagerly planning to add this. What this will allow you the Run BASIC program to do is to reload a small part of your web app in the browser so that each user action does cause the whole page to be refreshed from the browser. This provides for smoother feeling user experience, and it also can improve performance.

So, Ajax must not complicate Run BASIC. Our design philosophy is to respect the simplicity of BASIC as much as possible. There are too many complicated programming systems out there, and the world doesn't need another one.

Moving Up From Web Design

Sometimes you will see people posting something like, "I've been creating web sites for years using HTML and FrontPage but I'd like to know how I can take the next step. How do I become a web developer?" Usually the answer provided is something like, "You should learn PHP."

Is PHP the answer? The answer is of course, it depends.

If you're just looking for a job skill you can put on your resume, then PHP may be exactly what the doctor ordered. But, if you are building your own sites or are doing custom work for a client, or want build something for use at the office, or if you just want to learn because programming interests you then you really should consider Run BASIC. You can get something going faster with Run BASIC than with more traditional web tools because Run BASIC is designed to be easy. It doesn't try to fit into the mainstream notion of a web tool. There are just too many of those.

Take a look at the site at http://www.runbasic.com/ for more information.

Intel and the OLPC

I was shocked this last week to discover that when Intel left the One Laptop Per Child project, many people immediately used this as an opportunity to say that OLPC is finished, done for, kaput. Why, just because one of their most recently joined partners was ousted? Their other partners include Quanta, Chi Mei, AMD, News Corp, Google, Brightstar, Red Hat, Nortell, Marvell, eBay, SES/Astra, Citigroup, Real Networks, Seagate, Adobe, and more.

Seriously, it seems like people want this project to fail and I'm not sure why. I am a proponent many of the ideas that are intrinsic to the XO laptop and the software it comes with, so I'm rooting for it to be a success. I even participated in their Give One Get One program, and I'm eager waiting for my very own green and white XO laptop.

Some people think that because Intel is also selling laptops to education ministries in poor countries that this dooms OLPC. I hope they're wrong. Intel is selling what amounts to power guzzling Windows laptops. They aren't rugged enough, they need AC power to run, and they run Windows and Microsoft Office. In other words they are only in the market to kill OLPC and they don't care the least little bit about benefitting children.

A lot of other people trash the OLPC because it isn't useful to them personally. This is just a nonsensical position to take. It isn't designed for the affluent consumer but for education starved kids in poor countries out in the bush. It fulfills it's intended role perfectly. It is designed specifically to open a world of learning to kids, and not just give them boring drill and repetition games. Why do American consumers tolerate boring educational software BTW?

The OLPC is a completely open platform with a designed-for-kids collaborative GUI and built in wireless mesh networking, special BitFrost security, and very radical learning software. It is uncompromising in executing the vision it sets forth. Very cool.

Some people criticize OLPC saying that kids don't need computers, but clean water and food. There are already many charities striving to provide those things. Why is it wrong for another charity to enrich their minds?

I encourage everyone to go to http://video.google.com/ and search for OLPC or Negroponte. There are some excellent long presentations that explain all the important ideas of OLPC.

Web 2.0 Podcast Interview - Run BASIC

James Robertson interviewed me yesterday on his weekly podcast Industry Misinterpretations about our new web appserver Run BASIC, where he describes it as a Web 2.0 platform. I don't usually use that term, but I guess if the shoe fits...

The interview lasted more than an hour, and it was a great time. We talked a lot about how complicated programming systems are these days, and how badly we need simplicity to make a comeback. :-)

Listen to part one of the interview here:
http://www.cincomsmalltalk.com/blog/blogView?entry=3377692218

Part two will be posted next week.

iPhone BASIC?

Now that we've released Run BASIC, we would like to collect some feedback about the idea of adding some capability for the iPhone (and other mobile phones). There is a Javascript library and some CSS called iUi http://code.google.com/p/iui/ which provides the metaphor and visual look for iPhone (and iPod Touch) apps. This would make for very easy iPhone development, and it could be a great marketing button for Run BASIC.

Apple plans to announce some sort of SDK next month if I'm not mistaken, but a lot of iPhone software development will definitely still be web apps.

We could:

  • Work on this now
  • Work on this later
  • Encourage the RB community to integrate iUi by writing BASIC code

Perhaps the last option is the most sensible for now. Feedback is welcome.

Learn Web Programming

What does it mean to learn web programming (or web development) anyways? Most of the time it means that you need to struggle learning a programming language, a web server, and a bunch of frameworks. When I tell people that they can learn web programming with Run BASIC their automatic response (unless they're complete newbies) is, why not learn one of the popular web programming systems? Why learn Run BASIC?

I'll tell you why. Because you don't need a thick book with Run BASIC. Because you don't need to install a whole bunch of stuff. Because you can create a program and put it on the Internet in the blink of an eye with Run BASIC. Because you can think about programming instead of about trying to satisfy all the requirements of Apache+Perl, or PHP, or Ruby, or whatever.

http://www.runbasic.com/

Not web programming

Okay, the title of this post is slightly wrong because Run BASIC is a web programming system. But, it isn't wrong because Run BASIC emphasizes not the webish-ness of programming, but the act of programming in BASIC.

BASIC always was the people's language. It was a success as the first popular way to create programs for home computers. It was so easy that even children learned programming with it. I was one of them.

So, this is the age of the Internet. Run BASIC is the BASIC of the age of the Internet.

Come and join our online forum and see what people are saying: http://runbasic.proboards82.com

Run BASIC's Programming Model

Most web app systems model applications as a collection of pages. Information must be persisted between pages in some sort of datastore. Sometimes this is in memory but oftentimes it is done in a database or by passing files. Run BASIC does not force you to partition your applications in this way. Instead you can write your entire application as a single continuous program just like you would write a desktop app. You create a new page in your application by clearing the page and placing new things onto it in a dynamic way.

Traditionalist procedural programmers can create entire applications using subroutines and functions, similar to how it is done in popular languages like QBasic. This democratizes web programming because many casual programmers are comfortable with this way of coding software.

More object-oriented thinkers can componentize their systems into objects and call methods on them. The objects can be purely data, or they can render into a display buffer and be injected into a web page. This makes it easy to have different parts of a web page managed in a modular way.

http://www.runbasic.com

Run BASIC v1.0 is released!

Well I've been awfully quiet here for a couple of months, but for good reason. Everything we've been doing has been leading up to the release of our Run BASIC Personal Server, and now it's finally available. To pick up a copy head on over to http://www.runbasic.com !!

We've also launched a Run BASIC forum so come on over to http://runbasic.proboards82.com and see what's going on.

Check out this stream