Archive for the ‘bugfix’ Category

Concentrating in History and Science at Harvard

Thursday, January 28th, 2010

This post was originally at my Harvard Law / Berkman Center blog, but has since been removed. Though it is certainly outdated with respect to the current practices and personalities of the History of Science department, it still may hold some value for prospective students. I originally wrote it as advice to my younger self, and I think it might be particularly useful to undergraduates who share some biases, conceits, and preferences with that past self.

What you should know before undertaking an undergraduate concentration in History and Science at Harvard

Thu, May 6, 2004; by Randall Lucas.

Draft, 06 May 2004

Synopsis

Having completed an A.B. in History and Science, I wish I’d known the following before beginning:

1.You will not receive a thorough background in the history of science before being assigned work presupposing such knowledge. You must undertake to educate yourself with a foundational knowledge if you wish fully to understand and gain from the coursework.

2.You will be in a class with a large contingent of pre-med students who bring a potentially undesirable ethic to the department. You should carefully consider whether you want these people to be your peers for three years.

3.The influence of identity politics and philosophies hostile to science will be significant and may emphasize criticism and polemic. You should understand the “Science Wars” and their implications before you choose the concentration.

4.The department’s faculty is brilliant, but the ideology and personality of individual persons with whom you work will inordinately influence your learning, enjoyment, and grades. You must research the individuals within the department with whom you consider working.

5.MIT is available to you and has a science studies program with excellent faculty. You should seriously consider the MIT offerings for adding breadth and diversity to your coursework.

6.The History of Science Department is in the Science Center, the most dismal place known to man. You must convince your colleagues to flee that decrepit building at every chance.

Introduction

I chose to concentrate in History and Science as an undergraduate (class of 2001) because of my interest in both fields of inquiry and in their intersection. Despite an intense interest, however, I became fundamentally unsatisfied with and alienated by my experience in the department, and sought out other areas in which to focus my energy, causing my grades and level of achievement in my concentration to suffer. Looking back on reasons for this dissatisfaction, and seeking to help others avoid it, I have identified the caveats that follow.

The following points will likely be useful mainly to that minority of students who share certain of my preferences; there are certainly many people who enjoy and thrive on the status quo. However, if the numbered synopsis resonates with you, the entire article is likely worth reading.

While the intended audience of this paper is students considering, or struggling with, a concentration in History and Science, I hope it may be useful to those seeking to reform the department, or indeed, undergraduate education in general. Such readers should note that I take full personal responsibility for my past performance within the department while remaining critical of the defects I describe below.

Discussion

1. You will not receive a thorough background in the philosophy of science, nor in the historiography of science, nor in the actual history of science. Although a sophomore tutorial includes selected works relevant to all three of those disciplines, it provides a solid grounding in none of them. The remainder of the curriculum tends toward rather specific inquiries into the specialty fields of faculty members.

The History of Science Department (HSD) at Harvard is a meeting place of a number of overlapping subject areas (“related disciplines”) that might at another school be called Science Studies. The natural focus is on the history of science, but both critiques of how the history of science has been written in the past (the historiography of science) and studies relevant to the nature of scientific knowledge and its place in the world of knowledge (the philosophy of science) go on alongside and mixed in with the historical studies. These three areas are largely interrelated in practice, and some synthesis of these is usually expected in students’ work.

However, most courses offered in the HSD analyze a relatively narrow piece of history that a faculty member has staked out, organized typically along the lines of geography, time, and / or scientific discipline. These courses are excellent for “drilling-down” into the subject matter given, can be intellectually satisfying in their depth, and often make points of departure for senior theses. However, with regard to the three related disciplines (history, historiography, and philosophy), these drill-down courses offer only a “case study” approach and do not provide any systematic way to cover the related disciplines.

