
We read:
Planet PHP
Planet MySQL
Exciting E-Commerce
E-Commerce Blog
Fischmarkt
fukami
Lars Jankowfsky
Themenblog
Thomas Bachem
Matt Asay on OpenSource
Joel on Software
Ibrahim Evsan
Hasematzel
Techcrunch
Indiskretion Ehrensache
Sichelputzer
Alexander Schwinn
Managing Tech
F-LOG-GE
trycatchfinally
JSHint ist ein JSLint Fork von Anton Kovalyov. Dieser hat zwar nicht das Standardwerk der JavaScript-Welt "JavaScript - The Good Parts" geschrieben, dennoch kritisiert er Crockford's jslint, das in dem Buch ein eigenes Kapitel bekommen hat, pointiert mit:
JSHint is a fork of Douglas Crockfords JSLint that does not tyrannize your code. It is designed to detect errors that actually break your code while skipping things that, according to Crockford, are known to contribute mistakes in projects. In other words, JSHint is a fork of JSLint for the real world. The most important difference is that JSHint is developed and supported by the JavaScript developer community and not by one very opinionated person.
A couple of weeks ago, I was attending a three-day workshop for agile developer skills. The workshop was split into five topics: Colaboration, Refactoring, Design & Architecture, Continious Integration and Test Driven Development. Especially the session about Test Driven Development was very interesting. Although I know the principles of TDD I was really impressed by the demonstration of solving a simple exercise (a coding kata) done in Java by the instructors of the workshop. It was not so much the coding in Java that was interesting for me, it was the combination of writing a test, executing the test with a shortcut from the IDE, see the test fail, write the implementation and re-start the test again within the IDE. You will say “that´s test driven development- it´s nothing new!” and you are right! But is there a way to do Test Driven Development in the same way for JavaScript? I mean writing a test, execute the tests with a shortcut from the IDE, see the test fail, implement the method and re-start the test? Yes, there is a way! So let me show you what I have done to do the same coding kata (called Fizzbuzz) with JavaScript.
Dass Firebug in JavaScript programmiert wurde dürfte den meisten bekannt sein. Das gleiche gilt für den WebInspector von WebKit, wie er in Safari oder Google Chrome zu finden ist. Es dürfte also nicht wundern, dass für mobile Geräte mit Weinre von Patrick Mueller bereits 2010 eine Portierung des WebInspectors geschaffen wurde, die über eine JS-Include auf der im Website-Header im Mobilen Browser Remote Debugging Funktionalität zur Verfügung stellt. Somit kann bequem über dem Desktop eine Mobile Webseite debugged werden. Weinre läuft heute als PhoneGap Projekt, ist sozusagen Standard und ist natürlich auf GitHub zu finden.
Das Ganze hat aber leider eben leider Grenzen, was Features wie Breakpoints, Backtraces und Profiling angeht, d.h. genau die nützlichen Features, die normalerweis unter dem “Script”-Tab im Debugger-Panel zu finden sind.
Der nächste konsequente Schritt war also, den Debugger direkt in den Browser Runtime zu heben und eine Remote API anzubieten bzw. eine Verbindung zu dem ohnehin schon existierenden V8 DebuggerProtocol zu schaffen, dass sich allerdings nur auf JavaScript Debugging beschränkt. Das Gesamtpaket nennt sich dann WebKit Remote Debugging Protocol. Währenddessen arbeitete Google auch am ChromeDevToolsProtocol was aber mittlerweile deprecated ist.
Seit Frühjahr diesen Jahres bietet nun WebKit sein Remote Debugging Feature an, welcher praktisch alle bekannten WebInspector Features unterstützt - dazu zählen:
Das Feature kann bereits seit einigen Chrome Versionen getestet werden. Eine aktuelle Chrome Version bevorzugt kann eine Debugger-Instanz mit chrome --remote-debugging-port=9222 gestartet wird.
Sodann ist eine zweite Browserinstanz für den Remote Web Inspector nötig - diese muss jedoch Ihr eigenes Nutzerprofil verwenden, um Probleme zu vermeiden: chrome --user-data-dir=<existierendes Verzeichnis>
Mit Navigation auf http://localhost:9222 im zweiten Browserfenster findet sich nun eine Thumbnail-Übersicht der geöffneten Tabs des zu debuggenden Browsers. Ein weiterer Klick auf das ein Thumbnail lädt nun den Debugger auf die komplette Seite, mit dem wie gewohnt gearbeitet werden kann.

