Posted: August 21st, 2010 | Author: klaut | Filed under: mac | 3 Comments »
Next time I get a new mac (or reinstall a fresh system) the following is a must have:
I am still looking for a better replacement to pgAdmin.
Posted: April 13th, 2010 | Author: klaut | Filed under: haskell | Tags: haskell, learning | No Comments »
Haskell is a strongly typed static language.
This means that Haskell will not automatically cast one type into another. In other words, you can’t expect it to treat an integer as a float. If you define a function that takes a float parameter and you feed it an integer afterwards, Haskell will complain. Having static types means that the compiler knows the type of every value and expression at compile time. Before anything is executed. So if we try and use types in an expression that don’t match (say, trying to add a string “3” to an integer 5), Haskell will complain. But there is a bonus: Haskell has type inference. Meaning, Haskell will deduce the type of a value or expression for us everywhere it can. This makes type declaration optional.
Continuing my journey into the abyss of Haskell, it occured to me that we all already learned functional programming. Do you still remember the basic Algebra classes in your elementary school? Well, that is just it – functional programming. And Haskell’s syntax is just like algebra. With some extra sugar and batteries included (yes, i took that last part from Python … i just couldn’t resist).
At the algebra classes we learned that functions return values. Later we were spoiled by imperative programming languages and the returning values became an option explicitly stated with return keyword. Not in Haskell. All functions return values, because they are expressions. Always. And we don’t need the return anymore because we get it implicitly. Oh, and did I tell you that there are no objects in Haskell? Just functions!
To define a function that returns a sum of two numbers I could write something like the following:
add a b = a + b
Here I tell Haskell that add takes two parameters and it should return a sum of the two. I didn’t have to declare the types of the parameters, nor the returned value. And i could have, if I weren’t so lazy! But I am safe anyway. If i try to pass two strings to the function, Haskell will yell at me. That’s inference at work.
Let’s say that i want to be a good citizen and declare the types as well, but being new to Haskell i just am not really sure what they could be. Well, I can always check it out after I write my function down with the help of the interpreter.
ghci> :t add
ghci> add :: (Num a) => a -> a -> a
Haskell is telling us that for him, the add function can take any two parameters that are of the same type and it will return a value of the same type back, but the type must be of a Number typeclass. Ok, I had some hard time to decipher it as well, so let me rephrase this a little bit. The (Num a) part is telling us that for all the “a”s that follow they must be of a numeric type. The part “a->a->a” is simplified like this: the last a is the return value, while the first two are function arguments. So, armed with this insight i can go back and modify my function so that it has a type declaration as well.
add :: (Num a) => a -> a -> a
add a b = a + b
Yes, it is weird at first. But quite soon it starts to make sense, trust me. And wait till next week when i show you patterns and guards!
Posted: March 30th, 2010 | Author: klaut | Filed under: haskell | Tags: haskell, learning | No Comments »
Monday is here and so I met for the first time with Haskell.
Installation went quickly and without any problems (installed the Haskell platform for macosx). You get a compiler, a bunch of standard modules and an interactive interpreter. I like having the interpreter as a way to quickly try out stuff in Python, so the fact that Haskell has its own as well immediately gained points with me
It is much more convenient while you learn to have an immediate feedback than having to type some code to a file and compiling.
First thing you try is the “command line calculator”. Haskell is behaving as you would expect it to behave:
ghci> 2 + 4
ghci> 6
All the usual suspects are here: addition, multiplication, subtraction … nothing differs from Python.
But then quickly the similarities stop to be, well, similar.
Haskell is a functional language and as such it does not modify state. That, translated to something meaningful to me is: variables are just symbols that hold values. Once you assign a value to a variable you can’t change it. Variables in Python and variables in Haskell are not the same. At the moment it is still difficult for me to grasp what this mean and how it can be useful. But right now I am still looking and evaluating Haskell from the imperative languages point of view. Also the fact that Haskell is known to be *lazy* is somehow odd, but then it sounds like a cool feature – the fact that it won’t bother to compute things until it is really forced to do so.
This means that you can create lists with infinite number of elements and Haskell it is quite happy to create them for you. Fast. Well, unless you try to create them at the interactive interpreter. You will have to stop it from spitting all the numbers till the end:
ghci> [1..]
Lists.
They can have unlimited amounts of elements. But the elements must be all of the same type. Strings as we know them are lists of chars so the following examples are all the same to Haskell:
ghci> “hello”
ghci> [“h”,”e”,”l”,”l”,”o”]
If you want quickly construct a list of ranges you can do: [1..100]. This will create a list of numbers from 1 to 100. You can specify a step to the range as well: [1,3..20]. This will create the following list: [1,3,5,7,9,11,13,15,17,19].
For concatenating strings or lists you would use: [1,2] ++ [3,4] or “hello” ++ “ “ ++ “world”. Basically the ++ function inserts the stuff on the right (which must be a list) at the end of the list on the left side. But what if i want to insert something at the beginning? I can do that:
ghci> a:[b,c,d]
ghci> [a,b,c,d]
The only difference: the thing you insert is a single element. Not a list.
If you want to get the second element from a list (the indices start at 0) you would use the !! (yes, that is double exclamation mark):
ghci> [1,2,3,4]!!1
ghci> 2
There is a whole bunch of functions to manipulate lists and they all sound quite exotic (although I did remembered my CS semester of Prolog while trying some of them out).
Let’s say you want the first element from the list:
ghci> head [1,2,3,4]
ghci> 1
What about the last?
ghci> last [1,2,3,4]
ghci> 4
To get everything but the first element you use tail:
ghci> tail [1,2,3,4]
ghci> [2,3,4]
And everything but the last element? init.
ghci> init [1,2,3,4]
ghci> [1,2,3]
There is a lot of very well written and comprehensible material online that i am using as a learning material. Some of the best resource that I found are:
All in all, I enjoyed my Monday evening. Haskell does feel strange for now and I can’t possibly think of how i would go on about writing real life programs with it. But hey, it is only my first Monday
Posted: March 24th, 2010 | Author: klaut | Filed under: General | Tags: ada lovelace, women in tech | No Comments »
Today is the Ada Lovelace Day – a day to celebrate women in technology and science.
Although I am not much into dividing people into groups based on gender, race, religion, etc, it is a very noticeable fact that there simply are too few women in technology. I noticed it since I first developed an interest for computers, I continued to notice it during the university (hey, in the first year there were maybe 10 girls out of 100 students!) and it is a regular fact in every job that I had. Usually, I was one of the few female programmers, sometimes the only one.
I would like to bring attention to one of my heroes from the BSD community: Dru Lavigne.
Dru is an authority in the BSD world. She is a network and systems administrator, IT instructor and technical writer. She has written several books on BSD, the most famous one, BSD Hacks I happen to own, and has been my reference for most things BSD. I’ve read it cover to cover several times during my early years when I was learning FreeBSD.
Dru writes regulary on her technical blog A Year in the Life of a BSD Guru
Posted: March 23rd, 2010 | Author: klaut | Filed under: haskell | Tags: haskell, learning | No Comments »
Each Monday from now on, I am going to publish a small step that I made during the week into mastering Haskell. This is a commitment that I make to myself and by deciding to make the progress public (although you may be the one and only reader) I am kind of forcing myself to stick to it.
Why Haskell? Why now?
Well, first, let me tell you that learning a new programming language is actually very exciting. It is like when you were a kid and you were given a new toy. Remember how excited you were? You just could not wait to unwrap it and start playing.
Having said that, Haskell has been on my radar for some time. I just never really took the time to start looking deeper into it. And I realized that if I am going to wait until I think I have more time, it is never going to happen. You have only so much time as you give it to yourself. So this excuse is not going to cut it anymore.
Oh, and why Haskell I hear you wonder? Because I want to add a functional programming language to my arsenal. Because it is gaining in popularity but it is still underground enough to feel exotic. Because it is lazy. Because I’ve been pretty intrigued about what monad is.
Posted: February 24th, 2010 | Author: klaut | Filed under: General | Tags: development | No Comments »
Version control systems are important. No argue about that. At places where i used to work (and am currently working) i had the pleasure to meet three systems: cvs, perforce and subversion. All three have one important thing in common – they all suck. Well, some suck less than others (like subversion).
For my pet projects i decided to try these new kids on the block (read distributed version controls). I narrowed down to two: git and mercurial. I went for mercurial. Why? Well, first because it is written in Python and i have a thing for Python. I just love it. Second because bitbucket looks just nicer and cooler than github. And third … well, I think this guide by Joel Spolsky explains it much much better than i could do. Enjoy and be persuaded
Posted: May 6th, 2009 | Author: klaut | Filed under: General | Tags: Life, Social Media, Twitter | 5 Comments »
I just finished reading a little book by Tim O’Reilly and Sarah Milstei, The Twitter Book. It is aimed at Twitter newbies (such as myself) and it does a nice job explaining the power of Twitter and all its various usages for personal and business needs. It didn’t took me long to finish it as well, as it is written in the spirit of Twitter – short and to the point. It takes you from a Twitter ignorant to a pro in no time
But why would one want to know about Twitter anyway? Hmmm, tough one. To be honest, i didn’t see much value in Twitter either, when i first created an account. I actually didn’t use it much at all – I wasn’t sure why i needed yet another communication channel to tell the world about what I’m doing, thinking, eating. I have a blog, like everyone else, right? And I’m not posting much on it. I have an account on Facebook like everyone else, right? But i am not using it much apart from playing Texas Hold’em occasionally. So what is different with Twitter that would make me tweet regularly each week, or day, or even more times per day? And who would care about it anyway?
First, the tweets are short messages that must obey the 140 character limit. So you don’t have to engage more than a minute (unlike when you are posting on a blog) to get your thought across. And when you start following smart and witty people, it is actually very amusing reading their tweets. It is like peeking into their minds. And that gives you motivation to tweet back. And in a matter of no time it becomes great fun!
I admit, i am a Twitter newbie but i am starting to be really hooked. And not just thanks to the book
Posted: December 4th, 2008 | Author: klaut | Filed under: Python | Tags: Python | No Comments »
I just noticed now that Python 3.0 final is now available! Go get it and play!
Posted: November 11th, 2008 | Author: klaut | Filed under: General | Tags: updates | 1 Comment »
I haven’t posted something meaningful here for ages!
Anyway, i changed the theme of the blog and finally updated a small part of it – the Illustrations section. Hopefully, I am not going to stop here for another year or two
Posted: June 9th, 2008 | Author: klaut | Filed under: General | Tags: Life | 5 Comments »
It is so nice to find an old friend again! It really makes your day.