Skip to content

Archive

Category: Vim

I’d like to say that I write useful code all the time, but let’s face facts… useful code doesn’t come around all that often. In my new job I’m using Maven instead of SBT and I miss the cool tilde modifier in a big way. And now that I’m using the Artima book building strategy – which is based on Ant – I miss it even more.

So I finally wrote this little script that’s saving my ass.

I tend to use it in a number of different ways, but one of the simple ones is like this:

And that’s all she wrote.

Back to ZSH

Mar 16

A little while ago, I gave up on Zsh. There were a number of people that showed me how I could have fixed up Zsh so it would suck less, but I just didn’t have time. Well, I found myself with some time yesterday that couldn’t be spent doing much useful, so I made the switch.

It now feels like Bash but a little bit better, so I’m pretty happy. Thanks to @datanoise, and others for the tips.

Here’s what I did to make it useful:

  • unsetopt nomatch: I have no idea why this defaults to “on”. It’s useful about %0.00001 of the time and a pain in the bloody ass the other %99.99999 of the time.
  • Use bindkey -v instead of the vi-mode plugin: This is also odd. Most of what is needed (the prompt stuff) is pointless eye-candy and the zle reset-prompt is just an awful feature. You hit ESC-\ and it deletes the line above… which a lot of the time, carried data that you really wanted to read.
  • Ported my directory stacking stuff to Zsh (just barely :D). I can’t leave this feature behind… without it, running around the filesystem is a major drag.

My config can be found on GitHub if you’re interested in having a look.

I recently responded to someone’s question on StackOverflow and now I have to rant about something.

There is a large problem I find with programmers that I meet (generally in Real Life, as opposed to on the ‘net because on the ‘net I associate with passionate programmers) when it comes to learning new “stuff”. The first thing they do is try to draw it close to something they already understand. For example, they pick up Python and try to relate it to something like Java. This is not a problem.

The problem comes from the fact that it’s not just the first thing they do, it’s also the last thing they do. Why is this a problem? Oh for so many reasons…

It’s new

Relating this ‘new’ thing to something you are familiar with is vital in the first stages in order to get a foothold on a new experience. But once you’ve got that, you need to forget it.

Let’s take a new language as an example. If you’re a Java coder and you’ve never coded in Ruby before, then when you see Ruby you’re going to be looking for objects. This is all well and good, and it gets you into the language so you can start expressing your ideas. Awesome. But if Ruby was just a scripted Java then it wouldn’t have a lot of use, would it?

What you’re going to miss with Ruby (among about a million other things) is that Ruby is very much about functions and not so much about objects (Ok, I don’t want to get in a big debate with people here… I get it, it’s about objects too… and a lot of other stuff). And missing this means you’re going to miss out on a solid opportunity to enhance the way you think about designing and writing software.

Languages are not nearly as important as the paradigms they help you express. All we do for a living is think and the better you can think about your problems and their solutions, the better you are at what you do.

It’s not that other thing…

If the “other thing” you’re used to is worth anything at all, then it’s going to have some “good points” to it – it damn well better have. The “new thing” is going to have good points too, and they’re going to be different than those in your wheel house. If you’re used to feature X, chances are you’re not going to see feature X in this new thing. Why? It’s not that other thing. Seems obvious, right? If it’s so obvious then why do I see so many people not getting it?

Here’s an example. There’s a colleague of mine that loves Erlang – great language, and it’s awesome to love it. When talking about Akka, he asked me whether or not you could hibernate an Actor (closest equivalent to an Erlang ‘process’ as far as our discussion went). I said “no”. I was immediately met with statements like, “It must have that or it’s no good,” and stuff like that. What he didn’t grasp, until explained, was that Akka is modeled completely differently and has no need of the hibernate functionality. This is a fundamental difference between the two designs – and there are definite trade-offs being made for many different reasons. The point I’m making here is that, unless I explained it, he would have written off the technology based on a fabricated fantasy.

If you expect a new thing to be exactly the same as the old thing, then why would you look at the new thing? It’s not that other thing!

It misses the whole point

I’ve already said this earlier but it’s a very general idea. How many ways are there to solve problems in our industry? It’s pretty much infinite, right? I can select any language I want, for starters. I can then choose any tool within that language, or I can choose another language and bolt that on to help solve the problem. I can use existing programs or libraries from anywhere else to do it. And I haven’t even started coding yet. Once I start coding, I can code in nearly any paradigm I want to, or any hybrid set of paradigms that I want to (made easier by a multi-paradigm language of course).

So, let me ask you this: If all you know is one language, and one set of tools, and you view every other language and every other tool through the foggy lens of “what you already know”, then how many ways are there to solve problems when you’re the one solving it? Not many, right? You’ll probably come up with solutions, but if they suck, you’re stuck – you have no other tools in your head to help solve these things. You’re stuck with sucking. Not awesome.