The sophomore tutorial (as I observed it in 1999) seems nominally to be addressed towards this problem of laying the foundation in the related disciplines. However, it suffers from an even worse defect in this mission than does a drill-down course: in effect, the tutorial comprises a number of micro-case studies, thereby sacrificing the systematicity of a survey, yet covers each so superficially as to lose the benefits of in-depth study. The sophomore tutorial is centered around a series of reading selections in all three disciplines, typically with three or so selections (often, but not always, related) to be assigned and discussed in a week. Many of these are excerpts or single examples of primary sources (e.g., Copernicus, Sarton, Feyerabend, in history, historiography, and philosophy, respectively) and are presented as exercises in “close reading.” Such a series of assignments, without an underlying framework and system, is a recipe for a patchwork understanding.

The problem is that close reading and criticism, which are the focus of the later drill-down courses where it is appropriate to focus on a narrow field of inquiry, is an inappropriate starting point. The tutorial fails to give a general and comprehensive background in what, overall, Copernicus, Sarton, or Feyerabend did and said, and how that relates to the other major figures in those fields. What is desperately needed by the underclassman is a solid foundation in the disciplines themselves, not in “close reading” or criticizing the foundational knowledge. How can one be expected to say anything of worth about a closely read page on the philosophy of science, when the sum of one’s instruction in the philosophy of science has been three or four such closely read articles? How can a primary source reading from an ancient astronomer be helpful when one has not mastered at least the narrative history of that astronomer, his forebears and successors, and his work’s relation to that which went before and after?

Only a remarkably arrogant blend of sophistry and ignorance permits the sophomore who has only the tutorial as his guide to speak or write critically on the contentious ideas of, for example, Feyerabend, yet that is exactly what we ask him to do. Harvard undergraduates may be famous for their arrogance and sophistry, but we need not countenance ignorance.

Another problem with prematurely engaging in close, critical readings of primary sources is that, like in many academic fields, there is a lot of cultural context to the practice of History of Science. To produce work that engages the scholarship in the field surrounding it, one must first learn and apply the conventions and tradecraft of History of Science practitioners. Ideally, this, too would be formally taught in a systematic manner, but if it must be absorbed implicitly rather than explicitly, it can be gained effectively only from secondary sources, not primary sources.

I do not claim that my (professedly inadequate) History of Science education qualifies me to prescribe a detailed syllabus, but I can propose a very general prototype that would at least be superior to the current state of affairs. I propose that the sophomore tutorial be replaced with two semesters: first, a roughly chronological survey of science from antiquity to mid-20th century, and second, a full semester on the historiography and philosophy of science, covering Greek thought as a basis and beginning seriously with the renaissance, up through the “Science Wars” of the 90s (see below). The historical survey will not aim to criticize or challenge the “received history” — precisely because the “received history” must first be presented and known before it can thoughtfully be challenged. The second semester of historiography and philosophy will begin the questioning process in a systematic manner, asking the foundational questions such as: What is science, anyhow? How is it different from other forms of knowledge? Who has heretofore written the history of science, and with what biases, and what criticisms have been directed at the historical record? In both of these courses, focus will be away from the performance of actual historical research or philosophical criticism, and directed instead toward a broad, systematic understanding of the received history, the major schools of thought, and the historiographic issues at hand. The student will have two more years to engage these ideas in the performance of research and criticism, but will be much better prepared to do so.

(The inclusion of “Greek thought as a basis” is not meant to exclude the possibility of augmenting or replacing it with other times’ or cultures’ contributions. However, I reject categorically the suggestion that no foundation is proper because it may be biased. In other words, should it be determined that Arab science is the best starting place from which to build a foundational understanding for undergraduate history of science education, then make it so — but such a foundation must be built.)

This idea — that there is at least a general “canon” that one ought to know and that schools should try to cover systematically — has been out of favor for many years. President Summers is demanding of the faculty a reexamination of this issue, which reexamination is in order and indeed overdue.

In the event that you decide to concentrate in History and Science, and the department has not yet adopted measures similar to those I describe above, I highly recommend that you take measures to broaden and systematize your history and philosophy of science education before you enter the sophomore tutorial. Examine reading lists of science studies courses from other universities, acquire some of their recommended general texts, and read these prior to your sophomore year. If you can manage to read a good selection of secondary sources that aim to survey the field prior to your sophomore tutorial, you will be much better able to understand and put to use the ?close reading? materials that the remainder of your course of study in the HSD will comprise.

