Saturday, 28 July 2007

Silly language design decisions.

Didn't know that before:

Perl's zipping operator

Every self-respecting dynamic language has a zipping function (or method). Python has its built-in zip(), haskell as well. Ruby gets it implemented as one of Array methods. I just didn't know (untill 3 days ago), that it's particularly useful for perl programers. Unfortunately, its name is THREE CHARACTERS LONG! O_o, that is waaay too many. That's why Larry Wall introduced zipping operator. You wonder what is it? Isn't that obvois? It's Yen symbol! Come on, it looks like a zipper anyway!

Genius.

Except for the fact, that there are _two_ Yen signs in unicode (¥ and ¥). And only one is recognised by the parser. Lame. Fortunately, Larry changes it to 'Z' in perl 6

Take a look on Jonathan's blog entry

And some quotes:

The zipper/yen operator has been renamed to Z. This is good for me, as I’ve never been very good at memorizing Vim’s digraphs.
Maybe we should avoid other symbols like this for sigils
BTW, the exact same thing happens with the Won sign ₩ on Korean Windows
systems; it is also mapped to 0x5c in the default codepage, and paths
are displayed with the Won sign instead of the backslash as separators.
Just something to keep in mind in case you are tempted to use the Won
sign as a sigil or operator in the future.

Cheers,
-Jan

Visual Basic AndAlso short circuit operators

Well, story is simple. When Visual Basic was designed, either no one knew about short circuit operators, or they didn't recognise their virtues. And years after, they couldn't stick it in because of backwards complatibility. But they found a solution eventually: AndAlso and OrElse operators. Simple, isn't it? AndAlso it doesn't break the compatibility. I only wonder why OrElse is OrElse and not... let's say OrPossibly or OrMaybe or OrHowAbout.

Thursday, 12 July 2007

How to get a decent console under Windows

The reason

I had to switch to windows for some time and, after working under ubuntu for over a year, I finally realized what linux users meant when saying that win wasn't userfriendly. Linux' great power comes from its extensibility (obviously) and customizability. The poor support for the latter drives me mad every time I need to use win. It took me couple of days to set up a usable and useful console, so hereby I include the recipe.

Tabs and good look

Since being console under windows means running in one, to get a tabbed view we need to download a wrapper. Its name is, surprisingly, Console and the tabs feature is enabled in latest versions (Console2 has it, while 1.5 not. if you download the latest version (>2.0.131), you will get multiple shell support as well). There's no need to install. Just extract, run the Console.exe, et voila. Much prettier, isn't it. It is a good idea to put the folder in some appropriate place (like c:\Program Files\Console2).

Shell

Next thing we're gonna need is Powershell. I still haven't dicovered all its features, but tab completion, automatic slash-to-backslash convertion and aliases to many bash commands (including man and ls, yipeee!) makes it good enough for me. You can download it from microsoft's site. To get Console running with powershell you can use its options window (Edit/Settings...).

Multiple shell support

Console can use multiple shells. How does it work? Say, you prefer using powershell, but it's not fast enough for your machine. Or you use apps with command line interface quite often (python, mysql, irb). Here's how you can get Console to use all of them: open the console.xml file in your console dir, and find the <tabs> tag. Every tag is a preset for a type of console to open. There is only one <tab>...</tab> entry now. Duplicate it, and edit the shell attribute in the <console> inner tag. Here's what the section may look like afterwards:




<tabs>
<tab title="Powershell">
<console shell="powershell" init_dir=""/>
<cursor style="0" r="255" g="255" b="255"/>
<background type="0" r="0" g="0" b="0">
<image file="" relative="0" extend="0" position="0">
<tint opacity="0" r="0" g="0" b="0"/>
</image>
</background>
</tab>
<tab title="IronPython">
<console shell="ipy" init_dir=""/>
<cursor style="0" r="255" g="255" b="255"/>
<background type="0" r="0" g="0" b="0">
<image file="" relative="0" extend="0" position="0">
<tint opacity="0" r="0" g="0" b="0"/>
</image>
</background>
</tab>
<tab title="Python">
<console shell="python" init_dir=""/>
<cursor style="0" r="255" g="255" b="255"/>
<background type="0" r="0" g="0" b="0">
<image file="" relative="0" extend="0" position="0">
<tint opacity="0" r="0" g="0" b="0"/>
</image>
</background>
</tab>
<tab title="Windows shell">
<console shell="cmd.exe" init_dir=""/>
<cursor style="0" r="255" g="255" b="255"/>
<background type="0" r="0" g="0" b="0">
<image file="" relative="0" extend="0" position="0">
<tint opacity="0" r="0" g="0" b="0"/>
</image>
</background>
</tab>
</tabs>


Keyboard shortcuts

You get by default shortcuts Ctrl+F1, Ctrl+F2, etc. for shells you set. It's customizable (obviously). It is a useful trick to define hotkeys for launching Console, so that you can run it whatever window is active. There are plenty of hotkeys deamons for win, that let you do that. I'm using Hot Keys Plus

The final effect

Here it is.