Live data from Hacker News

Why C# is the best language for mobile development

blog.xamarin.com

121–125 of 125 posts

Re: Why C# is the best language for mobile development

#121

Earlier quoted context omitted.

Miguel I'm confused then - your experience with Mono certainly means you have a better understanding, but I thought I understood it pretty well, too. Places lacking type inference: - Parameter definitions - Method return types - Generic type parameters (sometimes) - Lambda expressions (due lack of syntax to indicate quoted code) - Field declarations The only place type inference works for declarations is in local var…

"var" is a shorthand to not declare the type when it can be inferred, in most cases to avoid Foo foo = new Foo(). The point is that it avoid repetitive typing, while still preserving type safety and everything that comes with it: compiler checking that right types are used in the right places. [Digression While it is possible to use in var foo = GetIt() the practice is discouraged because it makes the type of "foo" o…

Honest question: Are you just playing devil's advocate? It appears that the reasoning for C#'s design is that it targets LINQ as a goal, and the new features (like var and extension methods) were implemented just for the LINQ case, not considering those features by themselves.

In fact, the lack of type inference for fields was said to be due to technical limitations in the C# compiler implementation, not for any language reason. [1] Sure, any product will have limitations due to schedules/resources, but that doesn't change the fact that they're unfortunate limitations that could be fixed. C# hasn't addresses these issues, but they've had 2 or 3 releases since they were introduced.

>For a parameter definition, its use clearly makes no sense. What is the type for the following method? >void Demo (var x) {}

In that case, x has no constraints (it's unused), so it's generic. Pretty simple. An unused parameter isn't that useful outside of a few cases. Usually you'll use the variable, and constraints can be inferred. Or you'll find a constraint that limits the type to a concrete type. Here's some examples:

  void dub (var x) { Tuple.Create(x,x); } // x is T
  void uri (var x) { new Uri(x); } // x is string
  void cmp (var x, var y) { Nullable.Compare(x, y); } // x and y are Nullable where T : struct
The example of "void Demo (var x) { var j = x.Parent; }" is probably one place you'd want it to fail, because using member access to infer types can get complicated, at least within C#'s type system. You'd want a static duck typing system in this case like "anonymous interfaces" or something to that effect.

Arguing against return type inference is wierd: C# does that in anonymous functions - certainly you don't think we should have to annotate types there!

As for type signatures changing, if you need want to keep public contracts, then write them out! No one is saying you need to always infer everywhere, just that it's a great aid. Also, this particular example just demonstrates why C#'s type coercion is a bad idea, albeit understandable, given their desire to follow C style.

Generic type parameters. What do you mean it makes no sense? I can't write, e.g. "new List() { 1 }" - it complains List needs a type parameter. Another example: "Func = () => 1". Nope, I'm required to explicitly provide the type. What if C# didn't have syntax support for Nullable? You'd have to do e.g. "x = new Nullable(1)" or create a helper function like Tuple and have e.g. "x = Nullable.Create(1)". Generic type parameter inference only happens on methods.

Also note that C# can't infer generic type parameter constraints - you've got to annotate them all by hand. Makes sense, I guess, because it doesn't infer any generic type parameter definitions, either.

Lambda expressions can't be type inferred. "var x = () => 1" does not work (CS0815). This is because of the same syntax for expression trees versus anonymous functions. And if that was changed, you'd still need to "promote" func somehow, due to C#'s wierd nominal typing for delegates.

Fixed statements can't be type inferred either: error CS0821: Implicitly-typed local variables cannot be fixed.

The things you mentioned, for (and foreach), using -- those are all local variable declarations. So we have it working for local variables, for some generic type parameters, lambda parameter definitions (when the lambda type is known) and lambda return types.

It's a nice start, and it makes C# far more enjoyable than some other languages like Java. But it's still quite limited, without solid reasons.

1: http://blogs.msdn.com/b/ericlippert/archive/2009/01/26/why-n...

Re: Why C# is the best language for mobile development

#122

Earlier quoted context omitted.

I'm all for Objective-C, but your arguments were weak in the first place, and you're dragging a dead horse here. I mean: "I put about as much effort into my critique as the original article's author did in arguing for C#'s superiority." -- Why even write your critique then? At least the original article's author had a reason, it is marketing copy. > This is a problem that has bit me in the ass maybe once or twice sin…

I direct you to my final statement in my original post ( http://news.ycombinator.com/item?id=4998697 ): > Edit: just for the record, I'm not necessarily trying to refute all or some of the OP's points. I think the original article was poorly written, and the case for C# was poorly made. Hence my "let's play this game" comment. RE: "This is horribly mistaken in more than two ways." Not all code is created equal. That…

>Not all code is created equal. That 30% that needs to be rewritten for each device could be difficult to tune for each platform. Native widgets in iOS do not work the same as native widgets in Andoid. Unless there is some magical abstraction layer (which doesn't appear to exist), you're potentially rewriting the most difficult code for each platform.

Again, far better than writing ALL the code for each platform.

And in a lot of cases the GUI code is not the "most difficult", it's just the one that cannot be easily written once for all platforms (and still look native).

For example, if you make a music application, the sound engine, FFT, filters etc would be the difficult part (but it can be written just once) and the GUI layer is quite easy compared.

Re: Why C# is the best language for mobile development

#123
post #94

Earlier quoted context omitted.

95% of the time, what looks like a failed "loops 101" test actually doesn't matter at all. Maybe your list comparison function takes O(n^2) time... if your list never gets above 10-20 objects, who cares? Yes, if you're running LINQ over a list of 1,000,000 items, then you'll want to be careful what you're calling. But how often does that really happen in mobile apps? What LINQ does is make your code more concise and…

Depends on what kind of mobile apps you are writing. Most of the apps I've worked on written tend to deal with video/ pixel level image conversions. In these cases it's really common to say convert an rgb pixel array to yuv or simliar and a linq expression on one of those arrays would quite simply kill the app. Which I think is the best counter argument to the op. C# might be fine until you decide to do something bey…

This is really the crux of it. The counterargument essentially seems to be that such broad abstractions are fine in the small or when you have enough hardware, however that in no way carries over to smartphones where you want to do the most with the least, and even where you have a kick-ass processor and multi-GB RAM, you still want to reserve battery. The primary reason Android seems to need so much more hardware than iOS can be attributed to this. Even when you have powerful hardware, this can kill you in the large (which was the original failure of Windows Vista -- people forget that Microsoft did a complete revert after thousands of man years of work)

Re: Why C# is the best language for mobile development

#124
post #21

Earlier quoted context omitted.

And if you've worked on a large project with a lot of cats to herd for both platforms, you will appreciate java very quickly.

But it doesn't appear (anecdotally I admit) that people feel that way. Seems the "whole world" (speaking loosely) is turning against Java because of this very philosophy. Because Java has been so conservative, people actively hate it's verbosity, boilerplate-ness, and lack of language features (anonymous functions, first class functions, etc.). So Java has, for many years, helped huge teams of mediocre developers avo…

I'm not sure java is being increasingly scorned. The scorners are just noisier.

Re: Why C# is the best language for mobile development

#125
post #95

Earlier quoted context omitted.

POCO = Plain Old (CLR) Object The distinction I'm drawing here is what is meant by 'natively supports' and 'supported via a 3rd party library'

That's what I need clarification on. the dynamic keyword wasn't provided by any 3rd party library (it's part of the C# language specification)... how is System.DynamicObject and IDynamicMetaObjectProvider different then System.Object? All poco's inherit System.Object. Do you consider System.Object as 3rd party? True, by default poco's don't inherit from System.DynamiObject. Does that make it not 'natively supported'?

No, what I mean by that is in order to use mixins, in any example I've seen, you need to inherit from a class someone else provided that gives it.

Assembly provides all the mechanisms for the dynamic keyword, I wouldn't say it is a feature of x86.

Post reply on HN