Posts tagged ‘Software’

Recently I decided to move on with my web programming skillset, and see (at last) a little more modern approach that include much client side coding, with Javascript. The first thing you learn when studying such approaches is the XMLHttpRequest, which is used to send/receive data with the web server.

To aid me, i purchased the Head First Ajax, a really nice book, focused in practical things, than in theory and specifications.

Imagine my suprise when in the first pages of the book i found this code?

function create_request(url) {
    var req = null;
 
    try {
        req = new XMLHttpRequest();
    } catch (tryMS) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (otherMS) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (failed) {
                return null;
            }
        }
    }
 
    return req;
}

In my previous article, I stated that web programming is a little chaotic (the way it is), and the problem is the diverse technologies that are used, among with the ad-hocracy of the browsers.

And voila, one more snippet to my wall of fame, which shows the rubbish approaches that are used in some implementations. Internet Explorer decided that he should have another way to implement the http functionality object and with two different ways, making the programmers, trying to initialize 3 objects in total, with nested try/catch statements.

I really do not know, which great business policy is served with this implementation … maybe I lack the big picture management thing that exists in the head of some people, that take those superb decisions.

VN:F [1.9.17_1161]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Everyone that has a living (and networked) computer in his house has seen it. The revolution of our century in computing, the World Wide Web (WWW). Many consider it the next big-bang platform. Google, YouTube, and Facebook among others, deliver a variety of services for all kinds of taste. Social networks, video, music, and e-commerce is now done by web applications.

In addition, many traditional kind of applications are also web-ified, such as government facilities that have all transformed into e-Government. Yes, it is true. You don’t have to run anymore, two more clicks from your chair, and your dreams may come true.

Back then …

… i was a student. I remember surfing the web, that was comprised of simple, for today’s standards of course, HTML pages, downloading C compilers, and recent patches for video games. I also learned of dynamic content, CGI based applications with Perl and later with PHP. I even developed some web applications myself. Then i heard of Java and applets, more dynamic content in a stateless world. Cookies, hidden parameters, hashes, sessions, all concepts that gave birth to the modern era of computing.

Best effort …

… is what the standard says about HTML rendering. In simple english, “do the best you can” and in a more simple manner “write the worst code ever, it is my fault, not yours”. What happens if you open the <b> tag and never close it? Nothing at all. What even happens if you do not know what <custom_tag> means? Just ignore it.

In this platform, we based our dreams regarding the future of our applications, and to make it worse we decided to make it even worse. And we did it beautifully, we took the task of web design from the computer scientist and we created a bunch of incompatible technologies.

The Tower of Babel

Indeed the world-wide web consists of a bunch of unrelated, badly coupled technologies. For example, we have CSS and HTML. What was the key idea behind them? Who knows? We created HTML that followed a specific notation, that obeyed the tag open – tag close rule and then we decided (years later) to defy it and create something like the X configuration files. Why is that? Nobody knows, and keep in mind that they were proposed by the same organisation, W3C.

In all this, we tried to give more juice to it by adding a javascript, that simply added HTML in the start, and later of modified the DOM tree of a page. Superb idea, we created a scripting language that is domain-specific but not exactly to serve its purpose. Javascript has the design concept of a general-purpose programming language, yet we use it like XSLT, to modify XML data. I am sure it is fun to traverse node lists and create new tags the hard way.

At the end, to complete our divine masterpiece, we made the ultimate move. We created incompatible web browsers, that had unique features. So it is nice that a web developer, must have Internet Explorer, Opera, Safari, Firefox, Chrome and Camino to check if the web site works and is displayed correctly. And yes each browser it is like a platform with unique add-ons, interpretation and implementation of the web standards (what?). So what if the menu is an inch lower in Internet Explorer? We have to live with it.

I will not refer to Java applets, flash or Silverlight. All those technologies are helping to increase the complexity not reduce it, introducing more and more diverse features.

Give the Web Back …

… to the computer scientists, because now it is a playground. Everyone can do whatever he wants and get away with it. The web is now built on unstable ground, and it will soon collapse. See all the web apps, like gmail. Try to estimate the effort behind the creation of it. You think it is fun or creative to do it? Or do you think that it would require half the time of creating it in a decent development platform? No, I’m not trying to estimate the development time here, i know it is a very difficult task.

Programmers Love the Web …

… and they want the web to love them back. I do not think i have the required skill to propose things to do it better, so i want you to add a big IMHO (In My Humble Opinion) just before every bullet that follows. So i think that it is time to …

… to enforce the standards. And i mean no best effort service anymore. The web has now penetrated all households and all businesses, time to mature.

… to create a compatible platform. No more dozens of browsers with unique behavior. I want it to work the same way in each one of them. Why LaTeX does it? Do the same.

… to find a decent scripting language. I think javascript is not enough. We create specialized languages for this kind of work.

… to try and find a common syntax for all the related technologies. We like XML notation? Stick with it! Do not create more and more languages that cause diversity. We like humans to learn and use it.

… to find ONE standard for HTML. I do not care who will it be. But it is funny to see standards like, XHTML, HTML 4.01, strict, and transitional.

In the End …

… we all use it. Even the most non-technical user knows that <b>text</b> prints the text bold. We all like blogging, forums and googling. Let’s make it work the right way.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Today, i decided to search a little the latest j2sdk sources. My initial search began with the usage of final modifier in the signature of a method. What is its exact usage, etc.

