April 26, 2011

Alisp in wonderland

Lisp is great, I love it. It is so different from everything else that it just astonishes you. Everybody should learn lisp. If not for any other reason, then just to widen their perspective in programming, and finally to regain their respect to the language they are currently programming.

Lisp is for list processing, naturally. But that's not the point. Where most languages - so called procedural languages - say what should the computer do, in which order, and in which conditions, Lisp concentrates on rules on evaluation: what each variable evaluates into in which conditions. And finally, your program concludes in one root element, or variable, which is then evaluated by running the program.

Because everything in Lisp is about evaluation and there is no sequence of doing things, Lisp as a language does not define structural loops. For todays pgogrammer this is quite odd. (Ok, some lisp variant have some kind of loop macros, but those are some kind of add-on, and that's not the lisp spirit) So when you want to repeat something, you will implement recursion. Therefore you can not talk about lisp without speaking about recursion. I would say half of all lisp functions are calling themselves recursively. Isn't that just ridiculous.

Although Lisp is so different from procedural languages, it has made its impact to popular languages today. Have you ever noticed one particular syntax in C programming language, and wondered why it is so dramatically different from everything else you see in C?

(a ? b : c)

There is a reason. It has been taken from Lisp. That explains its peculiarity. Actually, using above mechanism and recursion, you could make C code look quite a lot like Lisp. Take a look at below example:

int days_per_month(int year, int month) {
    return (month==1||month==3||month==5||month==7||month==8||month==10||month==12 ? 31 :
        (month==4||month==6||month==9||month==11 ? 30 :
            (month==2 ?
                (year>0 && year%4==0 && ( year%100!=0 || year%400==0 ) ? 29 : 28 )
                0
            )
        )
    );
}

Yes this is a wannabe-Lisp C function. Notice the function has only one line, which starts with return and ends with a semicolon. No procedural thinking; the function directly returns something which then evaluates into a decision tree. And no, I did not try to compile it. It's just an example. You are free to comment your findings.

And what else have I done with Lisp then? Years back when I was at school I coded a game AI algorithm that calculated the best possible move in a board game. It was much fun, but the code turned out to be horrible. Maybe all lisp code turns out to be that. If I remember correctly, my professor gave me a rather high grade for this one, but maybe he was just fond of board games.

April 18, 2011

Do you remember Fortran?


Do you remember Fortran? I do. I have a headache when I even think about it. Trust me, I know what I'm talking about, I have programmed Fortran, although it was not a real IBM like in the picture above, it was an ordinary PC but it was a nightmare anyway.

I think people that wrote Fortran were just simply playing a practical joke to their colleagues when they made the rule in the language that every single line in the code MUST BE INDENTED with exactly 7 space characters. If you try 6 or 8 characters, the program just does not compile. And with a smile on their face they named the language "Fortran 77". Just for the sake of being cruel.

And the capital letters. Oh yeah. Programmers can be nasty when they are not given their bonuses, you know. READ, WRITE, IF, GOTO and other reserved words work only in capital, not in lowercase. Of course not.

Yes I know, now you people that have been reading mathematics start mocking me and claim that Fortran is the only language that introduces a native support for complex number calculation. If computers regularly introduce numeric types for integers and floats, Fortran does three; integers, floats and complexes, by the reserved keywords INTEGER, REAL and COMPLEX. But what's wrong in using libraries? Oh yeah... Fortran did not support libraries. Another headache.

Next week about Lisp... my head hurts already.

April 17, 2011

Programming badly ?

Hi all! Things that we most love are most often the same that we find most annoying. At least I have made that observation. For me it is this thing about software. Now don't get me wrong, I love software and especially I love programming, I really do. But it comes with a cost.  Not all people share your eye on code beauty and perfectionism. Of course, tolerating this is called "ability to work as member of a group". Doesn't that just kill you!

The same goes with programming languages. There are some aspects about them that are really great, but some things about them are just so freaking annoying that I just can not stand it.

This blog is dedicated to those who have a love-hate relationship to programming. It is a humoristic approach to a serious thing, or vice versa, how you like it. If you don't have a clue what I'm talking about, just go on and read another blog, but if you share my feelings - who knows, you might even like it?