2. You will be in a class with a large contingent of pre-med students who are seeking a way to combine their pre-med requirements with a humanities degree. These people will bring a potentially undesirable ethic to the department that it likely would not otherwise have.

The tenor of your HSD experience will be substantially influenced by the pre-med ethic. The following are attitudes characteristic of this ethic, and you may find them undesirable:

– Grades are of utmost importance, and certainly are of more importance than developing deep understanding or doing good work.
– Challenging of professors, instructors, or received ideas is virtually unknown (note that I exclude instructor-assigned “challenges” to straw-man notions of received ideas).
– Candor in discussions is unknown, replaced instead by the extremes of “flexing” or meek acquiescence.

If you are pre-med, you may want to reconsider surrounding yourself with so many folks on a similar path (remember, if your plan works out, you’ll be spending many, many years with those people anyhow). Furthermore, athletes should take special note that the HSD is not one of the traditionally athlete-friendly departments, and your colleagues and instructors may be nonplussed at the notion of rescheduling for practices or meets.

3. The influence of identity politics (gender, race, class) will be substantial, as will the influence of philosophies that count science as epistemologically non-exceptional. One result is that criticism and polemic will be prominent and may be emphasized over mastery.

You will likely be expected to include substantial criticism of gender, race, class, and similar issues in some of your work in the department, both implicitly by the nature of the coursework and the interests of your instructors, and explicitly by your coursework. To be sure: often, gender, race, and class considerations can be meaningful, helpful, and interesting to a thorough analysis. However, focusing on these issues tends to emphasize the polemical, and is often orthogonal to the main inquiry. If your interest is in the history of science or philosophy of science, rather than historical criticism or philosophical criticism of and through science, you may not appreciate that shift. If you are working with people (instructors, or classmates, in the case of discussion sections) who are particularly interested in this type of work, you might find the emphasis placed on these issues to be frustrating.

By way of introduction to the second part of this caveat (what I call scientific non-exceptionalism), let me explain very briefly and very generally a phenomenon known as “Science Wars.” Over the better part of the twentieth century, an intellectual current that might be described as a backlash to the notion of the triumphant march of technological progress came into fashion among academics, especially on the left. Work in this vein tends to be critical of scientific authority as an instrument of power, and tends to share methods and language with Marxism, feminism, and literary criticism. Let us call this side “group A.” Group A, along with raising legitimate concerns, tended to attack a straw-man version of “Science” due to their generally not understanding it very rigorously. At the same time, a “group B” took to what it imagined was a defense of science. Predictably, group B made some good points but largely argued right past group A, attacking a straw-man version of “anti-Science” because group B didn’t really understand the specialized critical language of group A. Group A imagined that group B was all about the Manhattan Project, eugenics, and Star Wars, while group B imagined that group A was in favor of astrology, having polio, and replacing Newton with a carved wooden fetish. Things got sillier and sillier until the mid nineties when a physicist named Sokal duped some second-stringer academics into publishing a goofy hoax about how physics was just a matter of subjective interpretation in an attempt to discredit group A. This radicalized folks, who either got angry about Sokal’s deceit or saw it as a debunking of group A.

“Science Wars” continues to this day, although it seems to be somewhat toned down from its peak. The main point of contention between the belligerents is whether science is exceptional; that is, whether science provides a way of knowing or a route to knowledge that is, like revelation is to the faithful, privileged and specially trustworthy. (Full disclosure: as the reader may have surmised, I believe in a limited scientific exceptionalism, but not without noting that, to paraphrase Derrida on philosophy, science appropriates for itself the dialog or process that defines it [e.g., if a supernatural phenomenon such as ESP is observed and documented and measured, it will come to be considered no longer “supernatural” but a scientifically explained phenomenon].)

