2013-09-29

Debian Wheezy, GNOME 3 and others small things


When my Ubuntu GNU/Linux distro received the "alert" that it wasn't supported anymore and the upgrade failed, instead of finding out why, first I tried to transform the distro into a LTS one (not totally successful because I had to downgrade too many packages), then I decided to compile what I "needed"; but my final thought is that it is not a good idea mixing automatically installed packages and packages compiled by you (out of the APT world), especially if you begin updating libs which many other programs rely on, or if you compile the last version of a program that needs the last version of a "core" lib. To make it short, the system started to behave inconsistently (maybe since I circumvented some dependency…). Time for a brand new installation.

2013-09-07

Pick a framework

I am paying for a website I do not update since I started paying for it. The reason why I decided to purchase the domain and the web space was that another site was gently hosting some content of mine, but that site was going to go down soon (and in fact, currently is). So I needed some room for my old content, but I also wanted to do something modern, maybe cool, to experiment with several technologies (?). Thus, instead of copy-pasting my old site into the new space, I decided to carve my own custom CMS from scratch. It soon turned out to be a task beyond the quantity of my spare time, and my ability and my will too. I lost interest in it and in the same time decided to wait before to put the old content back, soon I will pick some cooked CMS or alike and inflate the old contents in it, I was saying to myself. But that "soon" became years. Since 2011 my site is simply dead (and it exists since 2011…!). Maybe like me (don't you hear my cavernous voice?)

I have renewed the fee until 2014, therefore I have to do something with it before that endline. If the aim is to host contents online, then creating a custom CMS is totally worthless. I like the idea that if the content of a site is great, then you don't need too much lights and fireworks, since people land on your site searching for the content you provide, and they end to be caught by it, despite of what it looks like — and of course I am not chasing the fame. I agree with this simple idea: a website is about its contents. It could be made even by plain HTML, for the sake of its hypertextual power, and be successful among the target niche (i.e. the two or three persons interested in that content). I am thinking about a site like Fravia's. But if I look to my own content, I see poor things. This blog contains cheap tech posts, simple sillyness, pointless speechs, and other few stuffs that hardly are worth a reading, like this very same post. This is supposed to be a "tech blog" about mainly computer related topics, but it is no more than "curiousity material for computer unsavvy". Moreover my research (I dare to call it so) flow is dried since at least 1 year. I am like a surfer surfing on a wave, a moment it's up, then you slip, gaining speed, and at last you are down waiting for the next wave. But each wave has its own peculiarities. The wave I am (more or less satisfactorily) surfing now is more about literature and politics, even if there are some hook in the computer world — but it's just because their are powerful tools you can use for several aims. The fact is, I am not using my spare time to program (though I do it, say, 8h/day, 5 days per week) as I did before. This is going to change, soon, or maybe later, the problem is exactly when, I say tomorrow, then I wake up and realize a whole year has flied away, and there's dust on several project, and on knowledge too, and on partners too, and on languages I was learning like Erlang. Currently, as said, I am more on other interests, but something started to seethe underneath. It begins with idea like the following: let's pick a framework and put anything on the site.

It seems a simple idea, but as usual I put my goals too far from where I am now, likely overstimating my current skills and the amount of spare time I am willing to consume for those goals.

Instead of creating something from scratch, the idea is to practice a framework like CakePHP. I picked it since it was the one I already knew a bit someway, but not enough. But the drift is lurking, and I am very prone to it, I am always drifting someway. The clear, fast, almost near goal to use CakePHP to develop something to give life to my site was going a little bit further. It starts with asking few questions, but the most important is: what kind of content do you want for your site? For my old content I don't need more than a directory listing, and something like a wiki or a blog, but for these I've chosen third party places like blogspot. So, I can't focus on the old content. The reason why I need a lights-and-fireworks site is indeed that my content sucks: i.e. nobody can be interested in it spontaneously. I have to add some spice, some seasoning, tasty sauces, to avoid people run away. Or rather I stick to simple directory listing, which works for so-called "nerds" and content-searcher. It'd be easy. But also boring to me. 

At first I had maybe just a problem: what kind of web application I need in order to present my old contents and likely to be able to add new one easily and swiftly? This is a great problem: saying I want to develop something is greatly silly: it seems the aim is not clear. And in fact, it is so! So I have to take a pencil and a paper, or other tools on the computer, and sketch the site, I know the contents I have, I need to imagine how I want to show them. Do I need just a showcase? I can add things later, maybe in the 2023, when a bloody world war (maybe nuclear) will be in progress, and I will be biologically dead. Questions that need to be answered, not necessarily in the order I write them:
  • What kind of content will you put on your site? I could be interested in many things, though how much time I spend on them depends on the wave,  and there are waves that haven't risen yet.
    • Graphic creations
      • 3D (Blender, POV-Ray, etc.)
      • 2D (GIMP, gfx tablet,  photos, generated by computer programs/simulations or drew by hand, etc.)
      • vector gfx (SVG, PostScript, Metafont/Post)
      • short films (link to youtube channel), in fieri
    • Music/noise creation
      • MIDI (composition, algorithmic composition etc.)
      • samples (Csound, etc.)
      • songs (likely link to other hosting sites)
      • articles about processes about "music" (another blog?)
    • Programming and computer related topics
      • desk/laptop (Amiga, GNU/Linux, ...etc.)
      • mobile (Android, Java, etc.)
      • articles (this blog?)
    • Writings (PDF + LaTeX/TeX / wiki content?)
      • Essays, lessons, articles, papers, slides (wide range topics)
      • Tales, novels, scripts
      • blogs (this one, the others, new one?)
    • Link collection / social
      • Linking with "streams" from social network like Diaspora, Twitter, Pump.io or alike
      • Linking with articles on external blogs
      • Bookmarks (delicious?)
      • links to github, sourceforge, bitbucket, wherever I have something hosted (few things, mostly crap)
    • Experimenting with web apps and services
      • social networks
      • rendezvous-point (f2f apps?) 
    • Advertising myself
      • who am I? what I do? what I've done?
  • What kind of technology do you want to use?
    • Currently I am bound to PHP+MySQL serverside. I don't want to make something that works on every browser, so I can stay on the edge of HTML5/CSS3 and Javascript without problems.
      • RAD PHP frameworks (which paradigm? MVC...?)
        • CakePHP?
        • Yii?
        • Symfony?
        • Others?
  • How do you think to show the contents? Can the user add their own? (No, but I'd like to experiment with OAuth and allow limited controlled access to some service, but I don't know which, clear, isn't it?)
    • No idea.
I thought to have found the right one in CakePHP, but then I've seen how many other there are out there, some are maybe "smaller", and therefore they can fit my need better. Or maybe not,... but there would be always time to add another framework in another dir!

Ok, now it's clear I should be studying CakePHP and planning the app in details (and in surface, I am going for the minimalism), instead of writing too many words like these. And my Android device is even waiting for some fresh original bytes to bite from me. It must wait. O and I have admit that such posts comes to life just to remember me that this blog exists! (While I am feeding the italian side blog, with a lot of posts, not technical one of course).

P.S. Forgot the only maybe meaningful part: the problem with RAD tools is that they are Rapid only if you know them, so, let us suppose, they will be Rapid the second time you develop using them; otherwise, they are not rapid. But how fast you can learn them, how steep is the learning curve? This may affect the choice. I started with CakePHP, but now I consider interesting Yii, but which one fits better my need? And so on, in a circular trip!

2013-04-24

Just another thought about how patent can be silly

Occasionally (sometimes often, sometimes rarely) I try to do my best to answer some question on stackoverflow.

Recently I have answered this question but at first I had interpreted badly the OP request: in fact my first proposed solution told him to use grep to eliminate the lines containing final asterisk. But the user wanted the asterisk to be ignored, not the line to be deleted. So I fixed my answer to use sed to delete the asterisk and let diff make its work.

The edit has timestamp 2013-04-23 13:28:19Z.

Soon after I posted it, I saw another answer which proposed the same "double pipe" solution I gave but with the correct sed. Its timestamp was 2013-04-23 13:28:50Z, i.e. it came after the fix of my answer; in the same time it cites my previous wrong answer, so it was "built" on the shoulder of it (the one with the grep instead of sed).

That was interesting and made me think about a reason to be strongly against some kind of usage of patents (and maybe the whole patent industry), and how these can stop indeed independent innovation and ideas. Patent advocates state exactly the opposite, but it's of course a matter of defending their interests (and/or protegees)... a matter of money and not of innovation, progress, expanding human knowledge and so on.

The point is this: we proposed the right sed-solution independently. (He credited me just for the structure of the command line, i.e. the way the sed command is invoked in order to obtain the diff). Saying it differently, the functional part of the answer (the sed trick) was "produced" independently by each others.

This shows that having the same problem to be solved, having similar knowledges, similar shared informations and similar set of tools can make two minds to propose solutions that are similar if not identical.

That's why patents to "protect" intellectual properties are a very dangerous lie and stop innovation, giving the key to it in the hand of "who came first" in order to make money, prohibiting other minds to arrive to similar solutions independently.

The simpler is the "object" of the patent, the higher the probability two or more people produce the same solution. So that allowing patents can prevent others from using shared, common, widely available human knowledge to reach any result, lock the consumers of a solution to one solution provider (for a long time) and so promote differences, cutting the less rich out from the game and make it possible price control to maximize earning despite the intrinsic value of the "object" (when applicable), in detriment of the consumers.

2013-04-19

Against the misuse of word-processors

I should never be tired of repeating it: word-processors are one of the more overrated and misused software in the computers of too many common users.

It's not a battle against the infamous Microsoft Word, even if from the freedom point of view, office suite like OpenOffice or LibreOffice are a better choice. The speech holds for these software as well: the problem is with that kind of software, with what is called currently word-processing.

In short the main point is that textual, human readable formats in specific contexts are better than any binary format. It should be not hard to agree when the content is itself textual: an article, our next best-seller book, our thesis about political science, our screenplay, notes of several kind (shopping list, names and numbers you need to remember), a blog entry and so on. They all are primarily made of text.

Unfortunately people are accustomed to WYSIWYG, which is often evil unless you are an artist and you are doing some kind of visual elaboration of the text which is part of the message you want to convey, or if you have to arrange the text altogether with a lot of graphics. Users should emancipate from this visual approach and learn to focus on the content, when it is what they have to deal with.

Word-processors make users to believe they are in control of how things will be presented and that it is their responsibility. But often it's not their duty. Often it's someone else duty and the users must focus on the content and the role of segments of this content: they have to mark a piece of text e.g. as chapter title, but forget about how that chapter title will be rendered.

Often the way things must be presented is codified; there are rules describing page size, font styles, font sizes, spacings and so on. Once you get that you need to deal for real only with the meaning or role of the things you write, then you are ready to throw away your preferred word-processor (or use it in a totally different way — modern WP would make it possible, but they don't work as well as other tools).

So you must prefer human readable formats: the file containing the text you wrote does not need a specific piece of software. It's enough a text editor. You can use a language that allows you to describe the actual content, marking it someway. And that's the sense of a markup language.

When I talk about human readable formats and markup language I am not thinking about several eXtensible Markup Languages produced and consumed by a machine: in fact even the evil Microsoft new MS Office formats, altogether with the OpenDocument standard for documents (the standard you should use when you won't follow the suggestions of this article), are XML based formats. So you could read the contents, but unlikely you can benefit of this possibility, and it would be even harder if not impossible to write that content by hand. Moreover everything is packaged into a zip archive and so those formats appear as binary.

Some reason why purely textual, simple formats are better than binary or complex textual machine-addressed formats:

  • contents can be understood having no or few knowledge of the format (this does not mean it's easy or they are usable the same way you would do interpreting correctly and knowing the format);
  • script to parse the data can be easily written by a programming enabled mind. Although the finest art is not for everyone, simply grepping or data extraction should be, almost;
  • the only program needed to view or edit the file is a text editor: an application that must be on every computer with any operating system installed. The data are operating system independent and software independent (not 100% true, but it is in common modern computing worlds);
  • merging and splitting can be done easily; if there's some sort of structure, this minimal knowledge is required in order to let the splitted files or the single merged file to keep an independent meaning;
  • diff-ing and comparing can be done with standard common tools;
  • versioning tool can track changes more easily (without relying on the specific tools of the specific software that can handle the binary format)

Simple markup languages are particularly tailored for benefitting of these features. This article was written using a subset of HTML, the markup language of the World Wide Web, and stored into a directory managed by Mercurial, a distributed Source Control Management tool, that makes it possible to track the changes and the history and (pushing to and pulling from a remote server) I could also contribute with myself. Without using a special software to handle this particular format.

The format of course was chosen according to a specific need: in this specific example the format is suitable for direct web publishing. Other requirements would have made us choose other formats. E.g. since I am an Emacs user, the format I choose for notes and other casual writings is often the org-mode.

Interpreting the markup language (that could be easy and at hand for a lot of computer geeks) it is possible to transform it (to another markup language or to anything else) and elaborate it in several mechanical ways.

Another classic example is when you think about stuffs you want to see printed, like for example a book, or an article on paper; then one of the most suitable format is LaTeX.

Even if you need a specific application (a set of applications and data, indeed) in order to produce the final document ready to be printed (e.g. a PDF), the format is textual, structured, it was thought to be written by hand (with just a text editor) and focus on content and not on presentation. From one unique source you can produce e.g. PostScript, PDF, HTML document or (virtually) any kind of document and format. And yet, you can read it with a text editor. And you can even add metainformations in disguise of comments.

For sure everything is clearer if you use a modern powerful text editor able to highlight the syntax of such languages. But it is not something you can't live without.

Once you learn to separate the meaning from the way it is presented, then you get the value of using everything but a word-processor for the vast majority of the things you may imagine (when the value is the content and not the way it is shown).

Said it in another way: the WYSIWYG approach is largely overrated. You must learn to separate the actual content from the way you want it to be seen on a screen, paper or other media. Learn that a lot of these way are codified (or they should), and usually you are not the one who codified it. So, you must focus on content, since the description of how to show it sits elsewhere — maybe it's even someone else duty, thus you have not to worry about.

Finally: before to fire a word-processor, consider other approaches that can make your life easier, even if it doesn't seem so at first (in this article I have ignored several anecdotes that drove crazy a lot of word-processors' users trying to obtain what they wanted from their software, losing more time on these efforts than in producing their content). In general, if you drop all word-processors forcibly, you will discover how rarely useful they are and how beneficial other workflow can be.

2012-11-25

Compressing

Sometimes I have to compress-archive files which differ not too much. I can see it with a glance, but computers have nothing similar to human vision... The archive formats I consider are zip (only if I have to share with windowsers who could be scared by other formats), tar.gz (tgz), tar.bz2 and if I don't care about file attributes, 7z. Among these, 7z compresses usually the most.
But since the files I am archiving have very repetitive pattern, I am not satisfied with the result of all archivers (except maybe 7z...).
Could we obtain better results in some way?

First, I have generated two files. They are the same file except for a byte in a certain position.

15274 file1.txt
15274 file2.txt


Then I have archived them:

 1847 files.7z
 3363 files.rar
 7142 files.tar.bz2
 7918 files.tar.gz
15342 files.zip


I have added rar too for the sake of completeness. Zip compresses each file at 50% more or less, so the final archive size is more or less half the size of the two files altogether. The others perform better, and 7z is simply the best. (The content of the file is important of course: it contains the number from 0 to 4095 written in ASCII without spaces or newlines: few symbols, repetitive patterns, no random).

Could it be better if I store just the first file and then a diff file? The result is:

1833 files.7z
1803 files.rar
5180 files.tar.bz2
7776 files.tar.gz
7891 files.zip


Zip reaches the performance of tar.gz (we could say it keeps making the first file half, while the diff file is small and so does not contribute too much to the final size). Rar seems slightly better than 7z (but the difference is negligible), and 7z itself does not gain too much from this pre-processing: it almost seems it is the only one that implements an algorithm able to crash the repetitions. Tar.gz's gain is small, tar.bz2 is bigger but not yet enough to keep the pace with 7z.
(Small differences could be due also to the file name of the diff file, which is "file1.txt.file2.patch"; 7z and rar do not store the filenames in clear, zip does, tar surely write filenames in clear, but of course bz2 and gzip compress them too).

Now let's try with two 16k (exactly 16*1024=16384 bytes) files containing the same random bytes (no special care in the random distribution), except for 1 bytes which differs in file2. The results:

16838 files.7z
32971 files.rar
20904 files.tar.bz2
16796 files.tar.gz
33086 files.zip


Zip stores the files. Rar is a little bit better, but not enough. Interestingly, gzip beats everyone, and 7z is a bit behind. Anyway, it seems like 7z and tar.gz algorithm exploits differences between files (since gzip works at a level where it is not aware of distinct files, it means it "explores" the stream and recognizes repetition patterns? better than bzip2? this need further analysis...). If I store only the first file and the diff file, I obtain

16824 files.7z
16606 files.rar
17114 files.tar.bz2
16654 files.tar.gz
16765 files.zip


Now almost all the archivers-compressors obtain the "same" result. Strangely, tar.bz2 gain is the worst. Rar, tar.gz and zip wins over 7z!

No conclusions. The way I have obtained the diff file is:

diff <(xxd -c 1 file1.rand) <(xxd -c 1 file2.rand) >file1.rand.file2.patch

and similar for the no-(pseudo)random case. Btw this could be not the best way, but indeed it's not important for this argument.

2012-11-03

Golfrun is not running (too fast or at all)

My tiny project Golfrun is stuck. There are several reasons: first, time. Ok, I am lying: I would have the time to, if only I would spend all my spare time on it. But of course I don't want to. Second, something that began as a "as fast as possible" C translation of "high level" Ruby powered interpreter, took its own path towards becoming an almost serious (though toy still) language. I suspect that the most horrorful part is the set functions implementation: naive, to say the least: I wanted them quick saying to myself the biggest and maybe most common lie (I will program it better later — I will fix it — I will enhance it... and so on). What I really wanted quickly done was indeed the whole thing, so that I could say ok there exists a full working interpreter for the official Golfrun language specification. Wait! I have not finished the specification either! Maybe there's another fact to learn: C is not the best language for fast "prototyping". C++ would have been better maybe but indeed the parent-cousin GolfScript teaches that languages like Ruby are good at that. (But they may fail in performance, which is the main reason I began GolfRun!)
Saying it differently: to me GolfRun has become already unmaintenable. So tiny, so dirty (not the worst anyway!), so wrong: it needs to be rewritten from scratch having now a clearer look of the goals. I had already the intent and the chosen language was C++11, yes C++11; anyway not for tough object orientation, which I don't appreciate when stretched too much. I like C and I would like to keep a C implementation of GolfRun, but I need to pause.
Furthermore the idea to write a serious (as possible) and formal-like specification of the language is cool (to me), but it erodes time changing a small project into a fake big one. So I will drop it and stick rather to a simple and maybe unexhaustive documentation.
It looks silly to apply metrics to a toy project but I have just downloaded pmccabe so I have tried a run and the uninterpreted results (with -vT options over .c files only) are:
  • Modified McCabe Cyclomatic Complexity: 1171
  • Traditional McCabe Cyclomatic Complexity: 1297
  • # Statements in function: 3485
  • # lines in function: 7872
 but indeed more interesting are the single function results. Reading here suggests that there are 14 functions with moderate risk, 14 functions with high risk, and 2 functions that are "the most complex and highly unstable method function". It fits my own perception :) (But take into account the fact that the number of functions, as counted by pmccabe, with less than 11 are 148 — are there 178 functions?...)

Now let me drift away using as a weak hook the simple "rewrite from scratch" mantra. If a project is becoming a bog, full of decaying boiling spaghetti code, growing without a guide and design (enforced by some good software engineering principles, rules, whatever) and becoming rather unmaintainable it could be a great idea to do it. It does not mean you have to throw away all the old code (unless it sucks totally): you can recycle it as well. But it exists what I would call business driven development: the code is not important, the code is not the product, so if "it works", let it shine — until the next unexpected bug shows up and then you have to blame the programmers, the lack of some good development paradigm and tests (but topsitters ignore or pretend to ignore what TDD is and that there are clues suggesting it's the time to move on and beyond well established past bad habits and enforce some good SE principles — I like very much "don't test your own software", which pairs well with TDD despite what you may think), the skills of the enchained programmers and everything else but the lack of a plan to bring the code in the new century and reduce the bugs likelihood. It worked... but the less you modify the code, the less old bugs manifest themselves means that the code has never worked for real (and what about a bug dancing around because some compiling option has changed?!). It means we deserved the "works on the test machine badge". It is still the programmer who did not rebel or left, who decided to bow to some kind of wrong logic (sometimes with the excuse "it's the customer's will"), who did not say "I won't add features until we fix it all")... it is such a programmer to be blamed; this is the sad truth. Though you can think, my reader, that if we wait to have a bugs-free product, we can wait forever before we can add new features; true if I were talking about bugs... indeed I am thinking about something more substantial: the whole software! No, almost joking now...
Nonetheless it's also a common human pattern to shift responsibilities away (but this is also the reason why rules and methodologies exist) so that in a specific environment  we can say or only think one or more of the following: I am not paid enough to worry about it (even if someone could point at you screaming "it's your fault!" and you can get fired for this not-so-correct-claim); it's not my fault (spaghetti code entanglements give strong unexpected coupling with the help of global variables, unitialized structs which by chance happen to be correctly zeroed for a while or worse before you added your code, bad "pattern" cloning and copy-pasting in order to keep the code looks like it used to look and avoid other developers screaming "oh why did you do it the hard way, we've never done it like that before" or similar claims); where's the black-on-white requirements?; I have tried to apply some good software engineering principle, but I am alone and it turned to be impossible (I won't explain why further), so I have warned you that the probability of bugs occurring despite the fact that programmers and testers did their job well is far higher than the minimum acceptable threshold; and so on... the list can be long.
I admit I have a bad habit: when I am developing something and I notice something that could be a bug, I fix it. (Could be? I wrote could be? A bug is, or a bug is not... this is a part of the problem, indeed, but I won't explain). People may think that it's ok, if it is a real bug, you have to fix it. Wrong. It must not be done (unless it is your bug!). You have to wait the bug to manifest and then, not before, be the hero fixing it quickly. This is a matter of balance. If you fix, say, 5 bugs you have not contributed to, bugs which never had the chance to do their show, then nobody will notice. If you add 1 bug that wins its run exhibiting its evil, then you are the one who added that bug (not the one that added that bug but removed 5 other someone else bugs). Thus, a bug that nobody noticed yet (and that he does not "own") is an asset for the developer, and should not be "spent" without earning publicly something. The are other interesting finding: half the doubled skilled persons could maintain the same code at the same total cost, making less frequent bugs by redesigning the software in order to reduce their probability — which makes the difference between "it works" (good) and "eureka it works!" (surprise, not good). But it means more unemployed persons and topsitters having less slaves to control; it seems like they exist metrics where quantity is more imporant (than quality) so that a topsitters managing 10 persons is more important than one managing 3 persons, if even their budget is (almost) the same. Fuck the topsitters: what about unemployed persons? In a good world they wouldn't be unemployed for so long, they would find a job their skills are suited for (needless to say, maybe not in the same industry). But things are a little bit more complicated here. There would be a lot to say about topsitters too. But it's better I stop.
Final wandering words to summarize it: it's not always only developer's fault but it's the developer to be blamed, thus it's always the developer's fault. Developers are weakly bound to their seats while topsitters are strongly bound to their seats, so developers can be replaced swiftly and more easily. Topsitters can hide their own faults, architectural deficiencies, the lack of good software engineering principles and leaders or guiding rules behind the developers faults.
By the way, ants colonies are wonderful.

(links about SE are chosen at random from a cheap google search, they are by no way reference links)
 

2012-09-02

No magic

This is a nice technically correct suggestion. But if magic numbers would exist, why shouldn't I use them? (just to say I am still here or somewhere, maybe not kicking but alive).


2012-04-09

Modelling social relationships using a knowledge base

Weeks ago I attended Codemotion 2012. Among the talks I was interested in, there were those related to graph databases (personal consideration: currently I think classical relational databases are misused more often than one can imagine at first). At the first appearing of the first example, some old memory came into my mind: it was about Prolog. Each time I have taken a look at Prolog, I've stumbled on examples like these: Prolog describing genealogy (X has A and B as parents, Y has Z as sibling...), tastes (X likes A...), ... and of course graphs.
I had not thought about the analogy until then: a Prolog collection of facts is nothing but an internal representation of a graph database (by the way it is the opposite: the knowledge base made of Prolog facts can be represented as a graph, hence the idea of a graph database).
So I fired my gprolog installation (the most unused bunch of bytes on my hard disk, but I like to have the larger possible number of programming languages/environments installed) to do a little bit of testing. Just for the fun of it. But since nowadays "social stuffs" have a lot of momentum I wanted to create a small knowledge base focused on who knows who, who likes who, who loves who... and the possible conseguences. The imagined application is for «services» like "find friends", or dating sites, or alike.

In the given example there are five persons with fantasy names Mary Brod, Carl Stuckart, Rudolf Fisher, Amanda Least, Minority Report and the following informations: birth date, gender, sex orientation, who knows who, who likes who, and who loves who. Then there are some educational rules (a rule for friendship i.e. reciprocal knowledge, another to ask the system if two persons are "sex compatible") and some helper rules (get the birth year, compute the age). Everything is of course semplified: human relationships happen to be a little bit more complicated.

The following messed up graph (generated by graphviz's dot starting from a source generated by a perl script "parsing" the prolog knowledge base file) depicts the relationships between those persons; black edges are about "who knows who", blue edges are about "who likes who", red edges are about "who loves who"; the background of each nodes represents the gender of the person, while the male-female symbols are about their sex orientation.
The knowledge base file can be now used to do queries (I mean, Prolog queries). They are rather intuitive. For example, if we want to know all the people who know Minority, we write this query:

findall(P, knows(P, 'Minority Report'), L).

which returns the list L = ['Mary Brod', 'Carl Stuckart', 'Rudolf Fisher', 'Amanda Least'], and in fact everyone knows Minority (who doesn't?).

The knowledge base as it is written allow to check if two subjects can have sex according to the following criteria: if A and B love or like each others, and their gender is in the list of preferred genders (which I've called sex-sexual orientation) of the may-be-partner, and if their age is over 18 or is over 13 but the difference between ages is no more than 5, then they might have sex. Let's try between Minority Report and Amanda Least. Unfortunately for Minority, who is very young, they can't (because of the age difference is too great). Let's try between Mary and Amanda... no luck yet, since Amanda is not bisexual, so Mary's unrequited love can't be finalized into sex.

Instead of going on this way, let's ask the system to list, for each person, a possible lover. The query I would do looks like

setof(X, canHaveSex(Person, X), List).

We are asking the set (just to be sure not to have repetition, since some person could match more than one sex compatibility criterion) of persons X the person Person can have sex with (according to the stated rules and the knowledge in the database). The answer is

List = ['Rudolf Fisher']
Person = 'Amanda Least'

which can be read as: the Person Amanda Least is sex compatible with Rudolf Fisher. They are in love, in fact.

And who has  unrequited loves?

findall(P, (loves(P, X), \+ loves(X, P)), L).

gives

L = ['Mary Brod','Carl Stuckart','Rudolf Fisher']

i.e. Mary, Carl and Rudolf love a person who does not love them. People who loves more than one person are potentially polygamous, and this is the last query we do, promise:

setof(X, loves(P1, X), L), length(L, N), N > 1.

That is, find the set L of persons X loved by P1, where length of L is greater than 1, i.e. P1 loves more than one single person. The variable matching the criteria are:

L = ['Amanda Least','Mary Brod']
N = 2
P1 = 'Rudolf Fisher'

thus, Rudolf is potentially polygamous.

The way the queries can be done is rather intuitive (once you get accustomed a bit to Prolog programming), and likely the algorithms behind the scenes (backtracking and so forth) are already exploited in "digital social contexts", I think (and if they are not, why not?)


2012-03-25

C++11

To me the most interesting feature of C++11 I am aware of are lambda functions. Though, I think also the general direction taken by C++ is leading it to a very obscure path, where other languages shine since the beginning, and where the need to use C++ rather than those other languages is not clear to say the least. Differently speaking, the most interesting features could be the one programmer could use less, simply because when you need to use them in all their beauty, you are on the edge of considering sticking to another language to do the same thing.
Moreover, C++ syntax is someway cumbersome and not clean. In some cases (not so much to be worth noting, yet they jumped in my sight) it is misleading; I believe the usage of the same keyword to mean two different things is not good (C too has this flaw, e.g. the keyword static), and if the previous standard had a third meaning for it, the situation could be confusing (I am thinking about auto). Yes, it's not a hokum but it gives the impression of something too layered and hard to handle. Modern languages without a heavy heritage have less or nothing at all of this kind of flaws.

Anyway, let's see an example of folding done with the use of a lambda function.



Not particularly useful, but it shows the equivalent in C++11 of what in other languages we can write. E.g.

Smalltalk



Common Lisp




Haskell



Erlang



Perl5



Python



All these snippets run effortlessly and without the need of adding other lines of code; C++ needs "boilerplate" code, though the working line is as simple as



(note the use of -> here, which is not syntactic sugar for (*ptr_to_obj). as it is in other contexts).

It could be funny to use some of the new C++11 features; sometimes it could be even useful; but most of the time I believe it won't be a need and C++ is becoming one of the languages with a very large set of (maybe interesting) features which are even the most misunderstood, misused, or simply ignored.

2012-02-17

Whitney Houston punished by God because of her conversion to Islam

This is not my opinion of course, but sadly it is what you can read in this article by Carlo Di Pietro, a guy belonging to a sect called "Milizia di San Michele Arcangelo" (militia of St. Michael the Archangel), a scary denomination for a scary group of mad people who hide their madness behind this description: the community of "Milizia di San Michele Arcangelo" is a group of catholic persons engaged in spreading the right Christian cult of devotion to the saint angels and in particular to St. Michael the Archangel.
The article is hosted by a "newspaper" called Pontifex, edited by Bruno Volpe and the same Carlo Di Pietro. Pontifex  is nothing but medieval propaganda against different religions, against homosexuality and in general against every other things that do not fit into their narrow minds.
I think that all Catholic and Christian persons should be deeply ashemed by the violent words these guys write in name of their own god.
But let us take a look at one set of these words about the death of Whitney Houston (I won't translate everything, just the "most important" parts; italics or other emphasis is added by me):

Whitney Houston is dead: another talent who goes away. Admonition of God because of her recent conversion to Islam?
This morning I knew that the famous singer and actress Whitney Houston has died and I do not hide the fact that I felt deeply perturbed because of the great skills of a woman who unfortunately has chosen the large door, and has paid. [...]
Let us pray for this great artist, who's died (as it seems) because of diabolic vices, of a strongly troubled soul and harassed by many temptations. Unfortunately the success is not synonymous of happiness and too often they search for help and consolation in the wrong persons, false beliefs and destructive artificiality.
You can't believe it, since (as reported by Il Messaggero) she had found serenity again thanks to her conversion to Islam. ["It is strange (the fact that is happened), since"... I have no idiomatic english translantion for "E pensare che...", lit. it would be: "And to think that (she had ...)"].
The news, spread in the recent February, had found very much resonance in the american islamic sites that, with great exultation, welcomed a great star.
The very same Houston, according to rumors, stated that she had found in Islam a dimension of serenity, after the hard personal life events the star had been involved in.
These are the results.
Admonition of God? Who can say it, we can't know certain dynamics, even if the event and the sad coincidence make it clear.
The good example must be given first by the known persons who, having "received" so much, so much they must "give" first from a spiritual point of view, then from a moral and material point of view.
God have mercy of her soul.

The main topic of the article is of course her conversion to Islam and the main purpose is to "prove" that it is a bad thing that has caused her death: punishment for her bad choices. Simplistic propaganda techniques at work, naively used.

I hope no one (except maybe the common Pontifex readers) needs to show where this article is illogical, to say the less, even in the constructs of the sentences (I've already done more than the necessary italics-izing or coloring some words). It's a clumsy usage of very basic propoganda techniques. My fear is that it is enough for the average reader of this "newspaper".