Archive for the Category » Code «

Sunday, April 23rd, 2006 | Author: Kalle

One thing I’ve noticed that is degrading over the years, is the fact that certain email applications are catching on on the translations. To put it simple…

Just because I prefer a certain language, does not mean everyone that I will ever ever email in my whole full entire life … prefers that same language. Let’s take an example. You write on a mailing list, I reply. I have Swedish language preferred. You see…

“Sön den 23 april kl. 08:13 -0600 skrev George:”

So much for a useful quoting header. I mean, sure, “Sön” might probably mean Sun(day). “23 april” isnt’ that hard to figure out. And at that point, you have it, but why would you have to? Isn’t this logic sorta flawed? This reaches a point of ridiculousness when you start using a language which does not use the regular alphabet, such as, say, Japanese, where most readers don’t know a single letter.

Conclusively, translating apps is a very good thing. Not that it ever really affected me as I always preferred English. But translations have to be logical. Translating something that will very likely be read by people with different language preferences than the user is a bad idea. I don’t care about the level of political incorrectness stating that English is the universal language right now, but there you have it.

Fighting for the rights of semi-translation since 1980.

(Yea, I admit this is more of a rant than anything else.)

Category: Code, Software  | Leave a Comment
Friday, April 21st, 2006 | Author: Kalle

From the GPL:

“This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License.”

Well, that answers that.

Category: Code, Software  | Leave a Comment
Thursday, April 20th, 2006 | Author: Kalle

I’ve been quiet lately, for many reasons. The biggest reason is probably that my main computer died on me. Luckily I had two more to contend with, though I despise working from the laptop when I’m at home.

The second reason is that I’ve been inspired recently. That, too, has several reasons and is cause for some surprise in my neverending search to figure out what I am. One of the reasons is the weather. Being in Sweden, where nice weather is a luxury, I always get inspired come spring. In fact, I love spring. I love spring more than any other season, but that is not the only reason why I am inspired. Another, big reason is that whenever I face certain types of difficulties, I tend to struggle the hardest. Unfortunately, this is only a particular type of difficulty. I would have loved to be able to say that when I face difficulties I struggle and fight back with nail and tooth, but that is usually not how I am.

It is hard to describe this type of difficulty that does “boost” my inspiration. It is especially hard as I haven’t realized it even existed until last night (well, I have, but I hadn’t put words to it until then). But it has to do with the sense of indifference I feel when everything is okay. The lulling certainty and everyday aspect of “normal”, that tends to take the edge out of my inspiration even at the best of times.

I remember when I was working at a candy store, a few years ago. I loathed that job, and every day as I returned home, no matter how tired I was, I would sit down and work my ass off on code stuff, because I needed it. If I hadn’t, I’d have gone bonkers. That is the kind of difficulty I’m talking about.

My main computer died on me, as I said. Having two others, that is not a big issue, really, but it is. I tend to save my todo list as email entries (since I receive most of my “do”’s via email anyway) and these are now utterly gone until I’m able to get things back up and running. (In fact, I believe they are gone, period, but that’s for later to find out.) My “day-to-day routine” is also completely skewered on a 2×4. I initially told my boss that I wasn’t sure when I’d be able to get back in the thick of things, as I honestly had no idea how well I’d be able to work without things being normal, but to be honest, I’ve worked harder since my computer crashed than I have in months.

What would cause such an odd, seemingly illogical behavior in a man, I wonder? Where the presence of difficulties seems more beneficial than their absence, where inspiration shines the brightest under lesser conditions. I don’t know for sure, but I think it’s an important part of me that I’ve neglected to think about. It may not seem as big a deal. In fact, I’m sure I am not unique in this aspect. I think this drive that I feel is what makes people face great perils to do what they believe in, but that may be farfetched and self-glorifying (not that I ever said I would face great perils to do what I believe in…). In any regard, it is a part of me, and as such it is something I am going to think about. I am determined to get to know this guy that I am better and better.

Category: Code, General, Life, Random  | 2 Comments
Friday, March 24th, 2006 | Author: Kalle

