Tag Archives: c++

Quick thoughts on Xcode and Objective C versus Microsoft’s tools

I have been trying out JetBrains’ AppCode which meant working in an Apple development environment for a time. I took the opportunity to implement my simple calculator app in iOS native code.

image

Objective C is a distinctive language with a mixed reputation, but I enjoy coding with it. I used Automatic Reference Counting (ARC), a feature introduced in Xcode 4.2 and OSX 10.7, iOS 5; ARC now also works with 10.6 and iOS 4. This means objects are automatically disposed, and I did not have to worry about memory management at all in my simple app. This is not a complete memory management solution (if there is such a thing) – if you use malloc you must use free – but it meant that the code in my app is not particularly verbose or complex compared to other languages. Apple’s libraries seem to favour plain English method names like StringByAppendingString which makes for readable code.

I was impressed by how easy it is to make an app that looks good, because the controls are beautifully designed. I understand the attraction of developing solely for Apple’s platform.

I also love the integrated source control in Xcode. You find yourself using a local Git repository almost without thinking about it. Microsoft could learn from that; no need for Team Foundation Server for a solo developer.

I did miss namespaces. In Objective C, if you want to remove the risk of name collision with a library, you have to use your own class prefix (and hope that nobody else picked the same one).

image

Interface Builder, the visual UI designer, is great but many developers do not use it, because coding the UI without it is more flexible. It is a shame that you have to make this choice, unlike IDE’s with “two way tools” that let you edit in code or visually and seamlessly keep the two in synch. I found myself constantly having to re-display windows like the Attributes Inspector though it is not too bad once you learn the keyboard shortcuts. The latest Interface Builder has a storyboard feature which lets you define several screens and link them. It looks useful, though when I played with this I found it difficult to follow all the linking lines the designer drew for me.

It is interesting to compare the Mac and iOS development platform with that for Windows. Microsoft promotes the idea of language choice, though most professional development is either C# or C++, whereas on Apple’s platform it is Objective C and Cocoa or you are on your own. Although Mac and Windows are of a similar age, Microsoft’s platform gives a GUI developer more choices: Win32, MFC, WTL, Windows Forms, Windows Presentation Foundation and Silverlight, and in Windows 8 the new WinRT.

I get the impression that Microsoft is envious of this single-minded approach and trying to bring it to Metro-style Windows 8, where you still have a choice of languages but really only one GUI framework.

That said, Visual Studio is an impressive tool and both C# and C++ have important features which are lacking in Objective C. I would judge that Visual Studio is the more productive tool overall, but Apple’s developer platform has its own attractions.

Google offers the web a new language called Dart – but why?

Google has announced an early preview of Dart, a new language for web applications. The news is not a surprise, especially if you have been keeping track of the developer conference GOTO Aarhus, whose organisers had pre-announced that Google would be announcing its new language there, as indeed it did.

image

Dart is a curly-brace language like JavaScript, Java, C, C++ and C#. In Dart, as in C# and Java, a class can implement multiple interfaces, but only inherit from a single class. Dart supports both static and dynamic typing. Google says it can be executed by a Dart VM, or converted to JavaScript:

Dart code can be executed in two different ways: either on a native virtual machine or on top of a JavaScript engine by using a compiler that translates Dart code to JavaScript. This means you can write a web application in Dart and have it compiled and run on any modern browser. The Dart VM is not currently integrated in Chrome but we plan to explore this option.

Google also says that you will be able to “execute Dart code directly in a VM on the server side”, so you can infer that Google has Dart in mind as an alternative PHP as well as to JavaScript. The company is using the phrase “structured web programming” to describe Dart, and this phrase appears in the announcement and as the subtitle on the Dart site. The implication is that JavaScript code tends to be poorly structured and that Dart will promote more maintainable code.

In the preview Dart only runs in Chrome, Safari 5 and Firefox 4+ – spot the missing browser vendors.

At first glance, Dart looks like a promising language, though I find myself asking what it is really for, when it bears a strong family resemblance to existing languages, and bearing in mind that the Google Web Toolkit, which compiles Java to JavaScript, already enables structured programming for web applications. The list of problems which Dart solves in the technical overview is not all that compelling.

Google states that:

Developers have not been able to create homogeneous systems that encompass both client and server, except for a few cases such as Node.js and Google Web Toolkit (GWT).

This is or was one of the attractions of Microsoft Silverlight, presuming you use C# on both server and client, but Silverlight is a plug-in that was never going to run on an iPad and from which Microsoft itself is now retreating; though it is worth noting that Dart is not unlike C#, especially the latest version of C# with dynamic features.

