Sunday, 8 November 2015

/etc/hosts on OSX

I almost never post about a specific programming or setup issues, but this really caused me hours of pain so I try to prevent others going through the same.
OSX seems to ignore /etc/hosts file during DNS resolution. If you google it you will find thousands of results for different versions of OSX and hundreds of comments "it works for me" or "it doesn't work for me". The solution that worked for me I found in a comment of a blog entry. Permissioning. After adding global read access to /etc/hosts and everything works as expected.

sudo chmod o+r /etc/hosts

That's it. Hope it helps someone out there.

Friday, 5 June 2015

What does it mean to be reactive?

His presentation style and jokes are sometimes a bit annoying, but his approach is very systematic and easy to follow.

Monday, 18 May 2015

Emacs vs Vim

This is probably the oldest geek Holy War and I don't intend to join it. I just share my opinion and some (hopefully) objective reasoning why I ended up with Emacs.

From vim to Emacs

I used to be a vim user. Not a hard-core one, but I spent quite some time to configure my vim, setup some plugins and fixed a bug or two in a plugin when I needed it. Then recently I started learning Clojure. Because it is a Lisp dialect, Emacs is the most recommended and supported editor/IDE(?) for Clojure. Although by that time vim had an adequate Clojure plugin (vim-fireplace) I decided not to fight the community trends but give a go to Emacs. Even if that meant learning two (three, four?) new things at the same time: Clojure, Emacs, Emacs Lisp, ... It is not advised to put more obstacles in the way of learning, so I assessed the alternatives (Light Table, IntelliJ) but Emacs seemed the most beneficial to learn and Clojure is a good reason to learn Emacs the hard way.

I found Emacs a better tool than vim

I said "tool" not "editor". There is some truth in the old saying "Emacs is a great operating system, lacking only a decent editor." First thing first: Emacs is not a text editor. Emacs is a Lisp interpreter that runs whatever Emacs Lisp (elisp) programs are thrown at it. This is so much true that if you ask Emacs what function is executed when the right arrow key is pressed, the answer is:

<right> runs the command right-char, which is an interactive compiled Lisp function.

It is bound to <right>.

(right-char &optional N)

Move point N characters to the right (to the left if N is negative).


As you can see even the cursor movements run elisp functions. And this leads me to one of the main reasons I prefer Emacs to Vim.

Code quality

With all respect to the maintainers of vim, but that code base - all written in C with amazing portability - is a beast: a very complex and hard-to-maintain code. I didn't read the source code deeply, but there is a project, Neovim, that started as a fork of vim and one of their first achievements were that they reduced 300k lines of "scary C89 code" to 170k lines. Not that surprised: vim has a function 400 lines long... to wait for keyboard input!

Emacs, on the other hand, has a core written in C. It is fundamentally just a Lisp interpreter and display management. For those who think that it must be a very complex code: Lisp interpreters are one of the simplest programs a student writes at the uni when they learn about compilers. All the other functionalities of Emacs are written in elisp. Including all the plugins. Yes, elisp is not the nicest Lisp out there, but it is WAY nicer than C or Vimscript.
"The Emacs thesis is that it is delightful to create composite programs based on an orthogonal kernel written in a low-level language together with a powerful, high-level extension language."


Vimscript is the (primary) language of vim extensions. I have some experience with Vimscript and I can say that it is not a language I would like to write complex plugins in. It is a script language and in the good old days nobody really planned to extend vim with IDE capabilities. But in the recent years more demand raised to extend vim with complex features. Some plugins even cooperate with screen/tmux to meet modern expectations. Now, that is hacky!

And there is a huge philosophical advantage on the Emacs side: what other environments call "plugins" or "extensions" are here the part of Emacs. "Part" as in they are on the same level as the function that moves the cursor. I can't emphasise enough how amazing and powerful this is. No extension APIs, no restrictions, no limits.

The Emacs pinky

Yes, all those Ctrl/Meta(Alt)/Super key combos, they are almost a deal-breaker especially when compared to the fingers-on-the-home-row vim world. There are various workarounds for the Emacs pinky, some really strange ones. My solution is two-fold: I use evil mode, which incidentally is one of the best vim emulation out there. I also bind Cmd key (on Mac) to the Ctrl key of Emacs. The thumb is the most under-utilised finger during typing and this way I have a Ctrl on both sides in easy-to-reach distance.


I don't think emacs is the best text editor in the world. Far from that. But I would say it is the best open-source, extensible, multi-platform environment for coding. You can move to any OS, just get your configuration files, run Emacs and you are at home: never need to leave your familiar environment.

Thursday, 27 November 2014

Book rant: Functional JavaScript by Michael Fogus