What?

Contributor License Agreements — or CLA’s — are a fairly new phenomenon in the Open Source world. IANAL, but I am going to make an attempt to explain what a CLA is, and why it is necessary today, where it previously was not.

The most commonly used CLA is that of the Apache Software Foundation (ASF), and the purpose appears right at the top of the agreement:

In order to clarify the intellectual property license granted with Contributions from any person or entity, the Foundation must have a Contributor License Agreement (”CLA”) on file that has been signed by each Contributor, indicating agreement to the license terms below.

The agreement continues to in great detail explain that the person signing the document must both be the author (or hold rights or permission by the author), and be the copyright owner of the contributions they are planning on making to the project in question. It is clarified that the rights to use the contributions will always and forever remain with the contributor, and that the CLA simply extends this right to the project as well.

In other words, if you submit stolen code, you are breaking the CLA, but if you refrain from such follery, nothing’s changed. You’re still the copyright owner of your submissions, but you grant the other party these rights as well. Simple enough.

In the past, this has been a presumed agreement between the involved parties. If I help you out and patch up your code to make it run better, or submit documentation that makes your code more useful, or whatever, you and I both presume that I didn’t steal the code from someplace and handed it to you in evil. This presumption is no longer enough, for good or worse.

Why?

CLA’s became necessary as a direct effect of the SCO vs. Linux court case(s), which, summarized, are about: “SCO claims a bunch of contributors to the Linux source code stole that code without permission from SCO, and that thus, SCO is now the owner of Linux and may at their whim request that all users of Linux pay a royalty fee.” Pretty scary, huh? Be that as it may, the court negotiations are as of this writing ongoing, but things are looking bad for SCO (for what it’s worth).

But regardless, SCO’s claim was a bucket of cold water in the face of the many maintainers of and contributors to various Open Source projects out there, as a legal matter was suddenly making things a tad more complicated. What if someone helps you out and gives you a bunch of really good, professional code, and what if that code is ripped out of some commercial, copyrighted very-much-not-open-sourced product somewhere? How would you know? How could you possibly know?

A quick Google search on “contributor license agreement” shows 1.6 million hits. Obviously, a great deal of Open Source maintainers and organizations do care, and CLA’s are obviously the answer to this legal matter.

In the end, I think the majority of those who’ve followed the SCO vs Linux court case agree that it is exclusively a matter of halting the progress of the rapidly evolving Open Source world. Microsoft, the father of FUD, assuredly caught onto the dick-grip SCO had on Linux in particular and Open Source in general, and decided to sponsor SCO by handing $12 million dollars to SCO, “to purchase UNIX-type licenses so Microsoft customers can run UNIX-type applications” (this was in the year of 2005, and was reported by Business Week). In the end, though, did SCO win? Have they hampered the development of Open Source software?

In my uneducated opinion, yeah. They have won. They have won a fraction of what they aimed for, but yes, I believe SCO got if not the whole cake, they got a taste of it. But I also believe that what they won, the Open Source movement will ultimately benefit from. Ultimately. Eventually.

From personal experience, I know what a CLA can do to the quantity of contributors. A lot of people feel that they want to help a project out, but when they’re handed a big, scary paper which may be interpreted as giving up the rights to something you give away for free, they hesitate. And rightly so. Everyone should hesitate when prompted to sign legally binding documents; everyone should read the fine print and ensure they know what they’re getting into. But this, naturally, proffers a wholly different stage than the good old “wanna help out? just chuck yer code at me and I’ll eyeball it and if it looks good I’ll plop it into the svn tree, m8″ type of development.

In the long run, though, Linux and Open Source have been children until now, and it’s time to grow up and face the big crowd, and the big crowd usually wields lawyers like children wield wooden swords, and the difference is that more than a few bruises and tears are at stake. That SCO will ultimately lose to Linux I have no doubts of. And in a way, I am grateful that the world will get to see Linux prevail in court over the devil, and I believe companies worldwide will see this as a trigger to examine Open Source alternatives closer, au contraire to the belief that companies will shy away from it, due to its “run-ins with the law.”

