Older blog entries for rmathew (starting at number 160)

19 Apr 2006 (updated 19 Apr 2006 at 10:07 UTC) »
HTML/CSS/JavaScript
Ankh, dorward: Thanks for your comments. For a sloth like me, it's not easy to once again overhaul the entire site to make it XHTML - I'll let it remain at HTML 4.01 for the time being. By the way dorward, I did not know until very recently that unlike XML, things like "<br/>" are not valid HTML elements. I used to insert "<br/>", "<p/>", "<hr/>", etc. liberally throughout my pages mistakenly thinking it's the "right" thing to do.

A rant: I don't know much of HTML/CSS/JavaScript, but I really wish for the ability to "#include" files (for example, for page headers and footers) and to define macros (for example, to generate a news item's headline and content elements linked to each other). I know these can be overcome by using JavaScript and document.write(), but that's a kludge. I also know that these can be achieved on the server, but I do not want to depend on it - I keep moving my website from one (free) provider to another and I also like it to behave exactly the same way when accessed from my local filesystem as from a remote server. Note that we already have inclusion mechanisms for external stylesheets, scripts, etc. so this is not something too difficult to provide.

Now on to something that I hope you HTML/CSS/JavaScript gurus can help me with: I'm trying to implement a handy expandable/collapsible news entries mechanism for my website somewhat similar to what is explained in this article. I have already implemented most of what I want and it can be seen in action on my site, but it's not "right". In particular, I want this system to behave properly whether JavaScript is enabled or not and whether stylesheets are enabled or not, that is, under the following conditions:

  1. JavaScript enabled, Stylesheets enabled
  2. JavaScript disabled, Stylesheets enabled
  3. JavaScript enabled, Stylesheets disabled
  4. JavaScript disabled, Stylesheets disabled
My implementation works right now under #1.

For doing #2, I make the stylesheet actually declare "hidden" elements as visible, but then use JavaScript attached to the "onload" event of the page to turn them invisible - if the user doesn't have JavaScript enabled, he still gets to see all the content properly. Note that I cannot use the alternative suggested in the article I have linked to; that is, something like:

  <noscript>
    <style type="text/css">
      .hidden { display: block; }
    </style>
  </noscript>
does not work since the W3C validator rejects it - NOSCRIPT cannot occur inside HEAD, but STYLE can only occur inside HEAD. The downside of my approach is that there is a short but noticeable and sometimes distracting phase under both IE and Firefox, where the browser loads and renders the full page and then hides the hidden sections. Isn't there a better way of achieving this while still remaining strictly valid?

#3 poses a slight problem in that I wish that even the "togglers" do not appear if stylesheets are disabled. I was thinking of iterating through the stylesheets defined for the document in the DOM and check if all of them are disabled and omit emitting the togglers if they are. Is there a better way of doing this?

#4 is automatically taken care of by the "solution" to #2, since only JavaScript is used to emit the togglers. The user still gets to see the entire contents.

Perhaps I'm just wasting my time as #2 and #3 are unlikely to happen with real visitors to my pages - #1 is what almost all human visitors are likely to have and #4 is what almost all search engine bots are likely to have. This impractical fussing might explain why I have not become a manager. ;-)

Website Redesign
After a long procrastination, I have finally updated my website to be more standards-compliant, better looking and somewhat easier to navigate. I wanted to shift completely over to XHTML but that has its problems besides lack of support in Internet Explorer. I have therefore settled for HTML 4.01 Strict. Every page on my website should now validate with the W3C validator. To enhance the looks of the site, I am using a variant of the Sinorca 2.0 design created by haran and provided by OSWD. I stumbled upon OSWD while admiring the recent makeover of Tom's site (which uses the Blue Haze design also created by haran).

While I was at it, I renamed the folders and files that had names like "phartz", "philez", etc. - these names had looked "kewl" half a decade ago, but now look rather juvenile. This results in some of the links posted elsewhere becoming invalid and I apologise to anyone affected by this change. I have also implemented support for simple expandable and collapsible sections so that some of the pages do not appear intimidatingly verbose.

Right now the website is mostly an exercise in vanity. I need to add content that is actually useful so that someone other than googlebot finds the website interesting.

GCC and Google Summer of Code 2006
GCC is looking for students interested in working in Google's Summer of Code on a project helping GCC.

ZINC
ZINC is a variant of the game of Core War in which programmes (called "warriors") fight each other in a battle to control a virtual computer. The programmes are written in a simple language called Redcode and run inside an emulator known as Memory Array Redcode Simulator (MARS). ZINC implements a simpler and more symmetric dialect of the Redcode language than the current International Core War Society (ICWS) standard known as ICWS-94.