I wrote some sample programs and decompiled them, finding nothing of interest. Then i tried to investigate auto-boxing. I wrote a sample program that calls a method that has an Integer class as parameter. Something like that:

public void bar(Integer i) { ... }
 
int i = 1;
System.out.println(i);

When i used auto-boxing, the compiler used the Integer.valueOf(int) method. So i started searching if it is more optimized to use auto-boxing, or not.

When i changed the i variable to Integer type, and called normally the constructor of the Integer class, i realized that the constructor was invoked normally, with int as parameter.

The mystery solved when i read the original Integer class sources.

The contructor simply instantiates a new Integer object. On the other hand, the Integer.valueOf(int) does the following:

public static Integer valueOf(int i) {pre
	final int offset = 128;
	if (i >= -128 && i <= 127) { // must cache 
		return IntegerCache.cache[i + offset];
	}
 
	return new Integer(i);
}

The valueOf method uses an cache object and keeps 256 integers cached all the time. The pre for the integer cache follows:

private static class IntegerCache {
	private IntegerCache(){}
 
	static final Integer cache[] = new Integer[-(-128) + 127 + 1];
 
	static {
		for(int i = 0; i < cache.length; i++)
			cache[i] = new Integer(i - 128);
	}
}

So, if you use auto-boxing (or simply use the Integer.valueOf() method) instead of the normal constructor, you get a cached integer reference instead of a new object. This is an documented feature (see the Integer.valueOf(int) javadoc entry), and is demostrated by the following code.

public class Foo {
	public static void main(String[] args) {
		Integer i = new Integer(10);
		Integer ii = new Integer(10);
		Integer iii = Integer.valueOf(10);
		Integer iiii = Integer.valueOf(10);
 
		System.out.println("i == ii - " + (i == ii));
		System.out.println("ii == iii - " + (ii == iii));
		System.out.println("iii = i - " +  (i == iii));
		System.out.println("iiii = iii - " + (iiii == iii));
	}
}

Sample executiion output follows:

nefarian:~/devel/ew bkarak$ java Foo
i == ii - false
ii == iii - false
iii = i - false
iiii = iii - true

But the caching works only with the Integer.valueOf(int) method. See the implementation of the Integer.valueOf(String,int) for example:

public static Integer valueOf(String s, int radix) 
	throws NumberFormatException {
		return new Integer(parseInt(s,radix));
}

This method always returns a new Integer object. Doh!

VN:F [1.9.17_1161]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Lets have a look at the following example:

bkarak@linux-uho3:~&gt; python
Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1,2,3,4,5,6,7,8,9,10]
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> a[1:]
[2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> a[1:].extend(a[:2])
>>> a[1:] + a[:2]
[2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]

I am trying to concatenate two slices from a python list, using the extend method.

“| extend(…)
| L.extend(iterable) — extend list by appending elements from the iterable”

Why this does not work? … the list concatenation works fine with the “+” operator.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

5,1 GB and 23625 Files …. to be exact ….

HTML, 2525 / 23625
GIF Images, 2168 / 23625
JPEG Images, 1977 / 23625
Java, 1238 / 23625
XML, 928 / 23625
C/C++ Headers, 704 / 23625
C, 662 / 23625
C++, 650 / 23625
PDF Documents, 620 / 23625
Pascal, 619 / 23625
ASCII Text Files, 507 / 23625
MS Word Documents, 411 / 23625
ZIP Archives, 276 / 23625
JAR, 197 / 23625
PNG Images, 194 / 23625
TIFF Images, 132 / 23625
Excel Files, 132 / 23625
TeX/LaTeX, 109 / 23625
MS-Dos/Windows Batch Files, 109 / 23625
Powerpoint Files, 88 / 23625
RAR Archives, 80 / 23625
BiBTeX, 76 / 23625
X-Schema Files, 75 / 23625
GZIP Archives, 69 / 23625
make, 67 / 23625
Perl, 54 / 23625
C#, 48 / 23625
RTF, 31 / 23625
Windows HELP Files, 31 / 23625
PHP, 24 / 23625
Bourne Shell, 21 / 23625
SQL, 19 / 23625
PSD Photoshop Images, 16 / 23625
Javascript, 14 / 23625
Document Type Definition Files, 14 / 23625
Mac OS X Install Files, 6 / 23625
XSL/XSLT, 5 / 23625
BZIP Archives, 3 / 23625
Visual Studio C# Project File, 3 / 23625
SED, 3 / 23625
TAR Archives, 1 / 23625
Other, 8719 / 23625

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

The parsing facility of biblio.py is finally released as a stand-alone module. Current version of the module is v0.8.

You can find further information about it here.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

See a step-by-step tutorial and:

  1. Create the plug-in directory, edit the Makefile and add your plug-in’s directrory to the SUBDIRS variable
  2. Create the pom.xml
  3. If you want to include a jar, put it in the lib directory
  4. If you include jar and want to read resources, add them into your metric plug-in directory
  5. Implement the BundleActivator, AbstractMetric, ProjectVersionMetric, and ProjectFileMetric

For a more solid example, check out metrics directory in the Alitheia repository.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Today v0.51 of biblio.py is released. It includes a few bug-fixes my friend Christos discovered.

It should be considered a minor release. It provides better error handling and the new ‘list’ directive, which prints the current repository paths (includes validation).

Check out this page for more details.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)