Hacker News new | past | comments | ask | show | jobs | submit login
“C#, it’s just not portable” (fastchicken.co.nz)
94 points by DonnyV on Sept 15, 2011 | hide | past | web | favorite | 35 comments

You can use C# everywhere, but in practice it just seems like a huge effort to avoid learning a new language to me.

I have nothing against the language (writing C# is half of my day job), but all of these bridges are second-class citizens and built and maintained at the mercy of third parties just to interface with your target platform. Apple will never release updates for MonoMac or MonoTouch. Google isn't going to release C# Android SDKs or documentation. Mono for Linux always trails the Windows version and has significant community resistance, and Microsoft isn't going to integrate and maintain these bridges.

You're also always losing something in the translation too, be it idiomatic style of the target API or C#, or being totally cut off from new native features, or severely restricting what community support or documentation is available to you. Any way you cut it, it's a second class experience. Worse, some of the bridges aren't free. You get to pay $400 for the privilege of not learning a little bit of Java or ObjC to get MonoTouch for Android or iOS.

C# is good, but it's not so good that I refuse to learn other tools.

A lot of people just like C#. I think it's fair to say that it's a well designed language. It also depends on the task at hand and your personal preferences. I had to develop a couple of iPhone apps and in the process I've developed a pretty strong dislike for Objective-C (mainly its syntax, stupid, I know) - in the future I'd probably try MonoTouch.

Many people also tend to prefer the language they're strongest in when they need to get things done, especially when they don't know the other languages and frameworks that well.

In my case, I'm a Windows / C# guy at work, at home my laptop is running ArchLinux and I use it to code in a variety of languages. This didn't prevent me from trying to set up a mono / asp.net mvc app with nginx and postgresql on it :)

While I fully agree with the losing something in translation. I don't agree that people are trying to skip learning things. It is a do I want to do 100% of my software development 3 times because I need a java version for one platform, Objective-C for the second and C# for the third.

Oddly enough it seems like C++ is the only language all three platforms support natively.

Oddly enough it seems like C++ is the only language all three platforms support natively.

Indeed. But it's also quite harder than those to develop in.

I hate to keep on button-mashing, but it would be a big win to have a PlusPlusScript language - as in same philosophy and approach as CoffeeScript, but targeting C++ [1].

[1] http://news.ycombinator.com/item?id=2989936

Mono for iOS and Android and MonoMac for OSX all have different API calls for their respective platforms. GTK# is its own thing too. You might avoid a total rewrite from scratch, but the UI is going to need significant tailoring to each platform still. And it's not like Java, ObjC, and C# are radically different from one another.

Does keeping C# as a constant really solve this problem? (I honestly don't know, I've never done a multiplatform product like this)

Well, in most cases the GUI stack will be different anyways. There is no "official" Android or iOS support from Nokia / QT for instance.

I've deployed ASP.NET MVC apps on Linux / Mono and it was a relatively painless experience. The desktop and RIA guys in .NET land are doing their own thing with WPF and Silverlight (google MVVM / Caliburn-Micro), and frankly, it's freaking me out a bit. There's a tendency to overengineer and abstract everything. It might not be as bad as with Java but the tendency is still there.