The whole point of learning new things is to learn new things. Please, if you find yourself looking at something and scoffing and saying “Well, it’s not like this other thing that I’m comfortable with”, then say “GREAT!” If you find yourself outside your comfort zone then you’re doing it right.

If it were comfortable and familiar then you wouldn’t be learning, and if you’re not learning, then stop what you’re doing and go back to doing something productive with what you already know. Save that time for finding something to learn that you’re really not comfortable with.

Ok, so everyone and their grandmother appears to be using Zsh and I was starting to wonder what was wrong with me. Why was I still using Bash? So I grabbed Oh-My-Zsh (which was pretty cool, BTW) and dove in… but here’s the problem – I didn’t have time to dive in.

I’m sure that, had I days to dedicate to getting Zsh working, that I would probably find the “right” way to use it, and make myself happy. But, given that I just wanted to start using it and figure things out later… well, it absolutely f’ing sucked! I got no benefit from this approach and a lot of pain. Here’s why it sucked:

  • In bash, if I type — grep thing.*other myfile.txt — and — thing.*other — doesn’t glob, do you know what I get? That’s right, I get — thing.*other. With Zsh, I get an error.
  • Same thing for — sbt ~test. Blurgh!
  • I like a two line status. It keeps all of that long path information, git stuff, and whatnot on a line by itself, and then gives me a whole fresh line for writing commands. I get this in Bash, and I get this in Zsh. Difference? Every time I hit — <ESC> k — in Zsh, it would erase the line above it – a rendering bug. You know what? I really needed to read that line, thanks very much.
  • The directory stacking is pretty terrible, which is insane considering that “cd” is the command you probably run more than any other in the shell, by far.

There were some other annoying bits too, but not too big of a deal to mention.

The bottom line here, is that before I would be able to successfully use Zsh, I would have to figure out how to get it to stay the hell out of my way. Said another way: If there’s a feature of Zsh that I only use 0.5% of the time, then it should not be defaulted to be on 100% of the time such that 99.5% of the time I have to protect myself from it.

I know, I know… I didn’t give it a chance. Very true. What I was expecting was that I could use it and access features when I was willing to head down that path, but what I found was that I spent nearly all my time working around annoyances just to get things done.

I’ve put my Vim configuration on GitHub now. Have a gander at http://github.com/derekwyatt/vim-config

The Vim ‘indent’ script for Scala that I’ve been working on is now starting to take some decent shape. If you’re a Scala coder and are working in Vim, I can now actually recommend this script :). It’s actually the least complicated one I’ve written that achieves this level of functionality; I’ve had a few kicks at this particular can and one of them in particular was way complicated and also slow.

Go grab it from Github.

Posted with WordPress for BlackBerry.

I found some time to update the indent file for Scala recently. It’s getting better and more complicated, unfortunately. Please feel free to fork it and make changes/fixes… I hate writing this thing :)

Grab it from my vim-scala repository on github.

Posted with WordPress for BlackBerry.

So, a little over a month ago, I changed departments where I work – I used to work in the Enterprise Software group and have moved to the System Architecture / Research group. There are some great things that go with this:

  1. I get to work with Vim more than I used to because I now code a lot more than I used to.
  2. I’ve effectively deleted Windows entirely and replaced it with Ubuntu (YAY!)
  3. I’m getting a chance to deeply investigate Scala and Akka, which is a real treat! My research may not go anywhere, but the research itself is incredibly useful, I think – Scala and Akka are absolutely fantastic projects.

Once I figure out the right path to take in order to get some changes into the Scala repository for Vim, I’ll do that, but for the moment I’m just having a great time banging away at the docs and shoving things in my own repository.

What I’ve got at the moment is a 4000+ line reference file (in Vim help format, of course) that I’ve put together to help me better understand Scala, and give me a spot to put some critical information and tips / tricks I find as I go. I’ve also fixed up the indent file a bit and plan to enhance the syntax file when I get a chance too.

Because of Scala’s flexibility and terseness I find it a bit difficult to create code snippets for it, but I may do that in the future as well.

If you’re interested, head over to my vim-scala repository on GitHub and clone it down to your vim configuration.

Well, I got another patch from someone for protodef. It was just getting silly that I didn’t have anywhere to actually put this stuff and I was getting tired of people sending patches :). Now y’all can just fix stuff for me directly… go to it.

Head here for protodef.
Head here for fswitch.

I’ve finally updated FSwitch and ProtoDef after a long time waiting. Three guys gave me patches over many months and I’ve finally put them together into an actual couple of releases.

Thanks to Matt Spear, Timon Kelter and Dmitry Bashkatov. Sorry about the wait fellas.

Switch to our mobile site