Somit kann zusammenfassend folgendes zur Funktionsweise gesagt werden:
In iPhone oder Android-WebKits sucht man den Debugger derzeit noch vergebens (about:debug), auch wenn es bereits einige ROMs für Android mit Web Inspector Support gibt. Blackberrys Playbook hingegen besitzt schon entsprechende WebKit Funktionalität.
Der Debugger bietet für den Browser eine vereinfachte, aber noch experimentelle JavaScript API, die z.B. auch durch Chrome Extensions angesprochen werden kann. Nach Google’s Vorstellungen sollen damit auch WebIDEs wie Cloud9 zum bereits integrierten JavaScript Debugger (lib-v8debug) einen vollwertigen “WebInspector” erhalten.
Opera demonstrierte bereits 2008 mit DragonFly und Scope einen funktionierenden Remote Debugger, mit dem es möglich ist sich an an einen Opera Mobile oder auch Desktop Opera via TCP-Port ranzuhängen und nicht nur JavaScript zu debuggen. Nachteil an der ganzen Sache: Im Mobile Web dominiert derzeit WebKit.

Ein ähnliches Projekt existiert seit Anfang diesen Jahres mit Firebug Crossfire, was ähnliche Möglichkeiten bieten soll. Zudem unterstützen die JavaScript Development Tools (JSDT) für Eclipse bereits Crossfire. Derzeit befindet sich das Projekt jedoch noch in der Alpha-Phase, aber darf bereits getestet werden.
Für den, der nodejs debuggen muss, gibt es mit dem NodeInspector eine schicke Lösung, mit der es möglich ist, dies bequem im Browser zu erledigen. NodeInspector ist wie ebenfalls wie Weinre eine Adaption von WebInspector.
Für JavaScript Debugging in der IDE, d.h. bequem Breakpoints in den Quelldateien des geöffneten Projekts setzen, haben wir zum einen die ChromeDevTools als Eclipse-Plugin. Zum anderen hat IntelliJ mit IDEA 10.5 und PHPStorm 3 das V8 DebuggerProtocol bereits implementiert.