Category: Code, FUD, General, Life, Work  | Leave a Comment
Wednesday, March 15th, 2006 | Author: Kalle

[updated March 20th, to improve the code a bit]
In most lower-level programming languages, debugging functionality exists to allow the programmer to more easily track down bugs that appear in code. One of these functionalities is called “a stack trace” and allows a programmer to pull up the list of functions which were called which lead to some crash or exception in the code. An example of this in Java might look like:

Exception in thread "Thread-2" org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttribute(CoreDocumentImpl.java:572)
at com.sun.org.apache.xerces.internal.dom.ElementImpl.setAttribute(ElementImpl.java:523)
at sserve.DomSynchronizedProtocol.prot_ELA(DomSynchronizedProtocol.java:297)
at sserve.DomSynchronizedProtocol.examine(DomSynchronizedProtocol.java:438)
at sserve.Waiter.handleData(Waiter.java:323)
at sserve.ServerPool.processSocket(ServerPool.java:406)
at sserve.CommService.run(CommService.java:43)
at java.lang.Thread.run(Thread.java:595)

The above may look like soup, but is immensely useful to someone who knows their way around the various classes mentioned in the code. I can for instance tell you that the processSocket function called the handleData function at line 406 in the ServerPool.java file. The handleData function called the examine function, called the prot_ELA function, which in turn called some functions inherent in the Java API used in the code where the exception happened. So I can look at these functions in turn, and hopefully figure out why the exception mentioned happened.

This functionality, the ability to refer to a series of function-calls leading up to erroneous behavior, does not exist in JavaScript, for various reasons. One reason is that JavaScript has not until very recently been considered a language in which such advanced functionality is needed.

I have written a JS class which allows a user to set a “trace_stack” boolean in the code, which semi-automatically injects code into JavaScript functions, enabling a stack trace functionality. This is not useful unless you have several .js files with several classes which interact with each other to some extent.

Personally, whenever I see some (cool) package which enhances my JavaScripts somehow, I am always concerned first and foremost about performance. No matter how immensely helpful a script is to me; if it slows my code down, I don’t want it. I choose effort and efficiency over laziness and inefficiency any day of the week (see now why I do not consider Basic a programming language, as it is built on principles opposite of mine). That said, I have ran some fairly extensive testing on this implementation of mine, and as you might have guessed, the performance (with the trace_stack flag disabled) loss is 0%. That is, your code will run at 100% of its regular speed unless you toggle on the trace_stack flag on, which you will only ever do if you run into bugs anyway. (Which is what it’s there for.)

The script is contained in a single class, called stacktrace, in a single file called stacktrace.js. Admittedly, you will need to do some modifications to your existing code to make it compatible with this class, but the changes are fairly minor. Another matter is that the word “that” has become a reserved keyword in this implementation for reasons that will be obvious if you read on.

Take a look at the class itself here [stacktrace.js].

Presuming you know a bit about how classes are created in JavaScript, let’s see about putting this to use in an example script. How about this [testClass.js]?

A few things of note, before we actually test that script.

  1. that versus this. that is an internal keyword used by the stacktrace to generate code appropriate to the situation, where the two possible situations are a) you want stack trace data, and b) you do not want stack trace data. In the latter case, the stacktrace _reg() function will remove all stacktrace functionality from the base script. In the former case, _reg() will in fact add to the script a bit, by wrapping the function in another function. Thus you can see why there is a performance loss when tracing the stack, so you shouldn’t do this unless you are hunting bugs or unless your code is unstable. Thus, in any function registered with the stacktrace, you need to use that instead of this, in all cases.
  2. Every class constructor (var class = function() { [constructor code] }) must include a line identifying itself to the stack. E.g. var KalleClass = function() { stack.id(this, “KalleClass”); } is enough. Failing to do so will cause your code to crumple and croak whenever you attempt to enable the trace stack, with a bunch of “this._sti has no properties”
  3. The property “_sti” in a class using the stacktrace is reserved. For the record, it stands for “stack trace instance”.
  4. You can choose to exclude functions from the stacktrace registry. It is generally a good idea to exclude functions which do not call other (self-written) functions, as these functions may still present a stack trace and refer the user to “themself” as the final location where an error occured, and it is generally a good idea to include functions which do call other (self-written) functions. Regardless which, there should be no difference in performance when the trace_stack flag is disabled.
  5. By default, stack tracing is enabled via the URL of the web page. For example, if your code is triggered via http://example.com/foo.html, then you would enable stack tracing by going to http://example.com/foo.html?tstack=1.

