Learning Web Application Development
Semmy Purewal
Dedication
To my parents.
Thanks for all of your support and encouragement over the years!
Preface
In early 2008, after about six years of grad school and teaching part-time, I found myself hoping to land a job as a full-time computer science professor. It didnt take me long to realize that professor jobs are really hard to come by, and obtaining a good one has almost as much to do with luck as it has to do with anything else. So I did what any self-respecting academic does when faced with a scary academic job market: I decided to make myself employable by learning how to develop web applications.
This may sound a little strange. After all, I had been studying computer science for about nine years at that point, and had been teaching students how to develop software for about six years. Shouldnt I have already known how to build web applications? It turns out that theres a pretty large gap between practical, everyday software engineering and programming as taught by computer science departments at colleges and universities. In fact, my knowledge of web development was limited to HTML and a little CSS that I had taught myself at the time.
Fortunately, I had several friends who were actively working in the web development world, and most of them seemed to be talking about a (relatively) new framework called Ruby on Rails. It seemed like a good place to focus my efforts. So I purchased several books on the topic and started reading online tutorials to get up to speed.
And after a couple months of really trying to get it, I nearly gave up.
Why? Because most of the books and tutorials started out with the assumption that I had already been developing web apps for years! And even though I had a pretty solid background in computer programming, I found all of the material extremely terse and difficult to follow. For example, it turns out you can take an awful lot of computer science classes without ever coming across the Model-View-Controller design pattern, and some of the books assumed you understood that in the first chapter!
Nevertheless, I managed to learn enough about web app development to get a few consulting gigs to support me until I managed to land a professor job. And through that, I realized I enjoyed the practical aspects of the field so much that I continued consulting outside of teaching.
After a few years of doing both, I was offered the opportunity to teach my first class in Web Application Development at the University of North Carolina at Asheville. My initial inclination was to start with Ruby on Rails, but when I started reading the latest books and tutorials, I realized that they hadnt improved much over the years. This isnt to say that they arent good resources for people who already have a background in the basics, its just that they didnt seem suitable for the students I was teaching.
Sadly, but not surprisingly, the academic books on web development are far worse! Many of them contain outdated concepts and idioms, and dont cover the topics in a way that make platforms like Ruby on Rails more accessible. I even reviewed one book that was updated in 2011 and still used table-based layouts and the tag!
I didnt have much of a choice but to develop my course from scratch, creating all the material myself. I had done a little work in some consulting gigs with Node.js (server-side JavaScript) at the time, so I thought it would be interesting to try to teach a course that covered the same language on the client and server. Furthermore, I made it my goal to give the students enough background to launch into the self-study of Ruby on Rails if they decided to continue.
This book consists largely of the material that I created while I was teaching this course at UNCA. It shows how to build a basic database-backed web application from scratch using JavaScript. This includes a basic web-development workflow (using a text editor and version control), the basics of client-side technologies (HTML, CSS, jQuery, JavaScript), the basics of server-side technologies (Node.js, HTTP, Databases), the basics of cloud deployment (Cloud Foundry), and some essential good code practices (functions, MVC, DRY). Along the way well get to explore some of the fundamentals of the JavaScript language, how to program using arrays and objects, and the mental models that come along with this type of software development.
Technology Choices
For version control, I picked Git, becausewellits Git and its awesome. Plus, it gave my students the opportunity to learn to use GitHub, which is becoming immensely popular. Although I dont cover GitHub in this book, its pretty easy to pick up once you get the hang of Git.
I decided to use jQuery on the client because its still relatively popular and I enjoy working with it. I didnt use any other frameworks on the client, although I do mention Twitter Bootstrap and Zurb Foundation in . I chose to stay away from modern client-side frameworks like Backbone or Ember, because I think they are confusing for people who are just starting out. Like Rails, however, you should be able to easily dive into them after reading this book.
On the server-side, I chose Express because its (relatively) lightweight and unopinionated. I decided against covering client- and server-side templating, because I think its essential to learn to do things by hand first.
I decided against relational databases because it seemed like I couldnt give a meaningful overview of the topic in the time I allotted to that aspect of the course. Instead, I chose MongoDB because it is widely used in the Node.js community and uses JavaScript as a query language. I also just happen to really like Redis so I provided coverage of that as well.
I selected Cloud Foundry as the deployment platform because it was the only one of the three that I considered (including Heroku and Nodejitsu) that offered a free trial and didnt require a credit card to set up external services. That said, the differences between the platforms arent huge, and going from one to another shouldnt be too hard.
Is This Book for You?
This book is not designed to make you a ninja or a rock star or even a particularly good computer programmer. It wont prepare you for immediate employment, nor can I promise that it will show you the right way to do things.
On the other hand, it will give you a solid foundation in the essential topics that youll need in order to understand how the pieces of a modern web app fit together, and it will provide a launching point to further study on the topic. If you work your way through this book, youll know everything that I wish I had known when I was first starting out with Rails.
Youll get the most out of this book if you have a little experience programming and no previous experience with web development. At minimum, you probably should have seen basic programming constructs like if-else
statements, loops, variables, and data types. That said, I wont assume that you have any experience with object-oriented programming, nor any particular programming language. You can obtain the necessary background by following tutorials on Khan Academy or Code Academy, or by taking a programming course at your local community college.
In addition to being used for self-study, I hope that this book can serve as a textbook for community classes in web application development, or perhaps a one-semester (14-week) college-level course.
Learning with This Book
Developing web applications is definitely a skill that youll need to learn by doing. With that in mind, Ive written this book to be read actively. What this means is that youll get the most out of it if youre sitting at a computer while reading it, and if you actually type in all the examples.