Categories
Programming

Language of the Month: Rust, the results

Every now and then I do a “Language of the Month” feature when I spend one month to learn a new programming language. This last month in November I’ve spent with Rust, and it’s time to take stock. Will look at the impression I had in this short time, show one project that I get done in Rust, and some ideas what I’d like to do with Rust in the future!

Experience

According to my time log, I have spent about 20 hours this month learning Rust. That’s way too little to have a good understanding, but definitely enough to have some educated guesses (and excitement, and horror , as appropriate). This time I’m generally very impressed as Rust comes across as indeed a very modern and smart language, although that modernness is mostly in the tooling and non-essential parts. It is also changing very quickly, for good and bad. Here are some, admittedly subjective and incomplete list of observations. Good is what I like, Bad what’s less nice IMHO, and Ugly is what’s imperfect or confusing (at this stage of my Rust learning):

Good

It’s great to see that documentation is a not an afterthought, but a core part, that is making use a lot of modern development experience. Having a standard way to include example code in docstrings and actual tests are run on them to make sure the examples are also up-to-date with the code is a very cool concept. Also being able to auto-generate HTML documentation from the code is probably going to be standard in most new languages (I think Go does that also, and other languages have gained similar optional tools)

Categories
Learning Programming

Language of the Month: Rust

I found it hard to believe, that it’s been 4 years now since I finished the previous installment of “language of the month” column, in which I pick a programming language and dive in for a month to see something new. In that 4 years I have learned a lot of programming for sure – though probably very little computer science, and barely any new languages. It’s time to chance, and for the revival of this I’m checking out Rust.

Categories
Programming

Language of the Month: Javascript

Continuing the Language of the Month serious after a little bit of break when I was busy with other stuff:

Javascript icon
Just a Javascript icon...

It is very long overdue, since I was looking at Javascript like…. 14 years now? But never really spent time to understand it because I never needed it really. I’m old enough to remember that when I started to browse the web, every time there was a page using Javascript, people’s sentiment was “oh, no, that’s going to be very slow, I don’t even want to check this site anymore”. Pretty much like it was/is with Flash later on.

Compare this to now, how 100% static sites are practically disappeared, and no web developer worth their salt should skip on learning it. I’m glad that browsers spent a lot of time improving performance and that so many interesting projects came out of it.

My impression of the current state of the art is that using HTML + CSS + Javascript now it is easier than ever to make good front-ends for programs. I’m mostly a command-line guy (and that’s pretty easy with many scripting languages as well as Python that I use), but I cannot deny that I’m the minority. Still, when i need convenience, I can even imagine people creating local (meaning not internet-enabled) software with those things.

Since more and more people had similar idea and started to work on it, there are plenty of projects that make this even easier, like jQuery and all its plugins. I don’t think people need a lot of introduction and already can do a lot of things easier using that. One drawback is that many things could be just as easily done in pure Javascript but people quite often don’t know that. I certainly have to learn a lot more.

In this month I was reading a few books and sites that people recommended on Hacker News, as well as I used it to do a few actual projects. Now that’s a change compared to the previous Language of the Month columns.

Projects

WatchDoc: a Chrome extension that notifies you when your shared documents on Google Docs change. Chrome extensions are merely HTML+CSS+JS code, so it was a perfect way to try a few things. (Will write it up here later) (wrote up here).

NowJS real time games hackathon: NowJS is a real-time communication plugin for NodeJS, the JS server. I wanted to make a game for this hackathon, but run out of time. Spent some time working with it, and it’s actually pretty awesome when I started to understand it, I’m do want to finish the game at a later time (it’s a multiplayer trivia game) . (Will write it up here later)

Venus & Mars: a little afternoon project using Facebook to help my friend’s research assignment at her university. Listing people’s status updates separated by gender. It looks awfully ugly, because I just wanted to make it work, but for the fun of it it’s NodeJS so good to practice my JS-foo.  (Will write it up here later)

Impressions

I definitely going to learn more of it, because now that I start to understand I quite like it, and I cannot imagine it going away anytime soon. Now that it is just a matter of seconds to set up a project on the web (really, on Heroku, Appengine, dotCloud are all one click away) there’s no good excuse not to do that.

Good

  • JSON, ’nuff said. That’s just such a good data format that is both human and machine readable. Seem to be pretty much the
  • No problem (it seems) with Unicode and international characters. Though I think it uses UTF-16 while many other code is using UTF-8, not sure if that makes any difference.
  • Feels quite light and flexible (from the language point of view, not necessarily the resources needed)
  • Since the source of websites is necessarily open, it is possible to learn from others’ examples much easier than otherwise.

Bad

  • Feels like it has a lot of baggage from it’s long(ish) and torrid life, which makes it feel a bit inconsistent. E.g. the first day of the month is 1, but the first month (January) is 0.
  • People generally seem to write pretty bad Javascript code. Because it’s so easy everyone can make some useful project, but they are full of bugs. Fortunately it’s Open Source, so I can try to figure it out, and I did find a handful of upstream bugs. But the stress…. huh…

Ugly

  • Formatting of JS code can be pretty unreadable (especially comparing with Python where formatting is not optional). It is made more difficult when I’m editing JS within a HTML file, since Emacs cannot handle that well.
  • Up until quite recently there weren’t any really good tools to troubleshoot things. Fortunately there’s Chrome and it’s Javascript console, and Firebug for Firefox. There are still some mysterious errors and the debugging has to be planned well ahead.
  • There are many things that are straightforward but require a lot of typing. Fortunately projects like jQuery are trying to fix that, but still there’s a long way to go.
  • Just like in Lua, for keys in dictionaries the quotation marks are not required and they are still understood as strings. These kind of magic can be convenient but there are occasions when confusing.

