Elod P Csirmaz’s Blog: 2012

14 December 2012

Git: Invalid revision range 0000000000000000000000000000000000000000..*, or how to get the root of a new branch in a hook

When commits are pushed to a Git repository, Git calls the update hook with "oldrev" and "newrev" which determine the range of commits being pushed. However, when a new branch is pushed, oldrev is "0000..0000", which makes it impossible to call, for example, "git rev-list $oldrev..$newrev" or "git diff $oldrev..$newrev", because these would throw the "Invalid revision range 0000000000000000000000000000000000000000..*" error as explained here.

The task in these cases is to use, instead of oldrev, the commit that is the root of the new branch, which is the commit reachable from newrev but not from any of the other heads. Although there are a number of suggestions as to how to get this, I have found what I think is a simpler solution. In Perl, I use
if($oldrev eq "0000000000000000000000000000000000000000"){
$oldrev = `git rev-list $newrev --not --branches | tail -n 1`;
$oldrev =~ s/\s$//;
$oldrev .= "^";
}
$oldrev now references the parent of the earliest commit reachable from the new head only (git rev-list lists commit objects in reverse chronological order). Then, one can use
my @filestocheck = split(/\s/,
`git diff $oldrev..$newrev --name-only --no-color`
);
to get the list of files modified by the push.

27 October 2012

Blame the Victim and Play the Lottery: We Must Learn to Cope with Randomness

It seems that we as a species are unable to deal with randomness in life. This manifests itself, among other things, in our clinging to a higher power or will, a design or a master plan in the world. We feel that it would somehow demean us if we conceded that we as humans are here as a result of highly unlikely random events rather than as a result of some necessity. (Let us, for the moment, forget about the question whether the Universe is deterministic, which would mean that there is a "master plan." Even if it is, with our current knowledge and tools, we cannot determine it sufficiently to predict, for example, individual actions or thoughts.) Our thinking is teleological: that is, we seek a purpose in everything, even though every fact appears to point to its precise lack.

Is, for example, the fact that most organisms around us devote most of their time and energy to reproduction a result of a sentence in Genesis? Can't one argue that in any population where some living organisms focus on creating offspring, and others don't, the former will soon crowd out and finally destroy the latter? Looking at the overall population a few million years later, as we do, we will hardly see any exception to the reproduction rule. Or, to take another example of teleology, what would we think of Douglas Adams's famous sentient puddle, who gets convinced of the existence of a deity because he fits his hole so well it must've been designed for him?

But our inability to grasp randomness does not end here. There's also our sense of justice. It is unusually hard for us to accept that random bad things can happen to otherwise good people. While it is natural and laudable for everyone witnessing an unfortunate accident to wonder what could have been done to prevent it (lock your doors, drive at an appropriate speed, &c.), we usually go further than that, and, deep down, remain sure that the victim must have done something to deserve what had happened. And where else would this argument be the most visible than in the case of one of the most despicable crimes: rape? Who hasn't heard that the victim "had it coming," encouraging healthy males by lewd behaviour and scant clothing?

And then, last but not least, there are the games of chance. I hope no one thinks that anyone would spend real money on horses, blackjack, lottery or fruit machines unless they believed in lucky streaks and third time's the charm, almost deliberately turning a blind eye to the fact that one draw, deal or race has (or at least is supposed to have) no effect whatsoever on the next.

Randomness is a beautiful and liberating thing. Stop believing that your thoughts or wishes can alter the course of events, or that anything has happened, ever, with us humans in mind, and the world will be a better place to live in.

20 October 2012

Empiricism and Lévi-Strauss's Scandal, or What did Derrida See?

In a previous post I tried to call attention to how Derrida, in his "Structure, Sign, and Play in the Discourse of the Human Sciences," attempts to present Lévi-Strauss's definitions of the natural and the cultural and the non-categorizable-ness of the incest prohibition as a decenetring, a decentralising, a point around which metaphysics is torn along the stitches. I argued that the fact that incest prohibition appears to be both natural and cultural is, instead, quite explainable employing logical categories and common-sense observation, that is, from inside the very structures this "scandal" is supposed to deconstruct.

Let me quote Derrida's paraphrase of Lévi-Strauss's definitions once more:

[T]hat which is universal and spontaneous, and not dependent on any particular culture or on any determinate norm, belongs to nature. Inversely, that which depends upon a system of norms regulating society and therefore is capable of varying from one social structure to another, belongs to culture.

Now isn't the difference between natural and cultural as defined above reminiscent of the supposed difference between analytic and synthetic statements? Analytic statements are those which are true by some intrinsic property (like "A=A"), that is, their truth-value is "not dependent on any particular" well, not culture, but world, or state-of-things, or circumstance--that is, which are universal, and natural in Lévi-Strauss's sense. Synthetic statements rely on outside facts for verification, like the statement "this is a blog." The truth-value of such statements is "capable of varying from one" circumstance "to another"--in other words, they are cultural according to the above definitions.

With this connection in mind, it should come as no surprise that there are things that are both analytic and synthetic, just like incest prohibition is both natural and cultural. The near impossibility of drawing a border between the two sets has been superbly illustrated by W. V. Quine in his "Two Dogmas of Empiricism" (in From a Logical Point of View), where he shows the circular nature of nearly all attempts to demarcate analytic from synthetic statements. In the end, he suggests rejecting this dichotomy altogether as the first dogma of empiricism.

I think here is a telling difference between the Continental and the Analytic branches of philosophy here. Quine, belonging to the latter one, sees accepting and operating in this dichotomy as a central and grave problem (a "dogma"), but he treats it mainly as an erroneous presupposition. Derrida, who can be classified as belonging to the Continental tradition, sees something much more grandiose growing out of the faulty categories Lévi-Strauss stumbled upon. The unsustainability of the definitions, in his system, immediately leads beyond logos, beyond metaphysics, and--in a quite Heideggerian vein--, beyond what can be talked about.

