Today I transferred a lot of data—not MB, but good old-fashioned Anglo-Saxon pounds. I moved a 1,000 pounds books while changing my office from a code monkey room, filled with computer books, to a study, filled with real literature. My first love happens to be 19th century French literature (Stendhal, Balzac, Flaubert) and I have many, many books that I want to get back to after a 15-year hiatus.
I’m going to hang on to many of my PHP and Ruby books because I’ll need them for my work, but the others books, as wonderful as they are, will have to find their own way in the world; some will find a home in the attic bookcase simply because I can’t part with them, and the rest—I’ll have to find them a new home.
Below are some photos of the chaos. On the left are the computer of the books I moved out, and on the right are the literary books I moved in. The pug (Taco) is part of the swap, as he, like me, has a degree in Comparative Literature.
Book Swap as Metamorphosis
Computer books are out.
Literature is in.
As I was going through all the books, I counted about 100 O’Reilly books. Nice job, O’Reilly guys. You really helped me learn about Unix and Linux, Perl, Ruby and PHP, and everything that goes along with them. It’s been great doing business with you.
Keep hacking…and here’s an idea for you hackers, if any of you got past the word “literature” in the first paragraph: every now and then try reading something besides a programming/how-to-get-rich book. It doesn’t have to be “litearture”; just read something outside of your chosen occupation. It’ll broaden your horizons, and that’s a good, sustaining thing.
Over the last few days I’ve installed a smorgasboard of *nix distros, trying to find one that will work with my hardware. I was looking for a recent distribution with a decent desktop, either KDE or Gnome. My hardware is a pedestrian HP desktop that is so anonymous and faceless that I don’t even know it’s name. It has an NVidia graphics card, an Intel NIC, and an Intel Core 2 Duo processor. You’d think that this kind of generic iron wouldn’t be a problem to find an OS for.
The Candidates
The lineup consisted of Fedora, Ubunto, openSUSE, Mandriva, CentOS, and the non-Linux FreeBSD.
Mandriva
This is a no suspense post, so I’ll just say that the winner was Mandriva. Everything about it worked perfectly with my system. It recognized and configured my hardware, had up to date versions of the software I need (PHP, Ruby, Python, Rails, etc). It had one flaw: I didn’t like the way it looked. You have to understand that I’m a sensitive artistic type and I found the color schemes garish and over done.
Fedora
So, I installed Fedora. All went about as well as Mandriva with the installation, but when I came to compiling Ruby 1.9, I started getting missing dependency errors by the dozens. Being a man of action, I bailed on Fedora.
Ubuntu
Next I installed Ubuntu, and it went on the my hardware like a dream from the Live CD. However, when I rebooted, I had no network. I had experienced this problem before with Ubuntu, and I was hoping that I wouldn’t see it with 10.4. I scrounged around the Web and found some bug reports about this problem and threw in the towel. Being an artist, I’m also decisive.
CentOS
So, I installed CentOS, which I’ve heard so much raving about. It’s a conservative strain of Linux (think RHEL), with stable software that will not be updated frequently. I liked the idea that centOS 5.5 would be around for 5 years and I wouldn’t be hassled with daily updates. The nice thing was that KDE 3.5 was a desktop option. I liked 3.5. But the story turned sour when I checked ruby and found a terribly outdated 1.8.5, and I need 1.9. I downloaded the Ruby 1.9 source and began the compile. Whoa. Lotsa errors. Lotsa out of date C libraries. I would have to upgrade the system libraries to compile the software I needed. In effect, I would have to turn centOS into Fedora. Not gonna work. Being an artist, I’m also very economical with how I fritter away my spare time.
openSUSE
Next openSUSE. The Live CD loaded and ran nicely. The network was cool, and all the libraries were current. It all looked good until the installation process failed. Over the years I have experienced many an aborted installation with openSUSE, so I know this was no fluke. I was outta there in a flash.
FreeBSD
After all of the Linux installation failures (except for Mandriva), I installed FreeBSD. As you may know, FreeBSD is the Unix behind Mac OS X, and I’m quite familiar with that. I had high hopes. The installation went well, but the X-windows installation was choking on my NVidia card. I could have run the machine as a server, but I wanted a desktop, dammit. That last thing I want to do with my spare time is get a messed up X-windows system working. I jumped ship.
Back to Mandriva
I swallowed my pride and reinstalled Mandriva, then spent the day fixing the desktop well enough that I my eyes don’t hurt when I look at it. Everything works well enough—I’ve got networking running. I’ve got Ruby 1.9, the latest version of PHP, Squeak, and Lispbox running. I’m now officially good to go. No more fiddling for me.
It’s been fun taking a tour of Linux and FreeBSD land. Try it the next time you have a few days to spare. All of the distros are awesome in their way, but you may find, as I have, that there is one particular version that works best for you. You just have to kiss a lot of frogs to find your princess, or prince, as the case may be.
When I have to edit files on remote servers I use Vim paired with scp. The SCP protocol, along with SSH, are members of the OpenSSH family of encrypted communication protocols; on Unix-y system, scp is the SCP client, and ssh is the SSH client. Both ssh and scp are normally installed by default on OS X and Linux.
OPENSSH ON WINDOWS On Windows we can install the PuTTY family of SSH clients to obtain SSH and SCP for free. I will not be discussing PuTTY in this post.
A second option for Windows users is to install Cygwin. Cygwin is a Linux-like environment for Windows that offers great Linux functionality and the Bash shell. If you have Cygwin installed, you can use the code below without modification.
EXAMPLE If I have to edit my application_controller.php script on hackingthevalley.com, I can open my terminal (Terminal.app on OS X and xterm on Linux) and enter a command that will allow me to edit the file across the network through an encrypted connection:
vi scp://username@domain.com//users/username/phplib/controllers/application_controller.php
That’s a mouthful of a command and not a bit easier than starting up Flow (on the Mac) or FileZilla (on Windows) to do the same job. However, a little Shell scripting can transform that hairy, drawn out command into a simple function that does all of the heavy lifting.
In the code below I first create a function (viremote()) in a file named .functions. Once I have a library for my shell functions, I can load that file automatically every time I start my shell. I’ll describe how to do that later.
SHELL FUNCTIONS
Here’s an example of a simple shell function. Replace the pertinent details (username and domain name) with your own.
# File : .functions (This is an invisible file)
# Creator : Douglas Putnam
# Path : $HOME/.functions
# Desc : Bash shell functions. Edit files remotely with Vim and SSH.
# More : The Linux Documentation Project http://tldp.org/LDP/abs/html/
# $Id: $ (version control tag)
# Usage: viremote remote_file_name
viremote () {
if [ $# = 0 ] # $# is the number of agruments and '=' means "equal to"
then
# Open File Browser in HOME directory on remote server
# protocol user domain path
vi scp://username@domain.com//home/username/
else
# $1 holds the name of the file on the remote server
vi 'scp://username@domain.com//home/username/phplib/'$1
fi
}
We use it like this:
. ~/.functions # load the functions into the shell
# edit /home/username/phplib/app/controllers/application_controller.php
# on domain.com
viremote app/controllers/application_controller.php
MAKING IT PERMANENT
Sourcing the file (. ~/.functions) makes the functions available for the current session. What we want to have these functions available every time we log in. To make this all work automatically you will have to modify your Bash startup file (.bash_profile) to include the .functions file. Here’s how:
Create the .functions file in your HOME directory. This file will hold your functions.
Add this line to your .bash_profile in your HOME directory:
I keep coming back to PHP for my projects. I’m not talking about anything Industrial Strength like the Wikipedia or Facebook. I’m talking about the web sites I use to teach my courses. For the last 4 years I’ve had my PHP course content on a custom Rails site that I built when I was crazy about Ruby. It has languished recently, as the chore of reinventing every wheel (CMS, user authentication, etc) has taken its toll.
So this week I installed Moodle, a fiendishly complex bit of PHP that contains everything I need to run all of my courses online. In the domain of online course management, it’s the top dog. And because it’s written in PHP, I feel right at home.
Oops. My bad. Sorry about that, Rails.
Don’t bother to tell me that comparing Rails and PHP is a lousy comparison. PHP and Rails are both DSLs (Domain Specific Languages) written in general purpose languages: PHP is to C as Rails is to Ruby (not mention that Ruby is written in C, too). If you think about it, PHP and Rails really kissing cousins.
When duty calls and there’s work to be done, PHP is my preferred vehicle to get from point A to point B. Here’s how I spend my online/programming time these days.
5% Lastly, Rails for my course web sites: programmer.
I’ll be the first to tell you that PHP has many, many frustrating design oddities, but once you “get it”, you’ll have more time to kick back, drink some brews, and watch a little b-ball.
I want to hip all of you cool cats to one of my heroes: Peter Cooper. I’ve never met Peter in person, but I have met him online through his mighty Ruby blogs Rubyinside.com and Railsinside.com, his best of class book Beginning Ruby (which I use for my CCSF and CSM Ruby courses), and through his entertaining Tweets as @peterc.
One of the things I admire about Peter is that he fearlessly shares inside information about the business side of being a successful blogger and author. He reveals about how much money he makes for ads on RubyInside.com, and he writes about his his pain and gain as an Apress author. When you read this amazing post, be sure to check out the A-listers who added in their comments on the publishing business, including Geoffrey Grosenbach of Peepcode.com and Tim O’Reilly himself. This is priceless stuff.
Where many Rails developers have uncritically anointed DHH and 37Signals as prescient Royalty/Illuminati/Life Style Gurus, Peter Cooper matter-of-factly reveals that he’s lost his enthusiasm for Rails. He’s even donating his Railsinside.com blog (6,000+ subscribers) to the Rails community because he can’t muster the enthusiasm to keep it going. I find it refreshing to hear a clear voice say that the Emperor is no longer absolutely fascinating.
Since the introduction of the iPad a few weeks ago, Peter has learned Objective-C, gotten a strangle hold on the iPhone SDK, and hacked out an amusing arcade game in a matter of weeks. If you’ve been following his tweets as @peterc, you’ve been able to watch his game progress from concept to working code. This fun stuff.
This semester I’m going to have my Ruby and PHP classes build a form driven, AJAX-y web application as the final project. This is a bread-and-butter assignment that performs the basic task of storing form data in a database then displaying it. We’ll deal with the ever present Persistence Problem by using a SQLite3 database to store user input, and the AJAX/Javascript layer will be all JQuery.
A classroom project of this size can be completed in four to six weeks, depending on the programming and web skills a student brings to the class. More is always better.
The PHP course will be starting from scratch (no cakePHP, no Drupal, no Joomla), while my Ruby course will be using Rails. I’ll be doing the project in Seaside. When all is said and done, we will count the lines of PHP, Ruby, and Smalltalk to see who get bragging rights for writing the fewest lines of code.
If you want to work along wtih us, your project should have these features:
An HTML form.
JQuery form manipulation.
AJAX via JQuery.
Validated form input.
Form data stored in a SQLite database.
A Recaptcha form.
User data safely displayed (potentially harmful characters sanitized).
There are dozens of features we could hang on this skeleton: pagination, search, social features (Twitter, Facebook, Buzz, etc), as well as polls, voting, thumbs-up/down, email, XML export, RSS feeds, Section 508 compliance, and more. I’ll be satisfied if most of my students can achieve basic functionality before semester burnout sets in.
And about that Seaside course—there isn’t one yet. But it is on my TODO list for future courses at CCSF. For the time being, as part of my own Smalltalk education, I’ll take this opportunity to complete the class project using Seaside. Since Smalltalk and Seaside are new to me, I’ll be starting on the same page as my PHP and Ruby students. This will be fun. I’ll be doing this project with Cincom Visualworks Non-Commercial which is free for non-commercial use on Windows, Linux, and Mac OS X.
OK. I’d better get to work on the Ruby part of this project before the Rails team unleashes another new product release just to confuse me.
A reserved word in a programming language is a word that is off limits to the programmer. For example, in PHP print is a reserved word. This means that you, as the programmer, cannot create a function named print because PHP owns that word.
Most languages have reserved words, some a few, and some very, very many. Usually the fewer reserved words a language has, the more flexible it is. For example, in the list below, you will see that Lisp has no reserved words. We all know that Lisp is very flexible and powerful.
As you look at the table below, do not think unkind thoughts about PHP—it’s different from the other languages. It is not designed to be a general purpose programming language, though it can certainly do almost anything you want it to do. It is intended for web programming, which explains the existence of so many of the predefined functions and constants. Those are exactly the kinds of items that other languages must implement individually if they want to be as handy with web development as PHP. This is no small task, kids. Just take a look around try to find a web site implemented in C++.
Reserved Words
Language
Count
Reserved Words
Lisp
0
Lisp has no reserved words. Lisp is written in Lisp. Alan Kay, the creator of Smalltalk, said: “Lisp isn’t a language, it’s a building material.”
Smalltalk
5
self super nil true false
C
32
auto break case chart const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
C++
~62
and and_eq asm auto bitand bitor bool break case catch char class compl const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new not not_eq operator or or_eq private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor xor_eq
Ruby
38
alias and BEGIN begin break case class def defined? do else elsif END end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield
Python
31
and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try
Java
47
abstract do if package synchronized boolean double implements private this break else import protected throw byte extends instanceof public throws case false int return transient catch final interface short true char finally long static try class float native strictfp void const for new super volatile continue goto null switch while default assert
I spend most of my time with PHP and Ruby because I teach classes in these languages at CCSF and CSM. After years of teaching both beginning students and experienced professionals I have an accurate sense of what they need to get off to a good start. I’ve written a ton of content for these courses—screencasts, pdfs, projects, exercises, etc. I plan to use the PHP and Ruby blogs to share some of the material I’ve created for my courses.
Smalltalk is a different matter: I’m a complete newbie and I’m climbing the same learning curve that my PHP and Ruby students climb. As I learn Smalltalk I’ll use the blog to document the process. My plan is to turn my experience (blood, sweat, and tears) into a Smalltalk course. I’ve seen Smalltalk in action, and now I want to do it for myself, then show others how insanely great it is.
I’ll be adding content to the blogs as I as fast as I can proof read it and test the code. If you are on the front end of your PHP career, you will find some pearls of wisdom here. I suggest that you subscribe to these blogs to keep informed of new posts as I update these blogs.
It’s going to take time to fill in these pages, and I expect that I’ll make many errors along the way. I appreciate all feedback; if you see something that needs fixing—code errors, spelling errors, or something that’s just plain wrong—please let me know. Feedback is golden.
Keep hacking…
Respect
My good parts blogs are inspired by Javascript: The Good Parts by Douglas Crockford. His cogent little book has taught me to scrutinize programming languages with a pragmatic eye: embrace what works and find a way to deal with the rest.
Welcome to Ruby The Good Parts. This blog is part of the HackingtheValley.com empire of Good Parts blogs for PHP, Ruby, and Smalltalk. As we create Ruby content, we will post it here.
DHH has brilliantly coalesced the last 15 years of MVC web practices into a Perfect Storm (Rails). He dotted all the i’s and crossed all the t’s, mercifully allowing us to embalm the template-based MVC web design-strategy, put it into a glass coffin, and ship it off to the Smithsonian.
Here’s my Rails eulogy.
The first time I saw Rails—after doing Perl and PHP web development for a few years—my mind was blown: what would take me a week in Perl, or a day in PHP, could be done in 5 minutes with Rails. At the time I jokingly described Rails as crack for web developers. It’s so good, don’t even try it once!
Rails changed the way I do web development, and whenever I drop back down the evolutionary ladder to PHP, it’s like having dental surgery without anesthetics. Painful! All the repetitious tedium—building infrastructure, writing SQL, connecting to the database, the embedded language—was taken care by a the shiny Ruby black box. Rails is a web programmer’s deus ex machina.
“Don’t Repeat Yourself,” said DHH, and he lived up to his word. Rails nailed the door shut on Web 2.0.
Now that Rails has brought Web 2.0 to its end, can it do the same for Web 3.0? The answer is that Rails is no longer on the leading edge. Rails’ replacement has already dropped while you were trying to get a handle on Rails and Ruby. The new guy in town is Seaside.
Seaside arrived several years ago with little fanfare because it runs on Squeak, a relatively new version of Smalltalk. As you may know, Smalltalk is an “old” language that most of us have only heard the old-timers get sentimental about when they talk about the Good Old Days of the Computer Science Frontier.