Ruby again, part two.

This is a continuation of my previous post, based on new information.

I shall quote chalain directly:

<Chalain> It's a combination of two things.
<Chalain> 1. Ruby allows you to drop the semicolon if a statement parses to a complete expression. So the 3+2 gets parsed as an expression.
<Chalain> 2. "Everything returns" in Ruby. Like most languages, you can accumulate return values on the stack, and they get ignored.
<Chalain> So
<Chalain> (3+2; +4) is a legal expression. It returns 4.
<Chalain> A legitimate use of this would be, for example, (puts "It broke!"; logger.error 'It broke") if x>0

So, it's deliberate behaviour rather than a parser snafu. I am still of the opinion that it is broken, I have just changed where I'm pointing. I don't think parentheses should be used in this way. There is a perfectly good multi-expression conditional syntax, and it puts the if at the beginning rather than the end. Parentheses should enclose a single expression only rather than trying to be braces or begin/end as well.

Ruby is full of little things like this, where small wins and "it would be nice" features litter the language with booby traps.

Ruby again. This time the parser.

Disclaimer: The following was written while I was furious and frustrated. Please bear this in mind if anything offends you.

Until I came to my senses, I had actually fired up an editor to update my CV so I could find a job that wouldn't require me to fight with the festering pile of yuckiness that is Ruby. Consider the following irb session:
>> (1 + 2 +
?>     4)
=> 7
>> (1 + 2
>>   + 4)
=> 4

As far as I can tell, if the linebreak results in two valid expressions, the first is thrown away and the second is used. Why this is the case, I have no idea. All I can surmise is that whoever wrote that bit of the parser was smoking crack. The fact that this hasn't been picked up and fixed just demonstrates that the Ruby community completely fails to care about quality. I can't even find reference to it on the internet.

Ruby has long been way down on my list of languages to use. It has just dropped into the same class as PHP and Visual Basic. Congratulations, Ruby. I didn't think you could get worse. You did.

Edit: This saga continues in a new post.

Zimbabwe sanctions... or not

Have a look at the following BBC news article:

http://news.bbc.co.uk/2/hi/africa/7503135.stm

Now consider this. South Africa had sanctions imposed (and rightly so) because a legally elected government was oppressing part of its population. Zimbabwe doesn't have sanctions imposed because an illegal government is oppressing all of its population?

This whole thing makes me sick and is a reminder of why I should stay as far from politics as I possibly can.

Don't bring thin skin to the internet

I had an all-too-frequent argument this evening. This resulted (as it occasionally does) with the other person storming off in a huff, all offended. The conversations usually goes something like this:

Him: I like $broken_technology.
Me: $broken_technology is very seldom a good idea. Why do you like it?
Him: Because $common_misconception.
Me: Actually, that's a common misconception. $correction.
Him: But are there any $not_broken_technology things that do $common_misconception_thing.
Me: Yes, plenty. For example, $thing.
Him: Um, but $other_misconception.
Me: Actually, $other_correction.
Him: You people are a pack of technobigots! *storms off in a huff*.

Part of the problem is that I suffer from SIWOTI Syndrome. I find it incredibly difficult to just let people sabotage themselves because they believe something that is not true. Part of the problem is that I want to teach people to think rationally about their behaviours and motivations, because it's the only way to avoid muddling around in a fug of lies and excuses. Part of the problem is that I get too emotionally invested in trying to better the lives of strangers when I can see exactly where they are making their mistakes and have the data to back it up.

Also, to be perfectly honest, I like to be right. I like to dispense wisdom. I enjoy being the expert people come to when they have a programming problem. Being the authority is nice. It makes me all warm and fuzzy when people do something better because of advice I gave them.

The real problem is that people don't like to be wrong. Thinking is hard. The misconceptions are comfortable old friends. The work they have done under those misconceptions represents effort that they may need to throw away. This makes people defend their misconceptions. It also makes them see an attack on a misconception as an attack on them personally.

This is where the subject comes in. As soon as you take anything on the internet personally, you're opening yourself up to pain. It hurts me when my laboriously collected wisdom is written off as bigotry. It hurts you a lot more when you take a request for data backing up your assertions as "getting ganged by zealots".

I don't really have a good answer. I could probably be a bit more diplomatic, but it's difficult to say "you're not making sense" in a way that doesn't offend those with delicate sensibilities. I could just ignore people being wrong, but occasionally I do enlighten some poor soul who has merely been led astray by the propaganda machines and is capable of becoming a useful and productive member of the community. (That's not to say the others aren't, just that they need to shed some ego first.)

Another side effect of my SIWOTI is that I often come across as arrogant. Sometimes this is me misjudging the level at which to pitch my explanations and coming across as patronising (if I pitch too low) or elitist (if I pitch too high). Then if I ask a few questions to judge background, I'm interrogating instead of helping. Sometimes it's because I tell people they're wrong. If I kept quiet or only answered the questions asked, even when they pointed to deeper misunderstandings or flaws, I could avoid these issues. But then people would keep being wrong. And we can't have that.

Idiocy on residential roads

Dear white minibus, registration CA 688-820,

Stopping on the side of the road (even the wrong side of the road) while the driver goes into a house on a residential road is fine. Doing so next to the only other parked vehicle on the other side of the road, leaving a space too narrow for anyone to drive through is, however, antisocial to the highest degree. Doing this when there is no alternative route that does not require getting back onto a busy main road is positively psychotic.

No love,
Me.

Further to the above, a note to the pedestrian who stopped on the corner, looked at my car with its indicator on, and then proceeded to cross the road I was turning into just as I turned into it: The only reason I stopped is that I don't want to have to deal with police on a Sunday. Next time, you will be run over.

This one isn't really Ruby's fault

Consider the following regular expression, designed to validate a tab-separated string and extract data from it:
>> t = "a\tx\tb"
=> "a\tx\tb"
>> re = Regexp.new("a\t\S\tb")
=> a    S       b
>> re.match(t)
=> nil
>> re = Regexp.new("a\t[^\t]\tb")
=> a    [       ]       b
>> re.match(t)
=> #<MatchData:0xb7e57c90>

This, at first, had me glaring at the docs for Ruby's regular expressions to make sure \S was implemented as I expected. The second version was more restrictive, yet it matched where the first version failed. After a few minutes' fuming, I got the inklings of an idea and tried the following:
>> re = Regexp.new('a\t\S\tb')
=> atStb
>> re.match(t)
=> #<MatchData:0xb7b411dc>
>> re = /a\t\S\tb/
=> atStb
>> re.match(t)
=> #<MatchData:0xb7ae8c1c>

Then it hit me. See, Ruby double-quoted strings interpret escape chars. The reason \t worked above was pure coincidence -- it evaluates to a tab literal, which is treated the same as \t in a regex. Thus, in my original case (turning a bunch of strings into regexen) I could use single-quoted strings if I didn't have to interpolate values into them. Unfortunately I do. For reasons unrelated to this post, I can't use regex literal syntax which allows interpolation but does not evaluate escape characters.

Once again, Ruby foils me. This time, however, it managed to foil a righteously indignant rant about regex escape sequence handling. Go figure.

Another open letter

Dear people at Landis+Gyr,

Thank you very much for selling my landlord one of your remarkable prepaid electricity meters. Since it is a remarkable meter, I shall remark upon it. Hence this open letter. The particular unit upon which I shall remark is a CASHPOWER CIU 3.

This unit has a marvelous feature whereby it will helpfully beep at you loudly when it thinks you need to buy more electricity. What is not quite so marvelous, however, is the time period during which it decides to do this. I have let my electricity supply run low enough to trigger the warning twice. The first time, I was awoken at about 03h30 and the second 01h45. Now, while the fact that I have a mere two days' credit left may be dire enough to warn me, doing so at a time when I am entirely unable to go out and purchase more seems somewhat counterproductive.

In an effort to figure out just what triggers this warning, I sought documentation, as any rational member of this technological age would, on the internet. I came up with absolutely nothing of any use to me. I suspect some kind of internal counter is being checked, since my usage was different both times and the offending credit remaining was approximately 32kWh.

While I am on the topic, it would be much appreciated if future versions of this device would include a backlit display so that when one is dragged from bed by the insistent call of the electricity meter, one does not have to fumble for a light source before investigating.

Also, the cheery little tune played when new credit is entered does not make up for the interrupted sleep.

Yours,
jerith

The Great Train Jol

A week or so ago, a certain Jonathan decided it would be a good idea to take the train down the peninsula and have a day of fun and relaxation on the public holiday. Since I live about 150m from the Diep River station, I was the last person to hop on the train as it headed south and the jol1 was already in full swing. We enjoyed the relaxing trip down to Kalk Bay, although there was the occasional mild panic to figure out which station we were at to make sure we didn't overshoot.

We got to Kalk Bay at around 10 and went wandering down to the pier to look at the fishermen and watch the seals playing. When we got tired of that, we found a coffee shop/restaurant/eatery that purportedly sold sushi (although we were too early for that) and breakfast (although we were almost too late for that) and beer (which was warm). I held out and had a coffee first time around, but snagged a spare Windhoek with the second round when the waitress brought too many of those and not enough Heinekens. After some juggling of varying-denomination paper money, we had the bill paid and train fares sorted out. (Jonathan had bought a stack of tickets, we needed to repay him and he needed to dish out some change.)

After that, some of us headed down to the bookshops and antique dealers and browsed a bit while the rest went and did their own thing. We were starting to get peckish, so we arrived at the Brass Bell about 45 minutes early for our lunch reservation. Our table was ready anyway, so we had more beer and waited for the other half of the party to catch up before we did the food thing. There is an unwritten rule that when you go to Kalk Bay by train, lunch is fish and chips. Graham missed this somewhere, and had to send his burger back to be reheated.

After lunch, we got back on the train and went to Simonstown. We wandered around a bit and ended up at a place where they do awesome ice cream. I don't know about the ice cream, but they do really yummy pancakes. After chilling there for a while, we marched back up to the station and caught the train back home. My jol ended a bit prematurely when I got off before anyone else, but it was an awesome day nonetheless. We really should do this more often.


1. For readers abroad: The word jol, like the word kief, is a generic South African word. It refers to having a good time and is used in any context. "I am going on a jol (party)." "I am having a jol (good time)." "That spectacular wipeout at Super Tubes was a jol (rush)." -- Surfrikan Slang

On Ruby

A programmer I admire greatly twittered the following today:
Dear Ruby haters: I used to be afraid of the table saw until I learned how to use it safely. This did not involve nerfing the table saw.
I have great respect for this man, but we have a fundamental disagreement about a language he uses by choice and I use by necessity. I have a bunch of disagreements with the language, but my real problem is with the community. To continue with the power tool analogy, Ruby is a table saw with all sorts of dangerous fittings on it. It is powerful, and in skilled hands it can be exceedingly useful. However, part of the power is that it is easy to replace bits of the drive train or add extra blades as requires. Now, this is a non-issue in skilled hands. The problem is that many of the extra fittings and modifications are not built by skilled hands, including the manufacturer-supplied brand-stamped officially-approved ones. These dodgy fittings usually work fine, but can occasionally unleash a maelstrom of whirling metallic doom.

Back to reality from the analogy. The Ruby culture seems to value "clever" code and metaprogramming even when there are better alternatives. Individual programmers or competent teams can overcome this bias, but eventually they are going to want to use third-party code or some of the darker corners of the standard library. This is where the pain really starts.

SMS spam insanity

I received the following SMS today:
Need airtime?Buy it with your Visa or Visa Electron card at most supermarkets. No need to draw cash- U get 1 eXactcredit-To stop msgs,sms STOP SMS to 32227(R1)

Firstly, this is pure spam. Secondly, they want to charge me to use a premium service to remove myself from their list. This is, to me, completely unacceptable.

I did some research. It turns out that there is an organisation called WASPA that deals with Wireless Application Providers. Their list of members includes eXactmobile, which seems to fit the message ("eXactcredit"). They also have a code of conduct, from which I have copied the (abridged) relevant part:
5. Commercial communications

5.1. Sending of commercial communications

5.1.1. All commercial messages must contain a valid originating number and/or the name or identifier of the message originator.

5.1.2. Any message originator must have a facility to allow the recipient to remove his or herself from the message originator’s database, so as not to receive any further messages from that message originator.

5.1.3. Any mechanism for allowing a recipient to remove him or herself from a database must not cost more than one rand.

5.1.7. Upon request of the recipient, the message originator must, within a reasonable period of time, identify the source from which the recipient’s personal information was obtained.

5.2.1. Any commercial message is considered unsolicited (and hence spam) unless:

1. the recipient has requested the message;
2. the message recipient has a direct and recent prior commercial relationship with the message originator and would reasonably expect to receive marketing communications from the originator; or
3. the organisation supplying the originator with the recipient’s contact information has the recipient’s explicit consent to do so.

5.3.1. Members will not send or promote the sending of spam and will take reasonable measures to ensure that their facilities are not used by others for this purpose.

5.3.2. Members will provide a mechanism for dealing expeditiously with complaints about spam originating from their networks.

This message is definitely spam and, although the opt-out message meets the WASPA requirements, I see a paid unsubscribe mechanism as extortion.

I have contacted both eXactmobile and WASPA (the latter because I am not entirely certain that eXactmobile is the culprit). Updates when I hear from them.

Update: eXactmobile phoned me, and have removed my number from their db. It turns out that I was in there because I signed up for something five years ago and didn't uncheck the "you're allowed to send me crap" button. Go figure. Bonus points to WASPA for sorting it out quickly.