News for hackers. Stuff that matters.
Re:Microsoft takes .NET open source and cross-platform by eloisant on Wednesday November 12, 2014 @11:48AM (#8596497)
C# as a language is better than Java, but not as good as Scala.
Re:Microsoft takes .NET open source and cross-platform by eranation on Wednesday November 12, 2014 @12:15PM (#8596712)
I don't know why you are being down voted. Erik Meijer, a huge .NET contributor who worked at Microsoft (on C# among other things), and was behind the reactive .NET extensions (and also a big Haskell contributor) - he was saying exactly the same thing about Scala vs C# - http://www.infoq.com/presentations/covariance-contravariance...

I can also testify as someone who uses Scala on a day to day basis and used C# at work as well - I completely understand your statement, although it's very subjective.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @12:44PM (#8596899)
Probably because,

A), it was an uncalled-for digression into language wars, and

B), now that we're here anyways, a lot of us think the majority of features in scala and Haskell for that matter are fundamentally misguided. My goal is not to write elegant code, but to write the least complex code with the lowest cognitive overhead. TCO, 10x the man-hours in maintenance and all that. If the choice is between having to write null-checks or having to understand category theory to read my code, I'll take the null-checks.

Re:Microsoft takes .NET open source and cross-platform by eloisant on Wednesday November 12, 2014 @01:03PM (#8597038)
A) I think C# is a great language actually, and Scala's success is probably due to Java's severe limitations. I just don't think someone working on Unix should be jealous of C# because there are great languages available here.

B) Precisely, unlike Haskell, Scala doesn't force you to write "elegant code", you can even use variables. Purists will flame you for that, but sometimes it's the best way to write a small piece of code and as soon as no state leaks outside of the function, it's not that bad. That said, I believe most of the features of Scala make maintenance easier, including the absence of null-checks as it moves errors from runtime to compile time and make major modifications without regressions easier.