While it is necessary not to conflate historical with modern science while working on a purely historical topic, the question of exceptionalism will arise in any consideration of modern or historical philosophy of science. In the HSD, if your work relates to the place of science in an epistemology, you will likely be expected to hedge your arguments with reference to the non-exceptionalist ideas. Especially for those of you who engage seriously both with the philosophical question of the place of science and with your science coursework, you may find this expectation troublesome.

Like the presence of the pre-meds, this is more a cultural issue than a structural one, so these are less recommendation for specific changes than advance warnings to students about cultural issues to expect. In fact, I would not recommend any specific changes which would require coercion of persons on these dug-in and contentious topics. However, prospective students should be alert that the “Science Wars” are still smoldering, and that the environment that creates may be unpleasant.

4. The department’s faculty is packed with some of the most brilliant minds you can imagine, but you won’t pick the right courses (that is, the right people) based on the descriptions in Courses of Instruction. Therefore, you must research the individual persons with whom you wish to work.

This point in fact probably extends to all of Harvard. Alas, you are cursed with riches: the HSD has some truly brilliant and fascinating minds at work in its faculty, but you can only work with a few of them in your allotted time. What’s worse, the conventional course selection method is to read a paragraph, perhaps also read the CUE guide, shop a course (in the HSD, often one weekly meeting) and then commit to spend a whole semester on it. This is very risky, and you need to mitigate this risk by researching the individual style, interests, and ideology of the prospective instructors.

The HSD courses are intensely dependent on the personality and interests of the faculty instructors. It is very important for your enjoyment and for what you will ultimately take away from the concentration that you very carefully select the faculty with whom you work. I recommend reading as much as possible of the works of, and about the ideology of, any faculty member whose course you intend on taking.

By an instructor’s ideology, I mean his more or less comprehensive system of ideas about the topic, which can include the critical and polemical ideas I discuss above, but also includes his value judgments on what is interesting (and what is deathly boring) and what is good quality. The paragraph in Courses of Instruction will but hint at this ideology, and your first shopping period section will reveal little more. Your departmental advisors, such as they are, may be helpful for this — I found the departmental advisors of my day to be more of functionaries for processing undergraduates’ papers en masse than legitimately useful. You really must read about your instructors, including their relevant published work on the topic at hand, in order to decide if you want to work with them.

Unlike much of the rest of your education, this will not be a science course, and mental horsepower alone will not see you through: there are no objective exams, and you must be aligned with the ideology and personality of the professor in order that his instruction should prove to you satisfactory and that your work should prove likewise to him.

Although carrying out this recommendation takes time, consider: you are investing a lot in this degree, and you must do your due diligence before investing your precious time in an instructor. Better to lose a few hours in preliminary research than to lose a semester.

5. MIT is available to you and has a science studies program with excellent faculty.

The Science, Technology, and Society program at MIT is a mere two T stops away by train, but a world apart in terms of certain attitudes. If you find yourself dissatisfied with the HSD, or if you are having any hesitations about limiting your courses to those offered in the department, at the very least examine the MIT offerings. Although I discovered them late in my undergraduate career, the MIT courses were a wonderfully refreshing change of attitude.

6. The History of Science Department is in the Science Center, the most dismal place known to man.

Unfinished concrete, exposed ducts and wiring, cheap carpets and furniture, and radical, discomforting swings in temperature will be the hallmarks of your physical experience in the building housing the department. Happily, you are not require to spend much time there, and reasonable measures can be taken to mitigate the time that you must spend there. If your instructors or classmates propose to hold meetings in the Science Center, make every effort to dissuade them. There is plenty of decent real estate on and around campus, and unpleasant physical surroundings are not conducive to good learning.

Conclusion

I understand that this document jumps from broad theoretical issues to narrow practical ones and therefore makes for a poor plan of action for reform of the department. Such a plan is not my objective. Of utmost importance is enabling good choices by undergraduates, and offering concrete strategies for dealing with existing deficiencies.

If any of these points resonate with you, I urge you to consider my recommendations, and to contribute any ideas or strategies you have for dealing with the problems of the department, by way of publishing your own suggestions or by commenting on an interactive electronic version of this document.

