Tuesday, August 27, 2013

Not Classy, VimLPOO!

Rise, fellow VimLers and cease sobbing onto your consoles about the stink of VimLPOO (VimL Programming Object Orientedly). Vim keeps an open mind and so should you.

tl;dr : VimL OOP can haz class-reopening like Ruby

Okay, maybe not exactly like Ruby, but check it:

VimL’s OOP is more like javascript’s than Ruby’s. It doesn’t have explicit classes. It uses dictionaries to store data and methods that operate on it.

Here is one way in VimL to create an object factory:

function! Kid(name)                  <1>
  let k = {}                         <2>
  let k.name = a:name                <3>
  func k.say(blah) dict              <4>
    echo self.name . ': ' . a:blah
  return k                           <5>

let boy = Kid('Jack')                <6>
let girl = Kid('Jill')
call boy.say('wassup?')              <7>
call girl.say('chillin'' at the hill. u?')
echo boy                             <8>
Jack: wassup?
Jill: chillin' at the hill. u?
{'name': 'Jack', 'say': function('69')}
  1. I like to use the full command form function when creating object factories (classes?).
  2. The object container is a dictionary (hash).
  3. You can explicitly set attributes outside of methods if desired.
  4. I like to use the short command form func for methods. The dict argument tells Vim that this is an instance method, providing us the self. accessor.
    Note You don’t need the ! on method declarations as you do for the outer-level.
  5. The factory must return the newly created object.
  6. Create an instance using the factory.
  7. Call methods using dot notation.
  8. The object in its native format is just a dictionary (hash).
Typically, after creating the object factory, the VimLPOO developer can’t re-open it to augment its behaviour although you can derive a new factory type from an existing one (inheritance without paternity):

function! RudeKid(name)
  let rk = Kid(a:name)               <1>
  func! rk.say(blah) dict            <2>
    echo self.name . ': Yo, biatch! ' . a:blah
  return rk

let boy = RudeKid('Jack')
let girl = Kid('Jill')
call boy.say('wassup?')
call girl.say('wtf?')
echo boy
Jack: Yo, biatch! wassup?
Jill: wtf?
{'name': 'Jack', 'say': function('72')}
  1. Base this object on the parent factory.
  2. Override methods as desired.
    Note The use of ! is now required because the method already exists in the base object.
But I’m not here today to talk about weak inheritance. I wanna play with class re-opening, Vim style.

As a quick recap, a Vim object is a dictionary with data and methods that can use the self. modifier internally to refer to its data and other methods. It turns out that Vim is not too particular about who gets to claim dict access on your objects. You’re free to create external functions, adorned with the dict modifier, and have them manipulate your objects as if they were created with the class originally:

function! s:slapped() dict
  echo self.name . " just got slapped!"

This happens to be a script-local (s:) function; global scope would work too, but why pollute unnecessarily? Now, if you tried to do a naive direct call of this, you’d be sorely disappointed:

call boy.slapped()
Error detected while processing jack_and_jill.vim:
Line   42:
E716: Key not present in Dictionary: slapped

That makes sense… We created slapped() as a script-local function, not a method on the boy instance.
Note Adding the method to the Kid() factory after having created the boy instance would be just as useless.

Happiness is just a call away:

call call('s:slapped', [], boy)

" Jack just got slapped!

:-D How cool is that?!

I have a little project in the works that uses this to allow clients of the engine to inject their own solutions to various parts of the workflow. It’s almost done, so I should be able to show something a bit more real-worldy soon. For now, what mischief can you concoct with this shiny new toy? I look forward to finding out. :-)

Vim on!

Wait, Lost!

85 today; 92 a month ago. Sweet!

... ooh! that caramel macchiato sounds just the ticket! ...

Dieter: In your face, diet! 8-D
Scales: On your waist, dieter.
Dieter: :-/

Monday, August 26, 2013

MPG 1, laowai 0

Mobile Phone Guy: Hey, guy, buy net for phone!
Me: hmm... I dunno... sounds expensive...
MPG: Nah, guy, not expensive. Only 10 RMB!
Me: 10 RMB per...? Month?
MPG: ...sure. Why not? Plenty net. You buy?
Me: hmmm... ok... I'll try it.

... clickety-click ...

MPG: There you go. All done. Door that way. Bye.

... days later, laowai remembers phone net and decides to try it ...

Me: ooh! W00t! I can haz net! Fast too. Like.

... three minutes later ...

Me: oh, a message; let's see... hmm? 10086... I wonder what he wants to tell me...? WTF?! 65 kuai used?! My phone is out of money?! Mobile net, you greedy, lying cheater! Unlike!


