walls.corpus

By Nathan L. Walls

  • Sunset, Jan. 2, 2021/Williams Township
  • On Bougher Hill/Williams Township
  • Sunrise, Dec. 19, 2020/Williams Township
  • Sunset, Dec. 27, 2020

Articles tagged “software”

Code Kata: 99 Bottles

One of Chad Fowler’s recommendations in The Passionate Programmer is to practice Code Kata. Similar to musicians practicing scales or a martial artist practicing forms, this isn’t code that’s meant for practical value beyond practice. The means is the end.

I started with Fowler’s recommendation to implement programs that outputted the complete text of “99 bottles of beer on the wall” in a variety of languages. Very straightforward and I was pleased to observe/learn the following:

  • Out of four languages attempted, I was able to get all four to work. Yay!
  • I’m very familiar with Perl and Ruby. My career’s been spent on those two languages.
  • I’m very rusty with PHP. I used PHP as a primary language for web development for about a year, back around 2000. I used it again from roughly 2005 to early 2007 on a client project, but I wouldn’t say I ever became conversant in the language. What I was looking at was bad code, too. In the time since, I’ve forgotten what little I did learn.
  • I’ve never done anything with Python, but, for this exercise, it seemed pretty straight-forward.
  • To accomplish the same task, the languages landed, in order of brevity, as follows: Python, Ruby, PHP, Perl.
  • I don’t find using php tags for shell scripting ideal. At all.
  • I learned a bit more about Ruby’s case/when statements. Most of my Ruby experience has been with Rails, and I’ve not found the need to write case/when statements.
  • I wanted to use Perl 5.10’s features. You have to explicitly ask for them. I don’t like that so much. On the other hand, typing use strict; use warnings; doesn’t bother me.

Finally, I had David A. Black’s excellent The Well-Grounded Rubyist to draw from after seeing that my Ruby implementation was not doing what I expected. I used PHP Bible for finding what I needed for my PHP example. Language preference aside, there’s a broad-spectrum of programming book quality. One end offers encouragement to dig deeper and demonstrates best-practices. The other end is a fire hose of language info to write the site your uncle gave you $200 to build that he wants Monday. Regardless of the language, I need to find the first type of documentation and avoid the second.

If you’re interested, I’ve put all four languages into one gist on GitHub.

Why FogBugz doesn't have Gantt Charts

Fog Creek’s Rich Armstrong explains:

Gantt charts are great for managing projects where risk is low or measurable (5% chance that the drywall guy won’t show up for work), or where variability is low (the drywall guy can finish 200-250 linear feet of wall in a shift).

The temptation is to use the same tool to represent complex software projects, but software projects are fraught with risk (turns out the libraries you rely on have a bug) and variability (the customer called again). On a construction project, if the drywall guy gets the flu, that part of the chart might come in at 110% of its initial projected time. In software, a total unknown can triple the time it takes to do a portion of the project.

One of my ongoing revelations this past year is how desperately managers want to have an answer to the question, “How are things going?” If they’re accustomed to managing something other than software development, they’re very eager to use the tools they know (Gantt charts, Excel spreadsheets) to try to answer that question.

(Via Fog Creek’s first Developer Newsletter)

Laziness is a (business) virtue. Sometimes.

Rafe Colburn on what my previous job called “a buy vs. build analysis”:

The question people need to be asking is how little custom software can they get away with having. The ideal number is zero. If you’re working at one of those web design [firms] that rolls a new content management system for every customer, you’re doing your customers a disservice. Honestly, if you’re selling them your own proprietary CMS you’re probably doing them a disservice.

Software developers like to build things. And most developers are confident that they can provide something that perfectly solves whatever problem they’re confronted with as long as they can write it from scratch. Developers are horrible at estimating the long term costs of building applications yourself. And they have an incentive to be bad at it, because if they were good at it, nobody would let them loose to write custom software.

When you do bend the business to fit the software, you can end up writing a lot of glue code to get one API to talk to another API; to push or pull data whichever way it needs to go. That’s probably OK, when you’re dealing with a competent developer community or vendor.

The counterpoint is lack of confidence in the “off-the-shelf” solution. At my last gig, my coworkers and I preferred in-house development because we had just about zero confidence in the abilities of our vendors to provide a stable API, accurate documentation and reasonable integration cost. This collective opinion came from years of bad experience. In our minds, it was lazier to build a solution ourselves than continually fix what we bought from someone else. We were far more trusting of RubyForge and CPAN (and building on top of that) than anything that involved a contract.

Also, pray the company answer to the central question, “Do you want to be in the software business?” is either “yes” or “no.” “Maybe?” is a really scary spot to be.

Ruby on Rails phone number validation

I recently launched a Rails application that has a phone number field available to it. In the process of writing my spec tests, I allowed the phone field to be a certain number of characters and allowed it to be empty. The formatting test, however, I left pending. I searched for, but did not find a great solution past some very unreadable regular expressions.

In the course of watching a movie this evening, I had a solution. I created an array of acceptable formats, looped over the array and checked each entry against the phone number. If I had a match, the validation passes. Setting the string match to the beginning and I can allow for extensions without being too persnickety about formatting.

Here it is (via a handy gist):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def valid_phone
  return true if phone.blank?

  phone_formats = [
    /^\(\d\d\d\) \d\d\d-\d\d\d\d/,
    /^\d\d\d\.\d\d\d\.\d\d\d\d/,
    /^\d\d\d\-\d\d\d\-\d\d\d\d/
  ]

  valid = false
  phone_formats.each do |format|
    if phone.match( format )
      valid = true
    end
  end

  unless valid
    errors.add("Phone format isn't recognized")
  end
end

Here are some spec test examples.

It doesn’t handle international formats, but, for right now, it fits my needs.

Next →