News for hackers. Stuff that matters.
Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @05:14PM (#6660834)
But look at C# - since after they shipped version 3, they practically stopped doing anything neat with it. They haven't cleaned up any of the v3 features introduced (like type inference or expression trees) - it's just sitting there. In fact, from some of the statements I've read, it sounds like MS has purposely stagnated C# to avoid alienating their enterprise customers.

They mismarket F#, preferring to say it's for scientists and financial programmers. Instead of marketing it as what it is, a much more capable language all-around, unless you need certain GUI/tooling support.

These kinda things don't help .NET's reputation. If a non-MS affiliated company marketed a language as lean as F#, with as good a runtime and editor/debugger, they'd be a huge amount of "hipster" cred and praise.

Re:An analysis of the C#/.NET platform by stevecooperorg on Saturday November 02, 2013 @05:30PM (#6660897)
C# 4 added serious dynamic typing, so that you can make ruby/pthon/js-style dynamic objects;

    // properties not declared anywhere; runtime property definitions
    dynamic myObject = new JavaScriptStyleObject();
    myObject.firstProperty = "hello";
    myObject.secondProperty = 1;
C#5 added async/await, which I think is one of the most 'integrated' ways I've seen of doing async programming. Think node.js with a lot less syntactic cruft around the callback functions; in C#5 you could write, say;

    // evented I/O using the 'await' keyword;
    var fileContent = await ReadFile(@"c:\foo.txt");
    Console.WriteLine(fileContent);
rather than;

    fs.readFile('c:\\foo.txt', 'utf8', function (err,data) {
      console.log(data);
    });
This eliminates the need to write lambdas while retaining the evented I/O style.

Both of these seem pretty significant.

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @05:58PM (#6661008)
Both of which have been in F# for years, and C# re-implemented them later, poorly. F#'s dynamic is extensible (and around since 2007? 2008? earlier?)). If you wanted to implement a "dynamo" object, go ahead. If you want loosely typed CSV-reader access, go ahead. (You get the ? and ?<- operators to define as you'd like.)

C#'s async comes from F#'s async (available since Oct 2007), which in F# is just a library. That's because F# supports workflows aka computation expressions aka warm fuzzy things. What F# does as a library feature, C# requires baking into the compiler.

So for 5 years now, MS has added these two features. They've still yet to deliver a REPL, or finish implementing type inference, or any such stuff. It looks like Anders Hejlsberg, the main C# designer, seems more interested in adding some basic features to JavaScript, lately. C# seems fairly abandoned, language-wise, to me. They seem to be content to have put Java in its place, and leave it at that.

P.S. C#'s a great language, and I'm not trying to insult the people that have done great work on it. As a popular language, it's one of the nicest ones out there IMO.

Re:An analysis of the C#/.NET platform by stevecooperorg on Saturday November 02, 2013 @06:28PM (#6661116)
I would dearly love for the C# type system to get a bit stronger and less verbose. It's also confused, I think, because you have explicit classes, anonymous types, and dynamic, and they aren't always very well put together. I actually also like what Anders did in TypeScript around structural types, and wouldn't mind some of that mojo in C#.

I take your point about pace, though. I wonder how it compares over the same timeframe vs other languages? In the 5 years for C# to cover that distance, what have other languages achieved? The biggies are particularly interesting (JavaScript, Python, Ruby, Java, C++, etc) because users probably demand more in terms of support and compatibility. (For others contributing, I'm thinking language-specific, so not libraries, frameworks, or runtimes, just pure syntax.)

It's also worth throwing uptake into the mix here; it's not much use if there's a version of the language defined in a spec but everyone's using the compiler from 1999 (JavaScript, I'm looking at you) I'm not a pythonista but I understand Python 3 has struggled with uptake, too. Not too sure of the details; happy to be corrected.

Re:An analysis of the C#/.NET platform by rbanffy on Saturday November 02, 2013 @06:59PM (#6661228)
> C# 4 added serious dynamic typing, so that you can make ruby/pthon/js-style dynamic objects;

So you can match the so-so performance of dynamic languages (which is debatable, BTW) with C#'s horrid (when compared to Python or Ruby, at least) syntax.

I fail to see the advantages here. If I'm doing something that demands dynamic types, I do it in Python. If I need static-types, I do it in C, C++, Objective-C, Go, Java- whatever better fits the problem.

Re:An analysis of the C#/.NET platform by jpalomaki on Sunday November 03, 2013 @06:52AM (#6662886)
The purpose of dynamic is not to turn C# into a dynamic language. It was added to make it easier to interface with certain other parties. Sometimes you just don't have the type information (practical example is handling JSON data) and dynamic can make the code cleaner in these cases.

More about this: http://msdn.microsoft.com/en-us/magazine/gg598922.aspx

Re:An analysis of the C#/.NET platform by pdwetz on Saturday November 02, 2013 @07:49PM (#6661386)
Dynamic typing support helps in a pinch in C#, as you can avoid a lot of code in some cases where performance isn't paramount. I've personally used that in a few cases in the past.
Re:An analysis of the C#/.NET platform by NicoJuicy on Sunday November 03, 2013 @06:10AM (#6662810)
Develop in Asp.Net MVC and change your viewmodels to dynamic (ExpandoObject) types.

You'll notice the advantages :)

ps. want to iterate over the object like in reflection, just convert the object to a (IDictionairy<string,object>)

Re:An analysis of the C#/.NET platform by bryan_rasmussen on Saturday November 02, 2013 @08:05PM (#6661445)
What problems are there that you would consider choosing a statically typed language for them, because of the typing?
Re:An analysis of the C#/.NET platform by rbanffy on Saturday November 02, 2013 @08:40PM (#6661555)
Static typing helps generating very concise and fast native code. I'd go with C or C++ when speed and or very precise control are absolute requirements. It also doesn't hurt you when you have a clearly defined problem that will never change - when you know you'll never receive a float instead of a 64-bit integer.

But there are other reasons to pick static typing. Using Java is natural for writing Android apps, Go has a very natural syntax for expressing concurrency and C# is the best choice when you want to write a Windows app. A programmer should always pick the language that better fits the problem it has to solve.

Re:An analysis of the C#/.NET platform by gngeal on Saturday November 02, 2013 @07:17PM (#6661280)
C#5 added async/await, which I think is one of the most 'integrated' ways I've seen of doing async programming.

What's with the C# developers ans async/await? Almost every time I read their exhortations it feels like they're blissfully unaware that other languages have already had their own mechanisms for doing concurrency.

Re:An analysis of the C#/.NET platform by sitharus on Saturday November 02, 2013 @08:14PM (#6661476)
Having worked in a few languages over the years, all with different ideas of concurrency, the C# system is one of the nicest.

It's a bit tough to get your head around, but it does a good job of keeping code readable while correctly blocking and descheduling threads.

A lot of developers get async wrong, so anything to help get it right is a plus.

Personally I prefer the F# async system, but it's harder for a curly-brace developer to learn F# than a new C# keyword.

Re:An analysis of the C#/.NET platform by stevecooperorg on Sunday November 03, 2013 @06:13AM (#6662816)
We're talking languages here; the way a grammar construct helps the programmer.

The C# async language effectively writes a whole batch of code that you'd need to write yourself in other languages; try/catch blocks, callback functions, thread synchronization code, code to wait for results, etc. In effect, it makes into a language feature something that has previously been considered a design pattern.

So something like this in C# 5;

    01 var foo = await LongProcess1();
    02 var bar = await LongProcess2(foo);
    03 var baz = await LongProcess(bar);
does a significant amount of work. If I were to code it without the language support, I'd be writing a great deal of crufty code to handle errors, to make sure one thread completes before using the result in another thread (see foo set on line 01 and used on line 02 for an example) and it avoids the callback hell problem of languages like JavaScript, which become apparent in Node.js programming, for instance.

I'd be interested to know what other mainstream languages have as complete a solution for asynchronous programming -- afaik, JS, Python, Ruby, Java, and C++ don't have this. I'm guessing erlang probably has it built right in, but I'm not sure. Anyone care to share?

Re:An analysis of the C#/.NET platform by gngeal on Sunday November 03, 2013 @06:37AM (#6662858)
We're talking languages here; the way a grammar construct helps the programmer.

So do I. We've had CSP, Occam, Newsqueak, Alef, Limbo; now we have Erlang and Go. I'm just puzzled by the walled garden phenomenon present in such communities as that of the .NET programmers. The very fact that you're comparing C# to Node.js (!), of all things, just confirms it. It isn't very difficult to beat Node.js in terms of the language quality. Hardly seems like a fair fight to me.

Re:An analysis of the C#/.NET platform by stevecooperorg on Sunday November 03, 2013 @01:14PM (#6664294)
It's hard for me to see how I'm living in a walled garden here. If there is a Microsoft walled garden, Hacker News is very much outside the wall, isn't it? I'm here, not on MSDN, trying to have a reasoned conversation with intelligent people from different backgrounds, showing code samples, and asking openly for information about other languages. What else should I be doing?

> The very fact that you're comparing C# to Node.js (!), of all things, just confirms it.

The node.js comparison is fair, I believe. We're talking about language support for asynchronous programming, particularly the evented I/O programming idiom. That's exemplified by C#/await, and the Node standard libraries, and python/twisted, and I'm sure a lot of others.

Node is a very popular, visible platform which takes evented I/O as a core concept, so it's reasonable to compare the implementation of the idiom in C# to the current poster child. Is there a better comparison I missed?

> We've had CSP, Occam, Newsqueak, Alef, Limbo; now we have Erlang and Go.

Agreed. That's fine, and I specifically called out Erlang and asked for more info. However, the others you list suffer from not being mainstream development languages -- TIOBE[1] doesn't list any of them in the top 50 languages. Occam may well do it better, but since I can't pay the bills writing Occam, I'm more interested in the languages I mentioned -- JavaScript, Python, Ruby, Java, and C++. Feel free to throw in C, PHP, Perl or Objective-C. Do any of these languages have better language or core library support for async programming? Do they result in shorter, more readable, or more reliable code for parallel and async operations?

Your original reply -- "Almost every time I read their exhortations it feels like they're blissfully unaware that other languages have already had their own mechanisms for doing concurrency." -- suggests I'm unaware of something. Can you please start telling me what it is.

  [1] http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  [2]: http://www.paulgraham.com/avg.html
Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @08:05PM (#6661442)
Because it allows a nice syntax for async callbacks, instead of callback hell like JavaScript and C# APIs prior.
Re:An analysis of the C#/.NET platform by statictype on Sunday November 03, 2013 @12:21AM (#6662216)
Built-in to the language itself?

Very few mainstream languages have that.

Re:An analysis of the C#/.NET platform by nbevans on Saturday November 02, 2013 @05:42PM (#6660939)
They've admitted that progress has slowed but have also explained why and it's got nothing to do with enterprise customers.

The reason is that they're rewriting the C# compiler using, er, C#. It's as part of an initiative called "Roslyn" that aims to make the compiler a pluggable component with a public API for the compilation AST.

They did a blog post recently explaining that whilst this work is ongoing they are trying not to change the C# language too much to aid them with testing and verification. But that once Roslyn is released they will start a fresh wave of language enhancements for C#. I think we all have some ideas on what those will be to start off with... proper tuples support, and probably some form of pattern matching.

Re:An analysis of the C#/.NET platform by junkyarddog on Saturday November 02, 2013 @09:01PM (#6661631)
So basically, the plan is to turn C# into F# with curly braces.
Re:An analysis of the C#/.NET platform by spo81rty on Saturday November 02, 2013 @05:45PM (#6660950)
What?? Visual Studio 2013 just shipped a week ago. They have released 5 versions of the MVC framework in the last 3 years or so. The new async/await stuff is fantastic. EF6 is new. SignalR is new. We get new Windows Azure SDKs every 3 months or so. They are constantly improving everything.
Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @06:04PM (#6661027)
None of that, except async, is a C# feature. And that was taken from a 6-year-old F# feature of the same name, except in F#, it was implemented as a library, not baked into the compiler.

MS is moving .NET ahead as a platform, but C# doesn't seem to be doing much. As another comment said, they're rewriting the compiler and then are supposed to make it take off again. Still, 5 years with minimal additions seems "stagnant" to me.

Re:An analysis of the C#/.NET platform by hackinthebochs on Saturday November 02, 2013 @06:32PM (#6661132)
> it was implemented as a library, not baked into the compiler.

You keep saying this as if its a bad thing. Personally I consider it the exact opposite. I have no experience with F# but my experience with features that are baked into the language vs in a library is that having a feature be a first class citizen gives all sorts of benefits in terms of usability, consistency, tooling support, not to mention being able to justify introducing the fancy new feature into your project.

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @06:57PM (#6661217)
Nothing about having it be a library means there's anything less in terms of usability, consistency, or tool support. It's not like people avoid System.Text.RegularExpressions because it doesn't have a compiler-intrinsic ~= match operator.

The exception I see is if a certain pattern requires a drastically different compilation method, even if only as an implementation detail. That would perhaps break debugging support. But that's not much of an argument, because nothing stops you from special-casing your tooling support (which you'd presumably do anyways).

It just seems incredibly inelegant to have to special-case things in a language when the general case could be implemented.

Re:An analysis of the C#/.NET platform by MaulingMonkey on Saturday November 02, 2013 @07:47PM (#6661383)

    case /\(.+)!(.+)@(.+)/
        nick, user, host = $1, $2, $3
        ...
vs

    if( (match=new Regex("(.+)!(.+)@(.+)").Match(caseInput)).Success )
    {
        var nick = match.Groups[1].Value;
        var user = match.Groups[2].Value;
        var host = match.Groups[3].Value;
        ...
    }
If I'm using a ton of regexps, having domain specific language support can certainly help keep things simpler and clearer, aiding usability by aiding readability. This is important enough people can and will resort to implementing their own domain specific languages. While I'm all for erring on the side of general purpose language features for a general purpose language, if only to reduce the possible explosion of corner cases for language design mistakes, discounting language level support as "inelegant" and having no benefits is, to me, tantamount to discounting DSLs in general for the same.

And perhaps you do so, but the argument doesn't resonate with me.

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @08:10PM (#6661463)
F# active patterns allow you to do exactly this kind of thing, in a general and extensive way, without building support for regex into the compiler. That's what I'm talking about.

And it takes all of 4 lines to add the support:

  let (|Regex|_|) pattern input =
    let m = Regex.Match(input, pattern)
    if m.Success then Some(List.tail [ for g in m.Groups -> g.Value ])
    else None
Boom, done. I'd call that a far more elegant approach than hardcoding regex into the language. Edit: And nothing is stopping the core developers from including such patterns in the standard library. So you get the best of both worlds, a common well-known manner, and a useful general purpose feature that people can extend and use if they need so.

Usage looks like:

  match phone with
  | Regex @"\(([0-9]{3})\)[-. ]?([0-9]{3})[-. ]?([0-9]{4})" [ area; prefix; suffix ] -> ...
http://fssnip.net/29
Re:An analysis of the C#/.NET platform by overgard on Saturday November 02, 2013 @06:26PM (#6661106)
If you look at how much has been added to say, python or ruby or java in the same time frame it seems comparable. .NET 4 (released in 2010, so really only 3 years ago) added a ton of new features (dynamic, better generics, better expression trees, optional paramters, etc.).

NET 4.5 was comparatively a more quiet, but I think that's just a consequence of the language maturing.

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @06:52PM (#6661207)
C# 4 did bring forward the covariance/contravariance feature that's been in the CLR since v2, yes. And they did add dynamic, which was the big major feature of v4.

Better expression trees, as I understand, aren't accessible from C#. That is, the C# compiler doesn't allow you to write arbitrary code as an expression. What shipped was the DLR-based expression trees, which are more flexible, but require a cumbersome API. So that's not really a feature. (Correct me if I'm wrong; I haven't used C# extensively since 3.0 as I moved to F# for .NET tasks.)

Optional parameters were a mistake to leave out of the original spec. MS insisted that providing a ton of method overloads was a more elegant approach, for some insane reason. And at any rate, the C# implementation C# is the same, lame, VB/C-style callsite embedded optional parameters, which hampers their usefulness (but it's still much better than overloads!).

Perhaps I have unrealistic expectations from C#, as I certainly don't appreciate the effort required to design a language for such widespread use.

Re:An analysis of the C#/.NET platform by Mikeb85 on Saturday November 02, 2013 @05:26PM (#6660884)
> If a non-MS affiliated company marketed a language as lean as F#, with as good a runtime and editor/debugger, they'd be a huge amount of "hipster" cred and praise.

OCaml? Which is what F# is based on, compiles to anything (including fast native code), and is open-source?

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @05:36PM (#6660920)
Are OCaml's main libraries even threadsafe yet? Is there a smooth editor/debugger like Visual Studio? Just a quick look says the Windows version of OCaml doesn't even have a debugger. OCaml is neat, and more advanced than F# in some aspects, but I'm not sure the dev experience is nearly as slick.

Another thing not mentioned: libraries. Anything half-well designed on JVM or .NET has access to a massive amount of libraries (and both stdlibs are pretty complete). Depending on the project, that's not a trivial consideration.

More info from a biased source: https://www.quora.com/Functional-Programming/How-does-F-comp...

Re:An analysis of the C#/.NET platform by gaius on Sunday November 03, 2013 @06:31AM (#6662845)
You can get a fairly complete stdlib on OCaml too, as long as you are willing to commit yourself to using Jane Street Core rather than the one that comes with the language.
Re:An analysis of the C#/.NET platform by profquail on Saturday November 02, 2013 @05:50PM (#6660977)
I suspect F# can also be compiled to nearly anything OCaml can be -- that is specifically the point of the Code Quotations feature of the language.

F# is also open-source (https://github.com/fsharp/fsharp). Why do you keep implying it isn't?

Re:An analysis of the C#/.NET platform by Mikeb85 on Saturday November 02, 2013 @06:03PM (#6661024)
The .NET runtime isn't open source...

I like how this is down-voted as though it isn't true...

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @06:19PM (#6661081)
Perhaps because you're being pedantic about .NET versus the CLI? The CLI spec is a standard and open source. Microsoft's own version isn't open source (well, they did release an "open" source version, Rotor). But Mono's is.
Re:An analysis of the C#/.NET platform by profquail on Saturday November 02, 2013 @08:19PM (#6661485)
Correct -- the .NET runtime isn't open source.

F# has a very strong following on Mono though. In fact, I suspect a higher percentage of F# developers develop and/or deploy on Mono than any other language does.

You may not know this, but F# ships with the Mono distribution for OS X, and it may well ship with the Linux packages before long.

BTW, I maintain the F# port for FreeBSD, and the combination of F#, Mono 3.2.x, FreeBSD 10, and emacs is extremely fast and stable. http://fsharp.org/use/freebsd

Re:An analysis of the C#/.NET platform by platz on Saturday November 02, 2013 @09:41PM (#6661763)
I think the performance of Mono on Linux is a bit lacking though, compared to other Linux VM's/Runtimes or the Windows CLR runtime.
Re:An analysis of the C#/.NET platform by profquail on Sunday November 03, 2013 @12:07AM (#6662184)
That's true. Mono is generally slower than the CLR, though it has been improving ever since Xamarin took over. There's also an option now to use LLVM as the JIT compilation engine in Mono; for server-based applications (where steady-state performance matters more than start-up time), this can greatly improve the performance thanks to LLVM's optimizer.

With the improvements in the latest 3.2.x branch, I think Mono's performance is at least "good enough" for many use cases.

FWIW, I do a bit of F# + Mono development on FreeBSD 9 (and now FreeBSD 10) and have found the performance to be quite good. I wrote an installation guide (http://fsharp.org/use/freebsd) if you want to give it a try, e.g., in a VirtualBox VM.

Re:An analysis of the C#/.NET platform by platz on Monday November 04, 2013 @12:49PM (#6669990)
The LLVM as the JIT compilation engine in Mono option is very interesting! Thanks for that tip.

I used to use freebsd as a student a while ago. It was pretty interesting and I wish more people would give it a try.

Re:An analysis of the C#/.NET platform by nbevans on Saturday November 02, 2013 @05:47PM (#6660965)
F# is open source too. </minor pedant>
Re:An analysis of the C#/.NET platform by Mikeb85 on Saturday November 02, 2013 @06:03PM (#6661025)
The runtime (.NET) isn't...
Re:An analysis of the C#/.NET platform by nbevans on Saturday November 02, 2013 @06:20PM (#6661087)
I assume you're referring to the CLR here? As in: http://en.wikipedia.org/wiki/Common_Language_Runtime

Whilst no, the Microsoft CLR is not open source. It doesn't need to be. Because the CLI is a ECMA standard and known-good third party implementations (Mono) already exist.

The only thing to be gained from open sourcing the Microsoft CLR would be to benefit Mono. As Mono is the defacto official cross-platform port of the CLR. Since the Microsoft CLR almost certainly contains IP and trade secrets that they wouldn't want their commercial rivals to see, it would be more beneficial if Microsoft merely gave a fairly open code sharing and IP license to the Mono / Xamarin team so that they could benefit in the exact same way as though it were OSS MIT.

Re:An analysis of the C#/.NET platform by MichaelGG on Saturday November 02, 2013 @06:20PM (#6661085)
The runtime is actually the CLI, which is a standard and has open source implementations.