SWI-Prolog from MacPorts on OS X 10.5

Wednesday, December 23rd, 2009

Tried installing the binary of SWI-Prolog (swi-prolog-5.8.2-leopard-intel.mpkg) on my Mac OS X 10.5 box.  For whatever reason, it was bombing out with some nasty errors (Libary not loaded … image not found).  Read about others’ troubles and decided to try MacPorts.  Couldn’t get SWI-Prolog to install using a standard:

$ sudo port -v install swi-prolog

Ended up getting lots of BS errors on the lines of “ERROR: Could not load/find library -lXpm.”

*****************************************************************
* ERROR: Could not load/find library -lXpm.         *
* Please install the XPM library and rerun configure.       *
* The primary source for libXpm is at:              *
*                               *
*     http://www-sop.inria.fr/koala/lehors/xpm.html     *
*                               *
* NOTE: If your system has libXpm, check the following:     *
*                               *
*   - Do you have the development version of the library?   *
*   - Is the library you have of the right architecture?    *
*   - Could it be that other parts of X11 are missing?  *
*     (typically the case if -lXext is also missing)    *
*                               *
*   Examine packages/xpce/src/config.log for details    *
*   Linux users: check README.debian for dependencies   *
*   (note that the exact package names vary between     *
*   distributions).                     *
*****************************************************************

Long story short: For various reasons, the MacPorts installed software wasn’t finding my Apple Developer X11 libraries, and it also wasn’t appropriately requiring the software as dependencies for the swi-prolog package.  Had to do the following:

$ sudo port -v install xpm
$ sudo port -v install xorg-libXt
$ sudo port -v install Xft2

to get the prereqs installed (warning: those libs, in turn, have some mongo big dependencies, like Perl itself, so be ready for some serious compiling).  After that, installing swi-prolog worked just fine.

CGI.pm hangs in read_from_client under Catalyst / TT

Monday, November 16th, 2009

Aahhh.  The joys of a Monday evening with the Perl debugger.

I have a quite simple Web front-end to a relatively complex back-end system.  The Web app is written in Perl with Catalyst as a framework, and Template Toolkit (TT) as the templating engine.  Since we are smart-asses, we aped the Ruby on Rails “link_to” function, intending to use it within our templates.  Seems simple enough; and originally, we used CGI.pm‘s escapeHTML function to handle the anchor text escaping.  Old habits (using the ’90s era CGI mod) die hard, I guess.

# in our Catalyst root; we use CGI.pm
use CGI qw/escapeHTML/; #OOPS
# ...
# mimics the Rails "link_to", and can be used directly in template toolkit
sub link_to {
 my $self = shift;
 my $anchor_text = escapeHTML(+shift); #ANOTHER OOPS HERE
 my @args = @_;
 my $uri = $self->uri_for(@args);
 return '<a href="' . $uri . '">' . $anchor_text . '</a>';
}

Well, as it turns out, I was getting a particularly maddening behavior whereby my app, when loaded in a single-process server instance, AND when a login action is the very first POST submitted (as is meet, right, and good), would inexplicably hang.  Not being intimately familiar with Catalyst, and being generally irate, I muttered a curse at the choice of framework and assumed that my contractors must have enabled some kind of recursion or infinite loop.  Nope; even ensuring that View::TT had RECURSION => 1 and a reasonable WHILE_MAX, I still got the hang.

So, into the debugger I dove.  A couple hours later, I’d tracked it down:

DB<6> CGI::read_from_client((eval 505)[/usr/share/perl/5.8/CGI.pm:895]:5):
5:          return $MOD_PERL
6:              ? $self->r->read($$buff, $len, $offset)
7:              : read(\*STDIN, $$buff, $len, $offset);

(Aside: why doesn’t WordPress have a “paste as code??”)

In CGI.pm’s “init,” it sets itself up to read from the browser input (on STDIN).  But if Catalyst has already slurped in STDIN, there’s nothing there to read, and CGI blocks.  (Either that, or something about CGI being init’ed from within the context of a Template that’s compiled and eval’ed under a mountain of cruft doesn’t sit right with CGI).