So, finally, to see this in action, go here [test.html]. View source to see what the HTML looks like if you wish, but you should have a fairly good guess already.

With the trace_flag enabled, the output should look something like this:

--- debug pane ---
debugger initialized...
constructing testClass
stacktrace now knows who we are
created test, instance of testClass
firstFunction called with This is a test!; now gonna call secondFunction.
secondFunction; this is what the stack trace output looks like:
trace:	testClass: firstFunction
trace:		testClass: secondFunction

now I'm calling thirdFunction
thirdFunction; this is the stack trace:
trace:	testClass: firstFunction
trace:		testClass: secondFunction
trace:			testClass: thirdFunction

left thirdFunction; trace =
trace:	testClass: firstFunction
trace:		testClass: secondFunction

left secondFunction; trace =
trace:	testClass: firstFunction

called test.firstFunction('This is a test!')

With the trace_flag disabled, it should look something like this:

--- debug pane ---
debugger initialized...
constructing testClass
stacktrace now knows who we are
created test, instance of testClass
firstFunction called with This is a test!; now gonna call secondFunction.
secondFunction; this is what the stack trace output looks like:
[stack trace not available]
now I'm calling thirdFunction
thirdFunction; this is the stack trace:
[stack trace not available]
left thirdFunction; trace =
[stack trace not available]
left secondFunction; trace =
[stack trace not available]
called test.firstFunction('This is a test!')

To further explain what happens behind the scenes, the source code for the function test.firstFunction will look like this when the trace_stack flag is turned off,

function (somearg) {
dbgprint("firstFunction called with " + somearg + "; now gonna call secondFunction.");
this.secondFunction();
dbgprint("left secondFunction; trace = n" + stack.trace());
}

… and it will look like this, when trace_stack is turned on,

function (a1, a2, a3, a4, a5, a6, a7) {
this._sti.push(this, name);
return this._sti.pop(func(this, a1, a2, a3, a4, a5, a6, a7));
}

As you see, there are some limitations. There can only be 7 arguments to a function registered in the stacktrace, for instance (but this is a simple matter of my own limiting). Future revisions may examine the source for the function and limit the arguments accordingly. The values of this, name, and func are all internal here. func in this case has been modified to include a new initial argument, that, which is handed to it via the this reference in this._sti.pop(func(this, …)).

The only guaranteed performance loss, when the trace_stack flag is disabled, is a slightly longer load time, as the client has to reconstruct all the functions via the stacktrace class. But this is majorily minor and nothing I consider important — I care about runtime performance way more than load time.
Feel free to use this class wherever you want. It’s released under the MPL 1.1/LGPL 2.1.

Category: Code, Software  | 3 Comments
Tuesday, February 28th, 2006 | Author: Kalle

… with crayons.

Wednesday, February 01st, 2006 | Author: Kalle

“Whether you’re searching the web, comparing prices, or just staying on top of your favorite topic, Internet Explorer 7 lets you view many different websites at one time — all within one organized window.”

Holy SHIT, man, can you believe that? That fucking rocks! But… wait a minute. Isn’t that what Firefox/Opera have been doing for the last… 3 or so years? Heh. To be honest, they should’ve just written “We can do tabbed browsing now, too, just like the other browsers out there.” and they would’ve at least gotten some respect out of being honest about it.

Category: Code, Software, Stupid  | One Comment