I guess that Dart is a consequence of the failure of ECMAScript 4.0, which was a cooperative effort to create a more modern and advanced JavaScript. Google is now going it alone; the key question is whether it can win support from others such as Apple and Microsoft, or whether this will be a Google language for Google on the server and Chrome on the client, or an interesting experiment that never really catches on.

Do we need Dart? I would value hearing from others what you think of Google’s proposal.

C++ 11 is approved by ISO: a big day for native code development

Herb Sutter reports that C++ 0x, which will be called C++ 11, has been unanimously approved by the ISO C++ committee. The “11” in the name refers to the year of approval, 2011. The current standard is C++ 98, though amended as C++ 03, so it has taken 8 or 13 years to update it depending on how you count it.

This means that compiler makers can get on with implementing the full C++ 11 standard. Most current compilers implement some of the features already. This Apache wiki shows the current status. A quick glance suggests that the open source GCC is ahead of the pack, followed by Intel C++ and then perhaps Microsoft Visual C++.

C++ 11 is pretty much compatible with C++ 03 so existing code should still work. However there are many new features, enough for Bjarne Stroustrup to say in his feature summary:

Surprisingly, C++0x feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever. If you timidly approach C++ as just a better C or as an object-oriented language, you are going to miss the point. The abstractions are simply more flexible and affordable than before. Rely on the old mantra: If you think of it as a separate idea or object, represent it directly in the program; model real-world objects, and abstractions directly in code. It’s easier now.

Concurrent programming is better supported in C++ 11, important for getting the best performance from modern hardware.

It is curious how the programming landscape has changed in recent year. A few years back, you might have foreseen a day when most programming would be .NET, Java or JavaScript: all varieties of managed code. While those languages do still dominate, native code has come more to the fore, thanks to factors like Apple’s focus on Objective C, and signs of internal conflict at Microsoft over the best language for coding Windows applications.

That said, C++ 11 remains a demanding language to learn and use. As Stroustrup notes, since C++ 11 is a superset of C++ 98 it is technically harder to learn all of it, though new libraries and abstractions should help beginners. The reasons for using or not using C++ are not going to change significantly with this new standard.

The strategy behind Mono has shifted: ten years of open source .NET

Yesterday, SUSE and Xamarin announced, in effect, the transfer of all things Mono to Xamarin.

The agreement grants Xamarin a broad, perpetual license to all intellectual property covering Mono, MonoTouch, Mono for Android and Mono Tools for Visual Studio. Xamarin will also provide technical support to SUSE customers using Mono-based products, and assume stewardship of the Mono open source community project.

Xamarin is a startup formed by Mono founder Miguel de Icaza following the acquisition of Novell and SUSE by Attachmate, which ceased Mono development.

Attachmate acquired Novell in November 2010. Mono has been plucked from the abyss with impressive speed.

That said, the strategy behind Mono has shifted. Mono exists because de Icaza liked what Microsoft announced back in 2000 when it introduced C# and the .NET Framework. Microsoft made a show of standardizing the .NET CLI (Common Language Infrastructure), which made PR sense at the time since there was controversy over Sun’s ownership of Java, though nobody really believed that Microsoft knew how to steward an open source development platform or indeed believed that it was really serious about it. History largely justifies that scepticism; but de Icaza called Microsoft’s bluff and forged ahead with Mono, implementing not only the CLI and C# but most of the .NET Framework as well.

The goal of Mono, as I recall, was to bring the benefits of C# and .NET to Linux developers, and to enable developers to move applications freely between Windows and Linux. Apple OS X was also on the radar, though it took longer to become much use. Recalling Mono’s early days, de Icaza said:

Mono to me is a means to an end: a technology to help Linux succeed on the desktop.

Mono worked remarkably well from quite early on, but never quite well enough to persuade mainstream developers it was a sensible choice for applications that would otherwise have run on Windows. It did emerge as a viable and productive toolset and platform for Linux and a number of Mono applications became popular, including Beagle search, Tomboy notes, and F-Spot photo management. Some ASP.NET applications run on Mono; I have one on this site. Another Mono success was its use as the scripting engine in Unity, a game development platform.

A big problem for Mono though was the lack of a business model. There was support and servicing of course, which must have generated some revenue for Novell, but most Mono use is free. Novell possibly had in mind that Mono could be significant as an application server, but it has never become a really trusted platform in the Enterprise. For example, as Alan Radding (Dancing Dinosaur) notes:

DancingDinosaur has not found any SUSE on z user that has successfully implemented .NET apps on the mainframe. A few have tried but reported that Mono on z wasn’t ready for prime time.

Even among the free software and open source community, Mono was hampered by suspicion of Microsoft. If Mono became successful enough to threaten Microsoft, would lawyers appear? Given the way Microsoft is currently behaving with Android, filing legal actions and signing up licensees, those fears might not be unwarranted.

So what is Mono today? The answer is that Mono is now primarily a mobile platform. The Xamarin home page makes this clear, as well as making it apparent that the Mono team has discovered the value of a business model:

image

Xamarin is tapping into two real business needs. One is the need for a cross-platform mobile development platform that works. The second is a way for Windows developers to use their existing C# skills for mobile development, given that they might not be happy with the tiny market share currently achieved by Windows Phone 7.

When I had a quick try with Monotouch I was impressed, and I would like to spend some more time with it and with Mono for Android.

Mono has touch competition though. In particular, PhoneGap, Appcelerator’s Titanium, and Adobe AIR. I was interested to see that Adobe is coming up with a packager for AIR on Android, which may significantly improve it as a cross-platform mobile toolkit.

Still, Xamarin is small and nimble and I expect it to succeed. It has also has Visual Studio integration, which is an advantage. One of the pieces Xamarin has now licensed from SUSE is Mono for Visual Studio.

The downside of these latest developments is that if you depend on Mono for the desktop or for ASP.NET, you may find these parts of the Mono project getting little attention from the new company. But Mobile is all that matters now, right?

I write this on July 19 2011. According to Wikipedia:

Recognizing that their small team could not expect to build and support a full product, they launched the Mono open source project, on July 19, 2001 at the O’Reilly conference.

Well, if there was a launch there it was low-key. It is not mentioned in this report. But de Icaza does recall:

We planned the announcement to come by July 19th 2001, so we could announce this at the O’Reilly conference, as Tim O’Reilly had been very supportive of this effort, and had offered his help since the early stages, when it was still a very young idea. When we announced the project launch we had our team in place, and we were shipping our metadata framework and our C# compiler as well as a few initial classes So officially the Mono project was launched on that date, but it had been brewing for a very long time.

Happy Anniversary!

The frustration of developing for Facebook with C#

I am researching a piece on developing for Facebook with Microsoft Azure, and of course the first thing I did was to try it out.

It is not easy. The first problem is that Facebook does not care about C#. There are four SDKs on offer: JavaScript, Apple iOS, Google Android, and PHP. This has led to a proliferation of experimental and third-party SDKs which are mostly not very good.

The next problem is that the Facebook API is constantly changing. If you try to wrap it neatly in an SDK, it is likely that some things will break when the next big change comes along.

This leads to the third problem, which is that Google may not be your friend. That helpful article or discussion on developing for Facebook might be out of date now.

Now, there are a couple of reasons why it should be getting better. Jim Zimmerman and Nathan Totten at Thuzi (Totten is now a technical evangelist at Microsoft) created a new C# Facebook SDK, needing it for their own apps and frustrated with what was on offer elsewhere. The Facebook C# SDK looks like it has some momentum.

C# 4.0 actually works well with Facebook, thanks to the dynamic keyword, which makes it easier to cope with Facebook’s changes and also lets it map closely to the official PHP SDK, as Totten explains.

Nevertheless, there are still a few problems. One is that documentation for the SDK is sketchy to say the least. There is currently no reference for it on the Codeplex site, and most of the comments are the kind that produces impressive-looking automatic documentation but actually tells you nothing of substance. Plucking one at random:

FacebookClient.GetAsync(System.Collections.Generic.IDictionary<string,object>)

Summary:
Makes an asynchronous GET request to the Facebook server.

Parameters:
parameters: The parameters.

Another problem, inherent to dynamic typing, is that IntelliSense (auto-completion in Visual Studio) has limited value. You constantly need to reference the Facebook documentation.

Finally, the SDK has changed quite a bit in different versions and some of the samples reference old versions.

In particular, I found it a struggle getting OAuth authentication and access token retrieval working and ended up borrowing Totten’s sample code here which mostly works – though note that the code in the sample does not cope with the same users logging out and logging in again; I fixed this by changing his InMemoryUserStore to use a ConcurrentDictionary instead of a ConcurrentBag, though there are plenty of other ways you can store users.

I’m puzzled why Microsoft does not invest more in making this easier. Microsoft invested in Facebook and it is easy to get the impression that Microsoft and Facebook are in some sort of informal alliance versus Google. Windows Phone 7, for example, ties in closely with Facebook and is probably the best Facebook phone out there.