For the meantime, my solution is to use HTML::Entities and its encode_entities instead of CGI.  But beware using CGI when also using Catalyst; there’s a lot of dragons in CGI that you probably don’t want to have to understand and work around if you wake them up.  At least one other Catalyst / TT developer has had similar hang problems.  Better to use the equivalent functionality from cleaner, more predictable modules.

(Mad props to CGI and its rock star author, Lincoln D. Stein.  But any module that’s got workarounds for mosaic and mid-90’s server bugs has got baggage, period.)

Create blank objects in Perl’s Class::DBI

Tuesday, February 24th, 2009

Perl’s Class::DBI is something I’ve had a bit of a love-hate relationship with. It’s definitely been useful. And, like with Ruby’s ActiveRecord, it can sometimes rocket-propel you 10x with a development task.

However, it’s got a lot of weird gotchas built in. One of them seems to be the inability to instantiate an object with no data. Now, I know, you might well be saying, “why on earth would you instantiate an object with no data?”

Well, for one, perhaps you’ve got a legacy DB (or a non-legacy DB, for that matter) that intelligently fills in columns based upon a trigger, default, or other mechanism. (I’d venture to say that most all modern schemas use some variation of this, be it with AUTO_INCREMENT or sequence.) Another case is where you’ve got link tables that, on their own, don’t get any data added in until and unless their relationships get filled out.

In any case, it would be mighty nice to be able to insert an object that is empty, and have it just filled out with the defaults/triggers/whatever. But when you use Class::DBI, you get this nonsense:

  
DB<1> use My::Class;    
DB<2> $mc = My::Class->create; insert needs a hashref at  (eval 813)[/System/Library/Perl/5.8.8/perl5db.pl:628] line 2    
DB<3> $mc = My::Class->create({}); DBD::Pg::st execute failed: ERROR:  syntax error at or near ")" LINE 1: INSERT INTO my_table ()
                               ^ at
                                /Library/Perl/5.8.8/DBIx/ContextualFetch.pm
                               line 52.  

This is a Major Bummer, since Class::DBI Just Works for most other things.

Digging through the guts of Class::DBI, it seems like you could use something like the _prepopulate_id private method, but it only works if you’ve set __PACKAGE__->sequence(...). As it happens, I am using sequences under PostgreSQL, but I did not set up the sequence entry for each class (and don’t want to do so, as I’ve been using CDBI for 5+ years without ever bothering with the sequence method).

So, for all you PostgreSQL users with normal, plain-vanilla, single-PK tables that increment off a sequence, here’s some code to add to your base class (it’s always good to have your Class::DBI inheritors inherit CDBI through a base class that you define locally so you can add behavior to all your classes) that will permit a create_blank() constructor:

# this sub allows us to create a blank entry (with only it's 
# sequence-increasing ID): XXX NOTE: only works on Postgres  
# (pg-specific method of getting ID).  
our %CLASS_ID_SEQUENCE_NEXTVAL = ();  
sub create_blank {     
    my $class = shift;     
    #check cache     
    my $nextval_sql = $CLASS_ID_SEQUENCE_NEXTVAL{$class};     
    my $pk_col = $class->primary_column;     
    #cache miss:     
    unless (defined $nextval_sql) {         
        my $table = $class->table;         
        $table && $pk_col              
          or die             
        "create_blank only for single PK tables ($table $pk_col)";         
        ($nextval_sql) =              
        $class->db_Main()->selectrow_array(
                 'select column_default from information_schema.columns ' .
                 'where table_name=? and column_name=?',
                  {}, ($table, $pk_col)
             );
         $CLASS_ID_SEQUENCE_NEXTVAL{$class} = $nextval_sql;
     }
     die "didn't get a viable nextval() for class $class"
          unless $nextval_sql;
     my ($id) = $class->db_Main()->selectrow_array(
         'select ' . $nextval_sql
     ) or die "couldn't select $nextval_sql";
     return $class->create( { $pk_col => $id } ); }
   