O'Reilly books generally are really good. Not this one. I got only to the 32nd page but by that time I had enough red flags that I can recommend to never ever touch this book except if you need something to burn on a cold Winter night. This was the final straw (quoted from the book):

var bFunc = function() { return this };
var b = {name: "b", fun: bFunc};;
// => some global object, probably Window

The author uses this example to explain how the "self-reference semantics conflict with the notion of functional programming". Whatever that means. I really don't know what he meant and I will never know because the author doesn't get JavaScript. I had the same itchy feeling before this page; somehow the explanations are not clear, feels like the author himself doesn't "get it". I hoped that maybe the introductory sections don't try to explain what's going on and later in the book he does. Then I scanned the remainder of the book, just for the sake of this entry. No, he doesn't. Whenever he touches a topic that goes deeper than the conceptual level it's clear that he doesn't have enough understanding to explain it well. Or as the example above shows: sometimes he is simply wrong.

On a side note, and this is not the fault of the book, Underscore itself is a questionable functional library. It's a library that provides some higher order functions which resemble the ones used in real functional programming. But that's it. It's a shallow substitute and doesn't help you master thinking in functional programming. The guy in that video (Brian Lonsdorf) has an online video course. I haven't seen it yet, but I believe it must be a good one. However what I can strongly recommend is if you want to learn real functional programming in JavaScript go and read JavaScript AllongĂ© from Raganwald. For free if you wish. Then pay as much as you want to. Because that book is a piece of art. From somebody who does understand functional programming and does understand JavaScript.

Wednesday, 17 September 2014

Chrome has an 'antivirus' tool now

Chrome is my chosen web browser. Not because it is the best browser (which it is imho). But because it is the best OS. It is the case for many years now that you can do (almost) everything in your web browser. Although some browsers just recently learnt how to do it properly, the 'rendering webpages' is just a basic functionality that a good browser provides. You can login to Chrome. With multiple accounts on the same hosting environment (= that 'real' OS that runs the one you actually use). And install applications, plugins, extensions, themes. And the next evolutionary step: it requires now an 'antivirus' software. Technically speaking we are not talking about viruses. It is spyware/adware/malware extensions that can steal your data spy on you or break your browsing experience. I hope Google will embed this in their OS sooner than Microsoft did it for Windows (see: Windows Defender).
Google Software Removal Tool (beta)

Tuesday, 10 June 2014

Microsoft should learn how to demo

I am watching the MS Build presentations. So far I haven't seen a single one that "just worked". Here is my favourite one:
"The Nokia 630 is awesome. I happened to have one here, I was gonna show a demo on it. Ahm, apparently my TV device... and this is not a TV so it won't work. But look. It's great. I love it. It's an amazing device."

30 minutes later, same presentation:

Well, he could use that information to show off his great Android device on that non-TV :)

Sunday, 1 June 2014

Clojure - a liberal language with a conservative community

After playing with the idea of learning Haskell, Python and Ruby, eventually I chose to learn Clojure. I only understand now why it is such an appealing choice for me.

Steve Yegge is a technical blogger who used to write very long blog entries. It's worth to read all of them. And his drunken blog rants as well. He worked for Amazon (the drunken blog period) then he moved to Google. And believe me: he knows the world of programming languages. He probably wrote more language interpreters than languages I've ever touched. This week I found another long piece of his thoughts. TL;DR for those of you with short attention span: Steve introduces the terms `software liberal` and `software conservative`. The statement is that software engineers are also (software) liberals or conservatives. This, just as in politics, means that one group can't understand the other no matter how much they argue, simply because their value systems and beliefs differ. Steve places companies and programming languages on this axis as well: Microsoft and Google are conservative, Amazon and Facebook are liberal. Ruby, JavaScript, Python, C, Java, Clojure, Haskell - from extreme liberal to extreme conservative.

Then he picks a language that recently I am the most interested in: Clojure. In his early days with Clojure he liked it so much that he even wrote the foreword for The Joy of Clojure. That's one of the most important Clojure books out there (2nd edition's just released). Steve is a "hard core software liberal" and when he found that the Clojure community is conservative he turned from the language. I think Steve missed to emphasize this point: the language can sit on different side of this metric from its community. Clojure is a liberal language by all means. Even Steve knows that. And yes, the Clojure community is conservative. Liberal languages are powerful and sexy. If you say "But JavaScript is not sexy!" you should read JavaScript AllongĂ©. Liberal communities, however, are kind of a mess. At least for me they appear so. Just have a look at npm.

Software engineers with different views cannot agree on programming languages. That means it is pointless to say "Clojure is the best because..." All I can say is that for me Clojure is the best combination: a liberal language with a conservative community.