It was a matter of five years that Lévi-Strauss couldn't read Quine's book (his The Elementary Structures of Kinship was submitted in 1948 and published a year later; Quine's book appeared in 1953); a five years, it seems, most fortunate for Derrida.

9 August 2012

Click and hover events only trigger on part of an input field in IE8

I have encountered an issue where IE8 ignored click and hover events on an input field the background of which was transparent. The clue that helped me solve this issue was that the events were triggered without any problems in the area of the input field where it contained some text. I remembered that I encountered a similar issue before, and indeed, using a transparent image as the background instead of "background:transparent none" fixed the problem.

28 July 2012

Derrida's Points of Departure

It occurred to me that some points Jacques Derrida notes in his Structure, Sign and Play in the Discourse of the Human Sciences* as phenomena where categories and structures -- that is, metaphysics itself -- deconstruct themselves, are explicable away inside logic and metaphysics. Naturally, this might be the consequence of the nature of metaphysics itself, that it is what makes language possible, and thus nothing can be said / written that would point outside its jurisdiction.

Sign

On sign, Derrida writes:

[T]he metaphysics of presence is shaken with the help of the concept of sign. But, as I suggested a moment ago, as soon as one seeks to demonstrate in this way that there is no transcendental or privileged signified and that the domain or play of signification henceforth has no limit, one must reject even the concept and word "sign" itself -- which is precisely what cannot be done. [...] If one erases the radical difference between signifier and signified, it is the word "signifier" itself which must be abandoned as a metaphysical concept.

Continuing by citing Lévi-Strauss and introducing the opposition between the sensible and the intelligible which is to be transcended, Derrida continues:

The concept of the sign, in each of its aspects, has been determined by this opposition throughout the totality of its history. [...] But we cannot do without the concept of the sign, for we cannot give up this metaphysical complicity without also giving up the critique we are directing against this complicity, or without the risk of erasing difference in the self-identity of a signified reducing its signifier into itself [...] For the paradox is that the metaphysical reduction of the sign needed the opposition it was reducing. (85)

I interpret these passages along the following lines: while sign would present itself as a point where the opposition it is based on (metaphysics) deconstructs itself, it cannot be done, for by erasing the opposition the sign is also erased or is reduced to a chain of signifiers. The sign lives on this opposition and cannot exist outside it.

Far from trying to refute this argument, I would merely like to call attention to a phenomenon that might be paralleled to the evolution of the sign.

Somewhat echoing Baudrillard's notion (see Simulacra and Simulations) that an image evolves first by referring to a thing and at the end referring to nothing but itself (a simulation of nothing), let me consider the notion of the mathematical set and its possible representations.

On the first level, a set is a collection of things. We could consider a set of my pony horse, that ant over there, and Aunt Margaret. I could create many sets this way. Next, I realize that I might want to consider the collection of all my sets made so far. For the sake of convenience, I might term such a collection a class. I may, therefore, consider the sets of animals of the same species and the class of invertebrate species. Realizing, however, that sets are just things like my pony horse, I might see no reason to distinguish between sets and classes any more, and so I decide to refer to collections of sets as sets, too. This makes me able to consider a set containing Aunt Margaret and another set containing all the ants around the house. Making it this far, I will also allow a set to contain nothing, inventing the empty set.

The next step is the trickiest one. I might -- in a delusional state of mind -- decide that there is nothing but sets. The world will not be poorer this way. There will, for example, be the empty set, the set containing the empty set, the set containing the previous set and the empty set, etc. Using brackets instead of circles for the sake of convenience, such a series of sets might be represented this way:

{}, {{}}, {{},{{}}}, {{},{{}},{{},{{}}}}, {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}, etc.

Or, we may assign points (vertices) to each such set and draw an arrow (edge) from set A to set B if A contains B. This way, sets as such are represented not by things "containing" other things, but by a directed graph. The set, in other words, has ceased to be a representation of a collection of things. It now exists by its own right; a set is defined solely by other sets in a system in which identity is given by relation, immediately calling Ferdinand de Saussure and the idea of difference-defined signifiers and signifies to mind.

Now what I propose is to see sign as undergoing the same process as the set above, to acknowledge the possibility of seeing it not as rooted in the dichotomy of signifier-signified but as one that "transcends" it. It might be interesting to muse on the possible consequences of cutting the ground from under the feet of sign: would then it continue to be a singularity around which metaphysics is torn along the seams? If yes, would such a deconstruction really lead to the circle Derrida described?

Nature and Culture and Incest Prohibition

Derrida talks of decentering, which takes place when it is revealed that structures have been deprived of their centres and thus they cease to be structures -- in other words, when they, in a sense, get deconstructed. Ethnology, in Derrida's view, occupies a special place among the "human sciences" as it has

been born as a science only at the moment when a decentering had come about; at the moment when European culture -- and, in consequence, the history of metaphysics and of its concepts -- had been dislocated. (86)

He suggests that ethnology / ethnocentrism, like the sign, is another point which is indestructible by the nature of metaphysics, as "the ethnologist accepts into is discourse the premises of ethnocentrism at the very moment when he denounces them." (86) The way I see it, if one attempts to do away with the presuppositions propping up the structure of ethnology, they return as repressed content from the unconscious, forcing us back into metaphysics.

To illustrate his point, Derrida cites the opposition between nature and culture, natural and cultural (learned) behaviour. Lévi-Strauss, Derrida argues, having introduced this dichotomy, encounters "what he calls a scandal," namely, incest prohibition. For incest prohibition presents itself as being natural and cultural at the same time, and thus it questions the assumedly self-evident difference the dichotomy is based on. In other words, it cannot be grasped using the concepts nature or culture. From this observation, Derrida jumps to the conclusion that this fact is because incest prohibition precedes these concepts; that it is actually what made the concepts possible; that it is subsequently obscured (deferred) by the opposition (difference).

As I interpret this train of thought, I see incest prohibition as a reverse of sign inasmuch as sign was presented as being based on an opposition the erasure of which would lead to its destruction; incest prohibition, by contrast, precedes an opposition it generates. However, both things (I dare not say concepts) are, I think, points where the impossibility of getting rid of a dichotomy enables us to peer behind the scenes of metaphysics, which, in short, deconstruct (or show the need and the impossibility of the deconstruction of) metaphysics.

But how does Lévi-Strauss define natural and cultural? Derrida paraphrases the definitions in The Elementary Structures of Kinship the following way:

[T]hat which is universal and spontaneous, and not dependent on any particular culture or on any determinate norm, belongs to nature. Inversely, that which depends upon a system of norms regulating society and therefore is capable of varying from one social structure to another, belongs to culture. (86)

It is then hardly surprising that

The incest prohibition is universal; in this sense one could call it natural. But it is also a prohibition, a system of norms and interdicts; in this sense one could call it cultural. (87)

(Let me not consider the fact that while incest prohibition may be universal, the specific set of relatives it prohibits one from forming a sexual nexus with appears to vary from culture to culture.) The phenomenon of finding a thing belonging to more than one category is hardly surprising to one who has ever tried to give formal definitions for, for example, sets of phonemes, lexical items or types of soil. If one aims at creating an all-inclusive pair of disjoint categories, the safest way of doing it would be to say: something is A if this and this, and B if it is not A. Lévi-Strauss' definitions, however, do not follow this pattern. They define both categories independently of the other. His belief that he created disjoint categories simply points to a hidden presupposition which turns out to be untrue. Nothing more happens; Logos, Logic and, in my view, metaphysics stay unshaken.

One could imagine a linguist trying to categorize phonemes. At the moment, he considers unvoiced consonants, and, following common sense, tries to draw a distinction between sounds during the formation of which there is an air flow (for example, sh as in shiny) and sounds without an air flow (for example, t as in toil). The former category s/he names fricatives, for there is some friction in them, and the latter plosives, for there is a(n ex)plosion of air at the end of those sounds. Now our linguist considers the unvoiced consonant at the beginning of choose. It starts as a t and ends as an sh, and -- as other considerations show -- it is still one sound. In a sense, it fits both categories s/he established. Does this mean that this strange tsh sound precedes the plosive / fricative opposition? that it is what actually makes the two categories possible? that it is hidden as an oblique centre that can never be reached by the infinite chain of signifiers opened up if we tried to do away with our inaccurate categories? that it decenters Linguistics? I don't think one can whole-heartedly answer 'yes' to any of these questions. The fact that Lévi-Strauss' definitions are inaccurate, in itself, shows something not about metaphysics but about the definitions.

I, however, would not like to appear as one who thinks by showing the possible erroneousness of one example he thus deconstructed the deconstruction of metaphysics (or its impossibility). Still, I would like to argue that such examples have probably been magnified out of proportion in order to show us something about an all-inclusive (or, at least, an all-Western-culture-incluse) structure. It is, admittedly, an interesting, important, and hard question that is raised by the inaccurate categories of Lévi-Strauss, namely, whether anything formalized can successfully describe the world we live in or we will inevitably run into counterexamples to any number of and however refined categories, scientific models, etc. It is, however, a question that can be posed on the level of physical phenomena, measurement, mathematical models, computing and comparison. The "concept" of the metaphysical need not be introduced, and the examples cited by Derrida do not necessarily refer to it in any way. Unless in a way similar to the attempt of (re)presenting the existence / workings of a transcendental entity by listing a number of examples rooted in materiality.

And there's still the possibility that I constantly drag these phenomena back into Logic and Materialism precisely because concepts metaphysics made possible obscure from my sight the primeval things that ultimately generated the logical categories I operate in. As language is rooted in these concepts, everything said can be interpreted under metaphysics. I do not "see" beyond it because I can choose not to, and, out of a yearning for the comfort of concepts I think I know, I choose not to. But then the beyond-metaphysics becomes frighteningly similar to another entity that exists only if I believe in it, and would we really like to regard the possibility of a beyond to the Western history of metaphysics a kind of religion?


* Hazard Adams and Leroy Searle, eds. Critical Theory Since 1965, Tallahassee, Univ. Presses of Florida, 1986. 83--94.

15 April 2012

Modular CSS? Some thoughts (2)

Click here for part 1

Semantic IDs and class names. It is common advice that ID and class names should be semantically meaningful, that is, they should reflect the content (e.g. "sidebar", "widget", "promoted") and not the styling ("greybox", "red"). Unfortunately, this is not always possible, especially when some HTML elements need to be introduced solely for formatting. Still, it is worth keeping this in mind and starting from a semantic name, and name e.g. a DIV to be put around all widgets "widgetwrap" and not "newborder", and the narrow column on the right "sidebar" and not "leftbar".

Start CSS selectors with a top-level element. Unless a CSS rule is intended to be general (formatting, for example, all links, STRONG elements, or all text), I've found starting the CSS selector with a top-level element very useful. This way, one can avoid most clashes and CSS specificity issues, as the scope of the rule will be limited to well-defined areas on the page. Ideally, start with the ID associated with the main area (see the relevant suggestion in the previous post), that is, the promo box in the sidebar should be referred to as "#sidebar .promo", not as only ".promo". This allows re-using the class name elsewhere without causing problems.

In other cases, when the element can appear in any area (for example, a widget in either the navigation bar or the sidebar), try to start with the topmost still meaningful class name. For example, links inside the bodies of these widgets should be referenced using ".widget .widgetbody a" instead of ".widgetbody a".

Be as specific as possible. This is a continuation of the previous suggestion. The idea is to list all applicable intermediary classes when referencing an element. Using the previous example, for obvious reasons, links in the bodies of widgets should be addressed using ".widget .widgetbody a" and not ".widget a", as that would target A elements in the headers as well.

Avoid mentioning the element type. And finally, I think an argument can be made for addressing elements using class names and IDs, not element types. (Again, this only applies to CSS rules that are not general.) There are two reasons for this. One is that if the element type is not mentioned in the CSS rule, then it becomes possible to switch, for example, from a DIV to a P, or from H2 to a DIV with minimal changes to the CSS (mostly all that is necessary is to undo the default styling of these elements). Such changes may be necessary for any reason, standard compliance, SEO, or cross-browser issues.

The other reason is that styling a class rather than an element makes it possible to use the same element in the same context without having to worry about over-reaching CSS rules. For example, if ".widget .widgethead a" is used to style that one A element in widget header that is the title of the widget, one runs into problems when trying to introduce another A element to implement, for example, an accessible close button. This problem could be avoided by adding a class to the original A element (it can be as simple as using "tl" for title), and using ".widget .widgetbody .tl" to style it.

1 March 2012

Modular CSS? Some thoughts (1)

While rebuilding a family of websites in different languages a couple of years ago, I formulated some guidelines to follow while writing CSS code and assigning classes and IDs to HTML elements. For various reasons, back then, we decided against using CSS precompilers, mainly as it seemed to be easier to ensure cross-browser compatibility by hand-coding the CSS. These guidelines turned out to be very helpful in creating modular and optimised stylesheets where one had to repeat as little as possible, and didn't need to worry about specificity issues. With the wider and wider implementation of CSS3, I'm sure some of these guidelines will soon look outdated (I had to support IE6!), but I hope the rest will help someone out there.

Use as few IDs as possible. IDs should be unique on a page, so if you use an ID to mark, say, a counter to be updated every second, or an element with some special styling, and then this needs to be duplicated, you'll need to rewrite the HTML, the styling, and perhaps some JS. A good usage of IDs I found is the following:

Reserve IDs for areas on the page like #content, #sidebar, etc., which, because of the structure of the page, cannot and will not be repeated. This can also help to avoid CSS specificity issues: for example, a rule relating to one area on the page (e.g. "#sidebar a") will always take precedence over some general formatting (".widget strong a").

Consistent naming. Agree on the case and punctuation allowed in ID names and class names. Regardless of what is legal according to the standard, my favourite choice is all lowercase and underscores as separators, which helps to keep the CSS file clean, and it is easy to remember how something is written.

Use "subclasses" to mark types of things. By "subclass," I mean a CSS class name that has more than one part, with the parts separated by underscores in a "parentclass_subtype" format. (It is useful to use underscores only in subclasses.) Subclasses should be used in addition to the parent class. For example, if there are multiple buttons on the page, all marked with the .button class, but there is one green, then it should have 'class="button button_green"'. This is a possible way of avoiding multi-class CSS selectors like "DIV.button.green" some browsers don't support, as one can use "DIV.button" to style buttons in general, and "DIV.button_green" to style the special ones.

Use subclasses, if necessary, to mark things inside things. Although it should not be necessary to do so in general, I found it useful to use a similar naming convention for classes on elements inside other marked elements. For example, if there is a DIV.widget, and it has two parts, a header and a body, one could use


<div class="widget">
<div class="widget_head"> ... </div>
<div class="widget_body"> ... </div>
</div>


if one suspects that using class="head" only would clash with some general styling. Maybe it's a good idea to leave out the underscores in these cases (to separate these from real subclasses). And one can abbreviate the class names as well:


<div class="widget">
<div class="widgeth"> ... </div>
<div class="widgetb"> ... </div>
</div>


Use short class names on elements repeated many times. We don't want to type a lot, and if the HTML is generated in a loop, we don't want to inflate it either.

Click here for part 2

24 February 2012

Wrap or include? Thoughts about a common structural issue in code and templates

We know very well that any code duplication is a bad thing, but sometimes it can be unclear what to do with the repeated content. If function or method or template 'A' contains something that is also in function / method / template 'B', should we move the common content into a sub-template that is called by both A and B, or should we create a common parent that contains the duplicated code, and calls A or B based, for example, on a parameter? In this post, I'll investigate the consequences of each option. For the sake of brevity, I will only talk about templates, but the arguments here equally apply to functions and methods.

This dilemma may be familiar to anyone who has dealt with web templates. Basically, the question is this: if we have, say, different web pages, should all of these pages call another template to include the common header and footer (multi-entry-point model), or should there be a single wrapper template that outputs the header, the footer, and calls other individual templates to include the appropriate content (single-entry-point model)?

The first figure shows the multi-entry-point case, where the common content is in a sub-template (circle with lines) called by two top-level templates (other two circles). The decision (represented by the triangle) which one of these to call is made beforehand, based on some information (represented by the blue arrow). Both top-level templates contain a call (the small circles) to the sub-template that, in this example, contains the header and the footer (the grey lines).



We see that although the common content is only present once, the way it is called, its interface, determines the code at multiple points. Now if this interface is to change (which can happen quite often with templates: a new parameter may be introduced to control something in the header, for example), one would either need to modify the code everywhere the common template is called, or be forced to implement all changes in a backward-compatible manner. Based on personal experience, this can cause serious issues in templating.

The second figure shows the single-entry-point case, where the common code is called first; in this example, in the form of a wrapper template. The decision which second-level template to call is made inside this wrapper. The piece of information this decision is based on (blue arrow) needs to be passed to the wrapper. Here, there is only one point where something is called, which should solve the issue above.



One can argue that the interface is a two-way thing: if it changes, one needs to change not only the code that calls a template, but the called template as well. That is, in this latter model, if the signature of the second-level templates change, one still needs to do the same amount of work, as all of them must be modified to respect the new interface.

In real life, however, the second arrangement may still be simpler to maintain. The reason I see for this is that it is easier to disregard a parameter than to include one. In the single-entry-point model, if one of the second-level templates needs a new parameter, it can be added centrally, in the wrapper, and the rest of the templates will almost automatically ignore it (for example, if named arguments are used). However, in the multi-entry-point model, if the wrapper needs a new parameter, all top-level templates may need to be changed to pass it on. (One can, naturally, find workarounds to this problem, like passing arbitrary data structures or objects instead of parameters. Still, this issue seems to raise its head often enough on various levels.)

Notice however, that the single-entry-point model above also suffers from its own issues. If applied to templates, the current arrangement puts logic (control) as well as content (view) into the wrapper, which may be acceptable in certain templating frameworks, but less so in a strict MVC approach. Also, the decision-making process in the wrapper may get too complicated if it is difficult to figure out what content we should actually return. This, in turn, might signal that some refactoring is needed in the system.

All in all, both arrangements have their own advantages and disadvantages. Keeping in mind some of the considerations above can help to choose the best option in each individual case.

11 February 2012

Use strict is not very strict in Perl: 'my' in a conditional block

Strangely, "use strict" in Perl does not seem to correctly track improperly scoped variables if "my" is in a conditional block. The following throws no compilation-time errors in Perl 5.10.0 and 5.10.1, but its output shows that it is using a global variable:

use strict;
sub foo {
my $arg = shift;
my $var = 1 if $arg;
$var += 2;
return $var;
}
print foo(0).','.foo(0);

Output: 2,4

(The line "print foo(1).','.foo(1);" outputs "3,3", as expected.) Even more strangely, this only seems to happen if the condition follows the statement. The following code:

use strict;
sub foo {
my $arg = shift;
if($arg){ my $var = 1; }
$var += 2;
return $var;
}

throws the expected errors:

Global symbol "$var" requires explicit package name at - line 5.
Global symbol "$var" requires explicit package name at - line 6.
Execution of - aborted due to compilation errors.

This may have something to do with the presence of a statement block, but this throws no errors either:

use strict;
sub foo {
my $arg = shift;
do{ my $var = 1; } if $arg;
$var += 2;
return $var;
}