What is Larry Thinking? #37 => Becoming a Better Programmer, Part 2

February 25, 2011
The Yii Book If you like my writing on the Yii framework, you'll love "The Yii Book"!

In this edition…

About This Newsletter

I managed to come up with a theme for this newsletter: how to become a “real programmer”. I’ve received a couple of questions along these lines, and had begun the conversation in the previous newsletter, so I thought I’d write about the subject even more. In my next newsletter, I think I’m going to write about the other side of the equation: for those of you trying to build up a career, what it may be like when you get there. I don’t know: maybe not. Anyway, I’m likely to include a book giveaway in the next issue, regardless.

As always, questions, comments, and all feedback are much appreciated. And thanks for your interest in what I have to say and do!

Also, for those of you that would like to create an “official” connection with me, you can do so via LinkedIn (I don’t use Twitter, Facebook, or other social media).

What are You Thinking? => “PHP and MySQL for Dynamic Web Sites”

In this newsletter I’m starting a new subsection, titled “What are You Thinking?”. In such sections, I’ll directly ask you, the beloved reader, for your input on a given subject. As always, you’re not obligated to reply, but if you have any thoughts, brief or long, I would really love to hear them. The purpose of such sections is so that I might better cater what I do to what you really want.

In this newsletter, I’m wondering what, if anything, you’d like to see in the next edition of my “PHP and MySQL for Dynamic Web Sites” book. This will be the fourth edition, which I’m going to start writing soon. The immediate plan is to update all the code for the latest version of PHP, remove references to PHP 6 (PHP 6 died since I started writing the last edition of the book), and add a “Review and Pursue” section to the end of each chapter, as I did with the fourth edition of my “PHP for the Web: Visual QuickStart Guide”. The good news is that I should have room for a new chapter, so I’m wondering what you might like to see. Ideas off the top of my head include (in no particular order):

  • Another example chapter
  • An introduction to a framework
  • A quick (very quick) introduction to object-oriented programming
  • A JavaScript primer
  • More information about Web servers (such as .htaccess files)
  • More about databases

So what would be meaningful to you? What have I missed in other editions of this book or my other work? What haven’t I covered enough?

As an added incentive, I’ll give away 10 copies of the book to those in the pool of respondents.

On the Web => Two E-Commerce Articles Published Online

Peachpit Press has published online two of four articles I’ve recently written for them. Both articles are in support of my “Effortless E-Commerce with PHP and MySQL” book, although the ideas explained are applicable to any e-commerce project.

The first article is “Creating a Customer Review System in PHP and MySQL“. The second article is “Building an E-Commerce Site with PHP: Making Product Recommendations“. Two more articles, and a series of blog postings, are forthcoming, probably over the next two weeks.

On the Web => Several Excerpts from “Effortless Flex 4 Development”

Peachpit Press, the publisher of my book “Effortless Flex 4 Development” (technically, Peachpit’s sister company New Riders is the publisher), has posted excerpts from the book available for reading—for free—online. You can read about the following subjects:

You can see all the articles and blog posts that I’ve written for Peachpit Press by viewing my writer’s page there.

On the Web => Toad for MySQL

The technical editor on my past two books is a big advocate of Toad for MySQL, a free MySQL tool for Windows. I don’t regularly use Windows, so I haven’t tried it myself, but I take Jay (the technical editor) at his word on such things. Plus, it’s free!

On the Blog => Rendering View Files in Yii

On my blog, I recently wrote up a quick guide to rendering view files using the Yii framework. If you’re using Yii, the article should help you understand these fundamentals, but even if you’re not using Yii, I hope the article helps convey how frameworks and the MVC design pattern generate the output seen by the user in the Web browser.

On the Blog => Using Amazon’s CloudFront as a CDN

I just published, on my blog, a post explaining how I choose and setup Amazon’s CloudFront as a Content Delivery Network. I decided to finally utilize a CDN in order to improve my site’s sluggish performance. So far, the experience has been remarkably simple and even more remarkably affordable.

