stoimen.com/blog

web developing

IDEs and Autocompletion

One of my favorite things in IDEs, in my case Eclipse for Mac, is that they offer you the option of autocompletion. No developer knows the entire set of functions of the language he uses, neither the set of parameters of them. That’s why IDEs come to help.

In many cases when casting is not obvious and method call chain is to large your IDE may refuse to help you with this brilliant functionality. To be more precise let me give you an example.

In Zend Framework I was trying to fetch a RSS via Gdata interface. Something like that:

$videoFeed = $gdata->getUserUploads('youtube_username');
foreach ($videoFeed as $entry) {
    // do something
}

The problem is that whenever I try to do $entry-> in the body of the foreach loop I don’t see what methods are supported by the Zend_Gdata_YouTube_VideoEntry class. So I tried to force the casting of $entry to this class definition and it worked like a charm for me. The thing I’ve done was to add a definition of $entry before the loop body:

$videoFeed = $gdata->getUserUploads('youtube_username');
$entry = new Zend_Gdata_YouTube_VideoEntry();
foreach  ($videoFeed as $entry) {
    // do something
}

Than whenever you try to type $entry-> you’d receive a list of methods from the class definition of Zend_Gdata_YouTube_VideoEntry.

What if …

continuing from the previous post let assume there’s the following code:

if ( thisIsTrue ) {
   if ( myFuncReturnsTrue() ) {
      printMe('success');
   } else {
      printMe('error');
   }
}

This can be easily ported to:

thisIsTrue && (myFuncReturnsTrue() ? printMe('success') : printMe('error'));

Source

You can see the demo source here. Here’s a snippet:

function func1() {
	alert('func1');	
}
function func2() {
	alert('func2');	
}
 
var a = true;
var b = false;
 
a && (b ? func1() : func2());

A “Typical Installation” …

As most of the desktop software gives us opportunity to choose from typical or custom installations, let me write what’s a typical IF conditional statement in JavaScript and … every other programing language.

if ( thisIsTrue ) {
    printMe("some message");
}

A “Custom Installation” …

The first thing you can improve from the code above is removing the brackets.

if ( thisIsTrue )
    printMe("someMessage");

Because in JavaScript everything’s on the client – every symbol matters. What if we remove as much as we can!

thisIsTrue && printMe("someMessage");

Your Server Side Language of Choice?

Now continuing from the JavaScript libraries post, let me ask you who’s your server side language of choice?

  1. ASP
  2. PHP
  3. Python
  4. Other

Please feel free to share your opinion!

Javascript Libraries Popularity

JavaScript and Market Share?!

It’s kind of strange to speak about JavaScript libraries and market share, so lets called it “popularity”. Have you ever been interested on which is the most famous JS library.

I’d guess everybody has the answer in his head, right? jQuery is becoming for the JS community something like Google for the web or IE6 on the browser’s market in the beginning of the century. How odd?!

However here’s a short list of who’s first.

1. Robert Nyman’s poll:

Note: original poll page’s here.

Clear enough jQuery rocks. As I personally use jQuery I still think that its success is based on his easy to start nature. However lets see another result chart.

2. Chris Coyier from http://css-tricks.com is showing almost the same result:

Note: original poll can be found here.

3. Finally Polldaddy’s hosting a poll, where the results are even more interesting.

Polldaddy

Note: original source of the poll.

From these results I get more surprised not so much from the jQuery big advantage, but more from YUI. It’s a really very very powerful JavaScript library, perhaps misunderstood maybe because of it’s native complexity, don’t know?!

  • 4 Comments
  • Filed under: javascript