Links

Books

Interesting Javascript projects and sites

  • jQuery: making it easier to use JS, especially with respect to HTML DOM manipulation
  • Node.js: server side JS, thus it is possible for the first time (?) to use the same language for the front and back end on the web
  • jsFiddle: easy online editor, prototyping and code sharing for the web (JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML, CSS)

(last edited 2011-10-03)

Categories
Programming

Language of the Month: Prolog, part 2

If something, then this is a belated post. Prolog was the language of July and now it’s September. Anyway, before I completely fail, let’s just wrap it up and go on the next language with this one month hiatus in August.

I really enjoyed the language and one month is indeed barely enough to start doing something useful. So I have to come back to it again and maybe keep reading about it in the meantime. It’s actually quite interesting to try to figure out Prolog code on paper, without actually running something. I think one of the books I was reading had plenty of exercises like this: without running the code, can you guess what is it doing? Needless to say, there were plenty of tricky bits/

From the comments

During two months, some additional resources did show up. A dear commenter on the previous post recommended me the following book: Richard O’Keefe: The Craft of Prolog. I got about a third, maybe halfway through it and it’s interesting, written long time ago in a style that since gone out of fashion, unfortunately. It’s a programming book that is fun to read and one can see that the author is very knowledgeable. Some aspects of the book didn’t age very well, though. The author keeps comparing Prolog to other languages – many of them are not very widely available either. Also, some of the language features are specific to his version of Prolog, that wasn’t the same one I was using. Would recommend, though!

This last part, the different implementations of the same language, can be a real problem. Of the three compilers available for me, all of them had specific strengths and weaknesses. Guess they are converging, but not quite yet. So far I was mostly using SWI Prolog, but this might change in the future.

The said commenter also recommended a cross-compiler, doing Prolog-to-C magic, for portability and other goodness. Can grab it from here: http://ftp.shaw.ca/irvinsh/prolog.tar.gz I haven’t had time to try it yet, but once I have, I’ll do a comparison.

From the web

From a friend’s recommendation I was checking out a site with free textbooks. They are all advertisement-sponsored, which is an intriguing idea (for another post). The IT section had not one but two books on Prolog: Prolog Techniques and Applications of Prolog.

Two prolog book covers
Free textbooks on Prolog from Bookboon

This latter one has a Hungarian author so I’m even more intrigued, we used to have great computer scientists (John von Neumann / Neumann János, anyone?), so I hope we keep up that tradition. (Oh, yeah, and had great physicists as well, maybe I can do more on that front later).

I was only skimmed them a little bit, but looks like these will be good addition for my “programming for fun and efficiency” library.

Will update the original LotM:Prolog page with these links as well. Now onto September’s Language, fortunately I have idea what I want to learn for the next ~3.5 weeks. October will be something Artificial Intelligence related since I signed up for the AI-class.

Categories
Programming

Language of the Month: Prolog

New month, new programming language to learn, the 3rd one in this series. So the repertoire so far contains:

Prolog

It is again a very different choice, logic programming. Been playing with it for the last two weeks or so, and it really makes me think differently about programming and programs. Logic and complex thinking was always a favorite past-time of me (e.g. solving puzzles and such), but only now I realized that I do have a lot to practice in this area.

Prolog is also one of the older languages (feels like a “classmate” of Lisp and Fortran) so it was the first language in the series where I could actually go to a library, take out some books to learn it, and that book wasn’t hopelessly out of date (try to do the same thing with Python or Ruby…). Since these books were also written by academics and not necessarily computer scientists, their whole approach is different, in a way more curious, though probably less practical.

In the end, I think what I would like to gain is a tool that I can use to attack problems that are intractable or at least very difficult in other languages.

Start

One of the first thing I found hard to figure out was how to actually run a program. So in a nutshell: even if most of the interaction is within an interpreter-like environment, all the basics have to be prepared in a file and loaded.

E.g. I prepare a file like this (based on Ender’s Game), call it ender.pl:

%% Genealogy of Ender's Game.
% Facts
male(ender).
male(peter).
male('john paul').
female(valentine).
female(theresa).

parent('john paul', ender).
parent('john paul', peter).
parent('john paul', valentine).
parent(theresa, ender).
parent(theresa, peter).
parent(theresa, valentine).

% Predicates
father(X, Y) :-
	male(X),
	parent(X, Y).
mother(X, Y) :-
	female(X),
	parent(X, Y).

sibling(X, Y) :-
	father(F, X), mother(M, X),
	father(F, Y), mother(M, Y),
	X \= Y.
brother(X, Y) :-
	male(X),
	sibling(X, Y).
sister(X, Y) :-
	female(X),
	sibling(X, Y).

Then starting Prolog I can load the file with the [‘ender.pl’]. form, and ask questions like who is Ender’s sister? Who are Theresa’s kids? Who are Peter’s siblings?

?- ['ender.pl'].
% ender.pl compiled 0.00 sec, 144 bytes
true.

?- sister(Sis, ender).
Sis = valentine ;
false.

?- mother(theresa, Kid).
Kid = ender ;
Kid = peter ;
Kid = valentine.

?- sibling(peter, X).
X = ender ;
X = valentine ;
false.

Well, this is laughably simple, and I’m beyond this already, but it’s good for a first illustration.

By the way, it looks like 90% of elementary Prolog examples use family trees (Nordic or Greek gods, literary, real families…)

Now let’s get in there and learn some more stuff…

Links

Tutorials & Info

Books

Compilers

Code