Showing posts with label facebook. Show all posts
Showing posts with label facebook. Show all posts

Saturday, March 6, 2010

Getting in touch with Thrift - Get the turial example running

So - Thrift has been compiled - hopefully it does work (see earlier post). Before I jump to the "Simon says" Puzzle, I wanted first to check if my thrift build is working. Therefore I gave the example of the thrift tutorial a go. The tutorial is still in an early stage:

This tutorial is known to be woefully incomplete, and is a work in progress. This skeleton is illustrative of what is being worked on and will soon be available. [thrift webpage]


Sounds not that promising and indeed there have been some minor obstacles in my way. Prerequisits for the tutorial is the availability of
  • Simple Logging Facade for Java - SLF4J and
  • Log4j if you decide to use log4j behind the facade
jars in the classpath of the system. Instead of building from the provided build file, I decided to create a eclipse project. After setting the scenes, I still got some compile errors in JavaServer.java. Seven occasions like:

[javac] /home/stefan/thriftest/tutorial/java/src/JavaServer.java:57: an enum switch case label must be the unqualified name of an enumeration constant
[javac] case Operation.ADD:


which simply can be solved by replacing case Operation.ADD by case ADD. And two more problems:

[javac] /home/stefan/thriftest/tutorial/java/src/JavaServer.java:69: incompatible types
[javac] found : tutorial.Operation
[javac] required: int
[javac] io.what = work.op;
[javac] ^
[javac] /home/stefan/thriftest/tutorial/java/src/JavaServer.java:77: incompatible types
[javac] found : tutorial.Operation
[javac] required: int
[javac] io.what = work.op;

I omitted those by commenting those lines as they anyway don't add to the functionality of the server.

After this manual changes the tutorial seems to be running fine. Ready for Simon says puzzle.

Friday, March 5, 2010

Getting in touch with Thrift - Simon says

Selected Simon Says from the Facebook Puzzle selection as this one seems to be the easiest example which involves the usage of Thrift. Thrift is right now a apache incubation project and is a framework for x-language service development. It has been initially developed by Facebook.

Let's see how to get Thrift working on my Ubuntu 9.10 system. First of all I downloaded the current snapshot from the Facebook Developer Pages ( in my case thrift-20090330.tar.gz). After unpacking a run of the ./configure script unveils a unsatisfied dependency on boost libraries. Synaptic comes with a couple of boost packages. I gave it a try with libboost-dev package (incl dependencies). With that the configure script was happy but the make command produces this nice error:

make[3]: Betrete Verzeichnis '/home/stefan/thrift-instant-r760184/compiler/cpp'
g++ -DHAVE_CONFIG_H -I. -I../.. -Wall -I./src -I/usr/include -g -O2 -MT thrift-thriftl.o -MD -MP -MF .deps/thrift-thriftl.Tpo -c -o thrift-thriftl.o `test -f 'thriftl.cc' || echo './'`thriftl.cc
In file included from ./src/parse/t_const.h:10,
from ./src/main.h:11,
from thriftl.ll:20:
./src/parse/t_type.h:88: error: ISO C++ forbids declaration of ‘uint8_t’ with no type
./src/parse/t_type.h:88: error: expected ‘;’ before ‘*’ token
./src/parse/t_type.h:92: error: expected ‘;’ before ‘std’
./src/parse/t_type.h:110: error: ‘uint8_t’ has not been declared
./src/parse/t_type.h:149: error: ‘uint8_t’ does not name a type
./src/parse/t_type.h: In member function ‘virtual void t_type::generate_fingerprint()’:
./src/parse/t_type.h:76: error: ‘fingerprint_’ was not declared in this scope
./src/parse/t_type.h: In member function ‘bool t_type::has_fingerprint() const’:
./src/parse/t_type.h:81: error: ‘fingerprint_’ was not declared in this scope
./src/parse/t_type.h: In member function ‘std::string t_type::get_ascii_fingerprint() const’:
./src/parse/t_type.h:94: error: expected initializer before ‘*’ token
./src/parse/t_type.h:96: error: ‘fp’ was not declared in this scope
./src/parse/t_type.h: In constructor ‘t_type::t_type()’:
./src/parse/t_type.h:123: error: ‘fingerprint_’ was not declared in this scope
./src/parse/t_type.h: In constructor ‘t_type::t_type(t_program*)’:
./src/parse/t_type.h:129: error: ‘fingerprint_’ was not declared in this scope
./src/parse/t_type.h: In constructor ‘t_type::t_type(t_program*, std::string)’:
./src/parse/t_type.h:136: error: ‘fingerprint_’ was not declared in this scope
./src/parse/t_type.h: In constructor ‘t_type::t_type(std::string)’:
./src/parse/t_type.h:143: error: ‘fingerprint_’ was not declared in this scope
thriftl.cc: In function ‘int yylex()’:
thriftl.cc:1449: warning: label ‘find_rule’ defined but not used
thriftl.cc: In function ‘int yy_get_next_buffer()’:
thriftl.cc:2389: warning: comparison between signed and unsigned integer expressions
thriftl.cc: At global scope:
thriftl.cc:2483: warning: ‘void yyunput(int, char*)’ defined but not used
thriftl.cc:3138: warning: ‘int yy_flex_strlen(const char*)’ defined but not used
make[3]: *** [thrift-thriftl.o] Fehler 1

I played a little bit with different versions of flex, bison and such a like, but I couldn't get this one running. While I was browsing for help, I found this nice blog entry from Robert J Berger which talks you through the installation of Thrift on a Ubuntu system. However mine still does not work.

As a x-check I downloaded the 0.2 Thrift release from the project homepage and tried to compile this. And this worked without any visible errors (note that you need to execute ./bootstrap.sh before running ./configure. Next step will be to test this installation and than keep fingers crossed that this one works for the Facebook Puzzles as well.

Thursday, March 4, 2010

Facebook puzzles

Tonight I joined the community of people who are spending their time to solve Facebook Puzzles.

Those puzzles are programming exercises. Facebook provides couple of those puzzles in different difficulty levels. Each of them consists of a problem description, sample input and expected output data. Solution are excepted in a range of different programming languages like Java, C, C++, Ruby, Erlang (.. really long list ...). You submit your solution as an email which is processed by a bot which compiles and runs the submission against an input which is not known by us. Result of this run is provided as an email which provides a binary success / failure indication.

As far as I looked at those problems they are restricted variants of hard problems. Only the tiny restrictions make them solvable in polynomial time. So quite some thoughts on finding a proper algorithm is needed for this one which makes this stuff pretty interesting. Another dimension is that your solution will be run on large/difficult test data. Therefore you really need to spent some time to optimize your solution in runtime and space. That makes it even more interesting. The more advanced puzzle involve the usage of the Thrift framework and elements of distributed computing. Nice :-)

Facebook provides quite some ground for a vivid developer community around the puzzles. There is a fan page, quite some discussion threads and even stuff outside Facebook (like this FAQ) which deal with that topic. There is a Facebook application which allows you to share the glory of solved puzzles on your Facebook profile and there are public pages which show High-Scores like thriftpuzzle server. Everything set for a good competition ;-).

Facebook places the puzzle as a recruiting tool - showing guys which solved puzzles and have been hired. Definitely this is a good tool for a company to get smart developers into your orbit.

Some of my colleagues started solving those puzzles some time ago and I was trying to keep myself out of this one as this definitely would impact my family life. High risk of addiction ;-). Now it happened, but I try to keep my involvement low. Personally it is a nice opportunity to
  • solve some nice algorithmic challenges
  • learn/compare programming languages on valuable problems
  • get in touch with the Thrift framework - on my list anyway.
Why don't you try this as well?!