Re:Microsoft takes .NET open source and cross-platform by Filligree on Wednesday November 12, 2014 @05:17PM (#8598630)
You can use variables in Haskell as well, no problem. It just forces you to stack your monad on IO, STM or some other mutable-value-supporting monad, of which there are several.

The only difference worth mentioning is that they type system won't allow "leaks".

Re:Microsoft takes .NET open source and cross-platform by tome on Wednesday November 12, 2014 @12:59PM (#8597008)
> If the choice is between having to write null-checks or having to understand category theory to read my code

Me too. Luckily this is a false dichotomy.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @01:11PM (#8597106)
Here's a random line from the Scala standard collections library:

def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That

This is from the standard collections library.

In Java, I've got a List.add function. In case it's not clear from the name, 'add', I can click through to the implementation and it's pretty obvious what's happening.

In Scala, I've got +, ++, +:, :+, and a bunch of other nonsensical bullshit, and when I click through to the implementation? Even less sense. Whenever I use a standard scala collection, I have no idea what it's actually doing. Additionally, everything favors allocation-happy overly-clever immutable wrappers rather than a simple ArrayList which will smoke those immutable implementations in real-world performance.

The cure is far worse than the disease, here.

Re:Microsoft takes .NET open source and cross-platform by bad_user on Wednesday November 12, 2014 @01:47PM (#8597362)
For a Scala developer that signature makes sense. You want to add an element of type B to your collection with elements of type A, however the addition of an element of type B may not be supported (e.g. you may want to add a String to a BitSet and get in return a plain Set[Any]), so the above works only as long as there is a builder available that can build the new collection. The function also works on covariant collections, because it's building a new collection (i.e. it's for immutable collections), so it doesn't have the covariance gotcha of arrays.

Scala's collections have some quirks, but not as many as .NET's collections and you're actually comparing apples to oranges, because you won't find the equivalent of an "add" that returns a new collection instead of modifying the old one in .NET.

This is what happens when you pass judgement unto things you don't understand. Working with immutable data-structures is really, really awesome and Scala's API for these collections is very friendly and very type-safe - as in, if you feel the need to use `isInstanceOf` / `asInstanceOf`, then you're probably doing something wrong ;-)

And I really wish that C# would grow up a little in this regard, as modern programming languages need immutable collections as well, with a nice API to go along with it. And btw - working with Option is super awesome, no category theory needed.

That said, as I was saying in another comment, I'm really excited about this announcement, because this is mostly about the runtime, not the language. You can run things built with Scala on top of .NET right now by means of IKVM. And the JVM finally has some credible competition.

Re:Microsoft takes .NET open source and cross-platform by rasmuskl on Wednesday November 12, 2014 @02:21PM (#8597558)
Oh btw C# does have immutable collections now. Adoption isn't too high yet AFAIK, but they're pretty awesome..

http://msdn.microsoft.com/en-us/library/dn385366(v=vs.110).a...

Re:Microsoft takes .NET open source and cross-platform by bad_user on Wednesday November 12, 2014 @02:36PM (#8597650)
Interesting, thanks for the link.
Re:Microsoft takes .NET open source and cross-platform by smsm42 on Wednesday November 12, 2014 @07:33PM (#8599275)
>>> This is what happens when you pass judgement unto things you don't understand

I think it's kind of the point if the judgement is on the question "what is easier to understand". I think this is the sentiment many people staring to learn Scala are feeling - the barrier to entry, even if you are coming not from the blank slate but from the background of programming many years in many languages, is pretty high. It's not the judgement on "whether Scala and its collections are good/done right", which is entirely separate question from "whether it is easier for someone to understand how C# collections or Scala collections work".

>>> And btw - working with Option is super awesome, no category theory needed.

Well, if you want to do something like making a function that works on Option from a function that works on the underlying type, you pretty soon find yourself in that general area.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @02:03PM (#8597457)
I agree that Option types are great, so great that I'm happy to work in a much 'weaker' language, use option types, and solve 90% of the problems that more 'theoretically robust' languages address with none of their downsides.

As far as not understanding how awesome immutable data structure are.. I'd take a step back before you make assumptions about what other people understand. Do you know anything about cache hierarchy and memory models on modern CPUs? Performance is important to some of us.

Re:Microsoft takes .NET open source and cross-platform by bad_user on Wednesday November 12, 2014 @02:36PM (#8597647)
> Do you know anything about cache hierarchy and memory models on modern CPUs?

Yes I do. Worked 3 years on a soft real-time system with massive load, profiled the shit out of everything. There's an interesting discussion we could have about when immutable data-structures work best, when they've got problems and when it doesn't matter, especially given the extra benefits in dealing with accidental complexity. This isn't the right place though.

> Performance is important to some of us

Yes it is, but performance problems are fixed by means of profiling and optimizing the bottlenecks. Even in a system that has massive load, in many cases in doesn't matter and in some cases immutability increases performance by eliminating contention on reads. And seriously, most people invoking performance problems are not having those performance problems to begin with, therefore my assumption.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @04:02PM (#8598140)
Well, that's good, sorry for asking. I've had a lot of people point at the big-0 notation of that linked-list append and tell me that it's faster than an ArrayList append on average. Usually this is right after telling me that "I just don't get it" with immutable collections. So I hope you can see why I'd react that way.

As I'm sure you know, when it comes to real-world situations, reducing inter-thread communication and isolating anything mutable is the key concern. That's why I find immutable wrappers that mock mutability to be a bit of a sideshow. You shouldn't have read contention with locking in the first place unless it's for a very good reason.

Re:Microsoft takes .NET open source and cross-platform by bad_user on Wednesday November 12, 2014 @04:41PM (#8598402)
> You shouldn't have read contention with locking in the first place unless it's for a very good reason.

True, but you know how it is in practice :-)

For example I found that using persistent data-structures work best when you've got single producer, multiple consumers scenarios - so you mutate some state and you want to signal it over asynchronous boundaries to multiple consumers. With an immutable data-structure you just signal it, worry free and then you can keep on changing that state, completely non-blocking / wait-free and with good algorithmic complexity.

Actually non-blocking logic becomes really easy, as you can always shove an immutable value into an atomic reference (note - I'm not saying "wait free", which still takes a lot of work :))

So really, persistent data-structures are great in a multi-threading context, as long as you don't have multiple producers pounding on the same reference holding such an immutable value - if you do that, things can get bad, when compared to specialized concurrent mutable data-structures - because a good concurrent data-structure is able to distribute the contention in multiple buckets instead of just one. But then again, having multiple producers pounding on the same resource is just asking for trouble and has to be avoided, because Amdahl's law.

Also, as you've hinted at, the problem with a normal linked List is the level of indirection. And in general, persistent data-structures imply the usage of trees, which also implies indirections. More advanced persistent data-structures are much better than the linked list is and this is an active area of research, but on the whole there's still much room for improvement.

On the other hand, in my opinion when speaking about performance, the first problem one has is to actually use the available CPUs (e.g. getting CPU usage over, say 70-80%). Which usually is hard to achieve if you have a combination of CPU-bound and I/O-bound tasks and your I/O stuff is not asynchronous. Only after that you can then move on to optimizing the memory access patterns for cache locality and for minimizing the stop-the-world freezes.

Speaking about GC, that's another topic - persistent data-structures have a tendency to generate junk that is neither short term or long term and that invalidates the assumptions that current GCs are making. The JVM at least has really good GCs, but without paying for a pauseless one (like that one from Azul Systems), you can still end up into trouble if you don't pay attention - but then you fire up YourKit's Profiler, find the source for those STWs, optimize and it works out well.

All in all I encourage everybody to find a good library that implements persistent data-structures and integrate them in their toolbox.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @09:21PM (#8599598)
Hey, so I agree with your analysis in general, and sorry for being opaque earlier (was at work), but you totally got what I was driving at and explained it probably better than I could have.

The one thing I disagree with, in many server applications, is using the available CPUs is pretty easy. You've got thread pools handling various tasks, just crank them up. In JVM-land, a very heavy 512kb stack per thread is still not really much penalty to pay as long as you re-use them. Aggregate application performance then becomes a matter of completing tasks faster while creating less garbage.

So it all comes down to what you consider a 'task' and how you handle the handoffs between them. The architecture decisions at this level dwarf the improvements from using an array vs list, as you implied, but they also make the usage of immutable types somewhat irrelevant IMO. Seal off mutable code within single-task boundaries and it doesn't matter how ugly it is, as long as you're passing immutable types (just plain javabeans with final members are fine) between boundaries.

Anyways, just my opinion. Great comment.

Re:Microsoft takes .NET open source and cross-platform by room271 on Thursday November 13, 2014 @04:51AM (#8600714)
> Actually non-blocking logic becomes really easy, as you can always shove an immutable value into an atomic reference (note - I'm not saying "wait free", which still takes a lot of work :))

Why the atomic reference here? I know that provides CAS but if we're talking about a single writer aren't you okay to just replace things anyway?

Re:Microsoft takes .NET open source and cross-platform by bad_user on Thursday November 13, 2014 @06:27AM (#8600976)
Yes, I wasn't talking about a single writer. That was a new paragraph. Sorry about not making that clear.
Re:Microsoft takes .NET open source and cross-platform by room271 on Thursday November 13, 2014 @09:07AM (#8601529)
Ah cool, just wanted to clarify as I'm only a beginner for much of this stuff, but found your posts very interesting.

Thanks!

Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Wednesday November 12, 2014 @05:24PM (#8598672)
Nice effort, but judging from the non-sense emitted by jbooth, he won't understand the things you are explaining anyway.
Re:Microsoft takes .NET open source and cross-platform by Dewie on Thursday November 13, 2014 @05:48AM (#8600848)
> Well, that's good, sorry for asking.

Gotta test for any chinks in the armour.

Re:Microsoft takes .NET open source and cross-platform by teacup50 on Wednesday November 12, 2014 @02:35PM (#8597641)
> Do you know anything about cache hierarchy and memory models on modern CPUs?

Yes.

> Performance is important to some of us.

... and in those cases, you don't have to use data structures that model your problem domain poorly.

The problem isn't "immutable data structures" or "theoretically robust" languages. The problem is finding ways to express computations and their constraints in a way that can be efficiently modeled for your problem domain.

Re:Microsoft takes .NET open source and cross-platform by m_mueller on Wednesday November 12, 2014 @05:47PM (#8598782)
The problem with this logic is that you won't know about your performance problem until a system is scaled up to production level tasks - except if you build a comprehensive performance model beforehand, which takes about as long as the implementation (and is thus nonsensical for most tasks) and is really hard to do IMO in an FP language.

So what will probably happen is that once you see your performance problems, you can pray that it's only some hot spots that you can then replace with faster code - often it's not, so you have 100 places using around 1% of your time budget for example, which is when you can go and start over.

Re:Microsoft takes .NET open source and cross-platform by breischl on Wednesday November 12, 2014 @04:26PM (#8598309)
>>And I really wish that C# would grow up a little in this regard, as modern programming languages need immutable collections as well, with a nice API to go along with it May I suggest the Immutable Collection library from Microsoft? http://msdn.microsoft.com/en-us/library/dn385366(v=vs.110).a...

Admittedly not part of the core library, but installing a NuGet package is pretty darn easy.

>>This is what happens when you pass judgement unto things you don't understand ;)

[edit: Guess I should've refreshed the page to see the prior response before writing this. Apologies.]

Re:Microsoft takes .NET open source and cross-platform by yohanatan on Wednesday November 12, 2014 @03:09PM (#8597827)
The operators on collections always have alternate named forms. I actually instinctively skip over the operators when perusing the documentation and have no trouble at all finding what I need.
Re:Microsoft takes .NET open source and cross-platform by ssmoot on Wednesday November 12, 2014 @03:15PM (#8597855)
Pointing to CBF is a complete straw-man.

You're rarely actually going to _see_ that signature (the docs actually simplify it for you), and in practice, it's completely meaningless to 99.9% of Scala you'll ever see.

You might as well consider it pixie-dust.

+ for one, ++ to add a collection, the others are generally going to apply to Cons-like. It takes all of a couple minutes to let these sink in.

Use a mutable.MutableList if that's what you want. Or just use ArrayList.

All this is about as pure FUD as I've ever seen...

Re:Microsoft takes .NET open source and cross-platform by hibikir on Wednesday November 12, 2014 @10:52PM (#8599811)
It isn't FUD: It's just the kind of thing that turns newbies out of Scala.

Your typical Java developer is used to just look inside the code of whatever library they are using, and find a very straightforward implementation. Scala collections avoid a lot of boilerplate with canBuildFrom, SeqLike and suck, but simple and straightforward they are not. It takes quite a while before it stops reading like Japanese.

And IMO yes, a lot of symbolic methods in collections make relatively little sense. Don't forget that list also has ::, :::, +:, :+ and :\. There's more than a few, and there are no textual versions of them, for those that don't have them all memorized. They are a bit of a relic from the time Martin thought that /: was a good idea. It's fortunate that now only the scalaz people keep doing such things, because excessive use of symbolic operations hurt language adoption.

And he doesn't even get into other early confusion points, like how we have =>, <-, and ->, or how decomposing Seqs is not exactly pretty. Last week I had to help a guy that had been using Scala for 6 months to understand the 'punched in the face' operator :_*

So no, it's definitely not FUD. Are they issues that hurt my day to day Scala use? Not at all. Scala is my favorite language. Being able to use it instead of Java or Clojure is worth a good 15K a year for me.But that doesn't mean that I have forgotten some of the little things that made the learning curve tough at first. Thanks the heavens that I managed to end up finding a Scala job where I could learn from one Bill Venners.

Re:Microsoft takes .NET open source and cross-platform by ssmoot on Thursday November 13, 2014 @10:26AM (#8601941)
Maybe this is a Java developer thing.

Everybody decried Ruby's 107 methods on Array. Then Fowler came out with "fluent-interfaces", and how often do you see someone make the claims that Ruby's Array is indicative of a general badness because it has a lot of methods and you can't memorize them all in an hour as a newbie?

scala.collection is the same deal.

:\? Sure it's not a good idea. I wouldn't debate that. Who uses that? foldLeft/foldRight.

And what's the deal with trying to memorize the entire interface anyways? 8 or so years with Ruby, writing libraries with over 4 million downloads (https://rubygems.org/profiles/ssmoot), and there are definitely methods in Ruby's Array I'm unfamiliar with.

So what?

While :: and ::: look a little foreign, I don't think asking people to learn them if they want to work with Lists in a Functional manner is anymore difficult than learning what the "spaceship operator" does in Ruby. And it's optional. You don't have to use them. But they're usage will probably be the smaller part in the grand scheme of things. Pattern Matching and accomplishing functional recursion with immutable data is the bigger picture. Outside of that context (and the REPL I guess, for convenience) you're just not going to see either of those operators very often (IME).

You don't use a "splat" (aka 'punched in the face'? That's a new one to me) operator very often. It's actually one of the few semi-pattern-matchy areas of Ruby so it comes pretty naturally for me.

You don't become a pro overnight. You can trust I'd be teaching infrequently used idioms in Ruby to a developer who'd only been using it for six months. Been there, done that. ;-)

I guess where I'm coming from is using CBF to claim Scala is a confusing, indecipherable language. Everyone's had that argument. I don't know that anyone wants to stand up and claim it's the best. But it works. Actually using it is a non-issue since you don't actually explicitly use it. And look at the docs. They're actually pretty great overall.

It just bothers me I suppose that someone interested in exploring Scala would be dissuaded by something that's only ever been a problem for 1% of 1% of Scala developers.

If you're just looking to swap in Play to replace Rails, odds are you'll never run into any of these CBF "concerns". At all. That's the very definition of "FUD" IMO.

For every CBF in Scala there's a Calendar in Java. Languages aren't perfect. CBF is probably a wart. But it's a hidden one. If you let it scare you off from Scala that's sad, because it really has about as much to do with day to day Scala development as array.c (https://github.com/ruby/ruby/blob/trunk/array.c) has to do with Ruby development.

Re:Microsoft takes .NET open source and cross-platform by imanaccount247 on Wednesday November 12, 2014 @01:45PM (#8597346)
How on earth does "I don't like operators" support your claim?
Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @02:06PM (#8597467)
The claim was that scala code is very difficult to read and idiomatic scala code, as evidenced by their collections library, brings along a ton of conceptual overhead that creates much more complexity than it eliminates.

That line alone drives home the point for me, you can read the rest of scala.collection.immutable if you need more convincing.

Re:Microsoft takes .NET open source and cross-platform by imanaccount247 on Wednesday November 12, 2014 @04:53PM (#8598480)
The claim was that you need to know category theory. Your post is still there, we can still read it. It does not make much sense to pretend it says something other than what it says.
Re:Microsoft takes .NET open source and cross-platform by yarou on Wednesday November 12, 2014 @03:26PM (#8597913)
First and foremost, I think you need to read about Blub. [0]

Also, idiomatic Scala code is perfectly readable. You have no right to complain about readability until you've dealt with spaghetti code written for Megacorp Inc, that completely ignores the fundamentals of structured programming. :)

[0] http://www.paulgraham.com/avg.html

Re:Microsoft takes .NET open source and cross-platform by teacup50 on Wednesday November 12, 2014 @02:39PM (#8597663)
You're conflating a lot of unrelated issues here by lashing out against things you seemingly don't understand.
Re:Microsoft takes .NET open source and cross-platform by psibi on Wednesday November 12, 2014 @12:54PM (#8596975)
> majority of features in scala and Haskell for that matter are fundamentally misguided

I'm interested in the Haskell part. What features do you think are fundamentally misguided ?

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @01:04PM (#8597051)
I'm much less experienced with Haskell than with Scala, so I might be unfairly painting it with the same brush here.

But, for example, https://www.haskell.org/tutorial/io.html.

At the end of the day, this is a huge inner-framework anti-pattern over the same procedural syscalls that every other language handles procedurally. I shouldn't have to care what a monad is, and side effects? The whole point of I/O is side effects. It could be a no-op, idle process or CPU-burning busy loop if I didn't care about side effects.

From that doc:

" So, in the end, has Haskell simply re-invented the imperative wheel?

In some sense, yes. The I/O monad constitutes a small imperative sub-language inside Haskell, and thus the I/O component of a program may appear similar to ordinary imperative code. But there is one important difference: There is no special semantics that the user needs to deal with. In particular, equational reasoning in Haskell is not compromised. The imperative feel of the monadic code in a program does not detract from the functional aspect of Haskell. An experienced functional programmer should be able to minimize the imperative component of the program, only using the I/O monad for a minimal amount of top-level sequencing. The monad cleanly separates the functional and imperative program components. In contrast, imperative languages with functional subsets do not generally have any well-defined barrier between the purely functional and imperative worlds."

So, basically, they acknowledge that their theoretical model has a huge impedance mismatch with what we write programs to do (I/O, eventually, somewhere). And that's fine, they can knock themselves out and I hope it's fulfilling for them. It's not for me.

Re:Microsoft takes .NET open source and cross-platform by imanaccount247 on Wednesday November 12, 2014 @01:44PM (#8597335)
>At the end of the day, this is a huge inner-framework anti-pattern over the same procedural syscalls that every other language handles procedurally.

No, you have a tiny, very simple type that allows for type safe IO. It also happens to make haskell a more powerful imperative language than most imperative languages, as IO actions are first class and can be passed around and manipulated like anything else.

>So, basically, they acknowledge that their theoretical model has a huge impedance mismatch with what we write programs to do (I/O, eventually, somewhere)

No, they acknowledge that doing IO is so important that it should be done correctly. You are going to some pretty extreme mental gymnastics to misrepresent a language you want to hate.

Re:Microsoft takes .NET open source and cross-platform by yarou on Wednesday November 12, 2014 @02:39PM (#8597664)
To be fair, understanding I/O in Haskell takes quite a bit of mental gymnastics. :)

The I/O monad modifies the Universe that contains the set of all functions that comprise your program (if I even understand the concept correctly).

Re:Microsoft takes .NET open source and cross-platform by spion on Wednesday November 12, 2014 @04:37PM (#8598371)
The IO monad is just an action. Its a cons pair with a left and a right half. In an imperative language you could model the left half with a closure that takes no arguments, does I/O and produces a value.

The right half is usually empty, except when you use the `>>=` operator (or flatMap) on an existing action, e.g.

let c = a >>= f

That operator chains the function `f` can take the value produced by the first IO action and produce another IO action. After we apply that operator, the result `c` is a cons cell where the left part is the original action `a` and the right part is the function f which takes the value produced by a and produces the next action. Its sort of like a cons cell in regular lists, except the next value is provided by a function. A lazy cons cell, perhaps :)

The final result is a lazy chain of I/O cons cells (called "main", of course :P). Its passed to the Haskell runtime, which executes that chain as a recipe, alternating between doing I/O actions and evaluating the function to decide what to do next.

So what does this buy us? Mostly just referential transparency. What does referential transparency buy us? Easy refactoring. We can replace any expression with its value, even stuff like `putStrLn "test"`. We can say `let writeTest = putStrLn "test"` at the top of the file then write `do writeTest; writeTest` in main.

Another neat thing is that do syntax isn't limited to just IO, but works with anything that implements `flatMap` (and `unit`, which I forgot to mention). That means we can build our own imperative DSLs that produce IO-like monads which are then interpreted by our own interpreter, and the users of those DSLs can use the same do syntax. Which is pretty awesome. Here is a simple example: https://gist.github.com/tonymorris/b5dba9d7d877051d0164 and a much more complex one http://augustss.blogspot.com/2009/02/more-basic-not-that-any... :)

Re:Microsoft takes .NET open source and cross-platform by spion on Wednesday November 12, 2014 @07:03PM (#8599146)
or these PureScript examples https://gist.github.com/spion/982350f4b3d3464b1870 using the Canvas monad to pre-create a scene and then render it; the DOM monad to construct DOM elements.
Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @10:34PM (#8599766)
So how are errors handled?
Re:Microsoft takes .NET open source and cross-platform by spion on Saturday November 15, 2014 @02:06PM (#8612346)
You have the option of two monads, Maybe and Either. Usually errors are handled with the Either monad. An operation may either return a result or an error. Together with do syntax the Either monad gives you multiple choices in handling errors.

You can handle every single error explicitly (as in Go) using pattern matching

  eitherResultOrError = operation1 arg

  case eitherResultOrError of
    Left error -> handle error
    Right result -> handle' result
Its also possible to chain multiple operations then check the error later. If an error occurs, the next operations in the chain will not execute.

  let eitherResultOrError = do
    x <- operation1 arg
    y <- operation2 x + 1
    z <- operation3 x y

  case eitherResultOrError of
    Left error -> handle error
    Right result -> handle' result
Or simply use `orElse` to return a default value in case of errors.

For IO operations and other monadic actions, its best to use EitherT, ErrorT or MaybeT, which are monads that can add error handling to any other monad. To understand how these work, its probably best to implement MaybeT. Basically, they add another wrapper to other monads to redefine what the bind operator (`>>=`) does

Re:Microsoft takes .NET open source and cross-platform by tome on Wednesday November 12, 2014 @03:02PM (#8597786)
> The I/O monad modifies the Universe that contains the set of all functions that comprise your program

That sounds rather complicated. My way of thinking of it is simpler than that. a -> IO b is just a function from a to b that can do some I/O. Nothing more complicated than that.

Re:Microsoft takes .NET open source and cross-platform by SamReidHughes on Wednesday November 12, 2014 @07:34PM (#8599277)
I recommend just regarding IO a as an action, or some description of an action, that returns a value of type a. And (>>=) constructs bigger actions by attaching continuations to actions.
Re:Microsoft takes .NET open source and cross-platform by wbillingsley on Wednesday November 12, 2014 @07:25PM (#8599235)
It is (slightly) more complicated than that. Your return type is not b but IO b. Your callers will be performing functions that are defined on IO b with the result (such as bind)
Re:Microsoft takes .NET open source and cross-platform by rastapasta42 on Wednesday November 12, 2014 @04:17PM (#8598236)
Clearly you have no idea what you're talking about. I suggest first learning the language before spreading FUD about it.

Separation of pure and unpure components greatly simplifies the reasoning about the problem domain. Traditional imperative programs are often full of subtle bugs because calling a procedure can have arbitrary effect on your system. For example calling function with the same arguments can return different values based on arbitrary hard-to-track reasons (such as your OS's scheduler). It's just too much details to keep in your head.

But in Haskell pure functions are guaranteed to have same result with same input. It enables the programmer to create logically isolated blocks without messy interdependencies.

It's especially helpful for concurrent programming by freeing you from all the non-deterministic spaghetti.

Haskell has a steep learning curve, but it'll make you a better programmer in the long run.

Re:Microsoft takes .NET open source and cross-platform by nbevans on Wednesday November 12, 2014 @08:01PM (#8599378)
"But in Haskell pure functions are guaranteed to have same result with same input." I'm pretty sure that same law applies to a pure function in any language, not just Haskell. #shitthatHNsays
Re:Microsoft takes .NET open source and cross-platform by codygman on Wednesday November 12, 2014 @08:16PM (#8599418)
Correct. Though many languages don't encourage and as a result don't have nearly as many pure functions as Haskell code.
Re:Microsoft takes .NET open source and cross-platform by guscost on Wednesday November 12, 2014 @11:17PM (#8599900)
In fairness, I could also say that hammers don't encourage carpentry best practices and as a result they cause many more smashed fingers than wood glue. The fact that a tool doesn't prevent counterproductive usage patterns doesn't automatically make it inappropriate for every job.
Re:Microsoft takes .NET open source and cross-platform by jbooth on Thursday November 13, 2014 @12:58AM (#8600151)
Point being, I/O doesn't square with that concept. For some reason, every time I point this out, I'm accused of not appreciating the beauty of pure functions. I love pure functions. Maybe they're not appreciating the ugly reality of I/O?
Re:Microsoft takes .NET open source and cross-platform by codygman on Friday November 14, 2014 @07:26AM (#8606797)
How much experience do you have composing I/O in Haskell to prove that I/O doesn't square with that concept? Others here have experience using Haskell with I/O, but you just seem to have a hypothesis without experience or examples to support it.
Re:Microsoft takes .NET open source and cross-platform by dragonwriter on Thursday November 13, 2014 @01:00AM (#8600162)
> Point being, I/O doesn't square with that concept.

Sure it does, and composes well under it.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Thursday November 13, 2014 @01:03AM (#8600171)
I'm seeing I/O as "side effects with possible random error conditions". I really don't see how that squares with functional purity.

It's late on EST but I promise if you put effort into explaining a higher-order take on this I'll put effort into reading and understanding it tomorrow. Have a good night.

Re:Microsoft takes .NET open source and cross-platform by codygman on Thursday November 13, 2014 @02:05PM (#8603369)
Through monads functional purity with I/O is achieved, ergo you can compose I/O and get other advantages of purity.
Re:Microsoft takes .NET open source and cross-platform by Dewie on Thursday November 13, 2014 @05:51AM (#8600856)
What "pure" means varies from language to language.
Re:Microsoft takes .NET open source and cross-platform by nbevans on Thursday November 13, 2014 @08:37PM (#8605362)
It really does not.
Re:Microsoft takes .NET open source and cross-platform by tree_of_item on Wednesday November 12, 2014 @01:24PM (#8597196)
I don't think they are acknowledging any impedance mismatch there. The point of that paragraph is to emphasize that Haskell retains the usual feel of imperative programming, with the important difference that the imperative bits of your code are cleanly separated from the pure bits due to the IO type.

There's no theoretical stuff here, it's just making sure that the caller knows about callees having side effects.

Re:Microsoft takes .NET open source and cross-platform by eranation on Wednesday November 12, 2014 @12:59PM (#8597004)
Understood, By the way, I do null checks in Scala, may the lord have mercy on my soul. I don't like all the "I'm functional and smarter than you with my higher kind types, Monads and type classes" attitude that a minority of Scala lead figures have given it. Scala is very pragmatic down to earth language that you don't HAVE to abuse, the issue is that some people abused it on some libraries (e.g. with weird operators etc...) and some people are "either all the way functional or I rather die" but I think that if any C# developer would have jumped into Scala, they would have had much better things to say about it, even without using a single "purely functional" aspect of the language.
Re:Microsoft takes .NET open source and cross-platform by hibikir on Wednesday November 12, 2014 @10:58PM (#8599832)
I'd not say that avoiding null checks requires any serious functional magic. It's a matter of convention: If you are ever using anything that could be null, surround it with an Option. It just makes the fields that might need to be checked explicit.

One doesn't have to learn category theory to realize that Options are great, especially when accompanied by a little bit of help from pattern matching, map, flatten and getOrElse.

The fact that many Scala lead figures that come from a Haskell background are bringing with them a holier than thou attitude doesn't mean that there aren't some functional concepts that are very useful even if your code is mostly imperative, and Option is arguably the least controversial of the lot. It's so uncontroversial it's in Java 8, although suffering from the fact that it is lacking some of the great Scala goodies.

Re:Microsoft takes .NET open source and cross-platform by pistle on Wednesday November 12, 2014 @10:16PM (#8599715)
If I'm not mistaken C# 6 will be improving on the null check thing as well. Though, the syntax seems jarring to me right now (so did the inverted SQL-like linq style - yeah for the fluent style).
Re:Microsoft takes .NET open source and cross-platform by Pxtl on Wednesday November 12, 2014 @02:08PM (#8597478)
I'd rather duck the question by supporting non-nullable columns without resorting to higher-kinded types.
Re:Microsoft takes .NET open source and cross-platform by imanaccount247 on Wednesday November 12, 2014 @01:41PM (#8597311)
How can you think they are "fundamentally misguided" if you don't even know what they are? The category theory strawman is the absolute laziest, most absurd piece of FUD you could possibly resort to. It is even worse than the old "perl is bad because I don't want to read line noise" nonsense, at least that had some loose tie to reality.
Re:Microsoft takes .NET open source and cross-platform by jacquesm on Wednesday November 12, 2014 @02:15PM (#8597518)
Missed opportunity to explain why those are 'fundamentally misguided'.
Re:Microsoft takes .NET open source and cross-platform by SamReidHughes on Wednesday November 12, 2014 @06:07PM (#8598888)
GP didn't mention specifically which features were misguided, making a response require a disproportionate amount of effort compared to what he's put in. And he's talking complete nonsense about "category theory," which is just ridiculous so it's not like he's close to worthy of some effort-post.
Re:Microsoft takes .NET open source and cross-platform by _dps on Wednesday November 12, 2014 @06:43PM (#8599057)
In my experience the "category theory" claim is imprecise but not unfounded. Without fairly serious abstract understanding of monads, functors, and applicatives (at a bare minimum), it is not possible to write Haskell code profitably. By that I mean that without such knowledge you should have just written something else.

To make Haskell a serious advantage and not just a minor benefit (compared to, say, SML), you probably also need to understand kinds. Let's bear in mind that the vast majority of practicing programmers can't reasonably define an algebraic data type, and that it's not their fault, because the ROI for learning such things is often negative.

I do think there is a reactionary "don't-wanna-learn anything" vibe against Haskell among certain groups. But I think we should be clear that, to get the power that Haskell promises, you do need to learn many new things. Those things, while not exactly category theory in a narrow sense, are closer to category theory than they are to conventional programming knowledge.

Re:Microsoft takes .NET open source and cross-platform by imanaccount247 on Wednesday November 12, 2014 @07:00PM (#8599128)
Yes, it is completely unfounded. You do not need to know anything about category theory, or even what it is. All you need to know about Monad is its interface. If you can handle java, you can handle haskell. All you need to understand with kinds is "its how many arguments a type takes". And that isn't category theory in the first place. Anyone can define an ADT. That's one of the first things I taught our PHP team, nobody had any confusion or problems with it, it was a 2 minute thing. I have a hard time imagining how you could think:

    data Bool = True | False
is hard to learn or understand or woulf have a "negative ROI".
Re:Microsoft takes .NET open source and cross-platform by dkarapetyan on Wednesday November 12, 2014 @08:22PM (#8599442)
As a PL enthusiast that likes to dabble in different paradigms and basically learns a programming language or two every other year by far the hardest language to wrap my head around has been Haskell.

There are a few reasons for this that get dismissed by the day to day practitioners. First, there is the cognitive rewiring required to think of everything as an inert expression. In Haskell there are no actions, just descriptions of actions that the runtime manages. I'm specifically talking about I/O and its monadic implementation. Second, learning about monads is not enough. When effects are encapsulated as monads you need to understand monad transformers to fruitfully combine effectful computations. This is by no means the best way to do things because there are also implementations of effectful computations with row types and extensible effects, e.g. PureScript, that requires a lot less cognitive overhead and is less error prone. Third, many of the high-powered libraries in the Haskell ecosystem are so heavily reliant on categorical constructs, e.g. free (co)monads, functors, applicatives, monoids, bifunctors, Kleisli categories, etc. that getting through all that thicket to be truly productive with the libraries instead of just copying and pasting requires a time investment that is of dubious value to many programmers and you're better off learning about security practices on OWASP because you are more likely to encounter a SQL injection than you are to encounter a Kleisli category of a monad.

I'm not saying knowing these things is not useful or won't make you a better programmer but to just demonstrate that there is indeed a cognitive overhead that might not be worth it. I like category theory as much as the next mathematician but programming with categorical constructs is not necessarily the most optimal way to do things when all I need is a screen scraper for an XML feed.

Re:Microsoft takes .NET open source and cross-platform by imanaccount247 on Thursday November 13, 2014 @04:41PM (#8604313)
>There are a few reasons for this that get dismissed by the day to day practitioners.

Perhaps they get dismissed because we all went through the process of learning haskell in order to become day to day practitioners, so we know these reasons are made up nonsense.

Re:Microsoft takes .NET open source and cross-platform by Dewie on Wednesday November 12, 2014 @06:36PM (#8599028)
"""YOU NEED TO LEARN ABOUT MONADS JUST TO WRITE 'HELLO WORLD', LIKE WHAT IS UP WITH THAT."""
Re:Microsoft takes .NET open source and cross-platform by Vektorweg on Wednesday November 12, 2014 @12:27PM (#8596787)
Peyton Jones and some other nice people work at Microsoft to improve Haskell, which is IMHO the right tool.
Re:Microsoft takes .NET open source and cross-platform by seanmcdirmid on Wednesday November 12, 2014 @05:12PM (#8598603)
I went from scala to C# 7 years ago, and after some feature withdrawal, I began to like C# for its simplicity. It was not very elegant, I often had to settle for ugly solutions, but this was actually a step up from scala where I would obsess to find the most elegant solution for my code. In C#, the best way is more obvious even if not that good, and you settle more quickly.

As the language is considered holistically with tooling, the error messages are always good and they don't make dubious decisions (getting rid of semi colons) that are theoretically sound but screw up tooling.

Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Wednesday November 12, 2014 @05:19PM (#8598646)
> they don't make dubious decisions (getting rid of semi colons) that are theoretically sound but screw up tooling

Wait WUT? I'm not sure you know what you are talking about ... that just doesn't make any sense.

Scala 7 years ago is fundamentally different from today's Scala, so I'm not seeing how your experience is relevant anymore.

Re:Microsoft takes .NET open source and cross-platform by seanmcdirmid on Wednesday November 12, 2014 @05:34PM (#8598726)
Taking out semi colons reduced the amount of redundant information needed for error recovery in the parser, leading to poorer error messages and reducing the quality of interactive IDE feedback. I know this because I was working in the IDE when martin made the decision. Maybe it was the right decision, but there were definitely costs!

There is a very good reason they will never eliminate semi colons from C#, the visual studio team would never let them...C# is developed in a completely different style from Scala.

I'm sure you are right: scala today is probably a much more simple language with great IDE support...7 years ago, it was a bunch of advanced features and building a decent IDE for it was a struggle.

Re:Microsoft takes .NET open source and cross-platform by jkrems on Wednesday November 12, 2014 @12:21PM (#8596747)
Yes, that's why you would use F# in .NET if you want something like Scala. And then I heard many people say that .NET wins again.
Re:Microsoft takes .NET open source and cross-platform by bad_user on Wednesday November 12, 2014 @12:50PM (#8596947)
Meh, F# is pretty good, but Scala has a better type-system. You cannot model type-classes in F# for example and there's some ugliness in it, in a true Ocaml fashion - for example I don't like how you've got to deal with 2 types of generics or the prevalence of "static" methods, static methods that are complete hacks that go back to C++ at least (Scala has no such thing as static methods btw). In many ways Scala is a very elegant language, too bad that many people are scared by these myths that are flying around.

That said, people are missing the forest from the trees. This isn't about the language, but rather about the runtime and the standard library. That's the true value of the JVM, that's the true value in .NET.

There wouldn't be any problem for porting Scala to .NET. Sure, it would be difficult as .NET's reified generics are maybe too limited for Scala's type-system, but I'm sure somebody could make it work, at least partially.

And there was a Scala for .NET, but it lacked interest so it died. But hey, you can still run stuff built in Scala on top of .NET by means of IKVM ;-) Has poor performance compared to a JVM, but then again, people are willing to build stuff in Scala for Android. Also Clojure.NET is doing pretty good from what I've heard.

As a Scala developer that loves Scala and the JVM, I personally find this announcement very exciting. As finally, the JVM has true competition ;-)

Re:Microsoft takes .NET open source and cross-platform by noblethrasher on Wednesday November 12, 2014 @03:02PM (#8597787)
You can model type classes in F#, but it's not pretty[1].

Interestingly, C# can model type classes much more straightforwardly (using implicit conversions), and this is one of the reasons I continue to use it along side F#.

[1]http://stackoverflow.com/questions/9868327/f-type-constraint...

Re:Microsoft takes .NET open source and cross-platform by dragonwriter on Wednesday November 12, 2014 @05:21PM (#8598660)
> There wouldn't be any problem for porting Scala to .NET.

Other than the fact that .NET reified generics and Scala's type system don't play well together, which was one of the big challenges facing Scala.NET.

Re:Microsoft takes .NET open source and cross-platform by seanmcdirmid on Wednesday November 12, 2014 @05:18PM (#8598640)
Scala for .net never actually worked, at least when I tried it. I submitted a few bug reports and started leaning C#.
Re:Microsoft takes .NET open source and cross-platform by lmm on Wednesday November 12, 2014 @12:22PM (#8596754)
F# is elegant but ultimately held back by its lack of higher kinded types.
Re:Microsoft takes .NET open source and cross-platform by kvb on Wednesday November 12, 2014 @02:32PM (#8597618)
Held back from what? I mean, I'd love it even more if it had higher kinded types, but it's a pretty great language as is.
Re:Microsoft takes .NET open source and cross-platform by jakevn on Wednesday November 12, 2014 @04:45PM (#8598421)
It's simply less expressive.

Just as Go is fine without generics, F# is fine without HKTs.

It's a sad realization for those coming from a language that does support HKTs. Still a great language.

Re:Microsoft takes .NET open source and cross-platform by seanmcdirmid on Wednesday November 12, 2014 @05:20PM (#8598655)
I can't tell if you are serious or joking :). it is definitely a trade off to be made, the power offered by higher kinded typing doesnt come for free.
Re:Microsoft takes .NET open source and cross-platform by eloisant on Wednesday November 12, 2014 @12:54PM (#8596972)
F# is not really like Scala in the sense that it's more "extreme" in terms of FP, you can't easy fallback on more classical patterns if FP doesn't work well for your problem.
Re:Microsoft takes .NET open source and cross-platform by edgyswingset on Wednesday November 12, 2014 @01:57PM (#8597411)
Yes you can. I haven't found a traditional Object-Oriented pattern I can't use in F# ... but honestly, I've usually just ended up molding things to fit pattern-matching and reduced the complexity of things in the process.
Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Wednesday November 12, 2014 @05:31PM (#8598716)
> F# [...] more "extreme" in terms of FP

In the sense of lacking higher-kinded types and typeclasses?

Re:Microsoft takes .NET open source and cross-platform by brodo on Wednesday November 12, 2014 @12:08PM (#8596656)
In Scala, there are just too many ways to do things. It's optimized for flexibility and easy writability. C# on the other hand may be a little more verbose, but at least everyone can read everyone elses code.
Re:Microsoft takes .NET open source and cross-platform by ffreire on Wednesday November 12, 2014 @01:11PM (#8597108)
IMHO this works to Scala's detriment. I very much enjoy Python and Clojure precisely because they have one, generally accepted way of doing things. Is it a silver bullet? Of course not, but this works for me 9 times out 10 and I find that coming back to my code later (or sharing with colleagues) is far easier because most code will be structured in a familiar way and therefore take less time to understand the unique bits that solve the problem at hand.
Re:Microsoft takes .NET open source and cross-platform by moonchrome on Wednesday November 12, 2014 @03:25PM (#8597905)
Actually that's the one thing that's driven me away from Clojure.

I love the simplicity behind the language and it makes simple things actually simple - which isn't as trivial as it sounds. But once you start dealing with complex things in Clojure the language doesn't do much for you, if you can't fit your problem in to it's provided toolkit the code written will actually be horrible - for example go look at core.async [1] implementation - just reading that code gives me a headache - I understand it's complicated stuff with buffering and all but having type annotations on protocols and variables used would be extremely helpful when trying to parse that code. Types help me think more abstractly when I'm reading the code as I can take them as compiler enforced contracts and think of them in abstract terms, in dynamically typed languages complexity and the amount of things you need to be aware of is just too overwhelming IMO.

[1] https://github.com/clojure/core.async/blob/master/src/main/c...

Re:Microsoft takes .NET open source and cross-platform by nickik on Thursday November 13, 2014 @08:41AM (#8601413)
I think the nice thing is that you can start without types and add them later, staticlly or with dynamic checks. First I play around with data, once I know what I want I can write some schema annotation.

You can activate validation for everything in development and then in productive only activate validation on your api endpoints. In a future version, you will probebly be able to generate core.typed stuff directly from schema.

Other then that, I think extreamly high performace code a la core.async is not the norm, there the types are not used for the programmer, but rather for the VM. I have used type hints in the last couple of years maybe, one or twice.

Re:Microsoft takes .NET open source and cross-platform by moonchrome on Friday November 14, 2014 @04:20AM (#8606386)
I think you misunderstood what I was trying to say - core.async has no type annotations, you cant even figure out what the protocols are supposed to do because there is no documentation and no types - you literally have to find places its used and reverse engineer protocol semantics. And the function I linked to is very hard to keep track of - a large part of that is inherent with synchronization/buffering logic being complex but the language does nothing to make the code simple or easy to read - I'd bet that function would be easier to understand in Java than in Clojure.

I've tried core.typed, it's amazing in theory but in practice it's unusable (at least for me) and nobody annotates their code anyway. If core.typed becomes more widespread in Clojure community I might actually give it a second chance, in the mean time I'm just going to use Kotlin for JVM, it has transparent Java interop and reduces the Java noise, and the tools (IDEA) is infinitely better than anything I've seen in Clojure land.

Re:Microsoft takes .NET open source and cross-platform by taylorlapeyre on Wednesday November 12, 2014 @02:11PM (#8597502)
Clojure is my favorite language by far, but there's hardly "have one, generally accepted way" of doing everything.
Re:Microsoft takes .NET open source and cross-platform by saosebastiao on Wednesday November 12, 2014 @12:27PM (#8596783)
Funny, I find c# much harder to read. Its almost as if it is easy to understand code for languages you know well, and harder to understand code for languages you don't.
Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @12:47PM (#8596928)
You find C# harder than this?

trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[A, Repr] with Parallelizable[A, ParSeq[A]] { self =>

or

def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That

Re:Microsoft takes .NET open source and cross-platform by ssmoot on Wednesday November 12, 2014 @03:42PM (#8598017)
If you want to make a compelling argument to anyone that actually knows Scala, you need to drop the idea you can make it with scala.collections. Find another altar. This is a complete non-issue for the day-to-day Scala developer.

Outside of some pretty extreme examples (scalaz maybe), I don't think I've actually ever seen someone else's source that implemented a custom collection.

And you're purposefully trying to confuse people by digging into what might as well be "internal" signatures.

What do the actual, official docs say about SeqLike :+ ?

  > def :+(elem: A): Seq[A]
  > [use case] A copy of this sequence with an element appended.
Oh wow. Why does that look so much simpler than what you posted? Could it be you're exaggerating for effect and disingenuously implying that Scala developers will be routinely faced with the challenge of trying to parse such signatures? Of course you are.

Can you dig down further and find the CBF signature? Yes. Do you need to for anything outside of spreading FUD? Nope. Is it a bad thing that it shows how the sausage is made underneath the covers? I don't think so.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @03:58PM (#8598114)
Personally, I view the collections library as a showcase for how that language works when you're designing an API to be used for 3rd parties. If it's incomprehensible, that worries me.

If the collections API is purposely trying to confuse people, blame the Scala team, not me.

Re:Microsoft takes .NET open source and cross-platform by ssmoot on Wednesday November 12, 2014 @04:25PM (#8598298)
That's just BS and given the size of your axe to grind, you have to know it.

Akka? Spray? ScalaUtils? Do they take effort to learn? Yes. Are they anything like scala.collections? No.

Why didn't you pick scala.concurrent? Or scala.util? Or any number of other packages? Why didn't you use the signatures in the official docs as-presented?

The Scala team goes out of their way to present something simple and easily digestible to most programmers, even the ones unfamiliar with Type Classes.

I mean, you basically just use a Seq like an immutable version of Ruby's Array and it just does what you want 99.999% of the time.

How often do you see people go on to propose that because much of Ruby's Array implementation would be incomprehensible to 90% of Ruby programmers that that makes Ruby a bad language? It's an entirely ridiculous metric.

Re:Microsoft takes .NET open source and cross-platform by jakevn on Wednesday November 12, 2014 @01:05PM (#8597058)
[SerializableAttribute] [ComVisibleAttribute(false)] public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializable, IDeserializationCallback

Both languages can be difficult to decipher. I do find that Scala's syntax is much more flexible, which can lead to more stumbling when trying to read code.

Re:Microsoft takes .NET open source and cross-platform by katbyte on Wednesday November 12, 2014 @04:22PM (#8598284)
Its not as hard when you format it a little nicer (and when you have syntax colouring)

[SerializableAttribute] [ComVisibleAttribute(false)] public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializable, IDeserializationCallback { ... }

And this is of course ignoring the fact you copied that from the documentation witch shows all interfaces the class implements. IDictionary also implements ICollection & IEnumerable so you wouldn't need to include them. So to actually implement this class it would more likely be

[SerializableAttribute] [ComVisibleAttribute(false)] public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback { ... }

maybe less

Re:Microsoft takes .NET open source and cross-platform by louthy on Wednesday November 12, 2014 @02:15PM (#8597519)
I'm a fan of C#, although I prefer F#; however I have to agree, I think the choice of < > for generic definitions was a real mistake, it can be so hard to parse. The side effect of this is that first-class functions (Func<>) are chronically underused by C# programmers.

Annoyingly F# brought them along for the ride too, although you rarely have to explicitly write them.

Re:Microsoft takes .NET open source and cross-platform by rjbwork on Thursday November 13, 2014 @01:35AM (#8600233)
What would you have used for generic arguments? I think they work fine, and make use of Func<T> often.
Re:Microsoft takes .NET open source and cross-platform by louthy on Thursday November 13, 2014 @09:50AM (#8601746)
I haven't tried out many alternatives, but there's something about nested <> that seems to throw me off each time.

I wrote a library of monads for C# [1], and implementing the SelectMany method is a good example of how messy it can be:

    public static RWS<R, W, S, V> SelectMany<R, W, S, T, U, V>( this RWS<R, W, S, T> self, Func<T, RWS<R, W, S, U>> bind, Func<T, U, V> project)
    {
    }
I quite like F#'s alternative syntax for single type generics:

    Option<int>
Can be written:

    int option
Obviously it's a personal thing, so I doubt I would be able to suggest anything that would change your mind; I just had a quick go at an alternative, and I quite like this:

    public static SelectMany R W S T U V ( this self : RWS R W S T, bind : Func T (RWS R W S U), project : Func T U V) : RWS R W S V
    {
    }

    class Thing int
    {
    }

    class Thing T : BaseThing T
    {
    }
It's moot anyway really, it is what it is. I've just found it cognitively challenging over the years.

[1] https://github.com/louthy/csharp-monad

Re:Microsoft takes .NET open source and cross-platform by hokkos on Wednesday November 12, 2014 @03:13PM (#8597841)
It is easier, there is only one concept to understand : generics, with scala you must understand generics, co and contra-variance, implicits.
Re:Microsoft takes .NET open source and cross-platform by jakevn on Wednesday November 12, 2014 @03:42PM (#8598013)
That's true.

A talented C# dev will need to know co/contravariance as well as implicits considering they also exist in C#.

In Scala, being familiar with these concepts is practically a necessity, though.

Re:Microsoft takes .NET open source and cross-platform by dragonwriter on Wednesday November 12, 2014 @06:04PM (#8598870)
> A talented C# dev will need to know co/contravariance as well as implicits considering they also exist in C#.

True for co/contravariance. For implicits, that depends on which implicits you are talking about.

Scala has:

* implicit conversion operators (these have existed in C# for some time, under the same name)

* implicit parameters (C# doesn't have an analog to these that I can think of)

* implicit classes (C# has an analog in classes providing extension methods, though the classes themselves are distinguished by a keywords as they are in Scala; in Scala, these are essentially syntactic sugar for creating a normal class and an implicit conversion from the extended class.)

Re:Microsoft takes .NET open source and cross-platform by jakevn on Wednesday November 12, 2014 @06:50PM (#8599090)
> implicit parameters (C# doesn't have an analog to these that I can think of)

C# allows default values for parameters, but it's not quite the same.

Example of C# default value for parameter:

  static void Addition(int a, int b = 42)  
  {  
    Console.WriteLine(a + b);  
  }

  Addition(4); // Prints 46  
  Addition(4, 5); // Prints 9
In Scala, the default (implicit) value has more complex rules.

Like C#, implicit parameters must come after non-implicit parameters (if any).

Unlike C#, the implicit value does not need to be defined in the signature. Also unlike C#, if you provide the value for one implicit parameter, you must provide the value for all implicit parameters.

Re:Microsoft takes .NET open source and cross-platform by dragonwriter on Wednesday November 12, 2014 @07:05PM (#8599152)
> C# allows default values for parameters, but it's not quite the same.

Right. Scala has C#-style default parameters as well, implicit parameters are a different (though very loosely related) thing.

Re:Microsoft takes .NET open source and cross-platform by hokkos on Wednesday November 12, 2014 @05:18PM (#8598642)
Can you give me examples of implicits in C# ? I am unable to see a parallel.
Re:Microsoft takes .NET open source and cross-platform by jakevn on Wednesday November 12, 2014 @05:53PM (#8598820)

  using System;
  
  public class Program
  {
  
  public class Person
  {
    private string _name;
    private int _age;
    
    public Person(string name, int age)
    {
      _name = name;
      _age = age;
    }
		
    public static implicit operator int(Person p)
    {
      return 42;
    }
  }
	
  public static void Main()
  {
    var person = new Person("Jim", 51);
    var number = 100;
    AdditionPrinter(person, number); // Prints 142
  }
	
  public static void AdditionPrinter(int a, int b)
  {
    Console.WriteLine(a + b);
  }
  
  }
Re:Microsoft takes .NET open source and cross-platform by seanmcdirmid on Wednesday November 12, 2014 @07:10PM (#8599171)
Also consider extension methods, which serve some of the same purpose as implicits in Scala.
Re:Microsoft takes .NET open source and cross-platform by ssmoot on Wednesday November 12, 2014 @04:06PM (#8598172)
Good point.

Though implicits I feel are so much simpler than many people fear.

From a Ruby perspective: Just think of them as operating similarly to Refinements, except not completely insane because there is no global scope at compilation. You only have to worry about your own package, imports and inheritance.

Tracking down an implicit generally takes all of 10 seconds, and never more than a few minutes. Even moderately brain-bendy ones like akka.patterns.ask (where does the implicit "?" come from? "ask" is actually an implicit conversion to a class that defines it: https://github.com/akka/akka/blob/master/akka-actor/src/main...).

Re:Microsoft takes .NET open source and cross-platform by EpicEng on Wednesday November 12, 2014 @02:58PM (#8597764)
Given proper indentation, ifall to see what is difficult to understand here. You have acouple of attributes, a generic you're declaration (with easy to understand syntax), and an inheritance list.
Re:Microsoft takes .NET open source and cross-platform by jakevn on Wednesday November 12, 2014 @03:43PM (#8598026)
That's how it goes.

A Scala dev will look at the Scala type signature and shrug.

A C# dev will look at the C# type signature and shrug.

As usual, unfamiliar things are difficult and familiar things are easy.

Re:Microsoft takes .NET open source and cross-platform by EpicEng on Friday November 14, 2014 @04:20PM (#8609568)
Yeah, and not knowing Scala myself, I can't say that the OP didn't purposely use a contrived example. That said, I still don't think a class definition which is little more than a bunch of interfaces being implemented is confusing to anyone who got through chapter 4 of "Learn C# in 21 days".
Re:Microsoft takes .NET open source and cross-platform by MrRadar on Wednesday November 12, 2014 @01:31PM (#8597256)
Thank you! I'm working on a team that inherited some Scala code from contractors that no longer work for us and we've found that (at least their) Scala is almost as hard to read as bad Perl. Compounding this is a severe lack of good online documentation outside of the standard library reference and simple tutorials which don't go into the depths we need to know (like how do you create a Manifest from Java to call into Scala code that needs it? Or what even is a Manifest?). At least with Perl you have decades worth of online discussions and pretty good documentation of the core language.
Re:Microsoft takes .NET open source and cross-platform by dragonwriter on Wednesday November 12, 2014 @05:51PM (#8598806)
> Thank you! I'm working on a team that inherited some Scala code from contractors that no longer work for us and we've found that (at least their) Scala is almost as hard to read as bad Perl.

I've seen C# that is almost as hard to read as bad Perl -- also, not surprisingly, from contractors who weren't going to be maintaining the code.

I don't think this says anything about C# or Scala, I think what it says is something about the natural result of the economic incentives of people being paid to throw code over the wall before they leave for greener pastures.

Re:Microsoft takes .NET open source and cross-platform by MrRadar on Wednesday November 12, 2014 @06:03PM (#8598865)
Yeah, I would agree with that. Scala is, at most, probably 2-3% responsible for the problems we're having with this project (due to inexperience with it). The vast majority of the blame rests on our contractors and on our management's lax oversight of them.
Re:Microsoft takes .NET open source and cross-platform by ssmoot on Wednesday November 12, 2014 @03:54PM (#8598076)
I think you just need to hire an experienced Scala Developer for a month or two until your team gets up to speed. It'd be like a c# team having a Ruby app dumped in their lap. You're practically preordained to hate it. ;-)

The documentation for Scala is actually pretty outstanding IMO. I had a much easier time compared to Ruby. Daniel Westheide's introduction series "The Neophyte's Guide to Scala" is the single best language intro I've ever seen, for any language. It even goes into enough of Akka to get a basic chat application going. And while Akka works nicely with Scala, it's conventions are so different it might as well be a different language. In idiomatic Scala you probably don't run into mapTo or vars too often for example, but that's going to be a pretty common sight working with Akka.

At least the documentation on PlayFramework.com is mostly current, and doesn't gloss over important detail. Unlike rubyonrails.org, where even five years ago the basics were horribly dated, inaccurate, and skip important background.

Re:Microsoft takes .NET open source and cross-platform by teacup50 on Wednesday November 12, 2014 @03:20PM (#8597873)
> we've found that (at least their) Scala is almost as hard to read as bad Perl. At least with Perl you have decades worth of online discussions and pretty good documentation of the core language.

Programming languages you don't know are harder to read than programming languages you do know.

Unlike "bad perl", you have types that tell you exactly what something does.

> ... and simple tutorials which don't go into the depths we need to know (like how do you create a Manifest from Java to call into Scala code that needs it?

Calling Scala from Java is not beginner level material that winds up in a tutorial, and it's a bad idea to begin with; you're stuck speaking a pidgin Scala using Java-only constructs just to maintain Java interop.

Re:Microsoft takes .NET open source and cross-platform by MrRadar on Wednesday November 12, 2014 @05:43PM (#8598760)
> Programming languages you don't know are harder to read than programming languages you do know.

I will definitely agree with you there. It would help our team significantly if we had a Scala expert we could consult but there's not enough in the budget (monetary or political) to hire one. We are pretty much left to fend for ourselves with Google, Stack Overflow and a couple reference books. This project also contains a C++ component that would probably have been just as impenetrable to my teammates (who have C but no C++ experience) if I hadn't already been fairly familiar with the language.

> Unlike "bad perl", you have types that tell you exactly what something does.

Static typing doesn't help always when you actively try to subvert it. There are casts to and from Any all over this codebase. Reflection is used everywhere even when it's not necessary. There are even places where they convert between types by serializing an instance of one type and deserializing it as an instance of another (with similar fields but not actually related in the type system). They also loved Option[] types which might not be so bad if they weren't also storing Some(null) into them in just enough places you forget to check for it but it still blows up in your face at least a once a month. Basically, the original authors of this code tried their best to destroy the usefulness of the Scala type system and succeeded fairly well.

> Calling Scala from Java is not beginner level material that winds up in a tutorial, and it's a bad idea to begin with; you're stuck speaking a pidgin Scala using Java-only constructs just to maintain Java interop.

By mandate of our management we are not allowed to write any new Scala code except where absolutely necessary. The contractors went behind our management's back to write it in the first place (we told them they could use Java 8 which they interpreted to mean they could use anything that would run on a Java 8 JVM). After that was found out (about a 1/3 of the way through the contract and too late to rewrite everything without blowing our contractual deadline with our customer) new Scala code was banned and they had to (and we have to) use Java as much as possible after that point. This is also not helped by the fact that at the time they handed the code over it was barely half-baked and performing at less than 25% of the needed throughput and we're left trying to finish and fix it.

Of course, when it can take three or four developers (with a combined background in Java, C#, C, C++, Python, Javascript, and an academic familiarity with OCaml-family functional languages) a half hour or more to figure out what a some of the methods in this codebase even do (at both a syntatic and conceptual level) I am going to put (a small) part of the blame on Scala for allowing such impenetrable code to be written in the first place. I'm certainly not placing all or even a significant amount of the blame for this project's problems on Scala but it is certainly not helping.

Thanks for letting me vent.

Re:Microsoft takes .NET open source and cross-platform by saosebastiao on Wednesday November 12, 2014 @01:03PM (#8597045)
You intentionally chose code that is hard to read...I could easily do the same with C#. It isn't representative of the vast majority of the code that I use nor write.

That being said, when you understand the nuances of type annotations, that code is quite readable in the mathematical notation sense. It is concise and takes more time per byte to understand, but it tells me enough about the code that I rarely have to read the actual implementation to know exactly what it does.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @01:13PM (#8597124)
It's from the standard collections library, the most-used code in any language.

It is in fact representative of the vast majority of code you use.

The fact that it wasn't immediately clear to you that a lot of your code DOES use this code is probably the strongest argument I could make.

Re:Microsoft takes .NET open source and cross-platform by com2kid on Wednesday November 12, 2014 @01:48PM (#8597371)
Now I love C#, but in defense of the above poster, standard library code is often pretty gnarly stuff.

C++ is the poster child for this. No one argues that C++ is a bad language just because the standard library is full of magic.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @02:11PM (#8597495)
Actually, I hold exactly that opinion about C++ :)
Re:Microsoft takes .NET open source and cross-platform by 72deluxe on Thursday November 13, 2014 @04:40AM (#8600681)
I find the STL great! Sure, some compiler template messages can be tricky to understand but STL doesn't detract from C++ - you don't have to use the STL (but you're probably losing out if you don't use it and roll all those containers and algorithms yourself)
Re:Microsoft takes .NET open source and cross-platform by com2kid on Thursday November 13, 2014 @01:19PM (#8603053)
Oh using the STL itself is fine, but some of the code behind it looks like a completely different language!
Re:Microsoft takes .NET open source and cross-platform by saosebastiao on Wednesday November 12, 2014 @01:44PM (#8597331)
You have inferred more about me than you are entitled, and even if you were right, your argument is still poor. Have you read the c# stdlib? It is in no way any better. Stdlibs are always more complex than the code that builds on them, and that is by design. The same code that I use for a oneliner has to be robust enough to apply to play, akka, spark, finagle, etc. That is the primary reason why StdLib documentation is made more accessible. I have never had to read the Scala StdLib source code, and likely a tiny minority of Scala devs have done so.
Re:Microsoft takes .NET open source and cross-platform by Alphasite_ on Wednesday November 12, 2014 @04:49PM (#8598442)
The internals of STDlibs tend to be nasty, but externally they're designed to be clear. The problem here is externally these interfaces are extremely messy and hard to follow, i.e. the abstraction doesn't seem to work.
Re:Microsoft takes .NET open source and cross-platform by hrjet on Wednesday November 12, 2014 @10:57PM (#8599827)
That is a good distinction to make. But then, you need to consider other factors as well. How powerful is the API, how honest is the API (doesn't hide internal gimmicks), how consistent is the API across the lib, and how DRY it is (to the STDlib implementors).

Scala's STDlib might be more powerful, more honest and more consistent, and also might be striving to be DRY for the implementors.

Personally, I feel that Scala's Collections goes overboard in hitting the above goals, and the resulting signatures are too verbose. And this increases the cognitive load for the subset of people that need to bother about it (performance tuners, architects, etc). But that's not a fault of the language per se.

Re:Microsoft takes .NET open source and cross-platform by jbooth on Wednesday November 12, 2014 @02:14PM (#8597516)
I inferred that you probably use standard library collections. Not really an insulting inference, it'd be insulting to assume you didn't.

Personally, I make it a habit to always read (or try to read, in this case) standard library source code that I'm depending on to be correct.

Re:Microsoft takes .NET open source and cross-platform by ezy on Thursday November 13, 2014 @02:29AM (#8600358)
Have you read the implementation of the python collection types (list, map, etc.)?
Re:Microsoft takes .NET open source and cross-platform by hokkos on Wednesday November 12, 2014 @03:13PM (#8597846)
It is not representative probably because the IDE hide the ugliness.
Re:Microsoft takes .NET open source and cross-platform by ssmoot on Wednesday November 12, 2014 @04:14PM (#8598216)
The official docs do to.

To get the "ugly" signature you have to look at the actual source, or example the method definition in the official docs.

They go out of their way to make sure to present an easy-to-understand version for actual users.

Which is why every actual Scala developer rolls their eyes at someone bringing up CBF. You have to go out of your way to try to be confused about it. And if that digging stops at finding the method signature, well, probably serves you right for being confused. ;-)

Is CBF amazing? Probably not. Is it some sort of confusing eternal battle for most Scala developers? Absolutely not.

I mean just look at the official docs, find out where he got these weird examples from, and then tell me this is a well reasoned argument.

Re:Microsoft takes .NET open source and cross-platform by vithlani on Wednesday November 12, 2014 @08:56PM (#8599533)
LOL! amen brother, tell it like it is.... people seem to have NO appreciation for the idea of simplicity.
Re:Microsoft takes .NET open source and cross-platform by Vektorweg on Wednesday November 12, 2014 @12:41PM (#8596880)
Actually, the vast amount of features in C# isn't improving readability. But MS can't just throw out the bad half of features, which makes C# practically unimprovable. Scala has a similar problem.
Re:Microsoft takes .NET open source and cross-platform by alkonaut on Wednesday November 12, 2014 @04:14PM (#8598220)
Why not? I just can't see why every language needs to gather cruft rather than evolve elegantly. Imho major versions of compilers should aim to NOT remain backwards compatible, so they can remove or change things in the syntax while they add things.
Re:Microsoft takes .NET open source and cross-platform by marvy on Wednesday November 12, 2014 @10:40PM (#8599783)
Imagine this. I'm using Cool-Lang version 2. Now Cool-Lang 3 comes out. It has lots of features that I want to use. If the new version is compatible with the old one, I download it and start using it. If not, I have to convert my whole codebase first. In practice, that means it may be many years before I can use version 3. Look at Python. In 3.0, they decided to clean up some stuff from 2.x. They even wrote a tool 2to3 which will automatically fix most of the incompatible stuff for you, so converting the whole codebase is almost automatic. The problem is "almost" automatic is not enough. Many people and groups have yet to convert their old code.
Re:Microsoft takes .NET open source and cross-platform by alkonaut on Thursday November 13, 2014 @01:21AM (#8600204)
Py2 to py3 is too far a jump which is made obvious from the fork-like nature of the project. Minor changes like API deprecation is of course already taking place in most projects. Just need to strike a balance.

I rewrote 100klines at least from C#1 to C#2 when generics came in 2.0. It was compatible in that the non generic code still worked, but I don't really see what difference that made. If we didn't want to upgrade the cod me then we wouldn't have updated the compiler!

Obviously if you don't want the benefits of Py3 then you don't have to pay the upgrade cost either.

Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Wednesday November 12, 2014 @05:37PM (#8598737)
> But MS can't just throw out the bad half of features, which makes C# practically unimprovable. Scala has a similar problem.

How? Scala has been throwing out bad features in pretty much every single release for the last 5 years.

It's nothing breathtaking, it just gets done, people are happier and the language gets better.

Re:Microsoft takes .NET open source and cross-platform by pjmlp on Thursday November 13, 2014 @04:08AM (#8600597)
Scala has hardly the user base of C# developers.
Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Thursday November 13, 2014 @09:30AM (#8601647)
So how has Scala "a similar problem"?

Plus, for this question, the size of the user base doesn't matter: If a developer has to adapt his code to a new language version, he/she doesn't care whether ten or ten-thousand other people have to do the same.

Re:Microsoft takes .NET open source and cross-platform by pjmlp on Thursday November 13, 2014 @10:02AM (#8601809)
It matters for the language designers, how much people they want to make angry for breaking their code.

Scala's smaller user base means there are a lot of less people to get mad.

Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Thursday November 13, 2014 @10:31AM (#8601979)
And you still haven't explained how Scala has a similar problem.
Re:Microsoft takes .NET open source and cross-platform by pjmlp on Thursday November 13, 2014 @11:54AM (#8602518)
I am not the OP. Just commenting on this

> Scala has been throwing out bad features in pretty much every single release for the last 5 years.

You cannot throw out features in a language with the community size C# has, otherwise you just get another Python 3.0.

Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Thursday November 13, 2014 @01:37PM (#8603179)
I'm not sure comparing C# to Python makes sense.

  a) Microsoft is in an excellent position to make such 
     changes, unlike Python, because Microsoft shops will 
     largely do whatever Microsoft tells them.

     Just have a look at how often they have incompatibly 
     changed the standard library used by C#.

  b) Not every language has to botch the transition as badly
     as Python designers did.
Re:Microsoft takes .NET open source and cross-platform by Vektorweg on Friday November 14, 2014 @12:46AM (#8605960)
Scala keeps features for imperative and functional programming, which is one category too many, because they solve the same problem just different. Thats how Scala is supposed to work. Its impossible to remove an approach.
Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Friday November 14, 2014 @07:51AM (#8606870)
That's not even remotely related to the topic, isn't it?
Re:Microsoft takes .NET open source and cross-platform by Vektorweg on Friday November 14, 2014 @09:08AM (#8607140)
Theoretically, everything is related to each other. Practically, no.
Re:Microsoft takes .NET open source and cross-platform by moonchrome on Wednesday November 12, 2014 @12:07PM (#8596652)
F# is more of a .NET analogue to Scala.
Re:Microsoft takes .NET open source and cross-platform by edgyswingset on Wednesday November 12, 2014 @12:10PM (#8596667)
I'd say it's the .NET analogue to Scala with added elegance.
Re:Microsoft takes .NET open source and cross-platform by karavelov on Wednesday November 12, 2014 @01:08PM (#8597087)
And removed flexibility that make it awkward - see for example the lack of higher kinds
Re:Microsoft takes .NET open source and cross-platform by addicted44 on Thursday November 13, 2014 @12:16AM (#8600057)
Why would you compare C# (although they keep adding functional programming concepts to it) to Scala, instead of comparing F# (which can commingle with C# wherever you need it) with Scala?

I haven't looked into F# or Scala too much, but I bet F# comes out looking far better, because it was so deeply inspired by Haskell (but made practical).

Re:Microsoft takes .NET open source and cross-platform by frowaway001 on Thursday November 13, 2014 @09:35AM (#8601667)
> I bet F# comes out looking far better, because it was so deeply inspired by Haskell (but made practical)

Eh what? Scala is a lot closer to Haskell than F#/OCaml, and can express roughly the same things, while F# is a lot less expressive.

Re:Microsoft takes .NET open source and cross-platform by nathas on Wednesday November 12, 2014 @12:05PM (#8596634)
Can you explain why you think so?
Re:Microsoft takes .NET open source and cross-platform by lmm on Wednesday November 12, 2014 @12:28PM (#8596797)
Most of the selling points on scala-lang.org still apply over C# - type inference, pattern matching, case classes (C# makes these less bad than Java, but the field/property distinction can still bite you), an inheritance model that supports the good parts of multiple inheritance without the problems, covariance/contravariance, for/yield syntax that's generic and user-controlled, higher-kinded types.

It takes a while for your code to get big enough for the last part to matter, but it's huge when it does - you can handle any kind of "context" in a generic way, e.g. async calls, error handling, audit logging, software transactional memory, or custom things for e.g. database access. F# has a number of these specific implementations but they're kind of "hard-coded" in the language rather than fully extensible. So I guess the pitch is: imagine C# async/await could be "just a library", and other contexts that you wanted to handle similarly could also be a library, and the resulting functions are first-class citizens in the type system (no awkward choices of whether a particular function is async or not, you can handle that generically).

Re:Microsoft takes .NET open source and cross-platform by Locke1689 on Wednesday November 12, 2014 @12:45PM (#8596912)
So I guess the pitch is: imagine C# async/await could be "just a library", and other contexts that you wanted to handle similarly could also be a library, and the resulting functions are first-class citizens in the type system (no awkward choices of whether a particular function is async or not, you can handle that generically).

That's true in F# -- async is just a library in a computation expression.

Re:Microsoft takes .NET open source and cross-platform by yohanatan on Wednesday November 12, 2014 @03:13PM (#8597844)
> F# has a number of these specific implementations but they're kind of "hard-coded" in the language rather than fully extensible.

That's not true. You can extend the language yourself with "computation expressions" (and that's in fact how the 'async', 'let!' et al keywords are implemented).

Re:Microsoft takes .NET open source and cross-platform by lmm on Thursday November 13, 2014 @04:42AM (#8600696)
True, but what you can't do is abstract over them; you can't write a function that operates on "some generic computation expression" (you can't even write that type). So you can't write "sequence" or "traverseM" or more complicated/specific things you build on top of these.
Re:Microsoft takes .NET open source and cross-platform by yohanatan on Thursday November 13, 2014 @05:33PM (#8604606)
There is an encoding supporting that level of abstraction (perhaps though not as straightforward as you'd prefer); namely using interfaces (which are first-class) to encode module signatures. See: https://gist.github.com/t0yv0/192353
Re:Microsoft takes .NET open source and cross-platform by pjmlp on Thursday November 13, 2014 @03:56AM (#8600567)
> C# as a language is better than Java, but not as good as Scala.

However Scala is not a first class citzen in the JVM, but C# is the systems language of the CLR, already a huge difference.

Re:Microsoft takes .NET open source and cross-platform by joslin01 on Wednesday November 12, 2014 @12:15PM (#8596715)
+1 as a Scala fanatic :) It's all about what works for you though.
Re:Microsoft takes .NET open source and cross-platform by garrettheaver on Wednesday November 12, 2014 @12:13PM (#8596695)
As someone who has written applications in C#, Java and Scala (amongst others). I'd be curious as what makes you think Scala is a winner relative to C#?
Re:Microsoft takes .NET open source and cross-platform by eloisant on Wednesday November 12, 2014 @02:26PM (#8597583)
One big thing: Immutability by default. That's possible in C#, but it's hard to be sure everything is immutable => http://stackoverflow.com/questions/5097287/how-to-create-imm...

A lot of interesting aspects of Scala are possible only because of immutability.

And a lot of smaller things: * Typeclasses. In Scala you can implement them with implicit parameters, I have no idea how you would do it * Case classes. Again in C# you can implement something that kinda looks one with readonly and just a getter, but it's not as good as you won't get stuff like equality and copy, you'll have to write the boilerplate * Pattern matching, in particular with case classes * Option. You can create your own, or use the Option from FSharp, but all the lib you will use will be returning null all the time. * And more...

Additionally there are aspects that are more of a personal preference, like how the "map" function is called "Select" and "filter" is called "Where", and so on. All functional languages use the same names, the SQL-like naming for manipulating collections is just confusing for me.

At the end of the day, Microsoft tried to build a better Java when they designed C#. And it is indeed better than Java, especially because they moved fast in their versions while Sun/Oracle was terribly slow (why did we have to wait that much for lambdas??). But C# mostly sticks with the same concepts as Java (OOP) while Scala truly embraces both FP and OOP.

Re:Microsoft takes .NET open source and cross-platform by asdf1234 on Wednesday November 12, 2014 @01:12PM (#8597116)
I'd happily switch from Scala to F# but I would miss higher kinds and using implicits for typeclasses.
Re:Microsoft takes .NET open source and cross-platform by sixothree on Wednesday November 12, 2014 @04:20PM (#8598270)
Doesn't Scala run on the JVM, and isn't this announcement about porting the .Net runtime? And you're really drawing this comparison?
Re:Microsoft takes .NET open source and cross-platform by HeavyStorm on Wednesday November 12, 2014 @12:13PM (#8596690)
Apples and Oranges, my friend.