As it is, although I prefer coding in C# to PHP, I would say that choosing PHP as the platform for your Facebook app will present less friction.

RIM announces Java and Android runtimes for the Playbook, beta of native SDK

RIM has announced several new options for developing apps for its PlayBook tablet.

RIM will launch two optional “app players” that provide an application run-time environment for BlackBerry Java® apps and Android v2.3 apps. These new app players will allow users to download BlackBerry Java apps and Android apps from BlackBerry App World and run them on their BlackBerry PlayBook.

In addition, RIM will shortly release the native SDK for the BlackBerry PlayBook enabling C/C++ application development on the BlackBerry® Tablet OS. For game-specific developers, RIM is also announcing that it has gained support from two leading game development tooling companies, allowing developers to use the cross-platform game engines from Ideaworks Labs and Unity Technologies to bring their games to the BlackBerry PlayBook.

It sounds as if the Android runtime will not be perfectly compatible with real Android:

Developers currently building for the BlackBerry or Android platforms will be able to quickly and easily port their apps to run on the BlackBerry Tablet OS thanks to a high degree of API compatibility.

Nevertheless, this will be an attractive route for Android developers looking for a quick way to port to the Blackberry.

The native SDK is currently in “limited alpha release” but RIM is promising an open beta for this summer.

The BlackBerry Tablet OS NDK will allow developers to build high-performance, multi-threaded, native C/C++ applications with industry standard GNU toolchains. Developers can create advanced 2D and 3D applications and special effects by leveraging programmable shaders available in hardware-accelerated OpenGL ES 2.0.

The deal with Unity is important too. Unity is an increasingly popular toolkit for game development and adding the Blackberry to the list of supported platforms will boost its appeal. Ideaworks Labs makes the Airplay SDK, a cross-platform toolkit which already supports Apple iOS, Android, Symbian, Samsung Bada, HP webOS and Windows Mobile.

Note that the primary SDK for the Playbook has until now been Adobe AIR; and since the UI itself uses the Flash runtime this likely still makes sense for many applications.

RIM is doing a good job of opening up its platform. It is an interesting contrast to Microsoft’s “Silverlight, XNA or nothing” approach for Windows Phone.

Computer book stats show resilience of Java as Android booms

Mike Hendrickson at O’Reilly has posted four articles analysing the state of the computer book market in more detail than most of us care about.  The overall picture is not too good – sales are down – and there are some interesting trends.

Here is a good one for anyone who thinks Java is dying. The programming languages post shows that unit sales of books on Java increased by 17.2% in 2010 vs 2009, whereas the next most popular language, C#, declined by 1.7%. Objective C, in third place, also declined slightly. JavaScript unit sales were up by 14.5%.

Why is Java booming? There is a clue in one of the two bestselling Java titles mentioned by Hendrickson: Professional Android 2 Application Development

Another trend that caught my eye is in the first post. Some of the Down categories surprised me:

Adobe Flash –84.43%

Mac OS –32.12%

Web Design Tools –53.2%

Adobe’s Creative Suite 5 has sold well as far as I’m aware so although books on Flash and Dreamweaver have not been selling well, it is dangerous to draw obvious conclusions.

The influence of Android is unmistakeable though. Something for Oracle to consider as it pursues Google for breach of intellectual property.

Trying out MonoTouch – C# for Apple’s iPhone and iPad

I’ve posted an article on trying out MonoTouch, which builds on the open source Mono project to provide a means of developing apps for Apple’s iOS using C# and the .NET Framework.

It is easy to assume that since the .NET Framework is Microsoft’s technology, using a non-Microsoft implementation is risky. Then again, Mono is open source; and the more usage it gets, the better it becomes. MonoTouch is an important development for the project, since it is a commercial project which might actually be making some money for Novell/Attachmate. While it would be nice to get it for free, it is important that Mono makes business sense as well. MonoTouch has given the Mono project a significant boost.

How Microsoft’s Office Web Apps were written in C# and compiled to JavaScript, maybe

While researching another product I came across this 2009 tweet from Microsoft’s Nikhil Kothari:

Office 2010 web apps – perhaps one of the most ambitious script# projects!

Script# is loosely equivalent to the Google Web Toolkit, but whereas GWT compiles Java to JavaScript, Script# compiles C# to JavaScript. According to the site:

Script# is used extensively by developers within Microsoft building Ajax experiences in Windows Live, Office to name just a couple, as well as by a external developers and companies including Facebook.

