Web Development

Archive for the ‘Programming’ Category

We have a layer, say an unordered list with links in it. We want to hide/show the layer. We can hide the layer by attaching a handler to mouse out event of the layer. However this doesn’t work as expected. Because of event bubbling and the way browsers implement this event, mouse out event is fired whenever mouse moves from the layer to a link within it (even though the mouse pointer is still inside the layer). This might cause flickering of the layer based on the implementation. One way out of this issue is to check on mouse out if the ‘related target’ element is the child of layer. If yes, do nothing else hide the layer. Related target is the element to which the mouse moves. None of the links within the ‘ul’ will qualify for the mouse out event handler but when the focus moves out of ‘ul’ to its parent the handler is invoked.

quirksmode has a detailed article on mouse events and the intricacies of the above mentioned issue.

[Last night Nirav and I were discussing about closures and their implementation. I and Nirav often discuss tech. and I’ve been thinking since long to record those discussions. This is the beginning.]

(19:27:32) me: arre.. mereko closure samajh me aagaya.. [I understood closures]
(19:27:37) nirav: wah [gr8!] [my frnd. is always encouraging]
(19:27:44) nirav: isn’t that easy?
(19:27:53) nirav: and interesting at times?
(19:27:53) me: I read closure support in javascript
(19:27:56) nirav: yeah
(19:28:01) nirav: ECMA wala[one defined in ECMA?]
(19:28:03) me: yeah..
(19:28:38) me: to answer ur question.. PHP does’t have native support for closures.. ppl uses clumsy ways to emulate them.. which I don’t think are practicable..
(19:29:15) nirav: and how do they do it?
(19:29:16) me: may be because u can’t return a reference to a function in php..
(19:29:38) nirav: well i don’t need to return reference strictly
(19:29:43) me: they create objects for ‘closure’..
(19:29:46) nirav: i can use indirection using returning type
(19:29:59) me: didn’t get that..
(19:30:05) nirav: yeah, that’s how it is done in java as well
(19:30:06) nirav: i mean
(19:30:12) nirav: e.g.
(19:30:31) nirav: f * function(){}
(19:30:41) nirav: this function is returning function pointer to some closure
(19:30:48) nirav: or block of statement
(19:30:50) nirav: ok
(19:30:51) nirav: ?
(19:30:54) me: yeah,,
(19:30:56) nirav: now
(19:31:07) nirav: instead of returning raw pointer f*
(19:31:29) nirav: i can return a type say t => class t{ void f();}
(19:31:42) nirav: so that client of the method can get t and invoke f
(19:31:57) nirav: its indirect so ugly way of using ‘closure’
(19:32:05) me: hmm…
(19:32:10) nirav: samja? [understood?]
(19:32:14) me: 1 min..
(19:32:20) nirav: in java t would be interface
(19:32:29) nirav: with method f in it
(19:32:57) nirav: because in java you can’t return function pointers/ reference to blocks
(19:34:00) nirav: i was looking at this http://felix.sourceforge.net/
(19:34:05) nirav: sounds interesting
(19:34:41) me: in the above e.g. u return object of type ‘t’ right?
(19:34:49) nirav: yeah
(19:34:50) nirav: right
(19:35:33) nirav: where ‘t’ would be abstract class or interface to be nice
(19:35:47) me: and f() in that object uses the local variables declared in the outer function..
(19:36:23) nirav: yeah
(19:36:50) me: I’ll try that in php.. should be possible..
(19:36:54) nirav: ofcourse
(19:37:10) nirav: this is common;y employed in high level OO langs
(19:37:17) me: hmm..
(19:38:49) me: what are the problems with the method u said..?
(19:39:10) nirav: problems?
(19:39:17) nirav: problem is
(19:39:31) nirav: its pretty verbose
(19:39:50) nirav: and you have to write more and more code defeating the purpose of lambda expressions
(19:40:00) me: ok
(19:40:30) nirav: if i can directly express what i want to do in a lambda expression, i don’t need that ‘t’ and that ‘f’ declaration
(19:41:12) nirav: this way of creating closure is synthetic
(19:41:19) me: hmm..
(19:41:59) me: as in javascript support for inner functions and ability to return function references seems to be a better way..
(19:42:32) nirav: same is the case with python, ruby, scheme and many other lang which supports it
(19:42:38) me: hmm..
(19:42:58) nirav: java apparently supports it with the help of anonymous inner function but there are lot of problems

What a refreshful read that was!! While browsing I stumbled upon this exceptionally simple and pellucid description of Pointers and Memory. We learned these topics in college curriculum. But when I read this topic after a gap of around 3 years I find my self rejuvenated. Being engrossed in web development using a language like PHP that is so easy to use, I really lost touch of the basics of a language like C. While developing professional web applications we work at such an abstracted level that we seldom mull over what’s happening inside. After such a dry span of time reading something like this is really refreshing.

This work covers topics like Pointers, their allocation, deallocation, dereferencing, lexical scoping, local block semantics, shallow/deep copying, bad pointers, call stack, return address, heap memory and memory leaks to name a few.

A short, sweet and straightforward explanation indeed. Hats off to the writer!!

Wait! Wait!. Don’t miss this one