I release the “create_blank” method above to the public domain, feel free to use and abuse.

Fixing Net::Google error with 404 File does not exist

Tuesday, August 26th, 2008

I was trying to install Net::Google 1.0 using CPANPLUS on my Mac OS X 10.5 machine, and kept getting a pesky error:

Service description 'file:' can't be loaded: 404 File `' does not exist  

One thing I had to do to fix it was install an apparent prerequisite, SOAP::WSDL. It wasn’t included by CPANPLUS.

Another thing I had to do to make the tests run was to include the lib/ (not just the blib/) directory in @INC when running the tests:

perl -Iblib/lib -Ilib t/001-search.t  

Even though that made the tests succeed, the installed module still wouldn’t work and gave the same darn error.

It turns out that some deeply, deeply nested code in Net::Google searches through @INC to find:

$DIR/Net/Google/Services/GoogleSearch.wsdl  

This file doesn’t get installed by “make install”, unfortunately.

So, I had to do the following:

rlucas:/Library/Perl/5.8.8/Net/Google$ sudo mkdir Services Password: rlucas:/Library/Perl/5.8.8/Net/Google$ cd Services/ rlucas:/Library/Perl/5.8.8/Net/Google/Services$ sudo cp \ ~/.cpanplus/5.8.8/build/Net-Google-1.0/lib/Net/Google/Services/GoogleSearch.wsdl \ .  

Now my Net::Google using scripts seem to work right.

Entering a Hard Line Break in a Text Cell in Excel 2004 for Mac OS X

Monday, November 12th, 2007

No cutesy commentary for once:

The equivalent on Mac OS X of alt-enter for entering a hard line break within a cell in Excel is command-control-enter (open apple-control-enter).

wxPerl on Mac OS X must be run with special binary

Thursday, October 4th, 2007