Mobile net has since been banished from my phone... good riddance!
Should've trusted my instincts. Foolish laowai. :-/

Sunday, August 25, 2013

Time Out!

So far, nearly every class I've faced in the new job has had at least one 'naughty' kid who makes the whole lesson go painfully slow and frustrating. These are not slow kids - their level of English is usually reasonable. They're not obstinate participants either, in the sense that when called upon to do an activity or contribute to class, they usually begin to do so quickly and competently - they want to participate. The problem is that they lack self-control and deliberately pervert the intent of the lesson by getting out of their seats, running around, fidgeting, disturbing or constantly talking to classmates (in Chinese) and everything else you could imagine a nasty little urchin reaching for on such a disruptive mission.

On the face of it, you could assume that these are merely bright children being insufficiently stimulated in classes that are pitching below their level and so they are misbehaving out of boredom. There might indeed be a degree of that going on too, and that is something I have to consider in my regular reflection sessions. However, the core of the problem, as I see it, is that the children have not been raised (academically speaking) to be courteous and responsible classmates. They have not cultivated the Right Mind of a civil and conscientious student. Okay, granted, they are only ten years old and it might be a bit much for me to expect such grown-up behaviour from little kids, but put another way, that means they've been exposed to five years of inadequate (one might even say abusive) classroom environments resulting in deficient study habits. No doubt a decent portion of blame rests with their parents too, of course. We have some parents who dump their unmanageable child off at a campus as soon as it opens and picks it up as late as possible to buy themselves a day of freedom from the monster they've created. Even if the child has only a few hours of classes at that campus, it is left there all day to terrorize and disrupt. Where's the War On [classroom] Terror squad when you need them?

It's not all of the kids, by a long shot. Most of them are adorable, conscientious, diligent and a delight to teach. The problem lies with a tiny minority (a single child or usually not more than two per room) who are deliberately bent on disrupting the lesson and the teacher as much as possible. This ruins the fun & learning for the other children and darkens the mood of the teacher. If left unchecked, the blackened teacher will devour his next class, angels and all. When we've approached campus management about this problem, we've been given the same response each time: "There's nothing we can do about naughty children. Deal with it. It will be better in the future. Trust me. <Big Smile Saying Get Lost Now>"

This is a depressing situation to walk in on; to be handed classes that were not cultivated with adequate discipline, right etiquette, good morals and diligent study habits. It makes me appreciate even more my prior colleagues' persistent indoctrination of these traits into the minds of our pupils. Thanks, guys! :-*

And I take my hat off to any such professional and conscientious colleagues in my new job.

I've spoken to several of my new colleagues (Chinese staff) about this problem now. Some dismiss the possibility, thinking in their hearts that the fault must lie with me because they don't see such behavioural problems when they take the class. While I may still indeed have much to learn about child psychology and classroom discipline that my ten years as an English teacher has not yet taught me, I consider this response to be naive at best and insulting and malicious at worst.

Instead of pretending that there is no fault, try instead sitting in on a few lessons to observe what behavioural problems the foreign teacher is talking about. In this way, you can give appropriate suggestions to the foreign teacher and admonish blatant misbehaviour in errant children as it happens. I'm not asking for presence in every class, but currently there is a disconnect in the minds of the children between our classes and those of the Chinese English teaches. The kids see our classes as game time only, treating them as a circus.

I have sat in on several Chinese lessons in my short few weeks in this new job and the same kids were much better behaved in their classes than they were in mine. One reason I believe for this is the use of the Chinese language spoken by the Chinese English teacher. When an admonishment is sharply barked at a kid in his native language (L1), he can't help but understand it and instinctively comply with it. Additionally, he knows that if he doesn't curb his behaviour then the teacher can inform his parents, or at least threaten to. The kids know we foreign teachers do not have this power, so they take this as license to misbehave with impunity.

Kids merely laugh at a foreign teacher who tries to threaten in English - picture The Simpson's "Santa's Little Helper" watching Homer screaming at Bart. Not understanding the words involved, he's left with Homer's oafish arm waving, reddened face and incomprehensible gibberish. Comical. And that's the problem. Instead of receiving a cautionary message for the child to calm down and pull his head in, he bursts out laughing and steps up the comedy act with increased hooliganism. It takes a patient teacher to respond to that with less than exasperation.