To get a feel for ZINC and Redcode, look at the following simple warrior:

      ; Bomb every fourth cell in the core with a "DAT #0".
      org start
    target:
      dat #0
    start:
      add #4, $target
      mov #0, @target
      jmp $start
Redcode looks very similar to the assembly language of many modern microprocessors. A DAT #0 instruction indicates the number 0 stored as the datum at that location in memory. This instruction is itself encoded as 0 and is not executable - an attempt to execute this instruction leads to the death of a warrior. So the warrior shown above (called "Dwarf", a classic Core War warrior) bombs every fourth location in the core in the hopes of fatally wounding an opponent. Note that Core War only supports relative addressing and @ represents indirect addressing (the location pointed to contains a pointer to the final location). More details, including a tutorial for beginners, are available in the ZINC User Manual as well as on sites like www.koth.org and www.corewar.info. There is also an active USENET newsgroup rec.games.corewar for Core War enthusiasts.

ZINC is currently at version 0.1 and is Free Software released under the GNU General Public Licence (GPL).

By the way, I expect to receive a lot of flame for my decision to not recognise TAB characters as whitespace in the Redcode dialect implemented by ZINC.

GCJ
I seemed to be in my elements on the GCJ list this week, provoking a thread on the lack of good support in GCJ for Windows and eliciting a reply from the GCC Steering Committee on the status of the proposal to integrate ECJ into GCJ.

ECJ for GCJ: Still in limbo
It has been almost a month since Tom formally proposed integrating ECJ in GCJ to the GCC Steering Committee (SC). There has been no word from the SC yet on this request. However, the SC did ask the GCC developers to avoid gratuitously including source code from external projects in GCC. One consequence of this for GCJ was the removal of fastjar from the GCC source tree. I'm not sure if the SC's decision was coincidental or in fact a result of deliberations triggered by Tom's request.

More Front Ends in GCC
One of the great advantages of structuring a compiler such that the front-end, the middle-end and the back-end are relatively independent is that if you write M front-ends and have N back-ends, you get M*N compilers "for free" assuming you have a good enough intermediate representation in the middle-end. This idea was discussed as far back as the 1950s and UNCOL was an ambitious effort towards this goal. GCC is a stellar example of such a compiler - it supports C, C++, Java, Ada, etc. "out-of-the-box" and can target a whole bunch of platforms. You implement a language front-end for GCC and you immediately have a compiler for that language for a whole lot of platforms; you implement a target back-end for GCC and you immediately have compilers for several languages for that platform. Of course, this is grossly oversimplified, since you have to usually port the language runtime to a platform too or since your language might strain the GCC intermediate representation or expose latent bugs in the middle-end making the effort rather difficult. But the overall idea still remains valid.

The GNU Pascal Compiler (GPC) guys recently proposed an integration of GPC with GCC (in the same source repository, but on a different branch - weird). Some day, the GCC Scheme Compiler (GSC) guys, the PL/I for GCC guys, etc. might also want to integrate their front-ends with GCC. Having more front-ends in the GCC source tree itself means that middle-end changes do not inadvertently break these front-ends, latent middle-end bugs and unwarranted assumptions are exposed, general GCC enhancements are automatically applied, etc. So it's a good thing for GCC, in a way.

However, I personally think it is not a good idea. The GCC mainline is already quite bloated with a number of languages and runtimes and building all of the languages and their runtime libraries (thank you Sun for regularly increasing the bloat in the "standard" Java runtime with every release of the JDK) takes quite a while even on a decent system. Having more languages and their runtimes within GCC will only exacerbate this issue. I personally also feel (though I have no real practical experience in this area) that it does not let the optimisers make assumptions that they can use to perform stronger optimisations. A recurring problem in this area is the folding of constants, where languages like Java specify a bit too much with respect to what can be folded and how it should be folded.

On a slightly different note, the GSC guys have also created a "Hello World" front-end for GCC that shows you how to build a front-end for GCC for your favourite language.

On an entirely different note, I have ended up writing 3,000 lines of text in the user manual of a 4,000 line programme (both rough "wc -l" figures)! Either the manual is unnecessarily verbose or the programme is too complex.

Tatjana van Vark
Tatjana van Vark looks like an amazing Dutch inventor and machinist. Just look at her works and you'll know what I mean. My favourites were the oscilloscope that she created when she was just 14 years old and an Enigma-like "Coding Machine". I just wish they had put up some more information about the devices than just the pictures. Another of those humbling experiences for yours truly.
27 Mar 2006 (updated 27 Mar 2006 at 07:20 UTC) »
GNU Texinfo
I wanted to write the user manual for a small personal project that I have been working on in my free time. I wanted the user manual for the project to be available in both HTML as well as PDF and also look good in either case. I considered both GNU Texinfo as well as DocBook for this purpose, but settled for Texinfo simply because it is installed by default on almost all Linux systems and since GCC and many other Free Software projects use it for their documentation. This way, I can easily contribute to the GCC/GCJ documentation without having to learn a new documentation system, should I wake up one morning with the sudden urge to do so.

