No Git Version Control for Single File JSapp

Every programmer soon realizes the value of maintaining versions of code as it develops. For example, after you try out a not so good idea, you can always revert to the working code. So version control tools developed like subversion, git and other became required skills. I tend not to use them.

With a single file app, these tools become unnecessary. Let me explain my practice. I'll create a folder with the name of the project like "TableSauce". In that folder I'll create the file index.html and start coding. When I want to save a version, I go to finder or windows explore and duplicate or copy the file. I then rename the copy to index20110413.html for April 13, 2011. If I save more than one version during the day, then I'll append an letter like "a". Actually, I usually do this first thing in the morning and give it yesterday's date. After a few days I'll have a folder full of versions in date order.

My previous habit was to use the Save As feature of my text editor. However, I found I got myself into trouble editing what was suppose to be an achieved version like index20110413.html when I didn't reload the index.html file.

People may scream that I'm missing this or that feature of Git. They may be right. What I think one really gives up not using Git is Github and I'll come back to that in a future post.

In addition, most repositories also give you a backup or disaster recovery feature because the repositories are on an external machine. More about that too in a future post.

Aging with JavaScript

One of my ToDo items for JSConf was to finish reading Eloquent JavaScript. I'm not finished, but I have a few observations.

In my way of thinking, eloquent is the highest praise you can give a design. So I had high expectations for Eloquent JavaScript. So far it has not disappointed me and may even be my favorite JS book. How can you go wrong when it includes a sad story about the mountain forest of Western Netherlands?

Anyway, my reading has stopped on the chapter about functional programming and about Higher-Order Functions. The forEach function seemed completely new. Why did I not know this? I went to bed last night thinking it was just a "hangover" from my years of Fortran and BASIC programming that functions could not contain functions. 

So after dinner I went to David Flanagan JavaScript: Definitive Guide 4th Edition and read up on functions. Now David's writing about EMACScript v.3 versus v.X can make your head spin. Regardless, it made me realize that when I first learned JavaScript 15 years ago, functions were not as robust. That explained why all of this seemed so new.

Before I seem really dated, let me defend myself a little bit. I've passed functions to other functions for callbacks and other purposes for years. But how the arguments of the forEach is bound to the inner function, that was new. It was also new to have functions within functions. But that is why I keep reading JS books after co-authoring one of the first. JavaScript keeps surprising me.

This example is only part of my eventual answer on Quora about losing interest in programming as we age. When you have years of experience with a language, you have to discard some of what you know as new versions are introduced. Some call it relearning. It is a skill you have to learn as we age with a language.

This is also the beauty of aging with a language. It is like seeing your kids grow up. They both are a site to behold and doing things you never imagined.

 

All Code in a Single File

For most javascript applications I put all my code in a single file. All my HTML, my CSS and my JavaScript are in the same file. No linking to an external css file. No script tag with a src bringing in code from another file. The code I write is all in the same file.

The only external file is a JavaScript library like jQuery. So I'll pull those files from an external source like Google. This is a topic for another post. The point here is that I recommend you put your CSS and your JavaScript in the same page as your HTML.

This may run contrary to how you learned to create a website.  Remember that on a web site you may have hundreds or even thousands of pages (files) sharing the same CSS and JavaScript. It makes sense not to repeat it and only load it once. The browser can cache these external files and provide better site performance.

It is just the opposite for JS apps where each load is a significant performance hit. You'll have better performance by reducing the number of files loaded. JavaScript performance is another topic worth a longer post.

The primary advantage is during development on your laptop. A web browser can load a single file. With multiple files you'd need to have a web server. While running a web server on a modern laptop is not a big deal, it does become a major productivity gain to be able to load a single file into a browser on a smartphone or tablet.

So I start a jsapp with simple template like this one for a jquerymobile app.

<!DOCTYPE html> 
<html><head>
    <title></title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
    <script src="http://code.jquery.com/jquery-1.5.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
    <script></script>
    <style>
    </style>
</head>
<body>
</body></html>

Single File JavaScript Apps

How to write simple, elegant JavaScript apps is the topic of this blog. JavaScript will be used on both the browser (client side) and on the server with mobile being the focus.

Posts will relate to the code, discoveries, workarounds and dumb questions in writing a simple app. I don't intent to write about the app that I'm writing in this blog, but rather about how I'm coding. So I'll talk about tools, libraries, algorithms, usability, interfaces, hardware and some other computer science topics. In other words, this is a hack blog.

You'll also see a posts on marketing and start ups. I'm mostly interested in one-person startups. While I have some experience, I'll mainly link to others.

Design and the social impact of technology may sneak into a few posts, but I'll reserve those topic most for MultiPurposeRoom.com design blog.

My app is a side project or a notmydayjob project. It started over two years ago as several projects which are now all combined into one. It started with the iui library and then switched to the jqtouch library. I stopped until jquerymobile was announced. The app is designed to use CouchDB as a server, so more JavaScript. There are some features that nodejs seems like a perfect match, so I'll write up my observations. I'm also interested in several other JS libraries like Zeptos, Sammy, Raphael, Sencha, Sproutcore and others (too much, I know). Also using PhoneGap.

Also, I expect to write about blogging for 8 years. I'm not even sure what platform I should use. So I'll write about that process as well.

Finally, I love screencasts, so I'll feature a few.

I'll write an about raydaly post later.

Hope you enjoy this blog.