Saturday, 10 September 2016

Embrace the platform

Instead of building with tools, and using all of these tools to build our website and we ship all the tools to our users, essentially. What if we would write using the primitives on the web and then what the users get is just a slightly augmented version of that depending what their browser support. So it's like our tools become part of our deploy process, but not part of our development process.

Thursday, 2 June 2016

Clojure code browser in Emacs

A post from ProDevTips blog landed in my feed reader through PlanetClojure's RSS feed describing a custom-developed Clojure function browser in Emacs. I just wanted to post a simpler, built-in solution because I had this in my configuration and I find it a really neat feature. First, here is the end result:
Clojure function browser in Emacs
The package that does the magic is speedbar and sr-speedbar. Speedbar is a built-in feature of Emacs, the sr-speedbar package embeds speedbar in the buffer's frame, because otherwise it opens in a new frame. And to make speedbar work with Clojure you need this in your init file:
(require 'speedbar)
(speedbar-add-supported-extension ".clj")
For me this worked out-of-the-box, but I think it relies on one of the Clojure or programming packages I configured earlier. Here is the list of my packages that I think can be related:
  • cider
  • ac-cider
  • clojure-mode
  • projectile
  • company

Sunday, 15 May 2016

The decline of Programming

MIT has changed their curriculum some years ago: they started using Python instead of Scheme as they did in the legendary 6.001 introductory course, the one that gave us SICP. UC Berkeley did the same and many other universities use Python now in their introductory courses. What's wrong with that? Lisp is a niche language(family), almost nobody uses it today, it was a mistake in the first place to teach it for so long, very academical and useless knowledge. And I disagree. Yes, Lisp is not widely used, to say the least. And yes, Python is one of the most productive languages out there. This is amazing. I don't think such an easy solution would be possible in other programming environments. My problem is not with Python per se. The problem is that Python is completely inadequate to teach programming principles. It is a nice language to use but it is a terrible language to teach any principles. Let's see for example object oriented programming. I am not a big fan of OO, but if there is something worse than OO that's OO implemented badly. And Python's OO is the worst I've ever seen. Actually it fails so badly that, in my opinion, it's a mistake to call it OO in the first place. Or let's talk about parallel programming. It's a fact that one can't ignore parallel programming in the recent and especially the coming years. Yet, Python has no real answer to overcome the limitations of GIL. It is not the topic of an introductory course, but it's basically impossible to teach parallel programming principles using Python.

These are theoretical arguments. It is still a fact that Python is about a million fold more useful language than Scheme. So the question still stands: What's my problem with teaching a so much more practical language instead of a theoretically beautiful but more or less useless language? My problem is the degradation of Programming as an art and intellectual activity to a mere Coding as a conveyor belt job. It's not a new thing, it's happening for quite some time now. More about that in another post. But what makes it really bad now is that the most prominent institutes accepted and have signed up to this trend.

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 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.