Texinfo proved very simple to learn and produces fairly good looking HTML and PDF files (although some people prefer texi2html to "makeinfo --html" for HTML output). It can also output DocBook XML files, though I don't know how good the output is since I don't know the DocBook system yet. I am very happy with the tool so far. I haven't learnt a whole lot of Texinfo yet, but since when has that stopped me from making a fool of myself?

There are still some warts that I see with the Texinfo system though:

  • Info is a nice format/tool and I use it a lot under Linux, but you have to go through so many unnecessary hoops in Texinfo to properly support it. Why do you have to explicitly declare nodes and menus? Why can't Texinfo automatically derive these from the chapters and sections in the document in case they haven't been specified explicitly?

  • Creating an index and bibliography is unnecessarily painful. LaTeX has a far better support for these things via auxiliary tools.

  • As with TeX/LaTeX, inserting images is so painful. It could be one of the reasons why so many Free Software manuals do not bother to include figures at all.

  • Texinfo ostensibly focusses on content rather than presentation, but many presentation-related tags and conventions creep in.

  • Support for mathematical symbols is rather weak. Things look good only in the TeX output. The HTML output should be using MathML instead of just showing the text as-is. I don't particularly like MathML since it makes writing even simple things so tedious (TeX is so much better at this), but it's still a standard, as unfortunate as that situation might be.

  • A lot of things work well only for English documents and it does not seem well-suited to writing documents in other languages. As an aside, I personally cringe when I have to write tags spelt assuming American English (as with HTML, Java, etc.) not British English.

These rants aside, I am still sticking with Texinfo for the documentation for my little projects, though for "paper-like" stuff, I'm going to prefer LaTeX.

Miscellaneous
Steve Yegge is now on Blogger for those of you who can't seem to have enough of his rants.

Ranjit Madampath pointed me to a rather hilarious entry on Frameworks in the Joel on Software discussion group.

Planet Scheme used to be available as planet-scheme.yi.org, but it seems to be dead now. I used to like reading the aggregated weblogs of a lot of smart Scheme hackers, the weblog of José Antonio Ortega Ruiz in particular.

Assembly Language
saju's first post made me recall some of the things I miss in C which were so simple in x86 assembly language. For example, while doing fixed-point arithmetic with 32-bit operands, it was immensely useful that the CPU could hold the result of a multiplication (using MUL) in the EDX:EAX 64-bit register combination without overflow and that the same register combination could be used in a following division (using DIV), neatly separating the quotient and the remainder. The ADC ("Add with Carry") instruction was similarly useful for neatly handling overflows in addition. I don't know if you can achieve this in C without resorting to inline assembly. Readers of Michael Abrash's "Graphics Programming Black Book" and Oldskool PC coders will immediately realise what I'm talking about.

Miscellaneous
Firefox leads to a breakup. I don't know whether I should feel sorry for the bloke who was dumped or the lady who had to change her email address possibly after being bombarded with tonnes of silly emails. I do know that I found this bug report rather funny.

As I had feared, I performed miserably in the qualifying round of the Google Code Jam India 2006. Good luck to the people who moved on to the next round.

20 Mar 2006 (updated 20 Mar 2006 at 10:23 UTC) »
Miscellaneous Readings
Some random stuff to do when you're bored:
Wi-Fi
I bought a D-Link DI-524 wireless router the other day to set up a little Wi-Fi network at home so that Anusha and I can surf the Internet simultaneously using our broadband connection instead of one patiently waiting for (or cursing) the other - she on her laptop, me on my desktop PC.

What surprised me was how cheap the equipment was (Rs 2,600/- after 4% VAT) and how easy it was to set up. There was a slight complication due to the Huawei SmartAX MT880 ADSL modem-cum-router we were using for our BSNL DataOne broadband connection and the assumptions made by the wireless router, but that is easy to resolve if you know the basics of IP (Internet Protocol). It was also relatively easy to secure the access point.

Of course, this adds a few more cables to the jungle of cables behind my PC that had already made cleaning difficult and any expansion a chore.

By the way, I have been seeing the prices of networking equipment (modems, switches, wireless routers) dropping drastically over the last year here in Bangalore, possibly because broadband has become quite affordable and because more and more people have a laptop or two.

Stevey Yegge's Blog Articles
reddit.com regulars would have surely noticed several articles from Stevey Yegge's blogs bubbling up with a lot of moderation points. I must admit that I spent more than a couple of hours reading many of his articles. As with Joel Spolsky, I might not agree with everything he says but I have to say that he writes fairly well most of the time (though he is a bit verbose and somewhat incoherent at times).

151 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!