If you are having trouble with your “hello world” wxPerl script on Mac OS X, check your shebang (#!) line and make sure you’re running /usr/bin/wxPerl (or which ever wxPerl you have) rather than merely /usr/bin/perl — the normal perl will display the main window but won’t allow interaction between the window and the interface (e.g. you can see hello world but can’t click the button).

This posting seems to imply that Mac OS X 10.4 comes with a wxPerl installed; you can also get it via cpan / cpanp or from the wxPerl website if you don’t have it on your Mac.

Rails form_tag Changes in Rails 1.2

Monday, August 6th, 2007

I recently updated my dev machine (Mac OS X) to the latest Rails gems, and was getting deprecation warnings for using form_tag in its old, non-block, pre-Rails 1.2 way.

Then, in moving between my development and acceptance-testing boxes (you do have a mirror of your production environment running as an acceptance testing server before you push things from your laptop to production, right?) I started getting blank HTML pages out of the testing box. Whoops.

Well, one thing is that the two different versions of form_tag act differently with respect to output — so with the old one, you needed to put:

<%= form_tag ... %>  

While the new one takes:

<% form_tag ... do %>   ... <% end %>  

(Note lack of = sign in the new, block version.)

But that wasn’t it. My problem was that, even with the equal signs fixed, I was getting no love from my testing box. Things that should have been enclosed in the form tag block were just not happening.

My hunch was that the old version of Rails was barfing (this was sort of true: the new block form of form_tag is not backwards compatible). I updated Rails with a one-two punch of apt-get update; apt-get upgrade mixed with a gem install rails. No luck. Aha! Have to kill and restart the server process: still, I got no form tag love.

I checked the Rails version with rails -v and got 1.2.3, the latest version. gem list showed that 1.2.3 was coexisting with some older versions. Aha! And a real aha this time — for this was, it turns out, the problem.

Thanks to the folks who author the acts_as_authenticated wiki. It was there that I found a reminder that the RAILS_GEM_VERSION variable, in config/environment.rb, can be set to peg which, among several possible installed versions of Rails, the app will use.

It appears that if you comment out RAILS_GEM_VERSION, you get the latest installed version — which in my case fixed it to use 1.2.3, thereby giving me my form_tags back.

God Help You If You Get Derailed: "Model is Deprecated"

Friday, August 3rd, 2007

The comprehensible but often superfluous model method in Rails is used in an ActionController to tell it about an ActiveRecord model that it ought to have loaded in order to have the AR classes available to it. It’s kind of got the feeling of a require or a use in Perl. It’s fairly straightforward to reason by analogy about what it does.

(The only confusing thing, I think, is that it works by imputing a filename from a symbol representing the class to do its “magic” so if you define multiple AR classes in a single file, you’d want to make sure that the symbol that matches the filename containing the multiple classes is what you pass to the model method.)

But in a nutshell, you stick model :my_object_class in, say, the base ApplicationController class and you’re good to go to use MyObjectClass and any subclasses defined in the same file.

Well, it was the way you do it. Around Rails 1.2, it started barfing up preemptive deprecation warnings: model is deprecated and will be removed from Rails 2.0.

So, you follow the URL they give you for more info. Unhappily, nowadays (August 2007), the page they point you to, http://rubyonrails.org/deprecation, doesn’t say anything about model. WTF, guys?

Googling around tells you that you should use require_dependency instead. Oh, good. Way longer to type and harder to remember, but it’s OK, because require is part of the language itself and is familiar to those who understand it. Er, wait: it’s require_dependency, not require: it’s a Rails feature, not a Ruby core language feature.

Fine, you say, I’ll do it if I must. Just do a replace on those lines, and you’re good, right? Oh, wait again, now my app is bombing with an error 500, and the log says undefined method `ends_with?' for :my_object_class:Symbol. I won’t keep you in suspense: you can’t give a symbol :my_object_class to require_dependency, you have to give it a String ("my_object_class").

All of this highlights a pretty big issue with Rails. It’s really an infantile, nascent culture. To keep up with it, you really need to be in constant conversation with the community (like constant: I mean, you need to be sitting in the session at RailsConf with Colloquy open on your MacBook, chatting about stuff on an hour-by-hour basis). This isn’t bad, but you better understand it. And you better be refactoring your app constantly in order to keep up with best practices and to be able to use new plugins, etc. — which also isn’t bad, but it’s expensive and a hassle.

And to anybody who thinks a Perl app is tough to maintain: yeah, right. Try Rails code from a year or so ago if all you know is Ruby and you haven’t been heavily engaged in Rails culture during that time.

“Convention over Configuration” is fine and dandy as long as you’re steeped in the culture that maintains the shared conventions.

Printing From Mac OS X Without Going Bankrupt

Thursday, May 10th, 2007

One thing about buying a new(ish) MacBook Pro loaded with Tiger: they really aren’t cutting a lot of corners. This includes in the area of resource usage (see e.g. memory usage, as you buy another gig of RAM). This, of course, is done in the name of an “Insanely Great” user experience, and mostly, it works.

One difference from Windows is that the Mac, when printing, defaults to the best mode possible on our big office multifunction color laser printer; in this case, it’s fully glossy color. Those of you who’ve ever had to buy toner for such a printer are now wincing: it is damn expensive.

In Windows, it seemed, I had to opt in to print in color. I’d like to run the same sort of system on my Mac.

Well, as it happens, this is one sad case where the Mac requires you to know more about how the OS works than does Windows. Specifically, we want to use a feature of “Quartz” (the graphical engine) to convert colors to greyscale before sending them to the printer. Do it like this:

  1. Open a print dialog with command-P.
  2. It should show a box with pulldowns at top for “Printer” and “Presets”
    1. Make sure you’re working with the Printer in question.
    2. You’re probably using Standard Presets — that’s fine for now.
  3. In the middle is a third pulldown that says “Copies & Pages.”
    1. Choose it and change to “ColorSync.”
    2. Set a “Quartz Filter” to greyscale or black & white (maybe test each to see what works best).
  4. When satisfied, go up to “Presets” and save your settings under a name like “dreary grey.”
  5. Keep this selected and it should now show up as your default settings for this printer.