Q&A => How Can One Become a “Real” Programmer?

Celia had sent in this question:

Can a person become a “real” web programmer from studying books and online resources, or is it necessary to take college classes and study programming languages such as C++?

I expect many people have wondered this same thing, as you hear about C++ and Java and formal training and certification and can easily believe those things are required to be “real.” Well, as a counterpoint, there’s an argument to be made that I’m a “real” programmer, and my entire body of formal training consists of…one high school Pascal class (twenty years ago). In fact, I expect that a good percentage of people who read my work have more formal computer training than I have. I’m not saying that to be dismissive of my abilities but rather to say that many paths will get you where you want to go.

There are really two issues to this question: becoming an able programmer and being employed as a programmer. You can most assuredly become a “real” and capable programmer without formal training and without learning a more advanced language like C or C++. First, whatever training you have, formal or not, the fact is that you only master a language by using it. It’s just as possible to take a course on, or become certified in, a language and never truly master it as it is to teach that same language to yourself and become quite skilled.

As for the type of language, PHP, my favorite language and the one I use the most, is quite approachable, but that doesn’t mean it’s inconsequential. I can program in C and C++ (even Java, to a lessor degree), but don’t regularly have the need to. There is clearly more than enough that you’ll be able to do by just picking up PHP, or any other language, through books and online resources.

The second issue that I think is implied by the question involves “marketability.” In this regard, formal training and certification is often necessary (sadly). There are many technical jobs that I wouldn’t qualify for on paper because I don’t have a college degree in computer science (it’s in English). However, there are always ways around such things. Bill Gates doesn’t have a college degree (not a legitimate one, anyway), and he made out okay. This is to say that you can, with enough talent, imagination, and hard work, invent your own success. Or you can get your foot in the door at a company by performing an apprenticeship. Even when it comes to marketability, the fact is that formal training and certification can only, at best, get you over any initial qualification hurdles when you’re looking for a job.

At the end of the day, you can only ever become a “real” programmer by doing: creating functional, practical, Web sites, scripts, and applications.

What is Larry Thinking? => Becoming a Better Programmer, Part 2

In my previous newsletter, I wrote about how one becomes a better programmer. In the article, I came up with a simple mantra: Read. Do. Review. If it’s simple, it’s got to be right, right? A second, related question to how one becomes a better programmer is what actual qualities should a good (or better) programmer have? I haven’t come up with a pithy answer for that one, but here’s what I do know…

First, let’s distinguish between the “competent” programmer and the “incompetent” one. The primary basis for the quality of any programming task is: does it work? In other words, does the script or application do what it needs to do? For a competent programmer, the answer is “yes”. For an incompetent programmer, it’s “no”. For an incompetent programmer to become a competent one, she or he first needs to overcome this hurdle. To be fair, a competent programmer may write code that has bugs (in fact, is likely to) and the program might not be optimal, but basic functionality is always the first criteria. So the rest of this article is intended to differentiate among the strata of competent programmers.

(If “competent” and “incompetent” sound too harsh—because every one of us is incompetent when we begin, you could say “capable” and “incapable” instead.)

I’ve come up with three criteria for identifying the quality of code (and therefore, the quality of the programmer): security, usability/maintainability, and performance. You may think I’m missing something with just three items (and I may be), but sub-factors go into them. Let’s look at the least important of the criteria: performance.

On the bright side, performance is easily quantified: run tests and compare numbers. If you write two versions of a PHP script, run them both on the same server, and if one is consistently faster than the other, then it performs better. Better programmers, in my opinion, know how to write code that will perform better. This means that better programmers know things like:

  • How to properly design a database
  • How to use database indexes appropriately
  • To avoid using include_once() and require_once() (when using PHP)
  • How to use caches
  • And so forth

