<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2099230223105210050</id><updated>2012-01-11T05:16:09.905-08:00</updated><category term='xml'/><category term='technology'/><category term='Microsoft'/><category term='wozniak'/><category term='bot'/><category term='web 2.0'/><category term='web'/><category term='closures C/C++ programming-languages'/><category term='security'/><category term='software engineering'/><category term='programming'/><category term='languages'/><category term='history'/><category term='computer'/><category term='prank'/><category term='CAPTCHA'/><category term='Lisp'/><category term='book'/><category term='API'/><category term='feature request'/><category term='question'/><category term='libraries'/><category term='google'/><category term='GUI'/><title type='text'>Insight into nothing</title><subtitle type='html'>I'm sharing my thoughts on programming here.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-2693672397526517850</id><published>2009-10-27T12:46:00.000-07:00</published><updated>2009-10-27T13:14:11.839-07:00</updated><title type='text'>"Article 9 and 10"</title><content type='html'>Yesterday evening I checked my real mailbox and I found the following surprise:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_1XbBBgGDl48/SudOlRBii9I/AAAAAAAAAYw/jyyXW_vUKlc/s1600-h/sac.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 240px; height: 320px;" src="http://1.bp.blogspot.com/_1XbBBgGDl48/SudOlRBii9I/AAAAAAAAAYw/jyyXW_vUKlc/s320/sac.jpg" alt="" id="BLOGGER_PHOTO_ID_5397369080558816210" border="0" /&gt;&lt;/a&gt;My first instinct was to call the police and tell them that some drug dealer must have stashed his stuff in my mailbox. Then I cooled down and checked the hard-to-see-in-the-picture red label and it had my address written on it; I was sure someone was playing a practical joke on me. Then I checked out the back of the label and it had the magic number 85.83 written on it. Mystery solved. While 85.83 might not mean anything to you, it was the cost of some books I ordered from Amazon a few weeks back.&lt;br /&gt;Inside the dubious bag there was a normal Amazon paper box and inside the box my "*-at-work" books in good condition:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_1XbBBgGDl48/SudSHYWa6II/AAAAAAAAAZA/kCJDgkQwhfg/s1600-h/carti.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_1XbBBgGDl48/SudSHYWa6II/AAAAAAAAAZA/kCJDgkQwhfg/s320/carti.jpg" alt="" id="BLOGGER_PHOTO_ID_5397372965175879810" border="0" /&gt;&lt;/a&gt;On the label of the blue bag there was an yellow sticker written in a language resembling English which reads "Goods Do Not Meet The Requirement Of Article 9 and 10 Of The Contract For The Foundation Of The European Community" (verbatim). Googling for this mysterious "Contract" only returns &lt;a href="http://www.google.fr/#hl=en&amp;amp;q=%22contract+for+the+foundation+of+the+european+community%22+article+9&amp;amp;btnG=Google+Search&amp;amp;aq=f&amp;amp;oq=%22contract+for+the+foundation+of+the+european+community%22+article+9&amp;amp;fp=1&amp;amp;cad=b"&gt;blogposts&lt;/a&gt; about the same sticker. If anyone has any idea what is the deal with the weird blue bag please let me know.&lt;br /&gt;Meta-blogging aside, I've started reading the interview with Jamie Zawinski in "Coders at Work" and it seems pretty good. I'll be commenting on it on the blog later on. I can't wait to read the three books.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-2693672397526517850?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/2693672397526517850/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=2693672397526517850' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/2693672397526517850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/2693672397526517850'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2009/10/article-9-and-10.html' title='&quot;Article 9 and 10&quot;'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_1XbBBgGDl48/SudOlRBii9I/AAAAAAAAAYw/jyyXW_vUKlc/s72-c/sac.jpg' height='72' width='72'/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-3920272855932316853</id><published>2009-09-01T03:10:00.000-07:00</published><updated>2009-09-01T03:17:21.588-07:00</updated><title type='text'>Adventures in C++ land</title><content type='html'>I have recently discovered an interesting bug in a prototype implementation that I did for my research. For the current discussion, what exactly the implementation is about is irrelevant. It suffices to say that the code is C++ code.&lt;br /&gt;&lt;br /&gt;I thought I'd share the experience so that others can avoid the same pitfall. The code in question is slightly complicated, but the problem is well illustrated by the following abstracted version:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;std::vector&amp;lt;Foo&amp;gt; foos;&lt;br /&gt;&lt;br /&gt;void bar(const Foo &amp;amp;foo)&lt;br /&gt;{&lt;br /&gt;  while (*) {&lt;br /&gt;      foos.push_back(foo);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  // ...&lt;br /&gt;  assert(foos.size() &gt; 0);&lt;br /&gt;  while (*) {&lt;br /&gt;      bar(foos[0]);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here "Foo" is a very well behaved user defined class, such as the favorite class of every C++ book author, the "ComplexNumber" class. The tests in the while loops are irrelevant, so I replaced them by nondeterministic tests (denoted by "*"; so just imagine for example that each loop runs for a small number of iterations).&lt;br /&gt;&lt;br /&gt;The above code can crash. I experienced two types of crashes occurring: either the program terminates with an uncaught std::bad_alloc, or simply the program is terminated by a segfault.&lt;br /&gt;&lt;br /&gt;So let me describe why the crash happens. The problem is that the "foo" argument is passed by reference. The std::vector class implements a variable-sized array. Therefore, when the underlying implementation of the vector runs out of space, the std::vector class&lt;br /&gt;decides to allocate a bigger piece of memory, copies the old values of the vector into the newly allocated memory, and deletes the old memory.&lt;br /&gt;&lt;br /&gt;So this entire thing could very well happen during the push_back call. But what is "foo"? Well, "foo" is exactly a reference to memory that might be deleted during the push_back call. Ooops. Accessing such memory is of course undefined behavior which means very bad things could happen. I solved the problem by passing the argument by value.&lt;br /&gt;&lt;br /&gt;So the next time you do the classic "best practice" of passing arguments by const reference you might want to be more careful. It is interesting of course to analyze what led to this bug. One of the problems is having a global variable ("foos") which is used in an imperative fashion. This leads to the surprising sharing of state between the global variable "foos" and the local variable "foo".&lt;br /&gt;&lt;br /&gt;The second problem is the leaky mental model that I had of the vector class. I thought of it as an array that can grow. But in fact it's not, it's an array that is sometimes replaced by a bigger array...&lt;br /&gt;&lt;br /&gt;Also note that the bug lies entirely in the "bar" function, which is not correct in the particular case where "foo" is a reference to an element of "foos". However, the syntax of passing arguments by reference (indistinguishable from passing by value) does not help in detecting the possible bug at the point of call.&lt;br /&gt;&lt;br /&gt;I scratched my head for a long while without finding the source of the bug. I finally installed valgrind, which is a great piece of software of course, and which I recommend whole-heartedly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-3920272855932316853?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/3920272855932316853/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=3920272855932316853' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/3920272855932316853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/3920272855932316853'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2009/09/adventures-in-c-land.html' title='Adventures in C++ land'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-1724705722233745311</id><published>2009-02-01T11:52:00.000-08:00</published><updated>2009-02-01T12:10:31.387-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='closures C/C++ programming-languages'/><title type='text'>How to Hack Closures in your C Code (or "The Closure Design-Pattern in C").</title><content type='html'>A lot of languages have support for various forms of closures.&lt;br /&gt;&lt;br /&gt;For example, in most functional languages (Common Lisp, Scheme, Ocaml, Haskell), closures are first class citizens. In Java, you can implement them using inner classes. You can use &lt;a href="http://www.brics.dk/RS/01/23/"&gt;defunctionalization&lt;/a&gt; to simulate closures in almost any programming language. However, for several reasons described at the end of the post, this can be impractical in some scenarios.&lt;br /&gt;&lt;br /&gt;In this post, I'm not going to talk about any theoretical stuff. I'm going to present a hackish, evil and practical way to dynamically construct closures in C.&lt;br /&gt;&lt;br /&gt;C already contains a restricted form of closures that come in the shape of function  pointers. Essentially, a function pointer can be though of as a closure without the data. With a little care, you can use function pointers in a type unsafe (platform dependant, ready to blow up in your face) way that gets you closures.&lt;br /&gt;&lt;br /&gt;Let's take the classical example of a closure that adds a number to another number. You might implement such a closure in Haskell in the following way:&lt;br /&gt;&lt;br /&gt;let add x y = x + y&lt;br /&gt;&lt;br /&gt;let adder3 = add 3&lt;br /&gt;&lt;br /&gt;There you go: adder3 is exactly our closure: when you evaluate 'adder3 10' you get 13.&lt;br /&gt;&lt;br /&gt;How can you do this in C?&lt;br /&gt;&lt;br /&gt;Well, we'll start with a simple adder:&lt;br /&gt;&lt;br /&gt;int adder3(int x)&lt;br /&gt;{&lt;br /&gt; int data = 3;&lt;br /&gt; return data + x;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Not much of a closure, is it? What if we want to use something else instead of 3? What we would need is a function&lt;br /&gt;&lt;br /&gt;typedef int (*adder)(int);&lt;br /&gt;&lt;br /&gt;adder createAdder(int data)&lt;br /&gt;{&lt;br /&gt;   // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;that returns such an adder. But you can't do this in C, because functions are not first class objects. Oh wait! Actually, in C, memory is a first class citizen, and therefore you are free to do whatever you want with it. Including, wait for this, placing code in memory and returning a pointer to it.&lt;br /&gt;&lt;br /&gt;Without further discussion, we need the code for a generic adder function. This is not difficult to get, and we'll kindly ask the compiler to provide to us so we don't actually have to write machine code:&lt;br /&gt;&lt;br /&gt;int adderGeneric(int x)&lt;br /&gt;{&lt;br /&gt; int data = MAGIC;&lt;br /&gt; return data + x;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void endOfAdderGeneric() {}&lt;br /&gt;&lt;br /&gt;There you go. The machine code for the generic adder function is now between the starting addresses of the adderGeneric and endOfAdderGeneric function. Now our createAdder function only needs to copy this code, modify the data, and return the result:&lt;br /&gt;&lt;br /&gt;adder createAdder(int data)&lt;br /&gt;{&lt;br /&gt; char *start = (char *)adderGeneric;&lt;br /&gt; char *end = (char *)endOfAdderGeneric;&lt;br /&gt;&lt;br /&gt; char *result = (char *)malloc(end - start);&lt;br /&gt; memcpy(result, start, end - start);&lt;br /&gt; &lt;br /&gt; char *p;&lt;br /&gt; for (p = result; ; ++p) {&lt;br /&gt;  int *q = (int *)p;&lt;br /&gt;  if (*q == MAGIC) {&lt;br /&gt;   *q = data;&lt;br /&gt;   break;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; return (adder)result;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void deleteAdder(adder a)&lt;br /&gt;{&lt;br /&gt; char *m = (char *)a;&lt;br /&gt; free(m);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The createAdder first allocates enough memory for our adder. It knows how much it needs because (usually) C functions are laid out sequentially in memory; therefore the starting address of function endOfAdderFunction should match the end of the adderFunction.&lt;br /&gt;&lt;br /&gt;Then it copies the code of the adderGeneric function into the newly allocated location. Now all it needs to do is set the internal data. An unsafe, platform dependant, ready to blow up in your face way to do this is to search for the constant MAGIC in the function code. When it finds this magic number, it replaces it by the actual data.&lt;br /&gt;&lt;br /&gt;I defined MAGIC as follows:&lt;br /&gt;&lt;br /&gt;#define MAGIC 0xAEAEAEAE&lt;br /&gt;&lt;br /&gt;but you're free to set it to anything reasonable for your platform.&lt;br /&gt;&lt;br /&gt;Then the pointer to the newly created block of code is returned, which should work as well as the generic adder.&lt;br /&gt;&lt;br /&gt;To complete the example, check out the main code:&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; adder add3 = createAdder(3);&lt;br /&gt; adder add5 = createAdder(5);&lt;br /&gt; printf("%d %d\n", add3(10), add5(10));&lt;br /&gt; deleteAdder(add3);&lt;br /&gt; deleteAdder(add5);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;There you go: you have closures in C. The only question that remains is when you would want to use such a trick. The answer is: very sparingly. The above code can send you and your team in debugging hell. Any new version of the compiler might decide to optimize stuff in a different way, changing the way functions are laid out in memory and any other number of things can go wrong.&lt;br /&gt;&lt;br /&gt;However, you might have to do this when working with legacy code. The above code was inspired by the following question asked on stackoverflow:&lt;br /&gt;&lt;br /&gt;http://stackoverflow.com/questions/499153/&lt;br /&gt;&lt;br /&gt;The person asking the question wants a way to register a callback function that is a member of an object. Unfortunately, there is not way to explicitly pass around the this pointer. Being unable to change the interface of the library, a quick hack like the one I described can do wonders.&lt;br /&gt;&lt;br /&gt;I have uploaded the full code sample to &lt;a href="http://pastie.org/376806"&gt;pastie 376806&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-1724705722233745311?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/1724705722233745311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=1724705722233745311' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/1724705722233745311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/1724705722233745311'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2009/02/how-to-hack-closures-in-your-c-code-or.html' title='How to Hack Closures in your C Code (or &quot;The Closure Design-Pattern in C&quot;).'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-131088713824042492</id><published>2008-05-30T06:45:00.000-07:00</published><updated>2008-05-30T07:59:40.780-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CAPTCHA'/><category scheme='http://www.blogger.com/atom/ns#' term='bot'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><title type='text'>Bots and animals</title><content type='html'>Even though it is available since 2007, I haven't heard of Asirra until today, when I read someone's &lt;a href="http://www.codinghorror.com/blog/archives/001123.html"&gt;blogpost&lt;/a&gt; on spam.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://research.microsoft.com/asirra/"&gt;Asirra&lt;/a&gt; is a database of pictures of cats and dogs. Each picture comes labeled with the type of animal it contains. You can't see the database directly; but you can access it through their &lt;a href="http://research.microsoft.com/asirra/installation.aspx"&gt;webservice&lt;/a&gt;. The idea is to help fight bot spam by requiring the user to flag 12 images as either cats or dogs. I encourage you to test it out &lt;a href="http://research.microsoft.com/asirra/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I tried their demo and it is kind of cool. I didn't make any unintentional mistake in about ten tries and it is really quite a joy to look at the pets. Their academic paper is available &lt;a href="http://research.microsoft.com/asirra/papers/CCS2007.pdf"&gt;here&lt;/a&gt; and it is a light read if you are interested in the details. In my opinion, Microsoft's researchers did quite a good job of analyzing the technical advantages and disadvantages of their scheme.&lt;br /&gt;&lt;br /&gt;However, I believe Asirra will only remain safe if no high-profile website starts using it. Three million pictures is really not a lot, if you have the financial incentive to label them all. Furthermore, the database servers themselves could be compromised. Also, it is a poor business decision to rely on a single service that, at any time, may close shop or decide to charge a possibly absurd amount of money for their service.&lt;br /&gt;&lt;br /&gt;All in one, I believe Asirra is a good alternative to CAPTCHAs for smaller sites or amateur projects and I hope the state of the art in the field advances well beyond the annoying text recognition systems we have today.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-131088713824042492?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/131088713824042492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=131088713824042492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/131088713824042492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/131088713824042492'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2008/05/bots-and-animals.html' title='Bots and animals'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-3216418806111979030</id><published>2008-03-16T06:54:00.000-07:00</published><updated>2008-05-30T08:00:19.916-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='prank'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><category scheme='http://www.blogger.com/atom/ns#' term='computer'/><category scheme='http://www.blogger.com/atom/ns#' term='wozniak'/><category scheme='http://www.blogger.com/atom/ns#' term='book'/><title type='text'>"How I invented the personal computer, co-founded Apple, and had fun doing it"</title><content type='html'>It's been about nine months since I posted my last entry. In the meantime, a lot has happened. I graduated the &lt;a href="http://www.info.uaic.ro/"&gt;Faculty of Computer Science&lt;/a&gt; from Iasi, Romania, I had a great summer holiday (except I fucked up my Ocaml summer project because of a lack of time), I got a scholarship for a computer science &lt;a href="http://mpri.master.univ-paris7.fr/"&gt;research master&lt;/a&gt; at &lt;a href="http://www.ens-cachan.fr/"&gt;ENS Cachan&lt;/a&gt; and I started my internship at &lt;a href="http://www.lsv.ens-cachan.fr/"&gt;LSV&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I now live close to Paris and, of course, it's quite nice. This blog post is about a book I bought and read more than a year ago (and which I'm re-reading right now). I bought it in the US, at the time when I was doing my second internship at Microsoft.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Steve_Wozniak"&gt;Steve Wozniak&lt;/a&gt;  was on the Microsoft campus in Redmond to give a talk (I think it was part of the process of promoting his book). I went there, but the room was too small. It seemed that every other person in the campus decided to participate (ok, this is an exaggeration).&lt;br /&gt;&lt;br /&gt;Anyway, frustrated I couldn't find a place, I decided to buy the book anyway, and try to see the cast online (which I couldn't, due to technical problems). I'm  sorry even now that I didn't have the inspiration to go earlier, to get a seat.&lt;br /&gt;&lt;br /&gt;Anyway, the book is simply awesome. It's written by Steve Wozniak (with Gina Smith). I'm not sure about the "official" title, but the cover reads something like this:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;iWoz&lt;br /&gt;&lt;br /&gt;How I invented the personal computer, co-founded Apple, and had fun doing it&lt;br /&gt;&lt;br /&gt;COMPUTER GEEK TO CULT ICON&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;I knew a little history about Apple and Steve Wozniak and Steve Jobs, but to read it from Steve himself was really cool.&lt;br /&gt;&lt;br /&gt;He starts by describing how his father would teach him electronics at a very early age and how much this mattered to him:&lt;blockquote&gt;"He pulled out a blackboard from time to time, a tiny little blackboard we had in our house on Edmonton Avenue, and when I asked, he would answer anything and make diagrams for it. I remember how he showed me what happened if you put a plus voltage into a transistor and got a minus voltage out the other end of the transistor. There must have been an inverter, a type of logical gate. And he even physically taught me how to make an AND gate and an OR gate out of parts he got -- parts called diodes and resistors. And he showed me how they needed a transistor in between to amplify the signal and connect the output of one gate to the input of the other.&lt;br /&gt;&lt;br /&gt;To this very moment, that is the way every single digital device on the planet works at its most basic level.&lt;br /&gt;&lt;br /&gt;[...]&lt;br /&gt;&lt;br /&gt;It's amazing, really, to think that my dad taught me about transistors back when almost no one saw anything but vacuum tubes. So he was at the top of the state of the art, probably because his secret job put him in touch with such advanced technology. So I ended up at the state of the art, too."&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;There are books you read, and they forever change the way you think. For me, this was one of those books. Aside from the historically interesting technical content, the book also excels in entertainment value. Wozniak describes some of the pranks he loved to pull:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;"I got the idea to build a little electronic metronome -- you know, the thing that goes tick, tick, tick, to keep time when people take piano lessons. I built it, heard the ticking, and thought: Hey this sounds like a bomb. So I took some batteries, took the labels off the batteries so they looked like plain metal canisters, and I taped them together. And then I wrote in big letters on it: CONTACT EXPLOSIVE.&lt;br /&gt;&lt;br /&gt;I thought: Oh, this will be funny. I'll stick it in Bill Werner's locker. I just happened to know his locker code. Bill's locker was near mine so I put my so-called electronic metronome in. Now, this was in the morning before school, and after I put it in there, I could barely hear it ticking. Nobody was going to be tricked by this if they couldn't even hear it! I'm thinking: What a bummer and what a waste if this thing isn't going to work. But when I came out of my last final that day, my counselor walked up to me and said: "Steve, the vice principal wants to see you in his office." This was a bad sign. [...]&lt;br /&gt;&lt;br /&gt;And the principal starts telling me how the English teacher, Mr, Stottlemeier, had heard a ticking sound in the locker. The principal, Mr. Bryld, told me how he opened the locker, clutched the device to his chest, and then ran all the way out to the football field and dismantled it!&lt;br /&gt;&lt;br /&gt;I started laughing, even though I was trying not to, so then I tried to cough to cover it up. But I couldn't even do that, because I knew I had rigged the metronome with a switched resistor to start ticking faster when someone opened up the locker door."&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;I'm not going to ruin the pleasure you'll get reading this book by quoting more stuff. I'll let you enjoy the chapters on TV jamming, phone phreaking, creating the Apple I and II, crashing a plane and other delicious topics ;-)&lt;br /&gt;&lt;br /&gt;Even if you do not understand computer science or maths or physics, I think you will appreciate this book and I hope you enjoy it as much as I do.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-3216418806111979030?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/3216418806111979030/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=3216418806111979030' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/3216418806111979030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/3216418806111979030'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2008/03/how-i-invented-personal-computer-co.html' title='&quot;How I invented the personal computer, co-founded Apple, and had fun doing it&quot;'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-165110141115852741</id><published>2007-06-07T13:14:00.000-07:00</published><updated>2007-06-07T13:27:53.032-07:00</updated><title type='text'>Firefox 3 URL "Feature"</title><content type='html'>On &lt;a href="http://programming.reddit.com/"&gt;the programing subreddit&lt;/a&gt; I got to &lt;a href="http://blog.mozilla.com/faaborg/2007/06/01/the-user-interface-of-firefox-3-features/"&gt;this link&lt;/a&gt;, which describes some new features proposed for Firefox 3.&lt;br /&gt;&lt;br /&gt;The one feature that received my attention (in a bad way), is the highlighting of the domain of the current site. For example (taken from &lt;a href="http://weblogs.mozillazine.org/gerv/archives/2007/05/location_bar_proposal_1.html"&gt;here&lt;/a&gt;), the URL bar would look like this: &lt;span style="color:gray;"&gt;http://www.&lt;/span&gt;&lt;span style="color:black;"&gt;fred.blogspot.com&lt;/span&gt;&lt;span style="color:gray;"&gt;/archive/2007/04/06/mypost&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;I do not like this. The first problem is that the shade of gray is not readable. The next wrong thing, which is not that obvious, but more problematic, is that this could actually help phishers. I can only image an innocent looking Firefox user: "But the site was really Bank Example. I'm sure. The browser even highlighted www.example.com for me (where one of the letters is not what it seems)".&lt;br /&gt;&lt;br /&gt;Please, please, drop this "feature". There is no use case for it. (Ok. there is a small use case, where if the address is long, with may sub-domains, you don't immediately see the top-level domain...)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-165110141115852741?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/165110141115852741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=165110141115852741' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/165110141115852741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/165110141115852741'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/06/firefox-3-url-feature.html' title='Firefox 3 URL &quot;Feature&quot;'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-4582398422005544</id><published>2007-05-31T05:56:00.000-07:00</published><updated>2007-05-31T06:25:06.933-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web 2.0'/><category scheme='http://www.blogger.com/atom/ns#' term='API'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='google'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><title type='text'>Google Gears</title><content type='html'>Just today I've seen &lt;a href="http://gears.google.com/"&gt;this link&lt;/a&gt; on &lt;a href="http://www.reddit.com/"&gt;reddit&lt;/a&gt;. and I'm very excited about this. Remember an earlier post about &lt;a href="http://nothingintoinsight.blogspot.com/2007/02/microsoft-blew-it-with-ie.html"&gt;off-line web applications &lt;/a&gt;Well, they're closer than ever. Google released Gears, which is a Firefox/IE extension that provides an API for off-line web applications.&lt;br /&gt;&lt;br /&gt;On the developer page, google posted 4 demos showing off their API.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://code.google.com/apis/gears/samples/hello_world_database.html"&gt;the first one&lt;/a&gt; shows how an offline database can be used to keep track of stuff on the client side, without it going away the second time you visit that webpage&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/apis/gears/samples/hello_world_resourcestore.html"&gt;the second demo&lt;/a&gt; shows how google gears can remember an webpage and display it even when you are offline and the cache is emptied&lt;font class="down" style="display: block;" id="formatbar_CreateLink" title="Link" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmouseup="" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);"&gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;I didn't understand the usefulness of the &lt;a href="http://code.google.com/apis/gears/samples/hello_world_managedstore/managed_store.html"&gt;third demo&lt;/a&gt;, but I'm sure there are scenarios which use it&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.google.com/apis/gears/samples/hello_world_workerpool.html"&gt;the last demo &lt;/a&gt; is about asynchronous methods, but I'm not sure this belongs in gears.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;I am very excited about Gears, as it seems to work for both Microsoft Internet Explorer and Mozilla Firefox. Google says Safari support is work in progress.&lt;br /&gt;&lt;br /&gt;For the moment, I'm quite busy with my thesis, but I'm dying to get my code snippet web application to use Gears.&lt;br /&gt;&lt;br /&gt;Also, I can't wait to see a geared up version of Blogger and Gmail. Imagine preparing your posts without the need to access the internet and saving them to the local database. Next time you go online, Blogger will upload whatever you've been working on. Sounds cool, right?&lt;br /&gt;&lt;br /&gt;I like Gears because the API seems simple enough and is super useful. However, in the long term, Gears (or whatever other framework for off-line web apps will prevail) will make web applications even more difficult to create. Also, I suppose a whole new range of security issues will be uncovered by this new type of applications.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-4582398422005544?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/4582398422005544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=4582398422005544' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/4582398422005544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/4582398422005544'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/05/google-gears.html' title='Google Gears'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-5909245622180440163</id><published>2007-05-09T02:04:00.000-07:00</published><updated>2007-05-09T02:28:34.532-07:00</updated><title type='text'>To the Java refactoring maniacs</title><content type='html'>Every once in a while I have a virtual fight with some Java programmer over refactoring tools. They are not available for C++, Python, whatever. How can you even use an IDE without refactoring tools? Do you know how much productivity you gain? The Java language is the best language in the world; it was designed to be "refactorable". Bullshit!&lt;br /&gt;&lt;br /&gt;Let's see. Java is known to be a poor language from expressiveness' point of view. Tools save it somehow, and whenever I try to tell someone there are better languages out there, IDEs are thrown into my face and the refactoring tools they provide are the ultimate arguments for Java.&lt;br /&gt;&lt;br /&gt;So I set out to prove that the most simple refactoring tool one can think of is not totally automatable, even in a language as simple as Java. Let's wait no more. I clicked Eclipse in my Applications/Programming menu, went and grabbed a cup of tea while it was loading, came back just to see it's asking about the workspace (first time use), grabbed another cup of tea while waiting, and set out to test my theory.&lt;br /&gt;&lt;br /&gt;I entered this code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.lang.Class;&lt;br /&gt;import java.lang.reflect.InvocationTargetException;&lt;br /&gt;&lt;br /&gt;public class MainClass {&lt;br /&gt; public static void poorName() {&lt;br /&gt;  System.out.println("This is a stupid method.");&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] argv) {&lt;br /&gt;  try {&lt;br /&gt;   MainClass.class.getMethod("poorName", new Class [] {}).invoke(null, new Object[]{});&lt;br /&gt;  }&lt;br /&gt;  catch (NoSuchMethodException e1) {&lt;br /&gt;   System.out.println("there is no method with name poorName.");&lt;br /&gt;  }&lt;br /&gt;  catch (IllegalAccessException e2) {&lt;br /&gt;   System.out.println("there is an illegal access.");&lt;br /&gt;  }&lt;br /&gt;  catch (InvocationTargetException e3) {&lt;br /&gt;   System.out.println("invocation target exception.");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I was initially aiming at fewer lines of code, but then I decided to handle all the exceptions. Simply put, this program looks for a method called poorName in MainClass, using introspection. It then tries to call that method. If the method is not found or whatever, an error message is printed.&lt;br /&gt;&lt;br /&gt;As I run this program, I get the nice message:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;This is a stupid method.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then, because I don't like the name of the method, I set out to rename it. Of course, what better way of renaming a method than right-clicking on it's name, and selecting "Rename" from the "Refactor" menu?&lt;br /&gt;&lt;br /&gt;Tadam, no error message, method was renamed. Resulting code?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.lang.Class;&lt;br /&gt;import java.lang.reflect.InvocationTargetException;&lt;br /&gt;&lt;br /&gt;public class MainClass {&lt;br /&gt; public static void goodName() {&lt;br /&gt;  System.out.println("This is a stupid method.");&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] argv) {&lt;br /&gt;  try {&lt;br /&gt;   MainClass.class.getMethod("poorName", new Class [] {}).invoke(null, new Object[]{});&lt;br /&gt;  }&lt;br /&gt;  catch (NoSuchMethodException e1) {&lt;br /&gt;   System.out.println("there is no method with name poorName.");&lt;br /&gt;  }&lt;br /&gt;  catch (IllegalAccessException e2) {&lt;br /&gt;   System.out.println("there is an illegal access.");&lt;br /&gt;  }&lt;br /&gt;  catch (InvocationTargetException e3) {&lt;br /&gt;   System.out.println("invocation target exception.");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When I run this code, guess what? It changed behavior. It now prints:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;there is no method with name poorName.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;which is true, but sad. There you go: method rename is not computable (anyone care for the mathematical proof?), even in a language as simple as Java (well, the language is not as simple as it used to be, but still).&lt;br /&gt;&lt;br /&gt;To all Java refactoring maniacs out there: the next time you want to tell me you're not looking at another language because it doesn't provide automated refactoring tools, please think hard about why that happens in the first place.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-5909245622180440163?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/5909245622180440163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=5909245622180440163' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/5909245622180440163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/5909245622180440163'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/05/to-java-refactoring-maniacs.html' title='To the Java refactoring maniacs'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-2957098739853625959</id><published>2007-03-02T02:15:00.000-08:00</published><updated>2007-03-02T02:26:39.212-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='question'/><category scheme='http://www.blogger.com/atom/ns#' term='feature request'/><category scheme='http://www.blogger.com/atom/ns#' term='Lisp'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='languages'/><title type='text'>Language feature request: define by renaming</title><content type='html'>A few weeks back, I was looking at &lt;a href="http://www.cs.bham.ac.uk/~dxp/prism/"&gt;Prism&lt;/a&gt;. Prism is a probabilistic model checker. This means it can answer interesting questions about your model. For example, when designing a protocol, you can ask it: what is the probability that a message is lost? Or, when building a model of a soft realtime system, you can ask it: what is the probability that an operation will take longer than 100ms. etc.&lt;br /&gt;&lt;br /&gt;Anyway, that's besides the point. What I want to talk about today is a feature that I've seen in Prism's model description language (which looks a lot like &lt;a href="http://www.spinroot.com/spin/Man/promela.html"&gt;Promela&lt;/a&gt;). &lt;a href="http://www.cs.bham.ac.uk/~dxp/prism/tutorial/herman.php"&gt;Here&lt;/a&gt; is the second part of the Prism tutorial. It introduces a language feature that I loved instantly. It is called &lt;a href="http://www.cs.bham.ac.uk/~dxp/prism/manual/ThePRISMLanguage/ModuleRenaming"&gt;module renaming&lt;/a&gt; and it rocks.&lt;br /&gt;&lt;br /&gt;Module renaming basically works in the following way: take this function, which does this. Then create another function, which is exactly the same, but replace this symbol by another.&lt;br /&gt;&lt;br /&gt;I can imagine how this can work for a general-purpose programming language. Define a function which sums two numbers:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;pseudocode: sum x y = x + y&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then define the product to be like the sum, except replace + by *.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;pseudocode: product = sum where + = *&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's nice. So I thought I'd try and see if I can implement this using lisp macros. I don't have much experience with lisp, but here's how I sort-of did it:&lt;br /&gt;&lt;br /&gt;First thing's first. Create a function that takes a list and replaces every "source" with "target".&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(defun rename-symbol (list source target)&lt;br /&gt;  (if (eq list nil)&lt;br /&gt;      nil&lt;br /&gt;    (cons&lt;br /&gt;     (if (listp (first list))&lt;br /&gt;     (rename-symbol (first list) source target)&lt;br /&gt;       (progn&lt;br /&gt;     (if (eq (first list) source)&lt;br /&gt;         target&lt;br /&gt;       (first list))))&lt;br /&gt;     (rename-symbol (rest list) source target))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here's how it works:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;CL-USER&gt; (rename-symbol `(+ 1 2) '+ '*)&lt;br /&gt;(* 1 2)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Well, I actually want to perform multiple renamings, so I replaced source and target with an association list (sort of like a hash table):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(defun association (item alist)&lt;br /&gt;  (rest (assoc item alist)))&lt;br /&gt;&lt;br /&gt;(defun rename-symbols (list alist)&lt;br /&gt;  (if (eq list nil)&lt;br /&gt;      nil&lt;br /&gt;    (cons&lt;br /&gt;     (if (listp (first list))&lt;br /&gt;     (rename-symbols (first list) alist)&lt;br /&gt;       (if (not (eq (association (first list) alist) nil))&lt;br /&gt;       (association (first list) alist)&lt;br /&gt;     (first list)))&lt;br /&gt;     (rename-symbols (rest list) alist))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Which does the same thing, except it takes an association list and can replace multiple symbols. Here's how it works:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;CL-USER&gt; (rename-symbols `(defun sum (a b) (+ a b)) '((+ . *) (sum . product)))&lt;br /&gt;(DEFUN PRODUCT (A B) (* A B))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;See where we're going? Now let's write a simple macro:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(defun rename (list alist)&lt;br /&gt;  (eval (rename-symbols list alist)))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And here's how Lisp's syntax can be extended to allow renaming:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(setq my-function `(defun sum (a b) (+ a b)))&lt;br /&gt;&lt;br /&gt;(rename my-function nil)&lt;br /&gt;(rename my-function '((+ . *) (sum . product)))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When evaluating the above, you'll end up with two functions, sum and product, which do what you expect.&lt;br /&gt;&lt;br /&gt;Disclaimer: I am a Lisp beginner and I've probably made some mistakes.&lt;br /&gt;&lt;br /&gt;I welcome any and all corrections/improvements/suggestions. I would be especially interested in creating a rename macro that works as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(defun sum (a b) (+ a b))&lt;br /&gt;(rename sum product '((+ . *)))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If there is any Lisp guru reading this, please let me know ;-)&lt;br /&gt;&lt;br /&gt;Also, I am curios about how this could be implemented in languages such as Ocaml or Haskell. Some of the readers will be quick to point out that this feature is not really required, because you can get the same benefit by creating a function which is more generic that product and sum, which would look like this in Haskell:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;combine op x y = op x y&lt;br /&gt;sum = combine (+)&lt;br /&gt;product = combine (*)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But I find the rename feature extremely geeky and cool. So let me have it :D.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-2957098739853625959?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/2957098739853625959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=2957098739853625959' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/2957098739853625959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/2957098739853625959'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/03/language-feature-request-define-by.html' title='Language feature request: define by renaming'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-8172087099627725314</id><published>2007-03-01T13:43:00.000-08:00</published><updated>2007-03-01T13:51:56.378-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='libraries'/><category scheme='http://www.blogger.com/atom/ns#' term='GUI'/><category scheme='http://www.blogger.com/atom/ns#' term='languages'/><title type='text'>I need a GUI for my application. What library should I chose?</title><content type='html'>Hi there. I recently had an idea about a nice desktop application that I would like to write. I know a handful of programming languages, but none is very good for what I want. Let me tell you what it is about and please disagree with me.&lt;br /&gt;&lt;br /&gt;The application I want. I'm taking a course on Embedded Systems this semester. I'm a CS student, so I don't know much (read: know next to nothing) about hardware design. But I learned about logical gates, and latches, and stuff like that, and I have a pretty good idea about how one would go about building a small processor.&lt;br /&gt;&lt;br /&gt;I would like to be able to play with these small hardware components, and I intend to write a small simulator for myself. The basic nonfunctional requirements of the simulator are the following:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;graphical user interface. Although I understand the superiority of a text oriented hardware description language + parser, I feel that a GUI would allow me to get a better feeling for hardware&lt;/li&gt;&lt;li&gt;cross platform&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Of course, I have a good idea about how one would go in writing such a program. Except that I can't decide on a programming language/platform for the project because of the lack of good GUIs. Here are my current thoughts on this matter:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Java. As far as I'm concerned, even though I hate Java-the-language very much, this is my best choice so far. Java has a decent cross-platform GUI, is reasonably efficient, and I can get around the language for some of the more advanced things I want. However, thinking about the huge amount of code it would take to do even the most basic processing makes me take a step back.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;C#. I find C# to be better language than Java, but it has a huge problem: it's not cross platform (yes, I do know about Mono).&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;C++. Ah. This is the language that I am most experienced with. Even though it doesn't do garbage collection and doesn't manage the code for me, C++ is somewhat better than Java from a language semantics point of view. However, it lacks a standard GUI. Let's look at the GUI libraries you can find:&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;ul&gt;&lt;li&gt;QT. No thanks. I don't like metacompilers. Compiling C++ code is already very slow; I don't want the metacompiler to take another age. I don't like proprietary. I don't like the license. The GUI code, however, is quite clean and workable with.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;ul&gt;&lt;ul&gt;&lt;li&gt;MFC. NOT. The code is messy, proprietary and not cross-platform.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;GTK+. The syntax is somewhat better and wxWidgets, but it's still messy. Also, it's not really C++. I don't like reading GTK code. I do like the box feature though. Documentation is not as good as it should be.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;GTKMM. Better than GTK+ because it's more C++. However, the syntax is still not as good as it should be and it's not as flexible as wxWidgets. The documentation needs more work. If I would chose C++ for this project, GTKMM would probably be my GUI library.&lt;/li&gt;&lt;li&gt;wxWidgets. Well, this one is, imho, the best GUI for C++ ever. However, it's just as messy as MFC, and I don't like the code at all. Quite good documentation.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;                    You see, C++ libraries are huge mess. It's very difficult to chose one, and, once you do, you're pretty much stuck with it. Are you sure? [Y,n]&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Python is one of my favorite languages. It is very easy to write good Python code and you can find a library with good docs for just about anything. However, Python is lacking at the speed chapter. You see, Python can be up to 50 times slower than C++. That can be the difference between waiting one second for a simulation to finish, and waiting 1 minute. Python comes with standard Tk bindings, but I would probably chose it's wxWidgets bindings for extra power.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Haskell. Haskell is another favorite of mine when it comes to coding algorithms. Haskell comes lazily evaluated by default, but I'm not very concerned about it's speed limitations. What I am concerned about is that there is no standard GUI library and there are no good bindings to other libraries -- all of them wrap code around the IO monad, making it bad on your eyes.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Ocaml is Haskell's older cousin. Ocaml doesn't come lazily evaluated and is dead fast. It is very expressive when it comes to coding algorithms, but the GUI bindings are really bad from an aesthetic point of view.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Lisp/Scheme. Which one? I'm sure they are fast enough for what I need, and I'm sure that the code will end up to be very elegant, but I don't have any experience with GUIs for either of the two. Can anyone share some insight into this?&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Although I would like to have all the source code in just one language, I'll probably end up choosing one language for the GUI and another for the backend. Currently I'm thinking about choosing Java or Python for the GUI and C++ or Haskell for the backend. Of course, interop will be very fun and I'll probably end up duplicating code between the two languages.&lt;br /&gt;&lt;br /&gt;Have fun and may you never need to think about this kind of shit.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-8172087099627725314?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/8172087099627725314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=8172087099627725314' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/8172087099627725314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/8172087099627725314'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/03/i-need-gui-for-my-application-what.html' title='I need a GUI for my application. What library should I chose?'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-730490421857887620</id><published>2007-02-18T11:47:00.000-08:00</published><updated>2007-02-18T12:19:27.966-08:00</updated><title type='text'>Microsoft blew it with IE</title><content type='html'>Recently, the Mozilla Foundation announced &lt;a href="http://starkravingfinkle.org/blog/2007/02/firefox-3-offline-app-demo/"&gt;offline application support&lt;/a&gt; for Firefox 3. You see, this is the holy grail of the web. Once you have support for running offline applications in the browser, the browser becomes the framework/platform of choice for any king of application.&lt;br /&gt;You see, until just recently, Microsoft Windows was the platform of choice for most desktop applications. This was due to the largest install base and because Microsoft has done just about anything to make sure that programmers find it easy to target their platform (think MSDN).&lt;br /&gt;A platform is very different from your average library. A platform limits the ways in which you can write code. For example, in Windows, you create so-called applications. You know, you write a window procedure and Windows takes care of calling code for you. Before you know it, you're stuck. Fortunately, all the platforms that you can possibly care about are pretty similar, so if you want to port the code, it's not the end of the world. But it's still difficult. Plus Microsoft gets to dictate the changes.&lt;br /&gt;Platforms are a lot like frameworks. You must write your code to fit the platform/framework. Until recently, Windows was, of course, the platform of choice for general purpose applications (think office applications, etc). Microsoft did its best to keep you locked into their platform.&lt;br /&gt;Then the web happened. Microsoft got really lucky and &lt;a href="http://en.wikipedia.org/wiki/Embrace%2C_extend_and_extinguish"&gt;somehow&lt;/a&gt;managed to obtain some 90% of browser market. But then, then it screwed up really badly. Firefox started happening. A couple of years of no updates to Internet Explorer later, Firefox is the browser of choice for &lt;a href="http://paulgraham.com/gh.html"&gt;hackers&lt;/a&gt;. Now that everyone who matters runs Firefox, Mozilla (or maybe Google, because they hire the programmers behind Firefox) can go ahead and add their own features of choice. Offline application support is one killer feature.&lt;br /&gt;At the present moment, the only problem that keeps people from totally throwing away their desktop apps and switching to web-based ones is that Internet connectivity is not available everywhere every time. Now that offline application support is being added to Firefox, the browser can become the platform of choice for traditional "desktop" apps. I predict that other issues, such as raw speed, will become less and less important (JavaScript will do).&lt;br /&gt;I also predict that once Firefox gets a big enough market share (say 30-40%), its adoption rate will increase exponentially and we'll see 80% in a very short time. Microsoft looses.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-730490421857887620?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/730490421857887620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=730490421857887620' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/730490421857887620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/730490421857887620'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/02/microsoft-blew-it-with-ie.html' title='Microsoft blew it with IE'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2099230223105210050.post-6770475671098457239</id><published>2007-01-19T01:06:00.000-08:00</published><updated>2007-02-15T06:04:52.274-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><category scheme='http://www.blogger.com/atom/ns#' term='software engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Off to a bad start: XML sucks</title><content type='html'>I've been meaning to start a blog for a long time now. It's only now that I have the time to do it. Lots of things are getting in the way. One is school. Another is laziness. The other is that software sucks. Anyway, I've made it. Welcome to my blog.&lt;br /&gt;&lt;br /&gt;Topic de jour: XML. XML sucks. Why is that? Isn't XML the next-generation all-purpose future-proof data storage/exchange format? Well, no.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;XML is verbose: you know what? I'm not even going to complain about it anymore; this is a moderate failure that could eventually be fixed without much fuss (e.g. switch to lisp syntax)&lt;/li&gt;&lt;li&gt;XML is too complex: entities, namespaces, DOM, SAX, XSLT, XMLReader, XPath, XQuery, XUpdate, XPointer, DTD,  XSchema, RELAX NG and these are just off the top of my mind.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;XML is unfinished: Every one of the above technologies is not finished. You know DOM? Level 1, 2, soon to be 3. The specs are huge; no human should be tortured by having to read them.&lt;/li&gt;&lt;li&gt;XML will never be finished: Each and every one of the X* specs will die in a couple of years after it hits gold, being replaced with a newer, possibly incompatible, version. This will go on until the industry will have decided that you know, XML is just so unfashionable, they must move on to the next big thing.&lt;/li&gt;&lt;/ul&gt;So just why is the state-of-the-art data-storage/exchange format so lame? Well, because the industry is going after a chimera. The idea sounds very nice on paper: an universal interchange format, that is human readable and extensible.&lt;br /&gt;&lt;br /&gt;Human readable? No way. If you still think XML was made for humans to read and only incidentally for machines to process, go read some XML to yourself (for the best effect, try a SOAP message, generated by your favorite framework).&lt;br /&gt;&lt;br /&gt;Extensible? Yes. You can add new tags. Hmm. But, you know what? After you add that new tag, is your software going to work without modifications? In some cases, yes. Cases you had anticipated. In most cases, of course not; at least not like expected. Also, please remember to redo the DTD/XSchema/RelaxNG or whatever new validation technology will be invented.&lt;br /&gt;&lt;br /&gt;So is XML any good? Well, sort of. The best thing about it is settings the record straight on encoding. Another nice thing is the tree structure for holding data. The rest is mostly crap.&lt;br /&gt;&lt;br /&gt;Remember extensibility? XML solved a very very small problem about it: the syntax.  You still have to determine the semantics of the change. You still have to recode your application to some extent. You still need to worry about incompatibilities between server and client. XML is not the &lt;a href="http://en.wikipedia.org/wiki/No_Silver_Bullet"&gt;silver bullet&lt;/a&gt;. It just solves an accident in the history of computing. It has no essence whatsoever.&lt;br /&gt;&lt;br /&gt;Now XML is way over-hyped and will never be finished. Good. What are you supposed to use then? Well, it really doesn't matter all that much. If you need to design a new DSL, you can use XML. But more importantly, make sure you don't create essential complexity. Make sure you put in a version number somewhere. Better yet, chose a well documented text format. Also see the &lt;a href="http://www.catb.org/~esr/writings/taoup/"&gt;Art of Unix Programming&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2099230223105210050-6770475671098457239?l=nothingintoinsight.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nothingintoinsight.blogspot.com/feeds/6770475671098457239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2099230223105210050&amp;postID=6770475671098457239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/6770475671098457239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2099230223105210050/posts/default/6770475671098457239'/><link rel='alternate' type='text/html' href='http://nothingintoinsight.blogspot.com/2007/01/off-to-bad-start-xml-sucks.html' title='Off to a bad start: XML sucks'/><author><name>stefan.ciobaca</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
