some ‘back of the envelope’ notes on programming
This is easy if you can count in binary. If counting in Base 2 is not a drummed in skill then look here first and maybe here…
Using an integer field (column) in a table, you can store independent boolean flags (variables), all in this one field.
First you can define some bit masks (note the pythony ## inline-comments),
each one only sets one bit ON:
FEATURE_A_BIT = 1 ## or in base(2) this would look like 00000001 FEATURE_B_BIT = 2 ## or in base(2) this would look like 00000010 FEATURE_C_BIT = 4 ## or in base(2) this would look like 00000100 FEATURE_D_BIT = 8 ## or in base(2) this would look like 00001000
As an example Imagine that our field (let’s call it “features”) is initially set to Zero. This initial state represents all fearture (A – D) are OFF.
The bit wise OR “|” operator Adds in the feature_B bit and leaves all other bits just the same.
So for example: To set the feature_B bit ON: mysql> UPDATE your_table SET features = (features | FEATURE_B_BIT) where id = someid;
0000000
| 0000010
----------
0000010 # great the Feature B bit is set ON
The bit wise AND “&” and the NOT “~” operator Subtracts the feature_B bit, again leaving all other bits just the same.
For example: To set the feature_B bit OFF: mysql> UPDATE your_table SET features = (features &~ FEATURE_B_BIT) where id = someid;
0000010 ## the inital value of features
& 1111101 ## this is just NOT (0000010) from ~ FEATURE_B_BIT
---------
0000000 ## and this is what you wanted: the Feature B bit is reset OFF.
And to retreive a single bit value, with a SELECT statement: mysql> SELECT (features & FEATURE_B_BIT) as feature_B FROM your_table where id = someid;
You can make it more complicated by combining bits and logic, but these are the basics of using “Bit Wise Flags in MySQL.”
In practice you would use this to store data like “opt-in”, “is-valid-format”, or “ok-by-mom” etc… So, really you would replace FEATURE_A_BIT with OPT_IN and FEATURE_B_BIT would be called OK_BY_MOM, but make sure that your bit masks only set one bit, or it gets confusing fast. If you do need to set (or reset) two or more feature bits at once you can OR them together , like this (OPT_IN | OK_BY_MOM), when you feed that into the bit operations above, you will be setting or resetting all in one go.
By the time anyone develops an application using nodejs and all the related libs, the community may have done some of it for you, and better.
My experience was in a project combining “nodejs”, “express”, and “socket.io” together using the “pubsub” pattern to give a consistent coding API across the client and server code. No regrets in building it this way, but the coding community is developing new libs so fast, that they may have done it for you before you can finish you code. It is in the Air, everyone who is using these new Web technologies is moving in the same direction, so it’s really important to keep one ear to the rail (the other ear listening for trains :) while coding…
It only took one week of heads-down development in my own project, for a (possibly) better package to emerge that will do 90% of my coding for me.
So, I am in a rewrite of my app to include this better lib (NowJS.com).
But now, I am not really sure if I am hoping for yet another (even better) package to emerge before get this rewrite out…
Start making websites that use asynchronous sockets.
Stop using request based web programming.
Start listening on channels.
Stop working around the issues in AJAX.
Start emitting messages.
Stop making websites with PHP, C#, Python, Ruby, PERL.
Start coding websites with node.js in Javascript (or Coffeescript).
Stop using a huge server stack.
Start using socket.io (or another similar Web Sockets utility).
Stop creating OO and procedural code.
Start thinking in terms of Events.
Stop the waterfall that is relational data design.
Start working with schema-less data stores.
Enough, It is time to start coding Web 3.0, and to start this, use nodejs, socketio, NoSql, and see why these technologies warrant a version change.
PubSub is a pattern that makes coding an application, cleaner and more maintainable. Traditional procedural code often grows difficult to maintain. A quick trip into the “Event-Driven” land of PubSub will let us see how this simple pattern helps an application to be coded in discrete and meaningful segments.
PubSub is our ticket out of the Procedural Programming world, and even if you didn’t really want to leave this world, please consider just this small excursion to a land where: the code is not excessively indented; and the functions are concise; and you can still use all the usual code that you are familiar with.
The trip to PubSub is not long, because the only border crossing you need to make is to Code by Event. We will let PubSub events take care of the structure of the application, and in no time you will be wiring up handlers to event as well as triggering events, all together making your application sing.
To speak the PubSub language, here is a quick phrase book of translations:
| publish (make an event) | subscribe (handle an event) | |
|---|---|---|
| pub (lish an event on a channel) | sub (scribe to a channel, assigning a function that will be called) | |
| go (call all subscribers to this event) | on (this event do this action) | |
| emit (an event) | when (this event happens, call this function) | |
| trigger (an event) | listen (for this event, and act on it) | |
| throw (the ball) | catch (the ball, and tag second base) |
If you have been coding in and around any event-based systems (such as the Browser DOM) some of this lingo is sure to sound familiar, if not don’t worry, the natives are friendly and most of them speak your language. It is the custom, in the PubSub culture to do all of your application architecture in Publish and Subscribe calls. To experience the culture of this land, no better way than to start mingling with the code:

A diagram of the arrangement of events being published and the subscriptions to those events, in this example code.
I first saw a leaning toward “the use of diagrams as computer instruction” when I learned Pascal. Before Java, some college programs in Computer Science started you out by teaching Pascal. It was half-way between BASIC and C, and easy on the Eye. While leaning Pascal it was explained to me that the assignment operator ‘:=’ was a (sort of) left facing arrow (although somewhat mangled). There are some roots in other languages that used ‘<=’ for assignment, but it collided with the “less than or equal” comparison operator, so it was morphed into ‘:=’ . This did a good job of illustrating the action of the assignment operator, (i.e. a value is copied from one variable to the other in the direction of the arrow). Given only a keyboard, the best way to draw a left facing arrow is to use the “<” sign. It was still the day of text-only based computer interaction (the cheaper computers anyway), so there were relatively few graphics on screen, but there was a desire to make graphic elements using the lowly “character.” not quite ASCII art, but a hint of a visual element.
Programming still uses ASCII based graphic to show the meaning of the operator, for instance the PHP object reference notation is a right facing arrow made-up of the characters ‘->’, Coffee script has thin rocket “->” and thick rocket “=>.”, and C has always had the bit wise shift operators ‘>>’ and ‘<<’ to slide bits around. Matching brackets are in relative abundance on the keyboard and are graphical elements in character guise. The left and right parentheses ‘( , )’ are really just a way to draw a circle around something and the square brackets ‘[ , ]‘, a box.
This leads me to the use of diagrams as computer instruction, unlimited graphic elements used (along with text) as the source code for application, To Be Continued…
Here is a bit about database searching, especially those simple examples that are provided with web frameworks.
Every web developer has seen the example code that shows you how easy it is to query a data table or two and format the results as a HTTP response. This is great but in reality the user is often going to search on some term that yields no results. It is better to return something and this means loosing the constraints of the search criteria. But all the frameworks out there don’t make this is easy, so making a useful search interface is left as an exercise for the developer.
The basic search might look like this: mydomain.com/search?category_id=12
It yields a query set that might or might not have records in it, and then you show the results, if any. Cut and dry.
When you add more variables into the mix and you may also want to display the most relevant (best) results first, this is where many web frameworks do not help you.
Looking at just two variables,
say: mydomain.com/search?category_id=12amp;text_input=some+text+here
The intent of the UI in sending you two arguments is to get the best match on these parameters, but if there is no exact match, the user should not have to make a second query to see the next best results the data has to offer.
The developer must make several queries starting with the most exact and sequentially try less restrictive queries until non-empty results set is returned. While this seems like a best practice in usability, none of the web frameworks make this easy or have any examples of how to approach it.
This list of on-line flow charting applications compares and contrasts what is out there to see if any can be used as an editor for the GraphSpace effort to make a graph coded programming language.
The primary criteria are:
A second set of requirements are for an integrated editing environment that would allow tracing and debugging. A real API would be needed for this, but for now let’s see what is out there that meets the simpler criteria (above) [1, 2, 3, 4, 5, 6].
Mxgraph — http://www.mxgraph.com/ … http://www.mxgraph.com/demo/mxgraph/editors/grapheditor.html seems full featured enough. Editing the routing of arcs is more less intuitive and license cost is a question that needs to be looked into… ["yes", "yes", "yes", "yes", "yes", "no"]
Bubbl.us http://www.bubbl.us is a hopeful possibility. ["yes", "yes", "yes", "yea-sort-of", "no", "no" ]
Flowchart.com http://www.flowchart.com is a possibility as well. Their licensing is not known (web site needed updating in this regard, as of this post) ["yes", "yes", "yes", "yes", "yes", "no" ]
Gliffy http://www.gliffy.com has been around for a while (mature). Details of their API are not readily available? ["yes", "yes", "yes", "yes", "yes", "no" ]
LucidChart: http://www.lucidchart.com is a really clean and only lacks data export abilities.
More? Please suggest any that might fit.
The terms ‘graph’, ‘chart’ and ‘diagram’ are all used here to refer to a collection of nodes and edges that can be graphically arranged.
These criteria seem strict, and loosening them might open up the field, but to be clear, here are some more detailed reasoning behind these criteria:
“web based” because too much time is spent on managing updates to installed software. Web based applications are capable of this as long as the client footprint (code loaded into the browser) is small and efficient.
“graph editor” by this we need a true graph editor, and not a paint program that can make only flowchart images.
“plus text” The GraphSpace effort is not a pure graphical language. It embraces the integration of text into diagrams (see discussion).
“edges are directional” Edges must have an origin and destination for the language to work.
“multi-graph support” The graph structure must support many distinct edges between nodes.
“data export” A pretty image of the chart is OK for your power-point presentation, but what is really fundamental to using a graph as programming language is the structure of the nodes and edges with types and data assocaited with each. So with this in mind, a flow chart exported as a bunch of pixels does us no good, what we need is data on nodes and edges.
All Web Apps have:
Cloud based Web Apps different with respect to:
What you may not find are:
The idea of compiling this list is make a stab at finding the similarities of what is necessary in this arena. Then, with some common ground, to find a standard that could be implemented (ported) to any provider.
Like Microsofts Common Runtime, it would be a central open standard that any language could compile to, or be interprerated in, and like Java’s Byte Code, many cloud servies would host.
Interesting opportunities in web application hosting choices are developing. The classic buy or rent a server or two… are being challenged by the flexibility that cloud computing offers. There are some costs, although not much in the form of money. Here is the lineup that I have looked at:
Each of these has some real advantages over classic hosting and some disadvantages to. All have an eye on scalability, by taking advantage of a grid of computers, yielding both economy and scalability. They all lessen or eliminate your need to manage servers. They all change the development paradigm to some degree, especially in the area of database storage. All are innovative and being copied by Microsoft, but none have a hands down advantage in all regards.
Now to chart out the highlights of these services.
| Service | Open Source | Server lock in | Feature % | You code in | Notes |
|---|---|---|---|---|---|
| 10Gen | Yes | No | 96% | JavaScript, Python, Ruby | Three different languages to choose from (so far) |
| AppJet | ??? | No (but the license is unknown) | 78% | JavaScript | Code from a browser (that was fast to try it out) and fun. Srangely there is no real file system. Your code, HTML CSS etc. is all in one document. I was wishing for a template system, but it has a great lean simple feel. |
| AppEngine | No | Yes | 60% | Python | In beta, and has data-store size limitations that may be a deal breaker, and it is strange that no one quite knows if and when you can buy more data-storage. |
| Aptana | ?? | ?? | ?? | PHP, Jaxer, and Ruby on Rails (soon) | … have not researched this one yet |
| Mosso | No | No | 100% | Typical software stack (Win or Linux) | $100 per month to start. Strange that they let you use a variety of tools and at the same time say it will scale as it would on a grid or other cloud techniques. |
| Caspio | No | Yes | ?? | Wizard based database and application configuration | have not tried this one either (there is a free trial). |
| S3+EC2 | No | Yes and No | 100% | Anything that you can load on a server / connect to S3 | You have to (or you get to) manually scale up or down the number of servers that are working for you. You have to know about a spike beforehand. |
| GoGrid | No | Yes and No | 100% | Anything that you can load on a server | You manually scale up or down the number of servers that are working for you. Although you can use an API to spin up or down servers from your code, but I cant see this working better than a SaaS cloud that is managed for you. |
Yes, the USPS does do some last 5 mile delivery for USP, and that is because the postal service can do it cheaper (they are going to your mailbox anyway). Some day there will be a dynamic cloud system that will deliver your web application through the lowest bidder.
Not yet though, because we are still in a time of ‘app-lock-in.’ Google, Microsoft, Amazon and many hosting companies are all competing for cloud domination. But if server cycles can be better utilized in a bigger cloud, than why not have them compete to offer you the best deal. This could work to the advantage of your application. Here is how it might go:
You state the amount of money that you are willing to spend on your hosting, say $0.03 per hour (or less perhaps). Also state any preferences you have for speed (a minimum response time) and other quality of service options. Your app is ready to go (in some universal format) and let the bidding begin.
If a SaaS provider can offer better and cheaper application hosting service, then move what you can out into the cloud.
A cloud is better if it:
A cloud is cheaper if it:
The Application lock-in issue is big right now, and although Amazon (S3+EC2) and others (enomaly…) allow you to run any application, they also force you to manage exactly what level of service you want, and don’t (at this time) handle spikes for you. Google AppEngine is set up to handle the spikes (within quotas) but the code you write is somewhat specialized and can not easily be moved over to any other cloud service providers. When standards are established … everyone will have their own! ;P
To do: Add ‘cloud’ to your over used tech term list.
Blog at WordPress.com. Theme: Nishita by Brajeshwar.