Spam storm

In the last week I’ve gotten over three thousand spam comments, and I’m now averaging several hundred a day. This is way too much for me to cope with, so I’ve turned off comments to all posts. I’ve never had an actual comment anyway, so I guess it’s not that big a loss.

Posted in Site news | Comments Off on Spam storm

Stupid programming tricks: #1

In programming, simple things often turn out to involve obscure problems and techniques. I run into these and spend hours tracking down what went wrong, then console myself with the thought that “Next time I’ll know how to do it.” Unfortunately, by the time next time rolls around, I’ve forgotten all about it. Leaving little text files filled with incomprehensible notations scattered all over my computer doesn’t seem to help. My great idea this time: post all this stuff on my blog. Then I can google it like I do everything else! Brilliant, eh?

Today’s trick combines two obscure problems for one common activity, a stupid twofer, so pay attention, you in the back. It is very common for my perl scripts to fail to work the way I expect. When this happens, there are usually helpful error messages (always, always use strict and warn) to tell me how I’ve screwed up. Unfortunately, these are not always as helpful as one might hope.

A typical case is doing something with a large database table, say ~25,000 rows. I want to modify one of the fields based on certain conditions, and it works except for 200 exceptions. For these, 200 error messages pop up, repeatedly informing me

Use of uninitialized value $var in concatenation (.) or string at document x line y.

So something is wrong with my condition. But what? Where? I quickly pull out a trick from my stupid programmer’s bag and add a line printing out the field “id” from my table to stdout to find out what records are failing the condition, then run the script again. This is not helpful, because the field “id” prints 25000 times, scrolling so rapidly that I can barely see the longer lines that tell me there was an error. Undaunted, I pull out another trick from the bag and redirect output to my favorite, temp.txt, like so:

badscript.pl > temp.txt

This helpfully swallows up all the ids, while my screen still fills up with all the error messages without any “id” field info to tell me where the mistake was. Ids in temp.txt, error messages on screen. Whoops. This is because perl uses stderr to print out error messages, not stdout, and this is not redirected by >.

Let’s recap here in case you’re getting as confused as I did: what do I want to do? I want to send both stdout output (ids) and stderr output (error messages) to the same file. According to microsoft, this can be done as follows:

cmd.exe 1> output.txt 2>&1

Now why didn’t I think of that? Finding this info is the real trick; if you don’t google the right combination of words, it takes a while. (hint: “how to redirect standard error stream in windows”)

Now for the twofer. When I open the file, I find things that I know can’t be right, for example:
….
id = xx
error msg
id = xx
error msg
error msg
error msg
id = xx
….

I am only doing one thing per row, so it is not possible for there to be multiple errors per row. Much pulling of hair and gnashing of teeth until I realize that this is a problem I met a year and a half ago, and has to do with perl’s use of buffering. (See here for an amusing account of just a few of the many problems that this can cause.) The solution is to turn off buffering in the script before going into the loop that prints to stdout, like so:

$| = 1;

Good luck on googling that one! In fact, it is impossible to find any of the special perlvars using google. The only place you will find them is in perlvar, located on your computer as well as the internet. But how do you know to look in perlvar? And in case you’re wondering why 1 turns off buffering instead of 0, it turns out we must think of this as turning on autoflush (turn on the pipe?). Anyway, the result of adding this gewgaw and then running the script again is that temp.txt finally contains what I want: id followed by error messages immediately following where something really went wrong.

Summary: to get a file with output and error messages as they actually appear on your computer screen, you must: 1) turn on autoflush in your script ($| = 1;) and then use the microsoft way to redirect: script.pl 1> output.txt 2>&1.

I tell you, when it comes to stupid programming tricks, they don’t come much stupider than mine~~

Bonus obscurantism! If you really want to dazzle the rubes, don’t do this:
$| = 1;
try this instead:
$|++;
For a nice discussion of this and other gobsmackers, go to www.perlmonks.org and search for “Perl Idioms Explained”. I immediately printed all of them and pasted them on my wall.

Posted in Programming | Comments Off on Stupid programming tricks: #1

Welcome back

Back to the classroom at last. It looks like a full schedule, with some big, big classes. Plan to do new and interesting stuff this semester, and still keep up with the syllabus (don’t hold your breath). The school has a new version of moodle up with lots of changes, guaranteed to take time from regular class prep and my own projects, but that’s the price for staying current and out of the clutches of the hackers. And remember: if there are delays and mistakes with assignments, quizzes, resources and grade posting, it’s the software’s fault!

Posted in School | Comments Off on Welcome back

School’s out for summer

Congratulations to everyone who made it through the semester. While the students go home and relax, the teachers are chained to their desks grading papers, exams, and late assignments (no, you can’t turn in assignments 1-10 now). Results should be available by next Monday, so hold off on those emails this week.

Posted in School | Comments Off on School’s out for summer

Teaching translation on-line

[This ancient paper from a conference in 2000 is now a historical relic, but the teaching problems haven’t changed a whit.]

Introduction

I first taught “Introduction to Translation” in 1998 at Chaoyang University of Technology’s Department of Applied Foreign Languages. This is a required two-semester course taken in the junior year. Its purpose is to give students an extensive introduction to the pleasures and pains of English to Chinese and Chinese to English translation. It is an important class for all students, since most will regularly do short, business related translation in their future careers. It is also intended to serve as a beginning course for students interested in taking advanced translation courses in the senior year. Students are therefore highly motivated to do well in this course. It was not, however, an easy class to teach.
Continue reading

Posted in Recycled papers, Translation | Comments Off on Teaching translation on-line

Greetings

Hello! My name is Robert Reynolds. My Chinese name is 魏伯特. I’m an associate professor in the Department of Foreign Languages and Literature at National Chi Nan University in Puli Taiwan, where I’ve been a full-time teacher since 2000. This blog includes links to materials related to my teaching and research interests, and also campus and local interest information. Stop by every few days, there’s bound to be something new up.

Posted in School | Comments Off on Greetings