Of course, the take-away here is: Don't raise your voice and wave your arms around. Doing so merely makes you look just like the clown you're trying to distance yourself from in the first place. Instead, address the kid with silence and a closed body posture (arms down, square-facing, plain or stern face, and hold eye contact) and use corrective gestures to cease his current behaviour and lead him toward your desired behaviour. Silence is a much more devastating weapon than shouting. There are myriad other behavioural correction tools in the trade too, like tracking smilies and frownies on the board per kid, and rewarding participation & good behaviour with points (e.g. stars on the board) that have some real-world value somehow (e.g. 50 stars buys you a pencil sharpener, etc). And I do all that and more. But the abhorrent little delinquents I bemoan here today merely shrug their shoulders and smirk in indifference when I remove a star from their name for committing a transgression. They understand there is a rewards and punishment system, but they don't care to be a part of that system. It's very much like these kids have been placed outside of the system or have worked their way out themselves over the years and, looking in on it from the outside, they feel no connection to or love for it at all. Lost pupils.

I have successfully rebuked bad behaviour with short commands in Chinese. I think this will be a part of my effective strategy in future, but it would be sad if this were my only tool; sadder still if the need for it were to persist. Such a situation would indicate a failure to properly address the source of problematic behaviour, relying instead on this poor, blunt-force treatment of the symptom only.

Officially, of course, the foreign teachers are forbidden to use Chinese in class, which would take even this recourse from us. I choose to believe that after ten years of doing this job, I know well the difference between effective & irresponsible uses of L1 in the classroom. I'll use the right language for the right situation and the students' needs.

So, I am left now with how to better handle the problem of deliberately disruptive children in class. I am looking for advice and support for this problem.

Then again, I'm in two minds about this. First, it's a weekend job and if management, parents & colleagues don't care to address the problem, then our efforts in this direction will not be rewarded (indeed, may be punished) and instead we will be resented by all players, leaving us drained and depressed. On the other hand, if I truly see myself as an educator then a big part of my job is to address the morals, behaviour & study habits of my students. To be told by management that we can't do anything about naughty kids is insulting because they are putting profits ahead of education at the cost of our sanity and the customers' true benefit.

Tolerance of bad classroom behaviour is academic negligence.

Friday, August 23, 2013

It's Not What It Is; It's What We Say It Is

Swim to the shore...

The lessons were advertised as being forty-five minutes. They failed to mention, even in the fine print, that two such lessons are run back-to-back. When asked if that wasn't really just a single ninety minute lesson instead, they merely doped upon me the now very familiar look reserved for someone who's just made the socially unacceptable blunder of pointing out a reality contrary to the pre-established delusion.

Swim, like a mofo.

Monday, August 19, 2013

Geez, I Love Mondays

For the first time in many years, the customarily despised Monday has become a time of relief, recuperation and even rejoice. This absurd affair owes to working weekends, an arrangement furnishing me with a visa to stay here legally and the dollars to do so comfortably. Sadly, the Conservation of Misery principle demands recompense for this surplus of weekly joy, duly evidenced by the mess of Friday de'Night, Mostof Saturday and Allday Sunday lying beaten and bloody in the gutter.

Requiescant in pace dies felices.

Friday, August 16, 2013

Killer Artwork


Q: When is a zebra crossing not a zebra crossing?
A: In China!


They have zebra crossings here, but rather than act as traffic ordinance, they're merely pieces of artwork, carelessly disregarded by pedestrian and driver alike. For foreigners new to China, these pavement paintings are very dangerous indeed; wrongly assuming that they carry familiar authority is a sure way to end up under a bus (or truck, car or e-bike), adding your own crimson hue to the hapless drawings underfoot. Traffic lights have some following here, but many remain unbelievers and are yet to be converted to the faith. There is a strong adherence to the traditional belief models of "I was here first, so I get to go first" and "I'm bigger than you, so I get to go first". While these two schools of thought may at first appear to share common ideology, clashes between their respective proponents can often be observed at intersections all over the country. For new arrivals to the wilds of China's urban roads, my advice is to ignore any street signs, traffic lights and doodles on the bitumen and just follow the crowds. Don't follow the lone maverick straying across three lanes of flowing metallic indifference but rather clump with the herds crossing en masse at bewilderingly unpredictable moments in the chaotic gush and sputter (nothing ever truly stops) of torrential traffic.

Good luck.

Saturday, August 10, 2013

Rimming Vim

Vimmer, Luke Gruber, has released Riml, a ``Coffeescript for VimL``.

It looks pretty interesting at a distance.
I started dabbling with the beginnings of this idea a few years back, but Vigoriously never got past the Interesting Idea and Handful of Test Scripts stage. Kudos to Gruber for reaching the finish line.

I wish I had the time to play with it.

Tuesday, August 6, 2013

Wishing Birthday Happiness to a Vimmer

Ah, Raimondi!^[O, happy days^[D0wellmaiBro^[bai^[toayouth^[FoXxx,xJvex0xx