Posts tagged: C#

Facebook HipHop Compiler for PHP: What Is It For You?

By Steve Jin, May 6, 2010

I attended a great seminar at Stanford by Haiping Zhao on the open source compiler which converts PHP code to C++ yesterday. Haiping is the tech lead for the open source HipHop project at Facebook.

As many have known, Facebook is a PHP shop with all the front end dynamic pages written in PHP. The upside of using PHP is that it’s very easy to read, write and debug, plus platform independent. The downside is that it’s really slow, probably one of the slowest scripting languages.

Why PHP is slow?

Haiping summarized three reasons, which he thinks are common contributors for slowness of scripting languages in general:

  1. Byte-code interpreter.
  2. Dynamic symbol lookups, including functions, variables, constants, class methods, properties, etc.
  3. Weakly typing. The zval has to evaluate the data type of any variable before any operation. Plus, the PHP array is too generic because it can represent any collection. 

Why Should Facebook Care?

When Haiping joined Facebook, new servers cannot catch up the new users. The server farms became so big that any percentage saving could save the company millions of dollars. Like all the big web companies, Facebook does not disclose the number of servers they have. The size of the datacenter is guarded as a secret. One of the professors did an estimate in his questions anyway: 15,000 to 30,000 servers. Read more »

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to RSS or Email, and follow on Twitter.

Top 20 Most Popular Programming Languages

By Steve Jin, April 30, 2010

If you are a software engineer, you might have known Tiobe popularity index of programming languages. The index is updated on monthly basis. The following table shows the top 20 most popular languages this month.

The index caught many people’s attention this month because C regained its No.1 position. Java, used to be No. 1 for years, dropped to No. 2. Although percentage wise Java is still very close to C, the declining of Java popularity can be eye-catching.

There could be many interpretations on the result, not the least of which is that Java is now owned by Oracle due to its recent acquisition of Sun. The explanation of Tiobe is as follows,

So the main reason for C’s number 1 position is not C’s uprise, but the decline of its competitor Java. Java has a long-term downward trend. It is losing ground to other languages running on the JVM. An example of such a language is JavaFX script that is now approaching the top 20.

In the application development, Java is still clearly the dominant programming language. The JVM languages like Scala (not in top 20 yet, but very promising) definitely worths watching.

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to RSS or Email, and follow on Twitter.

Why does C# Web Service code look weird?

By Steve Jin, January 25, 2010

Today I read a posting at VMware community forum about the weird code required by C# Web Service. If the following line is missing, then the vSphere API call to get properties doesn’t work:

VimApi.VimService.PropertySpec.allSpecified = True 

But the problem is that there isn’t any property defined as allSpecified in the object PropertySpec according to vSphere API Reference.

So, where does the allSpecified come from? and why is it needed?

Having created a new Web Service engine for VI Java API 2.0, I know why the weird code is needed. Let me explain in details here.

For any primitive data type, it does not have a value representing the case that no value is specified. When serialized to an XML SOAP message, it can be a problem. If the value is for a required property, no problem. But if it’s for an optional property, then a big problem. The serialization engine has no way to decide whether to include the value by evaluating the value itself.

Let’s take a close look at the above example, there is a property called all in the PropertySpec. Since the property all is a boolean type, it has to be either true or false. There is no way to represent a value for not specified. The property all happens to be an optional field.

There are two solutions to this problem. One is to have an additional field for every optional field of primitive data type in the data objects, just indicating whether the value should be serialized to the SOAP XML request or not. This is exactly what is used in Microsoft Web Service tool. The naming pattern for the additonal property is like *Specified, all boolean type. These additional properties will be used by WS engine but never serialized to SOAP message. By default, they are false. So if you want a primitive property X to be serialized, you have to explicitly set up the xSpecified = True; otherwise it’s ignored. In the above example, the property all is not, although should, serialized if the line of code is missing.

The other solution is to use wrapping object types for the optional fields of primitive types. For example, for the primitive boolean type, use Boolean type. Then you can use null as the “not specified”. The down side of this is that a new object may be created. The good thing is that it’s much straightforward and no mistake can be made. Java 5.0 and later supports auto-boxing, meaning you can assign a boolean to a Boolean type and the compiler handles the conversion for you. So you don’t even notice that you actually assign a boolean to a Boolean in Java.

With these two approaches, I prefer the second one just because it’s so easy for a developer to forget the *Specified and get a problem sometimes with no clue on what’s going on. For API design, ease of use is way more important than anything else. In the VI Java API 2.0 Web Services engine, I chose the second apprach and the users have no chance to make a mistake as in C#.

The problem is found with vSphere API in C#, but goes beyond that. Any Web Services stub created by Microsoft has this problem. You got to watch out and pay extra attention while coding Web Services in C#.

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to RSS or Email, and follow on Twitter.

Page 1 of 11

OfficeFolders theme by Themocracy