The problem with performance is that this knowledge takes effort to learn. You’ll have to read a lot, run benchmarks, pay attention, etc. But over time better programmers learn these more optimal programming habits. Also, performance is less important as a criteria because it’s easily overcome. Not an ideal solution, but if code performs poorly, more hardware can always be thrown at the problem. Conversely, no hardware solution can remedy code that’s difficult to use or maintain.

A more critical skill for the better programmer is the ability to write code that’s easier to use, reuse, and maintain. This skill, while more valuable than being able to write code that performs well, is harder to quantify. But I can say what qualities go into such code.

Most importantly, code that is well documented is easier to use, reuse, and maintain than code that is not. In fact, if you were to ask me what is the most important quality of a better programmer, I would say better programmers write better documentation. I used to teach an online PHP course for the University of California at Berkeley and I expect that “document your code more!” was probably the feedback I gave most often. The last time I did a code review for a client, the code was so poorly documented that there was no way I could have told the client that what their in-house programmer was doing was good or valuable. So if you want to become a better programmer today, start doing a better job of documenting your code! Also, do make sure you update your comments as you change your code. It’d be better to have no comments at all than to have comments that contradict what the code actually does.

Second, code that is easier to use, reuse, and maintain is organized well, in terms of files, folders, and functions (I love alliteration; like simplicity, it just has to imply truth). The better programmer makes proper use of subdirectories, included files, and user-defined functions. As for a couple of concrete examples, the better programmer writes included files so that they don’t make assumptions about what has happened previous to their execution. And the better programmer writes good user-defined functions, with appropriate use of arguments, no reliance upon global variables or other external data, and a “black box” mentality (i.e., you don’t have know how the function does what it does in order to use it correctly).

Third, code that is easier to use, reuse, and maintain handles errors gracefully and reports them only when appropriate. In an ideal world, the best programmer is writing code without errors, but in the real world, applications have external dependencies that can undermine what you’ve done. Watching for, and handling, such exceptions is a hallmark of the experienced programmer.

Finally, and probably most importantly, the better programmer is aware of security: common hacks and how to prevent them, protecting the server, protecting the user, etc. This is a life-long pursuit.

So those are the qualities that I think of when it comes to differentiating between good and better programmers. I’m sure I forgot something (feel free to send in your thoughts). I will add that some people see a benefit to brevity when it comes to code. This is particularly true in object-oriented languages, such as Ruby and JavaScript, where multiple actions can take place in a single line. I don’t personally honor brevity as some great goal, at the very least because brevity often comes at a cost of legibility, which is more important to me. But even if you do value brevity, it’s really just window dressing compared to these other qualities.

Larry Ullman’s Book News => “PHP for the Web”, “PHP and MySQL for Dynamic Web Sites”, and More!

As mentioned already, some of the articles I wrote for Peachpit Press’s Web site, supporting my Effortless E-Commerce with PHP and MySQL book, have been published and more will be soon. I’ll post links to the new ones on my Web site, and in future newsletters, as they go live.

The fourth edition of “PHP for the Web: Visual QuickStart Guide” has gone to press. I’ll post updates when it should be available, and give away some copies in the next newsletter. Along with fixing any minor problems, updating the code for the latest version of PHP, and adding a “Review and Pursue” section to the end of each chapter, the book includes one new chapter, called “Putting It All Together.” The chapter demonstrates how to use everything covered in the book to assemble a mini-Web application, with authentication and full CRUD (Create, Retrieve, Update, and Delete) functionality.

Either this week or next, I begin writing the fourth edition of my “PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide.” Near the beginning of this newsletter I explain my intentions for this edition, and ask for any input you may have. The book should be available come August.

I have finally begun working on my self-published JavaScript book, although not as regularly as I would like. But starting is a key step. Once I get a decent first draft completed, I’ll begin looking for volunteer editors and tech reviewers (I’ll also figure out how to reasonably compensate them!).