For instance, the .NET community has been arguing for years about domain driven design and how you should abstract away (or not!) database access. Hundreds of blog posts about which application layer should be concerned with this and that, about generic data access repositories, enhanced query objects and so on. What was "the way to go" one day was suddenly "the new singleton". Some guys eventually came up with the glorious "CQRS" approach (inspired by Betrand Meyer's command query separation) and built entire frameworks such as NCQRS with separate read/write stores, event sourcing and audit trails. The problem is that a lot of people start to use these enterprise models in very simple applications.

I'd also say that the 3 mentioned languages are, in their current incarnations, very different from each other. Java itself looks rather stagnant to me? I don't know, the last time I checked I saw former high school / college friend of mine starting a serious open source effort for easier database querying because he was so fed up with hibernate - it's basically one gigantic DSL / fluent interface that generates sql. Me: "Why don't you use lambda expressions.. oh wait, ...".

Welp, here's an example. My project Flatland[1] is intended to be a 2D games library, providing graphics, audio, input, content loading, and a few other bits. My target platforms are Windows, Mac, Linux, iOS, Android, and WP7.

With a properly architected solution (and I like to think mine comes close) with sufficient abstraction, I literally can write a game once--with allowances for fundamental platform differences, i.e. "is this a touch device? then show on-screen controls, but wire them to the same backend logic"--and deploy it everywhere. I can't do that with a Java engine on Android and an Obj-C (ugh) engine on iOS, because there is no reasonable lingua franca. C#, on the other hand, works fairly well everywhere. The platform-specific bits are small, clearly delineated, and shouldn't take long to do (it's Windows-only for now).

[1] - http://bitbucket.org/eropple/flatland

You also get the luxury of ignoring many of the native UI paradigms with games.

That's true. I don't have to deal with native UI libraries. Instead, I also have to deal with disparate interfaces to graphics, audio, sound, the file system (if it's accessible at all), the content loading paradigm for the platform (relevant esp. for Windows Phone 7), timing differences between the platforms, and a number of other issues. I have to develop and code to lowest-common-denominator interfaces that contain a lot of hidden gotchas and limitations, and make the presented interface work identically on all platforms.

I'd take re-coding my UI layer over having to write near-identical code for XNA and OpenGL, then writing near-identical code for OpenAL, XNA, and Core Audio, then writing widely divergent input code for XNA and whatever not-well-standardized gamepad layers I can repurpose or build for Linux and OS X and the different touch frameworks...

Having to write all of this stuff is arguably on par, if not more complex and difficult, than reimplementing a UI layer. It's not a "luxury" at all.

Knowing that each API is slightly different there are two paths you could take. An MVC like approach where everything platform specific is sectioned off in the view and just have totally different views for each platform. The second is use the dependency inversion principle, and build a layer that abstracts the underlying api away then depend on your abstraction instead of the underlying API. Either way you end up writing 70%-80% of the code once, and 20%-30% of the code three times. Not great but it beats writing 100% of the code 3 times.

Is C# the right language to do that in, maybe, maybe not but it is an option.

I don't really think it is about refusing to learn other tools. My opinion is about choice.

I work with C# 90% of the time. I also happen to use other languages fluently. I think is a matter of choice.(I also have to admit that there are some developers that just don't want to get out of the comfort zone, but I don't think ALL C3 developers should be judged this way).

For example, I have used Xamarin products for a some projects, and it makes a lot more sense for me, to use C# with Xamarin products than Objective-C. That is a language I have been avoiding for a long time. And the reasons are not the scope of this comment. On the Android side I am definitely using Java.

So cutting to the chase, I think that for a company to support C# without Microsoft involvement is not bad, and it doesn't mean that ALL developers are lazy or mediocre, it just means more choices for developers. Specially if you have big investments in Software developed on C# (either .Net or Mono).

>C# is good, but it's not so good that I refuse to learn other tools.

To me it's too heavy. About 10Mb too heavy.

Apple and Android don't ship a "standard" Mono runtime, so you end up having to ship one with your app.

The sweet spot for me is to use Lua: I can build it anywhere that you can build C, and it's TINY. If I want speed I use C++; for the rest I script in a really forgiving multi-paradigm language.

MonoDevelop on the Mac bothers me. Even though the apps you create can be proper (and they emphasise that fact), the IDE itself screams "this is a second-class environment" by looking and feeling nothing like a Mac app.

... which corresponds with the state of almost every IDE on OS X.

XCode, on the other hand looks great. But it's also a pretty horrible environment to work on. Pretty much zero helping writing the code, unlike any other IDE out there.

Looks are deceptive.

Just like most languages, you can take some subset of C# and run it in many places. And, like most languages, there is some corner of the language that doesn't work on one platform or another. And most importantly, just like most languages, you end up depending on various libraries which may or may not be tied to hardware which makes significant parts of non-trivial applications non-portable.

People don't make games in C# because it's C#. They make games using C# and XNA, or Unity, or some other framework. They don't make web apps in C#, but rather in (whatever flavor of) ASP.NET. And it turns out that these frameworks are the important bits.

So when you choose to write something in C#, you are probably going to be choosing a framework that ties you down to a platform, and that's where the cross-platform nature of the language kind of becomes irrelevant.

That's my experience, at least.

If Clojure takes off on other runtimes, it will have this issue too. The JVM is it's "home" platform, and most Clojure software depends on JVM libraries, like how the vast majority of the C# software written thus far depends on Microsoft (and therefore Windows) libraries.

>>If Clojure takes off on other runtimes, it will have this issue too. The JVM is it's "home" platform, and most Clojure software depends on JVM libraries, like how the vast majority of the C# software written thus far depends on Microsoft (and therefore Windows) libraries.

There is a small difference.

The Clojure/JVM runtime is ported to quite a lot of operating systems, where it runs quite well.

C# is a good production language. It lets twiddle you your bits almost as well as C when you need to, provides a decent OO model, and has been piling on more functional and dynamic features as the years go by. However, as someone who has had to port a .Net C# app from windows to Linux, I can witness with sincerity that C# is NOT very portable.

First of all, a lot of the C# APIs are written with windows in mind. An example is system mutexes. These just don't exist on Linux, and the mono implementation to emulate them is very buggy. Another example is the process counter API. Although much of this same information is available on Linux via the Proc table, Mono provides no equivalent API because it would be a lot of work to make one that works on all the Unix variants. There are many such examples of C#'s windows-centric API not being ported well in Mono.

A bigger problem with Mono is that it just wasn't stable for us. The more standard library features we used, the more it would core dump on Linux even though it would never crash on windows. We ended up re-implementing a lot of functionality available in the standard library ourselves before the program stabilized on mono, which further incriminates the Mono stack. As a final note, we tried multiple versions of Mono, including 2.4, 2.6, and 2.10, and none of them worked well for us.

If you want to write a fairly performant cross-platform app, the JVM is still a much better place to play in right now than .Net, even though I like C# the language a lot more than I do Java. You can also go the route of combining your favorite scripting language with C for the CPU-intensive parts.

These days it seems like much of a language's benefit to developers comes from its libraries rather than from the elegance of its syntax or the ease of implementing an algorithm. The big question is, how much of the "standard" libraries are supported on these devices? I remember writing a C# application using Winforms back mid-last-decade and assuming that portability would be a cinch...right up until I realized that Winforms weren't supported by Mono yet and I was supposed to use Glade# or some such nonsense. C#'s mindshare mostly comes from Windows GUI developers, and telling these folks that they can use their pet language only if they relearn all the libraries isn't going to be much of a win, I don't think.

You could make the same argument about C, which exists on much more platforms than C#.

But writing in C does not make a program portable. Neither does writing it in C#.

So yes, C# compiler might be portable, but programs written in C# are not.

So yes, C# compiler might be portable, but C# programs are not.

C# as a system language running on Mono is actually usable. But the thing is, I've never seen an IDE worse than MonoDevelop. Writing C# without Visual Studio, a large part of the benefit of the language just disappears.

I would only use C# for window jobs, although I sincerely think it's a beautiful language.

I am currently writing an "enterprise" style application and backend framework (WCF, Fluent NHibernate, Castle, json-emitting webservices, etc) based on C# and Mono. I'd like to hear more stories of others doing the same. Mono has all the functionality I need, the only possible worry that I have is that of the default GC (and I don't know if the newer GC is stable enough).

Is anybody using Mono on Linux for ASP.NET MVC3 apps in production?

If so, is it stable, fast?

I wonder how it compares speed and stability wise to the Java Play Framework.

I am currently using Play (and it's great!) but I much prefer C# as a language to Java ...

Interesting. I always thought the Vita was running Android since it supports Android apps.

Are you sure about this. Reading their press release leads me to believe it's the other way around, that by developing for the Vita SDK, you can cross compile to Android if you choose.

Supporting C# as the programming language, PS Suite SDK can run programs developed in C# on virtual machine equipped on both PS Certified devices and PS Vita. By supporting development for multiple devices and by adopting libraries to create a variety of content not only limited to games, PS Suite SDK will not only help developers save their cost in creating new content but also allow them to efficiently create their content on one SDK and without having to create on several different SDKs.

Through PS Suite SDK, SCE will provide to game developers and publishers the potential to further expand their business opportunities to Android based portable devices.


I feel like there is too much attention paid these days to who badmouthed your precious programming language, or whether your language has the appropriate amount of respect, or whatever. I'm a C# dev, sometimes. People have been hating on it (and its devs) for years, but it just doesn't matter. Get over it and use whatever language or other dev tool you want.

Usually, hate-ons are perpetuated by those who lack the skills to make shit happen. Or, at least, that's been my experience. They're usually more concerned with Being Right On The Internet than anything else.

You might be able to write C# and target different platforms, but I've yet to be convinced that a codebase can be shared across platforms as easily as some other languages/platforms.

We run non-trivial, large, unmodified .NET 4 C# ASP.NET MVC web apps (compiled on Windows) on Mac Mini Servers on OS X with Mono and Apache. Never had a single problem. It's almost creepy how well it works.

That's interesting. Why do you do this?

Well, it's complicated, but the main reason is that since our premises are just around the corner from one of the biggest Apple Stores in the world, we can replace any of our servers literally within minutes if they fail. This makes me sleep a lot easier at night.

Also the savings on the electricity bill are not negligeable either.

>> our premises are just around the corner from one of the biggest Apple Stores in the world, we can replace any of our servers literally within minutes if they fail

I sure hope you don't have a server failure outside of business hours :-)

I think we're prepared for that too. First, we have a few currently unused previous generation Mac Minis lying around that could be used temporarily. Second, since everything we need (Apache and PostgreSQL, minus Mono) comes preinstalled with OS X Server, these machines can easily take over each other's tasks temporarily, e.g. the database server can become a web server too until we can get a replacement. It's not ideal but it'd do during off-peak hours. Fortunately, the Apple Store is open even on Sundays so even in the worst case scenario we could get a replacement within 12 hours max, which is not necessarily the case with, say for example, Dell servers.

You could still run windows server on those though..?

I could (and indeed that was what we were originally planning when we decided to go with Mac Mini Servers), but I simply don't need to. I open the packaging, put Mono on it and it's ready for work. Why would I waste time with Windows Server if it's not needed?

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact