Thursday, August 7, 2008

Beautiful Code

Finally I have finished reading this one. I read it almost for two months. Probably one of the longest books I have ever read, but it was worth every second.

The book itself is a collections of articles where "Leading Programmers Explain How They Think". The motto couldn't be more cleaner. You get exactly what it tells - experience of developers coming from different fields, programming in different languages (C, Java, Ruby, Python, Haskel and lots and lots more), but never the less great programmers. By now I will just stop telling how great it was and give a list of few of my favorite articles with descriptions:

A Regular Expression Matcher by Karl Fogel. Karl introduces us to a simple C powered regular expression matcher. The matcher doesn't have compiled expressions, nor does it have a full Regex syntax support, but instead he in simple terms describes to us what is under the hood of programmers' workhorse.

Finding Things by Tim Bray. While Karl Fogel describes to us how what the Regex engine is, Tim explains to us how to use it with such beautifull language like Ruby. He shares with us his experience of writing apache logs analizer for his blog.

Correct Beautiful, Fast (in that order), Lessons from Designing XML Verifiers by Elliotte Rusty Harold. Ellotte writes about few very useful optimization tricks like incremental ifs (my name for it :]). Ellote tells us a story about him writing an XML validator, more precisely an XML node name validator. After intensive development he was stuck with fast, but not fast enough for thouthands of validations, node names validator. Even though his validator only allowed latin characters and numbers he still managed to speed it up.

Beautiful Tests by Alberto Savola. In his tail Alberto shows us how to use JUnit to write unit tests. What caught my attention in this article are not unit tests themselfs, but instead what example he gives. As an example Alberto tests binary search algorithm for bugs that where undiscovered for about 30 years after it's introduction.

On-the-Fly Code Generation for Image Processing by Charles Petzold is about how one can bring optimization to a crazy level of code generating code, which will run faster than original code. The author tells about a situation where even machine code was not an option and where radical solution was required - something even faster than assembly language, as incredible as that may seem.

The Long Term Benefits of Beautiful Code by Greg Kroah-Hartman. CERN library was created 30 years ago, but is used up to this day. Greg Kroah-Hartman is a one of the long time users of CERN geometric library. He tells us how sometimes an ugly interface is really a beautifull perl which protects developers from their own mistakes.

Distributed Programming with MapReduce by Jeffrey Dean and Sanjay Ghemawat. This is a story about distributed programming used in Google. Jeffrey and Sanjay tells us how they managed to bring distributed programming to the level where very small amount of additional effort was needed for a novice developer to start writing programps distributed among thouthads of machines in corporation like Google. The success of this library can be proven by number of MapReduce users. By 2007 in Google MapReduce was used 35000 times a day and calculated about 100Gb of data per second!

Beautiful Concurrency by Simon Peyton Jones. Symon introduces us to another way of handling concurrency, where he uses DB like transactions instead of locks to make code multi-threaded. After investigating the internet on this topic I found many who are afraid that this method will bring even more problems then there is already, but nether the less learning how things can be done in different way was still very enjoying to me.

Beautiful Debugging by Andreas Zeller. Andreas tells us a story about the future of debugging becoming reality in his hands. He tells us about his experience searching for a broken code, which later became a fundamental for his thesis on automatic (delta) debugging.

That's it! Other's stories in this book are also great, so I appologize if somebodies else story wasn't included in my list. This is probably because I was not experienced with a language used in example or I just didn't look deep enough into the beauty.

Anybody living in Vilnius, Lithuania can lend the book from me. Just put a line in comments if you are interested. You can also read the book online in Google Library.

Tuesday, July 1, 2008

Reinventing a programming language

I decided that from today on I will be spending at least one our to develop a simple language. I don't know how to do it but I am willing to learn the basics in a month or so.

Here is what I have decided about the language. The language will be similar to C but a lot smaller. It will have following structures:

  1. Scalar values (1,2,3...) - only integers for now
  2. Variables (a,b,c...) - dynamic variables (Will hold only integers for now)
  3. Addition (+) - addition
  4. Subtraction (-) - subtraction
  5. Functions (function, return) - functions will accept dynamic variables and return any value or a void
  6. Core functions - a print() function and a general way to add core functions
  7. No semicolons

Example:
function calc(a, b) { var c = 5 c = c + a - b return c } var answer = calc(5, 7) print(sum)

I will write the compiler and core functions in Java on JVM, because I'm running Ubuntu at my desktop. There are talks that .NET and CLR is be a better suit for developing a language, but I am afraid that Mono will be too buggy for this.

Wish me luck and post any advices in comments.

Wednesday, June 25, 2008

Eclipse 3.4 kicks ass

Today is a big day for (Java) developers. Long story short. Eclipse 3.4 is out and it's great. Lots of new features, fixes and speed improvements.

Here are some interesting new features

New update UI. I don't care about the GUI change but hear this. You are no more required to search for required plug-ins before new plug-in installation. Don't believe me? Read this:

Unlike previous versions, you no longer have to find and select all prerequisites of the software you are trying to install.
Working with 64-bit Windows. Well... I don't care, but some sure do.

Close tabs with middle click. This is just nice. It seems like they care about us.

Java Editor Breadcrumb. I imagine this will be usable when you have lots of opened files with same names in different directories.

Rearrange content of files per drag and drop. Cool, but not worth it :)

