HomeBlog

Dec
26
2009
11:41

Howto: multi-threaded TCP server in Common Lisp

I'm writing this howto because I spent some considerable time on implementing a TCP server in CL; my lack of Lisp experience contributed to this, but also no quick guides or howtos seem to exist in this area.  And an undocumented argument to a function in usocket has a default value which defeats the documented behavior, making me spend lots of time to figure out what's broken (:ready-only in usocket:wait-for-input).  Poor documentation and lack of resources is a pretty bad situation for Common Lisp. :-(

The task is to write a simple TCP server class using a worker thread pool for handling the requests.  There is one listener thread that clients connect to.  The listener would read data from the socket, then when a full command is available for a certain client, it will send it to a worker thread to be handled.  (The idea was that there could be multiple listeners as well, but at this time it's buggy.)

[ read more... ]

Dec
19
2009
18:32

The greatest programmer in the universe

Want to know who that is?  It's me. ;-)

I submitted my Ymacs project to Ohloh (Ymacs project page at Ohloh).  They have a nice feature that gives some statistics, based on the source code (they can understand some source control repositories, including Mercurial, which is what I use).  The Ymacs statistics say the following (the whole source taken into consideration):

  • estimated effort: 4 person-years
  • project cost: $210,926 (for a $55000/year salary)

    Counting only the JavaScript files, which is the main programming language, we have:

    • estimated effort: 1 person-years
    • project cost: $61,739 (same $55000/year salary)

    The fact is: I did this myself in a bit more than 2 months (work on the website and infrastructure included).

    It's true that Ymacs includes a build of DynarchLIB in it's source repository, and DynarchLIB started in 2005 (I didn't work on it full-time, though, far from it).  However, Ohloh counts DynarchLIB as a single line of code, because the code is minified, so it probably doesn't add much in the 1 person-years estimation.

    Once I put up a public code repository for DynarchLIB, it will be interesting to see how much Ohloh underestimates me. :-)

        Nov
        10
        2009
        23:00

        Ymacs — AJAX source code editor

        I just released a new project that I've been working on for about a month: Ymacs is an AJAX text editor, suitable for editing source code (currently there is support for JavaScript and XML, but more modes could be easily implemented).

        Ymacs is a DynarchLIB widget, which makes it easily embeddable into any DynarchLIB application.  This doesn't sound impressive, isn't it, but here's the real good news: I've decided to open source DynarchLIB and release it under a BSD-style license.  Some folks might believe this project is already dead, but this isn't so; it is true that there was no new release in almost two years, but the thing kept being improved and there are people using it in successful commercial applications.

        Well..  This should happen any minute, but I'm running out of time, as usual.  So it could take a few more days to push a new DL release.  In the mean time, go check Ymacs, it's pretty cool.  It has Emacs key bindings too. ;-)

        Oct
        20
        2009
        15:27

        JavaScript: Unicode letters (in RegExps?)

        As you probably know already, Firefox's browsers' regexp engines don't "know" Unicode.  The \w specifier seems to be equivalent to [a-zA-Z0-9_], which is far from sufficient to match word characters.  After some googling I found XRegExp, a pretty cool library that extends the basic JS RegExp object.  It adds some useful magic, and—surprise—unicode support is available as a plugin.

        Nice going, but since I need this in a very time intensive operation, it was rather slow.  (As you will see below, it's quite possible that XRegExp isn't to blame for the slowness).

        So I thought I'd copy the bits that I need from the source code, and use them with standard JS regexps, rather than XRegExp.  If you look at the source code, it has a huge line for a "L" property (it's lowercase in the code) in a hash which defines the Unicode ranges for characters that are letters.  Later in the code, with a for loop it constructs the actual regexp.

        [ read more... ]

        Sep
        12
        2009
        16:09

        Hashes and raw strings in Common Lisp

        So I'm learning Common Lisp.  Why would I do that?  Well, for one thing, I don't have much work to do lately, which is pretty bad because it directly translates in a poor financial situation (wanna hire me?).  But on the other hand, because Lisp is cool and I've long wanted to learn it.  Friends of mine keep asking "What can you do with Lisp?  Can you find a job?  Can you make any money with it?" — I haven't got an answer to these questions yet, but one thing is certain: I can use it myself and finally replace Perl for my server-side needs.

        I'm writing in this article how I solved two of the things that bothered me.  It's probably not useful for experienced Lisp hackers. ;-)

        (read 'more)

        Aug
        24
        2009
        15:05

        Object oriented programming in JavaScript

        I'm pretty sure you know the Foo.prototype.bar = function(){ ... } syntax for declaring object methods, and also the Bar.prototype = new Foo stuff for setting up inheritance.  You also probably know that Prototype.js and jQuery have devised new, shorter/cleaner ways to declare objects.

        In the article below I'm presenting my own, which I developed around 2005 and kept refining it.  The described "syntax" is used in DynarchLIB (although not in the released version, which still uses the old eval()-based hacks).

        [ Read full article ]

        Aug
        09
        2009
        11:51

        js2-highlight-vars-mode

        This is a minor mode that I wrote on top of js2-mode which automatically highlights all occurrences of the variable under the cursor within its defining scope.  I once saw this at a friend who was using Eclipse, and I thought it's pretty cool.  With the powerful API that js2-mode exposes, it was pretty easy to write it, even despite my limited (E)Lisp experience.

        [ read more... ]

        Aug
        09
        2009
        11:51

        Editing JavaScript with Emacs — js2-mode

        I wrote about this topic before.  My small hackish mode attracted a few people for its good indentation, but it still had some issues that were hard to track down.  In short, it's quite impossible to use c-mode's indentation.

        In the last few days I played with Steve Yegge's excellent js2-mode and I'll write about my setup here.  js2-mode is different from most other programming modes that you can find in Emacs (and in any other editor for that matter), because it employs a full, solid parser of the language.  Instead of guessing the syntax with buggy regexps, js2-mode actually parses your code into an abstract syntax tree (AST) and can therefore provide complex information about it, not to mention very good syntax highlighting.  For example, js2-mode can and does warn you about syntax errors such as misplaced parens, or missing semicolon, or trailing comma.  Or about undeclared variables — a ”must have” with JavaScript, since it's usually the source of many subtle bugs.

        I noticed this excellent mode about an year ago, but indentation was simply unbearable so this is why I didn't use it.  But now I decided to give it a second try.  Indentation can be fixed.

        [ read full story... ]

        Apr
        29
        2009
        00:26

        Tried IE8 today

        I'm kinda late, huh?  But I took my time.  Every time M$ released a new browser (that's, err, twice in the last 7 years?  I think so) — so every time they released a new browser, I rushed to download it, install it, only to be horribly disappointed thereafter.

        Well, today I'm quite pleased.  I tried IE8.  It's OK!  Can you believe I said that?  I, I mean, me — Mihai Bazon — am telling you that IE8 is OK.  It's about as OK as Firefox was 6 years ago.  It's even as fast as Firefox was 6 years ago (and here I mean Firefox on that hardware, compared to IE8 on bleeding edge hardware).

        Other than speed (seriously M$, can't you do any better?  Come on!), IE8 does seem to do a lot better job than any older IE concerning rendering quality (and here I mean CSS).  And that's it.  No exciting news on the DOM side (but people didn't cry about it all that loud, because we could work around it).

        So to recap:

        • Slowest browser on Earth (as usual).
        • CSS support is better than IE7, but worse than real competition (as usual).  Firefox, Safari, Chrome, Opera — they're all still light-years ahead.
        • Still no support for standard DOM events (as usual).
        • filter:alpha(opacity=STILL_SUCKS) (as usual).
        • Oh wait, still no font antialiasing when opacity is not 100% (as usual).
        • Dude, it's unusably slow. (as usual).

        Good work folks.  Looking forward for the next 3 years.  Meanwhile, I'm happy to see your marketshare shrinking daily.

        And by the way, Vista sucks!  It truly, deeply, sucks!

          Feb
          05
          2009
          20:29

          The snake, seen from the eyes of the Camel

          I spent some time with Python and thought I'd share some opinions.

          In short, my conclusion is that Python is a great programming language and I'll definitely invest some time into it: it has a clean syntax, it's very fast (2x compared to Perl), it has lexical scope (which is the only kind I care about, but see below), true objects, first class functions.  It has its share of downsides and I hope I'm expressing them well here.

          I welcome any Perl and Python experts to state their opinion on the matter, and maybe fix/optimize my code if this is possible.

          [ read more... ]

          See also