I had come across the project before, but was waiting to see if would evolve beyond what looks like a personal project for Kothari. It is hosted on http://projects.nikhilk.net rather than on an official Microsoft domain, and the latest release is 0.6.2. In other words, it does not have the look of a project that you would recommend for production work, interesting though it is. Nor is there much public activity around Script# that I can see, though there is a CodePlex site dedicated to improving its JQuery support.

Seeing Kothari’s tweet though raises several questions.

  • Did Microsoft really use it for Office Web Apps, a high profile project which is a key part of Microsoft’s cloud computing strategy?
  • Is there another, more up-to-date version of Script# that is used internally and which may one day burst into the public arena?
  • How might it impact the Silverlight vs HTML5 debate, if Microsoft comes up with a C# to JavaScript compiler in Visual Studio that lets developers code in .NET but deploy to cross-platform JavaScript?

I am sure there are readers of this blog who know more than I do, so by all means let me know.

What you are saying about the Java crisis

A week or so ago I posted about the Java crisis and what it means for developers. The post attracted attention both here and later on The Guardian web site where it appeared as a technology blog. It was also picked up by Reddit prompting a discussion with over 500 posts.

So what are you saying? User LepoldVonRanke takes a pragmatic view:

I’d much rather have Java given a purpose and streamlined from a central authoritative body with a vision, than a community-run egg-laying, wool-growing, milk-giving super cow pig-sheep, that runs into ten directions at the same time, and therefore does not go anywhere. The Java ship needs a captain. Sun never got a good shot at it. There was always someone trying to wrestle control over Java away. With the Oracle bully as Uberfather, maybe Java has a place to go.

which echoes my suggestion that Java might technically be better of under more dictatorial control, unpalatable though that may be. User 9ren is sceptical:

Theoretically, the article is quite right that Java could advance faster under Oracle. It would be more proprietary, and of course more focussed on the kinds of business applications that bring in revenue for Oracle. It would be in Oracle’s interest; and the profit motive might even be a better spur than Sun had.

But – in practice – can they actual execute the engineering challenges?

Although Oracle has acquired many great software engineers (eg. from Sun, BEA Systems, many others), do they retain them? Does their organizational structure support them? And is Oracle known for attracting top engineering talent in general?

In its formation, Oracle had great software engineers (theirs was the very first commercial relational database, a feat many thought impossible). But that was 40 years ago, and now it’s a (very successful) sales-driven company.

There’s an important point from djhworld:

Java is hugely popular in the enterprise world, companies have invested millions and millions of pounds in the Java ecosystem and I don’t see that changing. Many companies still run Java 1.4.2 as their platform because it’s stable enough for them and would cost too much to upgrade.

The real business world goes at its own pace, whereas tech commentators tend to focus on the latest news and try to guess the future. It is a dangerous disconnect. Take no notice of us. Carry on coding.

On Reddit, some users focused on my assertion that the C# language was more advanced than Java. Is it? jeffcox111 comments:

I write in C# and Java professionally and I have to say I prefer C# hands down. Generics are very old news now in .Net. Take a look at type inference, lambdas, anonymous types, and most of all take a look at LINQ. These are all concepts that have been around for 3 years now in .Net and I hate living without them in Java. With .Net 5 on the horizon we are looking forward to better asynchronous calling/waiting and a bunch of other coolness. Java was good, but .Net is better these days.

and I liked this remark on LINQ:

I remember my first experience with LINQ after using C# for my final-year project (a visual web search engine). I asked a C# developer for some help on building a certain data structure and the guy sent me a pseudocode-looking stuff. I thanked him for the help and said that I’d look to find a way to code it and he said "WTF, I just gave you the code".

From there on I’ve never looked back.

Another discussion point is write once – run anywhere. Has it ever been real? Does it matter?

The company I work for has a large Java "shrinkwrap" app. It runs ok on Windows. It runs like shit on Mac, and it doesn’t run at all on Linux.

write once, run anywhere has always been a utopian pipe dream. And the consequence of this is that we now have yet another layer of crap that separates applications from the hardware.

says tonymt, though annannsi counters:

I’ve worked on a bunch of Java projects running on multiple unix based systems, windows and mac. GUI issues can be a pain to get correct, but its been fine in general. Non-GUI apps are basically there (its rare but I’ve hit bugs in the JVM specific to a particular platform)

Follow the links if you fancy more – I’ll leave the last word to A_Monkey:

I have a Java crisis every time I open eclipse.