Enhanced debug hover. We all know that Eclipse debugging sucks. Everybody, who have worked with Visual Studio know how superior VS debugging workspace is. Not anymore... almost...

And lots and lots and lots more...

Features I hoped for this release, but still missing.

Debuging still sucks. Though it sucks less it still sucks :(

My congratulations to Eclipse team on new release. Everybody can download it here.

Monday, June 23, 2008

I miss programming

It has been almost a month since I coded last time. My project manager got married and went to honeymoon leaving me with all the paperwork.  Moreover I am refreshing my memory for the master program exam coming next week. In the end the closest I get to programming is designing a common interface for lithuanian/latvian project. That's all! Not a single line of code in a month :(

As i said these activities take a lot of time so I thought about what can I do instead of programming while getting as much experience. Here is a list of things I did to replace programming while not actualy doing it:

  • I started reading "Beautifull code" by Andy Oram and Greg Wilson. In general the book is not great but some examples of beautifull code are sure worthy few posts in the future
  • I started reading more blogs about coding. This is like Playboy for me. Code examples help me forget about sex... I mean programming :)
  • I am thinking about the best language there is for me. My criterias are: speed, readability, testability. I did programming in PHP, javascript, C#, bit of ruby, java and python. So far the best for readability and testability is javascript, C# is best at performance (except asp.net), but python has nice balance. If javascript could be compiled on request It would defenetely winn.
  • I'm doing a research on how to write my own language parser (at first)

What would you do?

Saturday, June 21, 2008

Svetlin Nakov Microsoft interview experience

In his least post Svetlin Nakov writes that he rejected a program manager position at Microsoft Dublin even though he succeed in interview. While his rejection was based only on several times lower salary than he already had, we who would like to work at Microsoft at some time could learn.

Svetlin has posted all questions that he was asked at interview in Microsoft, because he wasn't asked to sign any NDA agreements.

Svetlin gives some examples of interview questions at Microsoft starting from basic ones:

Question 5: What is SQL injection? SQL injection is vulnerability coming from dynamic SQL created by concatenating strings with an input coming from the user, e.g. string cmd = “SELECT * from USERS where LOGIN=’” + login + “‘ and PASS=’” + password + “‘”. if username has value “‘ OR 1=1 ‘;”, any login / password will work. To avoid SQL injection use parametric commands or at least SQL escaping.
To medium difficulty:
Question 11: How you write a distributed Web crawler (Web spider)? Think about Windows Live Search which crawls the Internet every day. You have a queue of URLs to be processed and asynchronous sockets that process the URLs in the queue. Each processing has several states and you describe them in a state machine. Using threads with blocking sockets will not scale. You can still use multiple threads if you have multiple CPUs. The Web crawler should be stateless and keep its state in the DB. This will allow good scalability. A big problem is how to distribute the database. It is very, very large database. The key here is to use partitioning, e.g. by site domain. Take the site domain, compute a hash code and distribute the data between the DB nodes based on the hash code. No database server can store all the pages in Internet, so you should use thousands of DB servers and partitioning.
You can read other questions on his blog. To me these questions are actually very easy. Am I so good that I even don't see a challenge or there is something else here? I will find out only when Microsoft invite me for an interview I guess :) There is one other thing that touched me. The answer to second question is brilliant.
Question 2: You are given a string. You want to reverse the words inside it. Example “this is a string” –> “string a is this”. Design an algorithm and implement it. You are not allowed to use String.Split. After you are done with the code, test it. What will you test? What tests you will write? Elegant solution in 2 steps: 1) Reverse whole the string char by char. 2) Reverse again the characters in each word. You need to write a method Reverse(string s, int startPos, int endPos). Test normal cases first (middle of the word, beginning of the word, end of the word, 1 character only, all letters in the string). Check bounds (e.g. invalid range). Test it with Unicode symbols (consisting of several chars). Perform stress test (50 MB string). Write a method ReverseWords(string s). Test it with usual cases (few words with single space between), with a single word, with an empty string, with words with several separators between. Test it with string containing words with capital letters.
Svetlin, have you seen the answer somewhere before, or did that just hit upon you? A truly elegant solution I must say. Other answers were good too, though sometime I would offer other solutions. I am glad that that you didn't accept the offer. After all programmers are we : if(newSalary > currentSalary && newChallengeRate == currentChallangeRate) { currentJob.Stay(); }

Tuesday, June 17, 2008

Banking 2.0

I think Web 2.0 is becoming less hype and more mature idea. It already passed that point when serious white collars start talking about Enterprise 2.0.

Zopa is a Bank 2.0 project, based in United Kingdom. Zopa is seeking to allow it's users to lend and borrow money from each other.

The idea is just great. I mean as a bank you don't need to worry (at least not that much) about the risk you are taking, as borrower or a lender you get a smaller and larger annual interests respectively. This is a game when everybody wins. I just wish we had such site in Lithuania. 

Sunday, June 15, 2008

Conferences. How to find them?

Yesterday a friend of mine asked me if I could advice him where to find any conferences, seminars, workshops and etc. He was asking because his company offered him to pay for any courses he would choose.

Now you might think of this as an easy task. In Silicon Valley maybe, but not in Vilnius. There is just no good sites for finding conferences (sites with Google maps you know).

The idea.

The idea for today is quite simple. Build a web page where one could search for conferences in his area. Say, 100km around Vilnius. Who knows, I might even do it myself.