Eine weitere einfache JavaScript-Konsole stellt z.B. JSConsole bereit, dass zum Debuggen von iPhone oder Android-Mobile Apps benutzt werden kann.
Here is a short example how a test for jsTestDriver could look like
MathmaticsTest = TestCase("MathmaticsTest");
MathmaticsTest.prototype.testAdd = function() {
var mathmatics = new school.Mathmatics();
assertEquals(3, mathmatics.add(1,2));
}
MathmaticsTest.prototype.testSub = function() {
var mathmatics = new school.Mathmatics();
assertEquals(1, mathmatics.sub(4,3));
}
MathmaticsTest.prototype.testDiv = function() {
var mathmatics = new school.Mathmatics();
assertEquals(4, mathmatics.div(8,2));
}
MathmaticsTest.prototype.testMultiple = function() {
var mathmatics = new school.Mathmatics();
assertEquals(9, mathmatics.multiple(3,3));
}
Monitoring your web application is essential for professional maintenance and development. Especially if you have a high load on your website and you want to keep the current users on your site, you definitely should stay alert for problems and be able to react fast in case of problems. Monitoring is also crucial for A/B tests, since you have to evaluate somehow which version of your website performs better. Many big players also measure constantly how much revenue the website produces. For them it is important to monitor if a new feature increases or decreases the revenue and take decisions based on that information.
Mayflower is currently developing a javascript framework which provides a smart tool for realtime monitoring and measuring. Read the full article for more information.
A lot of people are talking about a particular research paper featured by Wired of late. That paper describes, how users can be, and are, tracked against their express wish. Even deleting cookies does not solve the tracking problem. A lot of folks talk about how unethical, probably unlawful and unfair it is.
So far, although, I have not seen a site that gives more than hints how to prevent being tracked. Firefox users have a couple of tools at hand that can easily circumvent most, if not all, attack vectors. Using these measures comes at the cost of comfort, though.
|
Variable |
typeof Variable |
|---|---|
|
{company: 'Mayflower'} |
“object“ |
|
['Mayflower','PHP'] |
“object“ |
|
function(){} |
“function” |
|
“a simple String” |
“string” |
|
123456789 |
“number” |
|
true |
“boolean” |
|
new String(“Mayflower”) |
“object” |
|
new Employe( ) |
“object” |
var myArr = [ ];
if (myArr.constructor === Array) {console.log(“yes, I am an Array!”)}
The downside of this approach is the needed comparison to a known data type. If you create your Array with the new operator, you can get the data type with the prototype property, like this:
var myArr = new Array();
console.log(myArr.prototype); // Array()
var myArr = ['Mayflower','PHP','JavaScript'];
In JavaScript is something like an associative array, but this has nothing to do with the Array data type. The JavaScript world calls this an object literal and is a collection of key value pairs.
var obLiteral = {company: “Mayflower”, offices: ['München','Würzburg'] };
By the way, you are right if you say “the syntax looks like for a JSON string”. The syntax for an object literal and a JSON string are pretty similar with one main difference: For a JSON string the property names need to be wrapped in quotes to be valid. For object literals the quotes are only required if the property name have spaces or any other not valid identifiers.
function user(){
return
{
company: “Mayflower”,
business: “PHP Development”
}
}
The user function will run without any error and will return a valid value (Ok, it´s undefined but it´s a valid return value). It´s not the desired object literal because the semicolon insertion terminates the function after the return.
Am kommenden Donnerstag, den 25.03.2010 findet wieder ein öffentlicher Vortrag im Mayflower Büro in München statt (Mannhardtstraße 6, S-Bahn Isartor).
As
my last projects were mostly web 2.0 online applications I had to do
a lot of javascript programming. Using JS-Frameworks like JQuery or
Dojo the size of all necessary javascript files had added up to more
than one megabyte. Even today with highspeed internet connections one
megabyte needs several seconds to be transferred, so I had to find a
way to reduce the size of the code. For all my previous projects I
used Dean
Edwards Packer. This amazing packer was able
to reduce it to appr. a fourth of the original size. Getting this
nice result I was wondering if the tool delivered with Dojo – the
Dojo
Shrinksafe – or other minification tools
like JSMin
and the YUI
Compressor could do this as well. After some
tests, however, I realized that they couldn't.
Searching
the web for more information about the best way I found a cool tool /
website that shows the transfer sizes of well known javascript
libraries after minification / packing. It is also possible to let
the tool calculate the results for your own piece of code:
http://compressorrater.thruhere.net/
In
addition, the tool also calculates the size of a transfer with
http-compression (gzip). Before I found this website I did not see
the size after minification / packing and compression in combination.
Perhaps I should have done this before...
Analyzing
the results of CompressorRater it seems that Dean Edwards Packer
might really be the best choice – even with zip compression. Very
interesting is the fact that the results of packing and minification
is nearly the same after zip compression.
Yet
the size of javascript files and their transfer speed is only one
aspect which affects the loading delay of websites. The other aspect
is the time the browser needs to interpret those scripts. As packed
files have to be interpreted twice – first to eliminate the eval
and second to interpret the generated code – their loading delay is
higher than those of minified files.
After
taking a closer look at the loading time of those minimized
javascript files it turned out that the Packer is not always
the best choice: In case of bigger javascript files, the Packer
needs up to several seconds to d'eval the code. This doesn't matter
so much in web applications where javascript is only loaded and
interpreted once at the beginning but it will slow down a typical
website even more because javascript has to be interpreted at each
site request, even if it is in the browser's cache. Using a minified
script avoids this.
Summarizing
I suggest to use Packer only if it is not possible to realize an
http-compression.
Gestern wurde endlich die Version 1.0 von Dojo released (http://dojotoolkit.org). Im Vergleich zu Dojo 0.43 hat sich in Version 1.0 einiges getan, die wichtigste Änderung: es werden nun die Funktionalitäten sauber getrennt in drei kleinere "Projekte". Persönlich freue ich mich, dass in Sachen Performance sich einiges getan hat und die Engine massiv beschleunigt wurde. Bereits in PHProjekt 5 haben wir Dojo für einige Teile eingesetzt, für die Version PHProjekt 6 nutzen wir nun neben einigen Widgets auch die Möglichkeiten des Event- Handlings und der DOM- Manipulation von Dojo, sowie natürlich die Ajax- Funktionalität. In PHProjekt 6 wird eine MVC- Architektur auch auf Seiten des Clients umgesetzt. Unabdingbar für die Entwicklung des Client- MVC ist für mich ebenfalls die Tatsache, dass Dojo ein "normales" objektorientiertes Interface für JavaScript zur Verfügung stellt, das Klassen und Vererbung anbietet. Um es in den Worten von Kollege Hartmann auszudrücken: „Dojo ermöglicht dadurch ernsthafte Programmierung mit JavaScript!“
Leider ist auch mit dieser Version das Problem der Dokumentation nicht endgütig verbessert worden, es bleibt einem nicht erspart, sich durch das „Dojo- Book“ auf den Webseiten zu kämpfen. Hoffentlich gibt sich das im laufe der Zeit, denn das ist immer noch ein großes Manko.



















